예제 #1
0
        /// <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));
        }
예제 #2
0
        public void Refresh(bool force)
        {
            if (force || DateTime.Now - lastRefresh > Configuration.BucketRefreshPeriod)
            {
                lastRefresh = DateTime.Now;

                GetClosestNodes getClosest = DistributedRoutingTable.GetConsumer <GetClosestNodes>(GetClosestNodes.GUID);
                foreach (var item in getClosest.GetClosestContacts(CreateRefreshId()))
                {
                    item.Ping(LocalContact, Configuration.PingTimeout);
                }
            }
        }