public void Add(TorrentManager manager, IConnection connection)
 {
     System.Net.BitTorrent.Client.Peer p = new System.Net.BitTorrent.Client.Peer("", new Uri("tcp://12.123.123.1:2342"), EncryptionTypes.All);
     base.RaiseConnectionReceived(p, connection, manager);
 }
示例#2
0
 /// <summary>
 /// Creates a new PeersAddedEventArgs
 /// </summary>
 /// <param name="peersAdded">The number of peers just added</param>
 public PeerAddedEventArgs(TorrentManager manager, Peer peerAdded)
     : base(manager)
 {
     this.peer = peerAdded;
 }
 public AttemptConnectionEventArgs(Peer peer)
 {
     this.peer = peer;
 }
        private void EndAccept(IAsyncResult result)
#endif
        {
            Socket peerSocket = null;

            try
            {
#if NETSTANDARD1_5
                Socket listener = listenerSocket; //(Socket)result.AsyncState;
                peerSocket = result;              //listener.EndAccept(result);
#else
                Socket listener = (Socket)result.AsyncState;
                peerSocket = listener.EndAccept(result);
#endif

                IPEndPoint  endpoint   = (IPEndPoint)peerSocket.RemoteEndPoint;
                Uri         uri        = new Uri("tcp://" + endpoint.Address.ToString() + ':' + endpoint.Port);
                Peer        peer       = new Peer("", uri, EncryptionTypes.All);
                IConnection connection = null;
                if (peerSocket.AddressFamily == AddressFamily.InterNetwork)
                {
                    connection = new IPV4Connection(peerSocket, true);
                }
                else
                {
                    connection = new IPV6Connection(peerSocket, true);
                }


                RaiseConnectionReceived(peer, connection, null);
            }
            catch (SocketException)
            {
                // Just dump the connection
                if (peerSocket != null)
#if NETSTANDARD1_5
                { peerSocket.Dispose(); }
#else
                { peerSocket.Close(); }
#endif
            }
            catch (ObjectDisposedException)
            {
                // We've stopped listening
            }
            finally
            {
                try
                {
                    if (Status == ListenerStatus.Listening)
                    {
#if NETSTANDARD1_5
                        var r = await listener.AcceptAsync();

                        EndAccept(r, listener);
#else
                        listener.BeginAccept(endAcceptCallback, listener);
#endif
                    }
                }
                catch (ObjectDisposedException)
                {
                }
            }
        }