public void TestDeadlock()
        {
            AutoResetEvent finishedEvent = new AutoResetEvent(false);
            using (BitcoinConnectionListener server = new BitcoinConnectionListener(IPAddress.Loopback, 28333, DeadlockTestConnectionHandler))
            {
                server.Start();

                Exception threadException = null;

                Thread thread = new Thread(() =>
                {
                    try
                    {
                        using (BitcoinEndpoint client = new BitcoinEndpoint(DeadlockTestMessageHandler))
                        {
                            client.Connect("localhost", 28333);
                            SendDeadlockTestSequence(client, "client");
                            //let other peer to send remaining data
                            Thread.Sleep(1000);
                        }
                    }
                    catch (Exception ex)
                    {
                        threadException = ex;
                    }
                    finally
                    {
                        finishedEvent.Set();
                    }
                });
                thread.Name = "Test Sending Thread";
                thread.IsBackground = true;
                thread.Start();
                Assert.That(finishedEvent.WaitOne(5000), Is.True);
                Assert.That(threadException, Is.Null);
            }
        }
 public void TestServer()
 {
     using (BitcoinConnectionListener listener = new BitcoinConnectionListener(IPAddress.Any, 8334, ConnectionHandler))
     {
         listener.Start();
         Thread.Sleep(30000);
         listener.Stop();
     }
 }
예제 #3
0
        public void Start()
        {
            blockchain.Init();

            //todo: review the order in which services and listener start/stop, dispose created entities when start fails
            services.CreateServices(this, cancellationTokenSource.Token);

            addressCollection = new NodeAddressCollection();
            connectionCollection = new NodeConnectionCollection(cancellationTokenSource.Token);
            //todo: review, maybe registering event handler is a responsibility of nodeDiscoveryService
            //todo: connectionCollection.Changed += nodeDiscoveryService.Signal; - signal nodeDiscoveryService to connect to new nodes (is it its responsibility?)

            //todo: discover own external address? (it seems useless without external port)
            //todo: use setting to specify port and operating mode
            listener = new BitcoinConnectionListener(IPAddress.Any, 8333, HandleIncomingConnection);
            listener.Start();

            services.Start();

            Started = true;
        }