Esempio n. 1
0
        private void ConnectionListInformationFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
        {
            ITransport transport = (ITransport)model.GetValue(iter, 0);

            if (transport.Operation is LocalNodeConnection)
            {
                LocalNodeConnection connection = (LocalNodeConnection)transport.Operation;
                if (connection.NodeRemote != null)
                {
                    (cell as CellRendererText).Text = String.Format("{0} on {1}, {2}, {3} ms",
                                                                    connection.NodeRemote.NickName,
                                                                    transport.Network.NetworkName,
                                                                    connection.ConnectionState.ToString(),
                                                                    connection.Latency.ToString());
                }
                else
                {
                    (cell as CellRendererText).Text = String.Empty;
                }
            }
            else if (transport.Operation is FileTransferOperation)
            {
                FileTransferOperation operation = (FileTransferOperation)transport.Operation;
                (cell as CellRendererText).Text = String.Format("{0} on {1}", operation.Peer.Node.NickName, operation.Transfer.File.Name);
            }
            else
            {
                (cell as CellRendererText).Text = String.Empty;
            }

            SetConnectionListCellBackground((CellRendererText)cell, transport);
        }
Esempio n. 2
0
 private void network_NewConnection(Network network, LocalNodeConnection connection)
 {
     try {
         connection.ConnectionError += connection_ConnectionError;
     } catch (Exception ex) {
         LoggingService.LogError("Error in network_NewConnection: " + ex);
     }
 }
Esempio n. 3
0
 private void Connection_PongReceived(LocalNodeConnection c)
 {
     try {
         UpdateConnectionList();
     } catch (Exception ex) {
         LoggingService.LogError(ex);
         Gui.ShowErrorDialog(ex.ToString(), Gui.MainWindow.Window);
     }
 }
Esempio n. 4
0
 private void network_NewIncomingConnection(Network network, LocalNodeConnection c)
 {
     try {
         AddConnectionEventHandlers(c);
     } catch (Exception ex) {
         LoggingService.LogError(ex);
         Gui.ShowErrorDialog(ex.ToString(), Gui.MainWindow.Window);
     }
 }
Esempio n. 5
0
 private void AddConnectionEventHandlers(LocalNodeConnection c)
 {
     c.ConnectionConnected   += (LocalNodeConnectionEventHandler)DispatchService.GuiDispatch(new LocalNodeConnectionEventHandler(ConnectionConnected));
     c.ConnectionClosed      += (LocalNodeConnectionEventHandler)DispatchService.GuiDispatch(new LocalNodeConnectionEventHandler(ConnectionClosed));
     c.PongReceived          += (LocalNodeConnectionEventHandler)DispatchService.GuiDispatch(new LocalNodeConnectionEventHandler(Connection_PongReceived));
     c.ConnectionReady       += (LocalNodeConnectionEventHandler)DispatchService.GuiDispatch(new LocalNodeConnectionEventHandler(ConnectionReady));
     c.ConnectionInfoChanged += (LocalNodeConnectionEventHandler)DispatchService.GuiDispatch(new LocalNodeConnectionEventHandler(ConnectionInfoChanged));
     c.ConnectionError       += (LocalNodeConnectionErrorEventHandler)DispatchService.GuiDispatch(new LocalNodeConnectionErrorEventHandler(LocalConnectionError));
 }
Esempio n. 6
0
        private void LocalConnectionError(LocalNodeConnection c, Exception error)
        {
            try {
                // TODO: !!!!
                //(c.Properties ["ListItem"] as ConnectionListItem).ErrorText = ex.Message;

                UpdateConnectionList();
            } catch (Exception ex) {
                LoggingService.LogError(ex);
                Gui.ShowErrorDialog(ex.ToString(), Gui.MainWindow.Window);
            }
        }
Esempio n. 7
0
 private void connection_ConnectionError(LocalNodeConnection connection, Exception ex)
 {
     LoggingService.LogError("Error in connection {0}: {1}", connection.RemoteAddress, ex);
 }
Esempio n. 8
0
        internal void Add(ITransport transport, TransportCallback connectCallback)
        {
            try {
                // XXX: This should be negotiated as part of the initial handshake.
                transport.Encryptor = new AESTransportEncryptor();

                transports.Add(transport);

                if (NewTransportAdded != null)
                {
                    NewTransportAdded(transport);
                }

                LoggingService.LogInfo($"Transport {transport} added");

                if (transport.Incoming)
                {
                    if (connectCallback != null)
                    {
                        throw new ArgumentException("You can only specify a ConnectCallback for outoging connections!");
                    }

                    if (transport.Encryptor != null)
                    {
                        var dh = new DiffieHellmanManaged();

                        var keyxBytes = new byte[transport.Encryptor.KeyExchangeLength];
                        transport.Receive(keyxBytes, 0, keyxBytes.Length);
                        keyxBytes = dh.DecryptKeyExchange(keyxBytes);

                        var keyBytes = new byte[transport.Encryptor.KeySize];
                        var ivBytes  = new byte[transport.Encryptor.IvSize];
                        Array.Copy(keyxBytes, 0, keyBytes, 0, keyBytes.Length);
                        Array.Copy(keyxBytes, keyBytes.Length, ivBytes, 0, ivBytes.Length);

                        keyxBytes = dh.CreateKeyExchange();
                        transport.Send(keyxBytes, 0, keyxBytes.Length);

                        transport.Encryptor.SetKey(keyBytes, ivBytes);
                    }

                    //Receive connection type, which is a ulong (8 bytes)
                    var responseBuffer = new byte[8];
                    transport.Receive(responseBuffer, 0, 8);
                    var connectionType = EndianBitConverter.ToUInt64(responseBuffer, 0);

                    // Recieve network ID (64 bytes)
                    responseBuffer = new byte[64];
                    transport.Receive(responseBuffer, 0, 64);
                    var networkId = EndianBitConverter.ToString(responseBuffer).Replace("-", "");

                    // Match to one of our known networks!
                    foreach (var network in core.Networks)
                    {
                        if (network.NetworkID == networkId)
                        {
                            transport.Network = network;
                        }
                    }

                    if (transport.Network == null)
                    {
                        throw new Exception($"Unknown network: {networkId}.");
                    }

                    transport.ConnectionType = connectionType;

                    if (connectionType == ConnectionType.NodeConnection)
                    {
                        var connection = new LocalNodeConnection(transport);
                        transport.Operation = connection;
                        transport.Network.AddConnection(connection);
                        connection.Start();
                    }
                    else if (connectionType == ConnectionType.TransferConnection)
                    {
                        core.FileTransferManager.NewIncomingConnection(transport);
                    }
                    else
                    {
                        throw new Exception($"Unknown connection type: {connectionType}.");
                    }
                }
                else
                {
                    if (connectCallback == null)
                    {
                        throw new ArgumentNullException(nameof(connectCallback));
                    }

                    connectCallbacks.Add(transport, connectCallback);

                    LoggingService.LogInfo("Transport {0} connecting...", transport);

                    TransportCallback callback = OnConnected;
                    transport.Connect(callback);
                }
            } catch (Exception ex) {
                transport.Disconnect(ex);
                RaiseTransportError(transport, ex);
            }
        }
Esempio n. 9
0
        public void Add(ITransport transport, TransportCallback connectCallback)
        {
            try {
                // XXX: This should be negotiated as part of the initial handshake.
                transport.Encryptor = new AESTransportEncryptor();

                transports.Add(transport);

                NewTransportAdded?.Invoke(this, new TransportEventArgs(transport));

                this.loggingService.LogInfo(String.Format("Transport {0} added", transport.ToString()));

                if (transport.Incoming == true)
                {
                    if (connectCallback != null)
                    {
                        throw new ArgumentException("You can only specify a ConnectCallback for outoging connections!");
                    }

                    if (transport.Encryptor != null)
                    {
                        DiffieHellmanManaged dh = new DiffieHellmanManaged();

                        byte[] keyxBytes = new byte[transport.Encryptor.KeyExchangeLength];
                        transport.Receive(keyxBytes, 0, keyxBytes.Length);
                        keyxBytes = dh.DecryptKeyExchange(keyxBytes);

                        byte[] keyBytes = new byte[transport.Encryptor.KeySize];
                        byte[] ivBytes  = new byte[transport.Encryptor.IvSize];
                        Array.Copy(keyxBytes, 0, keyBytes, 0, keyBytes.Length);
                        Array.Copy(keyxBytes, keyBytes.Length, ivBytes, 0, ivBytes.Length);

                        keyxBytes = dh.CreateKeyExchange();
                        transport.Send(keyxBytes, 0, keyxBytes.Length);

                        transport.Encryptor.SetKey(keyBytes, ivBytes);
                    }

                    //Receive connection type, which is a ulong (8 bytes)
                    byte[] responseBuffer = new byte[8];
                    transport.Receive(responseBuffer, 0, 8);
                    ulong connectionType = EndianBitConverter.ToUInt64(responseBuffer, 0);

                    // Recieve network ID (64 bytes)
                    responseBuffer = new byte[64];
                    transport.Receive(responseBuffer, 0, 64);
                    string networkId = EndianBitConverter.ToString(responseBuffer).Replace("-", "");

                    // Match to one of our known networks!
                    foreach (Network network in Core.Networks)
                    {
                        if (network.NetworkID == networkId)
                        {
                            transport.Network = network;
                        }
                    }

                    if (transport.Network == null)
                    {
                        throw new Exception(String.Format("Unknown network: {0}.", networkId));
                    }

                    transport.ConnectionType = connectionType;

                    if (connectionType == ConnectionType.NodeConnection)
                    {
                        LocalNodeConnection connection = new LocalNodeConnection(transport);
                        transport.Operation = connection;
                        transport.Network.AddConnection(connection);
                        connection.Start();
                    }
                    else if (connectionType == ConnectionType.TransferConnection)
                    {
                        this.fileTransferManager.HandleIncomingTransport(transport);
                    }
                    else
                    {
                        throw new Exception(String.Format("Unknown connection type: {0}.",
                                                          connectionType.ToString()));
                    }
                }
                else
                {
                    if (connectCallback == null)
                    {
                        throw new ArgumentNullException("connectCallback");
                    }

                    connectCallbacks.Add(transport, connectCallback);

                    this.loggingService.LogInfo("Transport {0} connecting...", transport);

                    TransportCallback callback = new TransportCallback(OnConnected);
                    transport.Connect(callback);
                }
            } catch (Exception ex) {
                transport.Disconnect(ex);
                RaiseTransportError(transport, ex);
            }
        }
Esempio n. 10
0
        internal void Add(ITransport transport, TransportCallback connectCallback)
        {
            try {
                // XXX: This should be negotiated as part of the initial handshake.
                transport.Encryptor = new AESTransportEncryptor();

                transports.Add (transport);

                if (NewTransportAdded != null)
                    NewTransportAdded (transport);

                LoggingService.LogInfo(String.Format ("Transport {0} added", transport.ToString()));

                if (transport.Incoming == true) {
                    if (connectCallback != null)
                        throw new ArgumentException ("You can only specify a ConnectCallback for outoging connections!");

                    if (transport.Encryptor != null) {
                        DiffieHellmanManaged dh = new DiffieHellmanManaged ();

                        byte[] keyxBytes = new byte[transport.Encryptor.KeyExchangeLength];
                        transport.Receive (keyxBytes, 0, keyxBytes.Length);
                        keyxBytes = dh.DecryptKeyExchange (keyxBytes);

                        byte[] keyBytes = new byte[transport.Encryptor.KeySize];
                        byte[] ivBytes = new byte[transport.Encryptor.IvSize];
                        Array.Copy (keyxBytes, 0, keyBytes, 0, keyBytes.Length);
                        Array.Copy (keyxBytes, keyBytes.Length, ivBytes, 0, ivBytes.Length);

                        keyxBytes = dh.CreateKeyExchange ();
                        transport.Send (keyxBytes, 0, keyxBytes.Length);

                        transport.Encryptor.SetKey(keyBytes, ivBytes);
                    }

                    //Receive connection type, which is a ulong (8 bytes)
                    byte[] responseBuffer = new byte[8];
                        transport.Receive (responseBuffer, 0, 8);
                    ulong connectionType = EndianBitConverter.ToUInt64 (responseBuffer, 0);

                    // Recieve network ID (64 bytes)
                    responseBuffer = new byte[64];
                    transport.Receive (responseBuffer, 0, 64);
                    string networkId = EndianBitConverter.ToString (responseBuffer).Replace ("-", "");

                    // Match to one of our known networks!
                    foreach (Network network in Core.Networks) {
                        if (network.NetworkID == networkId) {
                            transport.Network = network;
                        }
                    }

                    if (transport.Network == null) {
                        throw new Exception (String.Format ("Unknown network: {0}.", networkId));
                    }

                    transport.ConnectionType = connectionType;

                    if (connectionType == ConnectionType.NodeConnection) {
                        LocalNodeConnection connection = new LocalNodeConnection(transport);
                        transport.Operation = connection;
                        transport.Network.AddConnection(connection);
                        connection.Start();
                    } else if (connectionType == ConnectionType.TransferConnection) {

                        Core.FileTransferManager.NewIncomingConnection(transport);

                    } else {
                        throw new Exception(String.Format("Unknown connection type: {0}.",
                                                          connectionType.ToString()));
                    }

                } else {
                    if (connectCallback == null) {
                        throw new ArgumentNullException("connectCallback");
                    }

                    connectCallbacks.Add (transport, connectCallback);

                    LoggingService.LogInfo("Transport {0} connecting...", transport);

                    TransportCallback callback = new TransportCallback (OnConnected);
                    transport.Connect (callback);
                }
            } catch (Exception ex) {
                transport.Disconnect (ex);
                RaiseTransportError(transport, ex);
            }
        }
Esempio n. 11
0
 private void ConnectionReady(LocalNodeConnection sender)
 {
     UpdateConnectionList();
 }
Esempio n. 12
0
 private void network_ConnectingTo(Network network, LocalNodeConnection connection)
 {
     AddConnectionEventHandlers(connection);
 }
Esempio n. 13
0
 private void ConnectionInfoChanged(LocalNodeConnection connection)
 {
     UpdateConnectionList();
 }
Esempio n. 14
0
 private void network_NewConnection(Network network, LocalNodeConnection connection)
 {
     try {
         connection.ConnectionError += connection_ConnectionError;
     } catch (Exception ex) {
         LoggingService.LogError("Error in network_NewConnection: " + ex);
     }
 }
Esempio n. 15
0
 private void connection_ConnectionError(LocalNodeConnection connection, Exception ex)
 {
     LoggingService.LogError("Error in connection {0}: {1}", connection.RemoteAddress, ex);
 }