Exemple #1
0
        private static IEnumerable <Contact> LoadBootstrapData()
        {
            foreach (var line in File.ReadAllLines("Bootstrap.txt").OmitComments("#", "//"))
            {
                UdpContact udpC = null;

                try
                {
                    string[] split = line.Split(' ');
                    Guid     a     = Guid.Parse(split[0]);
                    Guid     b     = Guid.Parse(split[1]);
                    Guid     c     = Guid.Parse(split[2]);
                    Guid     d     = Guid.Parse(split[3]);

                    Identifier512 id = new Identifier512(a, b, c, d);

                    IPAddress ip   = IPAddress.Parse(split[4]);
                    int       port = Int32.Parse(split[5]);

                    udpC = new UdpContact(id, networkId, ip, port);

                    Console.WriteLine("Loaded bootstrap contact " + udpC);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception parsing bootstrap file: " + e);
                }

                if (udpC != null)
                {
                    yield return(udpC);
                }
            }
        }
Exemple #2
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();
        }