Beispiel #1
0
        public void Can_deliver_messages()
        {
            Session session = new Session(30312, LimboLogs.Instance, _channel, new Node("127.0.0.1", 8545));

            session.Handshake(TestItem.PublicKeyA);
            session.Init(5, _channelHandlerContext, _packetSender);
            IProtocolHandler p2p = BuildHandler("p2p", 10);
            IProtocolHandler aaa = BuildHandler("aaa", 10);
            IProtocolHandler bbb = BuildHandler("bbb", 5);
            IProtocolHandler ccc = BuildHandler("ccc", 1);

            session.AddProtocolHandler(p2p);
            session.AddProtocolHandler(aaa);
            session.AddProtocolHandler(bbb);
            session.AddProtocolHandler(ccc);

            session.DeliverMessage(new Packet("p2p", 3, Bytes.Empty));
            _packetSender.Received().Enqueue(Arg.Is <Packet>(p => p.Protocol == "p2p" && p.PacketType == 3));

            session.DeliverMessage(new Packet("aaa", 1, Bytes.Empty));
            _packetSender.Received().Enqueue(Arg.Is <Packet>(p => p.Protocol == "aaa" && p.PacketType == 11));

            session.DeliverMessage(new Packet("bbb", 1, Bytes.Empty));
            _packetSender.Received().Enqueue(Arg.Is <Packet>(p => p.Protocol == "bbb" && p.PacketType == 21));

            session.DeliverMessage(new Packet("ccc", 0, Bytes.Empty));
            _packetSender.Received().Enqueue(Arg.Is <Packet>(p => p.Protocol == "ccc" && p.PacketType == 25));
        }
        public void Can_start_p2p_session()
        {
            IPacketSender sender = Substitute.For <IPacketSender>();

            IMessageSerializationService service = Build.A.SerializationService().WithP2P().TestObject;

            P2PSession factory = new P2PSession(new NodeId(NetTestVectors.StaticKeyA.PublicKey), ListenPort, service, Substitute.For <ISynchronizationManager>(), NullLogManager.Instance);

            factory.Init(4, Substitute.For <IChannelHandlerContext>(), sender);

            sender.Received().Enqueue(Arg.Is <Packet>(p => p.PacketType == 0 && p.Protocol == "p2p"));
        }
Beispiel #3
0
        public void Can_deliver_messages()
        {
            Session session = new Session(30312, LimboLogs.Instance, _channel, new Node("127.0.0.1", 8545));

            session.Handshake(TestItem.PublicKeyA);
            session.Init(5, _channelHandlerContext, _packetSender);
            IProtocolHandler p2p = BuildHandler("p2p", 10);
            IProtocolHandler aaa = BuildHandler("aaa", 10);
            IProtocolHandler bbb = BuildHandler("bbb", 5);
            IProtocolHandler ccc = BuildHandler("ccc", 1);

            session.AddProtocolHandler(p2p);
            session.AddProtocolHandler(aaa);
            session.AddProtocolHandler(bbb);
            session.AddProtocolHandler(ccc);

            session.DeliverMessage(PingMessage.Instance);
            _packetSender.Received().Enqueue(PingMessage.Instance);
        }
        public void Can_deliver_messages()
        {
            Metrics.P2PBytesSent = 0;
            
            Session session = new(30312, new Node(TestItem.PublicKeyA, "127.0.0.1", 8545), _channel, NullDisconnectsAnalyzer.Instance, LimboLogs.Instance);
            session.Handshake(TestItem.PublicKeyA);
            session.Init(5, _channelHandlerContext, _packetSender);
            IProtocolHandler p2p = BuildHandler("p2p", 10);
            IProtocolHandler aaa = BuildHandler("aaa", 10);
            IProtocolHandler bbb = BuildHandler("bbb", 5);
            IProtocolHandler ccc = BuildHandler("ccc", 1);
            session.AddProtocolHandler(p2p);
            session.AddProtocolHandler(aaa);
            session.AddProtocolHandler(bbb);
            session.AddProtocolHandler(ccc);

            _packetSender.Enqueue(PingMessage.Instance).Returns(10);
            session.DeliverMessage(PingMessage.Instance);
            _packetSender.Received().Enqueue(PingMessage.Instance);

            Metrics.P2PBytesSent.Should().Be(10);
        }