Beispiel #1
0
        private (ConnectionLoop, SocketDescriptor) CreateConnection(IDuplexPipe pipe)
        {
            var(socketDescriptor, writeReceiver) = _socketDescriptorFactory.GetNewSocket(pipe.Output);
            var conn = new ConnectionLoop(pipe, socketDescriptor, PeerManager, writeReceiver, EventNotify.Writer);

            return(conn, socketDescriptor);
        }
Beispiel #2
0
        public void PeerManagerTestsSimple()
        {
            var socketFactory = new SocketDescriptorFactory();

            using var peerMan = getTestPeerManager();
            var socket1 = socketFactory.GetNewSocket();

            peerMan.NewInboundConnection(socket1);
            var socket2      = socketFactory.GetNewSocket();
            var theirNodeId  = _pubKeys[1];
            var theirNodeIds = peerMan.GetPeerNodeIds(_pool);

            Assert.Empty(theirNodeIds);
            var actOne = peerMan.NewOutboundConnection(socket2, theirNodeId.ToBytes());

            Assert.Equal(50, actOne.Length);
            // Console.WriteLine($"actOne in C# is {Hex.EncodeData(actOne)}");

            theirNodeIds = peerMan.GetPeerNodeIds(_pool);
            // It does not count when handshake is not complete
            Assert.Empty(theirNodeIds);
            peerMan.Dispose();
        }