コード例 #1
0
ファイル: KademliaProtocol.cs プロジェクト: tor0405/libplanet
        /// <summary>
        /// Updates routing table when receiving a message. If corresponding bucket
        /// for remote peer is not full, just adds given <paramref name="rawPeer"/>.
        /// Otherwise, checks aliveness of the least recently used (LRU) peer
        /// and determine evict LRU peer or discard given <paramref name="rawPeer"/>.
        /// </summary>
        /// <param name="rawPeer"><see cref="Peer"/> to update.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <paramref name="rawPeer"/> is <c>null</c>.
        /// </exception>
        private void Update(Peer rawPeer)
        {
            _logger.Verbose($"Try to {nameof(Update)}() {{Peer}}.", rawPeer);
            if (rawPeer is null)
            {
                throw new ArgumentNullException(nameof(rawPeer));
            }

            if (rawPeer is BoundPeer peer)
            {
                // Don't update peer without endpoint or with different appProtocolVersion.
                _table.AddPeer(peer);
            }
        }
コード例 #2
0
        // This updates routing table when receiving a message.
        // if corresponding bucket for remote peer is not full, just adds remote peer.
        // otherwise check whether if the least recently used (LRU) peer
        // is alive to determine evict LRU peer or discard remote peer.
        private void UpdateAsync(Peer rawPeer)
        {
            _logger.Verbose($"Try to {nameof(UpdateAsync)}() {{Peer}}.", rawPeer);
            if (rawPeer is null)
            {
                throw new ArgumentNullException(nameof(rawPeer));
            }

            if (!(rawPeer is BoundPeer peer) || rawPeer.AppProtocolVersion != _appProtocolVersion)
            {
                // Don't update peer without endpoint or with different appProtocolVersion.
                return;
            }

            _routing.AddPeer(peer);
        }
コード例 #3
0
        // This updates routing table when receiving a message.
        // if corresponding bucket for remote peer is not full, just adds remote peer.
        // otherwise check whether if the least recently used (LRU) peer
        // is alive to determine evict LRU peer or discard remote peer.
        private void UpdateAsync(Peer rawPeer)
        {
            _logger.Verbose($"Try to {nameof(UpdateAsync)}() {{Peer}}.", rawPeer);
            if (rawPeer is null)
            {
                throw new ArgumentNullException(nameof(rawPeer));
            }

            if (!(rawPeer is BoundPeer peer &&
                  peer.IsCompatibleWith(
                      _appProtocolVersion,
                      _trustedAppProtocolVersionSigners,
                      _differentAppProtocolVersionEncountered)))
            {
                // Don't update peer without endpoint or with different appProtocolVersion.
                return;
            }

            _routing.AddPeer(peer);
        }