示例#1
0
        static void Main(string[] args)
        {
            myDomainMappings = ReadDomainMappings("MyDomainMappings.txt");
            ReadSettings(ref dnsport, ref peerport);

            dnsServer = new DnsServer(new Dictionary <string, DomainMapping>()
            {
                { "hellequin.p2p", new DomainMapping()
                  {
                      Address = IPAddress.Parse("78.105.97.103"), Name = "hellequin.p2p", TimeToLive = TimeSpan.FromSeconds(1234)
                  } }
            });
            dnsServer.Start();

            Identifier512 myId = Identifier512.NewIdentifier();

            routingTable = new DistributedRoutingTable(Identifier512.NewIdentifier(), (a) => new UdpContact(a.LocalIdentifier, networkId, LocalIp, peerport), networkId, new Configuration());

            UdpContact.InitialiseUdp(routingTable, peerport);

            Console.WriteLine("Bootstrapping DHT");
            routingTable.Bootstrap(LoadBootstrapData());

            Console.WriteLine("Bootstrap finished");
            Console.WriteLine("There are " + routingTable.ContactCount + " Contacts");

            Console.WriteLine("Press any key to close");
            Console.ReadLine();

            UdpContact.Stop();
        }
        public void ThreeNodeNetwork()
        {
            Func<DistributedRoutingTable, Contact> contactFactory = drt =>
            {
                return new LocalContact(drt);
            };

            Guid networkId = Guid.NewGuid();
            Configuration config = new Configuration();
            DistributedRoutingTable table1 = new DistributedRoutingTable(Identifier512.NewIdentifier(), contactFactory, networkId, config);
            DistributedRoutingTable table2 = new DistributedRoutingTable(Identifier512.NewIdentifier(), contactFactory, networkId, config);
            DistributedRoutingTable table3 = new DistributedRoutingTable(Identifier512.NewIdentifier(), contactFactory, networkId, config);

            table1.Bootstrap(table2.LocalContact);
            table2.Bootstrap(table3.LocalContact);

#if DEBUG
            config.UpdateRoutingTable = false;
#endif

            FindTable(table1, table1);
            FindTable(table1, table2);
            FindTable(table1, table3);

            FindTable(table2, table1);
            FindTable(table2, table2);
            FindTable(table2, table3);

            FindTable(table3, table1);
            FindTable(table3, table2);
            FindTable(table3, table3);

            TestUtilities.TestCallbackLeak(table1, table2, table3);
        }
示例#3
0
        static void Main(string[] args)
        {
            myDomainMappings = ReadDomainMappings("MyDomainMappings.txt");
            ReadSettings(ref dnsport, ref peerport);

            dnsServer = new DnsServer(new Dictionary<string, DomainMapping>()
                {
                    { "hellequin.p2p", new DomainMapping() { Address = IPAddress.Parse("78.105.97.103"), Name = "hellequin.p2p", TimeToLive = TimeSpan.FromSeconds(1234) }}
                });
            dnsServer.Start();

            Identifier512 myId = Identifier512.NewIdentifier();
            routingTable = new DistributedRoutingTable(Identifier512.NewIdentifier(), (a) => new UdpContact(a.LocalIdentifier, networkId, LocalIp, peerport), networkId, new Configuration());

            UdpContact.InitialiseUdp(routingTable, peerport);

            Console.WriteLine("Bootstrapping DHT");
            routingTable.Bootstrap(LoadBootstrapData());

            Console.WriteLine("Bootstrap finished");
            Console.WriteLine("There are " + routingTable.ContactCount + " Contacts");

            Console.WriteLine("Press any key to close");
            Console.ReadLine();

            UdpContact.Stop();
        }
        private List<DistributedRoutingTable> CreateNetwork()
        {
            Func<DistributedRoutingTable, Contact> contactFactory = drt =>
            {
                return new LocalContact(drt);
            };

            Guid networkId = Guid.NewGuid();
            Configuration config = new Configuration();
            DistributedRoutingTable table1 = new DistributedRoutingTable(Identifier512.NewIdentifier(), contactFactory, networkId, config);
            DistributedRoutingTable table2 = new DistributedRoutingTable(Identifier512.NewIdentifier(), contactFactory, networkId, config);
            DistributedRoutingTable table3 = new DistributedRoutingTable(Identifier512.NewIdentifier(), contactFactory, networkId, config);
            DistributedRoutingTable table4 = new DistributedRoutingTable(Identifier512.NewIdentifier(), contactFactory, networkId, config);
            DistributedRoutingTable table5 = new DistributedRoutingTable(Identifier512.NewIdentifier(), contactFactory, networkId, config);

            table1.Bootstrap(table2.LocalContact);
            table2.Bootstrap(table3.LocalContact);
            table3.Bootstrap(table4.LocalContact);
            table4.Bootstrap(table5.LocalContact);
            table5.Bootstrap(table1.LocalContact);

            return new List<DistributedRoutingTable>(new[] { table1, table2, table3, table4, table5 });
        }
        private static void AddPeer(Configuration config, Func<DistributedRoutingTable, Contact> contactFactory, Guid networkId, IList<DistributedRoutingTable> tables, Random r)
        {
            Identifier512 id = Identifier512.NewIdentifier();
            DistributedRoutingTable t = new DistributedRoutingTable(id, contactFactory, networkId, config);

            t.Bootstrap(
                tables[r.Next(tables.Count)].LocalContact,
                tables[r.Next(tables.Count)].LocalContact,
                tables[r.Next(tables.Count)].LocalContact);

            tables.Add(t);
        }