コード例 #1
0
ファイル: MessageLoop.cs プロジェクト: gweffect/monotorrent
        internal async ReusableTask SetListener(IDhtListener listener)
        {
            await DhtEngine.MainLoop;

            Listener.MessageReceived -= MessageReceived;
            Listener = listener ?? new NullDhtListener();
            Listener.MessageReceived += MessageReceived;
        }
コード例 #2
0
        public MessageLoop(DhtEngine engine, IDhtListener listener)
        {
            Engine                  = engine ?? throw new ArgumentNullException(nameof(engine));
            Listener                = listener ?? throw new ArgumentNullException(nameof(engine));
            ReceiveQueue            = new Queue <KeyValuePair <IPEndPoint, DhtMessage> >();
            SendQueue               = new Queue <SendDetails>();
            Timeout                 = TimeSpan.FromSeconds(15);
            WaitingResponse         = new Dictionary <BEncodedValue, SendDetails>();
            WaitingResponseTimedOut = new List <SendDetails> ();

            listener.MessageReceived += MessageReceived;
            Task sendTask = null;

            DhtEngine.MainLoop.QueueTimeout(TimeSpan.FromMilliseconds(5), () => {
                if (engine.Disposed)
                {
                    return(false);
                }
                try
                {
                    if (sendTask == null || sendTask.IsCompleted)
                    {
                        sendTask = SendMessages();
                    }

                    while (ReceiveQueue.Count > 0)
                    {
                        ReceiveMessage();
                    }

                    TimeoutMessage();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error in DHT main loop:");
                    Debug.WriteLine(ex);
                }

                return(!engine.Disposed);
            });
        }
コード例 #3
0
ファイル: DhtEngine.cs プロジェクト: miryuan/monotorrent
        /// <summary>
        /// 构造DHT引擎
        /// </summary>
        /// <param name="listener">监听对象</param>
        public DhtEngine(IDhtListener listener)
        {
            if (listener == null)
            {
                throw new ArgumentNullException(nameof(listener));
            }

            BucketRefreshTimeout = TimeSpan.FromMinutes(15);
            MessageLoop          = new MessageLoop(this, listener);
            RoutingTable         = new RoutingTable();
            State        = DhtState.NotReady;
            TokenManager = new TokenManager();
            Torrents     = new Dictionary <NodeId, List <Node> > ();

            MainLoop.QueueTimeout(TimeSpan.FromMinutes(5), () => {
                if (!Disposed)
                {
                    TokenManager.RefreshTokens();
                }
                return(!Disposed);
            });
        }
コード例 #4
0
 public Task SetListenerAsync(IDhtListener listener)
 {
     return(Task.CompletedTask);
 }
コード例 #5
0
 public void SetListener(IDhtListener listener)
 {
 }
コード例 #6
0
 internal void SetListener(IDhtListener listener)
 {
     Listener.MessageReceived -= MessageReceived;
     Listener = listener ?? new NullDhtListener();
     Listener.MessageReceived += MessageReceived;
 }
コード例 #7
0
 public async Task SetListenerAsync(IDhtListener listener)
 => await MessageLoop.SetListener(listener);
コード例 #8
0
 public static IDhtEngine Create(IDhtListener listener)
 => Creator(listener);
コード例 #9
0
 public void SetListener(IDhtListener listener)
 => MessageLoop.SetListener(listener);