Example #1
0
        private void HubConnectionRequest(object sender, IncomingConnectionRequestEventArgs e)
        {
            // we have a request from a passive user, we need to be active to connect to him
            if (Settings.ActiveMode)
            {
                var hubConnection = (HubConnection)sender;

                var ea = new ConnectionRequestEventArgs
                {
                    UserNickname  = e.Message.SenderNickname,
                    HubConnection = hubConnection
                };

                OnConnectionRequest(ea);

                if (ea.Cancel)
                {
                    return;
                }

                if (TransferManager.HaveRequest(e.Message.SenderNickname, sender as HubConnection))
                {
                    return;
                }

                // we need to set LocalAddress to allow connection
                e.LocalAddress = LocalTcpAddress;
                TransferManager.AllowConnection(e.Message.SenderNickname, sender as HubConnection);
            }
        }
Example #2
0
        private void HubOutgoingConnectionRequest(object sender, OutgoingConnectionRequestEventArgs e)
        {
            var hubConnection = (HubConnection)sender;

            var ea = new ConnectionRequestEventArgs
            {
                UserNickname  = "",
                Address       = e.Message.SenderAddress,
                HubConnection = hubConnection
            };

            OnConnectionRequest(ea);

            if (ea.Cancel)
            {
                return;
            }

            TransferConnection transfer;

            try
            {
                transfer = new TransferConnection(e.Message.SenderAddress)
                {
                    AllowedToConnect = true,
                    Source           = new Source {
                        HubAddress = hubConnection.RemoteAddressString
                    }
                };

                if (Settings.NetworkInterface != null)
                {
                    transfer.LocalAddress = new IPEndPoint(Settings.NetworkInterface, 0);
                }
            }
            catch (Exception x)
            {
                Logger.Error("Unable to create outgoing transfer thread {0}", x.Message);
                return;
            }

            TransferManager.AddTransfer(transfer);
            transfer.FirstMessages = new[]
            {
                new MyNickMessage {
                    Nickname = hubConnection.Settings.Nickname
                }.Raw,
                new LockMessage {
                    ExtendedProtocol = true
                }.Raw
            };
            transfer.StartAsync();
        }
Example #3
0
 public void OnConnectionRequest(ConnectionRequestEventArgs e)
 {
     ConnectionRequest?.Invoke(this, e);
 }