示例#1
0
 public FingerTable(IOptions <DhtSettings> options, ISchedule scheduler)
 {
     _numDHT = options.Value.MaxNumberOfNodes;
     _numberOfFingerTableEntries = (uint)Math.Ceiling(Math.Log(_numDHT - 1) / Math.Log(2));
     FingerTableEntries          = new FingerTableEntry[_numberOfFingerTableEntries];
     scheduler.Enqueue(new Timer(TimeSpan.FromSeconds(options.Value.FixFingersCallInSeconds).TotalMilliseconds),
                       FixFingers);
 }
示例#2
0
        /// <summary>
        /// Create fingertable for specific node (id).
        /// <param name="node"></param>
        /// <param name="id"></param>
        /// <returns>"void"</returns>
        public void CreateFingerTable(uint id)
        {
            if (id > _numDHT - 1)
            {
                throw new ArgumentOutOfRangeException(nameof(id), $"ID index out of range: {id}, max is {_numDHT-1}.");
            }

            for (uint i = 0; i < _numberOfFingerTableEntries; i++)
            {
                FingerTableEntries[i] = new FingerTableEntry {
                    Start = (uint)((id + (uint)Math.Pow(2, i)) % _numDHT)
                };
            }

            for (uint i = 0; i < _numberOfFingerTableEntries - 1; i++)
            {
                FingerTableEntries[i].SetInterval(FingerTableEntries[i].Start, FingerTableEntries[i + 1].Start);
            }

            FingerTableEntries[_numberOfFingerTableEntries - 1].SetInterval(
                FingerTableEntries[_numberOfFingerTableEntries - 1].Start, FingerTableEntries[0].Start - 1);
        }