Esempio n. 1
0
 public TestPipelineFilter(CountConnectionOutboundHandler ccohTcp, CountConnectionOutboundHandler ccohUdp)
 {
     _ccohTcp = ccohTcp;
     _ccohUdp = ccohUdp;
 }
Esempio n. 2
0
        public async void TestDirectReconnect()
        {
            // TODO this test must be adapted to newest TomP2P implementation, where ports/configs are treated differently
            Peer sender = null;
            Peer recv1  = null;

            try
            {
                var ccohTcp = new CountConnectionOutboundHandler();
                var ccohUdp = new CountConnectionOutboundHandler();
                var filter  = new TestPipelineFilter(ccohTcp, ccohUdp);
                var csc1    = PeerBuilder.CreateDefaultChannelServerConfiguration().SetPorts(new Ports(2424, 2424));
                var csc2    = PeerBuilder.CreateDefaultChannelServerConfiguration().SetPorts(new Ports(8088, 8088));
                var ccc     = PeerBuilder.CreateDefaultChannelClientConfiguration();
                csc1.SetPipelineFilter(filter);
                csc2.SetPipelineFilter(filter);
                ccc.SetPipelineFilter(filter);

                sender = new PeerBuilder(new Number160("0x50"))
                         .SetP2PId(55)
                         .SetEnableMaintenance(false)
                         .SetChannelClientConfiguration(ccc)
                         .SetChannelServerConfiguration(csc1)
                         .Start();
                recv1 = new PeerBuilder(new Number160("0x20"))
                        .SetP2PId(55)
                        .SetEnableMaintenance(false)
                        .SetChannelClientConfiguration(ccc)
                        .SetChannelServerConfiguration(csc2)
                        .Start();

                recv1.RawDataReply(new TestRawDataReply());

                var peerConnection = sender.CreatePeerConnection(recv1.PeerAddress);
                ccohTcp.Reset();
                ccohUdp.Reset();

                var taskDirect1 = sender.SendDirect(peerConnection).SetBuffer(CreateTestBuffer())
                                  .SetConnectionTimeoutTcpMillis(2000).SetIdleTcpSeconds(10 * 1000).Start().Task;
                await taskDirect1;
                // TODO await listeners?

                Assert.IsTrue(!taskDirect1.IsFaulted);
                Assert.AreEqual(2, ccohTcp.Total); //.NET: there are 2 csc's
                Assert.AreEqual(0, ccohUdp.Total);

                // TODO thread sleep?
                // send second with the same connection
                var taskDirect2 = sender.SendDirect(peerConnection).SetBuffer(CreateTestBuffer())
                                  .Start().Task;
                await taskDirect2;

                Assert.IsTrue(!taskDirect2.IsFaulted);
                Assert.AreEqual(4, ccohTcp.Total); //.NET: 2 csc's, 2 server sessions
                Assert.AreEqual(0, ccohUdp.Total);

                await peerConnection.CloseAsync();
            }
            finally
            {
                if (sender != null)
                {
                    sender.ShutdownAsync().Wait();
                }
                if (recv1 != null)
                {
                    recv1.ShutdownAsync().Wait();
                }
            }
        }