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(); }
/// <summary> /// Create a new DistributedRoutingTable /// </summary> /// <param name="localIdentifier">The identifier of this node, or null to autogenerate one</param> /// <param name="createLocalContact">A factory function which creates a contact for this table</param> /// <param name="networkId">the ID of the network this routing table is part of</param> /// <param name="configuration">The configuration of this node</param> public DistributedRoutingTable(Identifier512 localIdentifier, Func <DistributedRoutingTable, Contact> createLocalContact, Guid networkId, Configuration configuration) { LocalIdentifier = localIdentifier != null ? localIdentifier : Identifier512.NewIdentifier(); NetworkId = networkId; Configuration = configuration; LocalContact = createLocalContact(this); contacts = new ContactCollection(this); //Register internal consumers RegisterConsumer(MessageCallback = new Callback()); RegisterConsumer(getClosest = new GetClosestNodes(contacts, MessageCallback)); }