コード例 #1
0
        public KademliaProtocol(
            Swarm <T> swarm,
            Address address,
            int appProtocolVersion,
            ILogger logger)
        {
            _swarm = swarm;
            _appProtocolVersion = appProtocolVersion;
            _logger             = logger;

            _address = address;
            _random  = new System.Random();
            _routing = new RoutingTable(
                _address, TableSize, BucketSize, _random);
        }
コード例 #2
0
        /// <summary>
        /// Creates a <see cref="KademliaProtocol"/> instance.
        /// </summary>
        /// <param name="table">
        /// The <see cref="RoutingTable"/> where <see cref="Peer"/>s are stored.</param>
        /// <param name="transport"><see cref="ITransport"/> to process messages.</param>
        /// <param name="address">The <see cref="Address"/> of the <see cref="Peer"/>
        /// to be the reference point.</param>
        /// <param name="findConcurrency">The number of concurrency in peer discovery.</param>
        /// <param name="requestTimeout">
        /// A timeout of waiting for the reply of messages.
        /// If it's omitted or <c>null</c> is given, will automatically be set to 5 seconds.
        /// </param>
        public KademliaProtocol(
            RoutingTable table,
            ITransport transport,
            Address address,
            int findConcurrency     = Kademlia.FindConcurrency,
            TimeSpan?requestTimeout = null)
        {
            _transport = transport;
            _logger    = Log.ForContext <KademliaProtocol>();

            _address         = address;
            _random          = new System.Random();
            _findConcurrency = findConcurrency;
            _table           = table;
            _requestTimeout  = requestTimeout ?? TimeSpan.FromMilliseconds(5000);
            _transport.ProcessMessageHandler.Register(ProcessMessageHandler);
        }
コード例 #3
0
        public KademliaProtocol(
            Swarm <T> swarm,
            Address address,
            int appProtocolVersion,
            ILogger logger,
            int?tableSize,
            int?bucketSize,
            TimeSpan?requestTimeout = null)
        {
            _swarm = swarm;
            _appProtocolVersion = appProtocolVersion;
            _logger             = logger;

            _address        = address;
            _random         = new System.Random();
            _tableSize      = tableSize ?? Kademlia.TableSize;
            _bucketSize     = bucketSize ?? Kademlia.BucketSize;
            _routing        = new RoutingTable(_address, _tableSize, _bucketSize, _random, _logger);
            _requestTimeout =
                requestTimeout ??
                TimeSpan.FromMilliseconds(Kademlia.IdleRequestTimeout);
        }