Ejemplo n.º 1
0
        public void Start(byte[] initialNodes)
        {
            CheckDisposed();

            messageLoop.Start();
            if (Bootstrap)
            {
                new InitialiseTask(this, initialNodes).Execute();
                RaiseStateChanged(DhtState.Initialising);
                bootStrap = false;
            }
            else
            {
                RaiseStateChanged(DhtState.Ready);
            }

            DhtEngine.MainLoop.QueueTimeout(TimeSpan.FromSeconds(1), delegate
            {
                if (Disposed)
                {
                    return(false);
                }

                foreach (Bucket b in RoutingTable.Buckets)
                {
                    if ((DateTime.UtcNow - b.LastChanged) > BucketRefreshTimeout)
                    {
                        b.LastChanged          = DateTime.UtcNow;
                        RefreshBucketTask task = new RefreshBucketTask(this, b);
                        task.Execute();
                    }
                }
                return(!Disposed);
            });
        }
Ejemplo n.º 2
0
        internal async Task RefreshBuckets()
        {
            var refreshTasks = new List <Task> ();

            foreach (Bucket b in RoutingTable.Buckets)
            {
                if (b.LastChanged > BucketRefreshTimeout)
                {
                    b.Changed();
                    var task = new RefreshBucketTask(this, b);
                    refreshTasks.Add(task.Execute());
                }
            }

            if (refreshTasks.Count > 0)
            {
                await Task.WhenAll(refreshTasks).ConfigureAwait(false);
            }
        }
Ejemplo n.º 3
0
        public async Task StartAsync(byte[] initialNodes)
        {
            CheckDisposed();

            await MainLoop;

            MessageLoop.Start();
            if (RoutingTable.NeedsBootstrap)
            {
                RaiseStateChanged(DhtState.Initialising);
                InitializeAsync(initialNodes);
            }
            else
            {
                RaiseStateChanged(DhtState.Ready);
            }

            MainLoop.QueueTimeout(TimeSpan.FromSeconds(30), delegate
            {
                if (Disposed)
                {
                    return(false);
                }

                foreach (Bucket b in RoutingTable.Buckets)
                {
                    if (b.LastChanged > BucketRefreshTimeout)
                    {
                        b.Changed();
                        RefreshBucketTask task = new RefreshBucketTask(this, b);
                        task.Execute();
                    }
                }
                return(!Disposed);
            });
        }
Ejemplo n.º 4
0
        public void Start(byte[] initialNodes)
        {
            CheckDisposed();

            messageLoop.Start();
            if (Bootstrap)
            {
                new InitialiseTask(this, initialNodes).Execute();
                RaiseStateChanged(DhtState.Initialising);
                bootStrap = false;
            }
            else
            {
                RaiseStateChanged(DhtState.Ready);
            }

            DhtEngine.MainLoop.QueueTimeout(TimeSpan.FromSeconds(1), delegate
            {
                if (Disposed)
                    return false;

                foreach (Bucket b in RoutingTable.Buckets)
                {
                    if ((DateTime.UtcNow - b.LastChanged) > BucketRefreshTimeout)
                    {
                        b.LastChanged = DateTime.UtcNow;
                        RefreshBucketTask task = new RefreshBucketTask(this, b);
                        task.Execute();
                    }
                }
                return !Disposed;
            });
        }