Example #1
0
        private static void Session2OnIncomingConnection(II2PSession sender, AcceptConnectionEventArgs e)
        {
            var reader = new BinaryReader(e.Client.GetStream());

            while (true)
            {
                Console.WriteLine(">> Received: " + reader.ReadString());
            }
        }
Example #2
0
        private void AcceptConnection(AcceptConnectionEventArgs e)
        {
            var applicationProtocol = peerInitiator.PrepareAcceptIncomingConnection(e.TransportStream, out BitTorrentPeerInitiator.IContext context);

            applicationProtocol.AcceptConnection(new AcceptPeerConnectionEventArgs <PeerConnection>(e.TransportStream, () =>
            {
                e.Accept();
                var c = new PeerConnectionArgs(LocalPeerId, applicationProtocol.Metainfo, new QueueingMessageHandler(mainLoop, applicationProtocol));
                return(peerInitiator.AcceptIncomingConnection(e.TransportStream, context, c));
            }));
        }
        void AcceptConnection(TransportConnectionEventArgs e)
        {
            var stream = new TcpTransportStream(e.Client);

            // Notify application protocol
            bool accepted      = false;
            var  applicationEE = new AcceptConnectionEventArgs(stream, () =>
            {
                _logger.LogInformation($"Accepted connection from {stream.RemoteEndPoint}");

                accepted = true;
                _streams.Add(stream);
            });

            AcceptConnectionHandler?.Invoke(applicationEE);

            if (!accepted)
            {
                e.Client.Dispose();
            }
        }
        public void AcceptIncomingConnection(AcceptConnectionEventArgs e)
        {
            var reader = new BigEndianBinaryReader(e.TransportStream.Stream);
            var header = ReadConnectionHeader(reader);

            // TODO: check if exists
            var applicationProtocol = _applicationProtocolLookup[header.InfoHash];

            applicationProtocol.AcceptConnection(new AcceptPeerConnectionEventArgs(e.TransportStream, () =>
            {
                e.Accept();

                var writer = new BigEndianBinaryWriter(e.TransportStream.Stream);
                WriteConnectionHeader(writer, applicationProtocol.Metainfo.InfoHash, _localPeerId);

                return(new BitTorrentPeer(
                           applicationProtocol.Metainfo,
                           header.PeerId,
                           header.ReservedBytes,
                           header.SupportedExtensions,
                           new QueueingMessageHandler(_mainLoop, (BitTorrentApplicationProtocol)applicationProtocol),
                           e.TransportStream));
            }));
        }