Brunet.Services.Dht.RpcDhtProxy.Register C# (CSharp) Метод

Register() публичный Метод

This is a RpcDhtProxy rpc call entry, which can be called using "RpcDhtProxy.Register" Register the entry to Entry. If the key,value pair does not exist in _entries, it creates the pair in the list. Otherwise, it updates the ttl. After inserting the entry, this module try to register the key, value pair to neighbor node.
public Register ( MemBlock key, MemBlock value, int ttl ) : bool
key MemBlock dht entry key to insert
value MemBlock dht entry value to insert
ttl int dht entry ttl to insert
Результат bool
    public bool Register(MemBlock key, MemBlock value, int ttl)
    {
      Entry entry = null;
      lock(_sync) {
        Dictionary<MemBlock, Entry> key_entries = null;
        if(!_entries.TryGetValue(key, out key_entries)) {
          key_entries = new Dictionary<MemBlock, Entry>();
          _entries[key] = key_entries;
        }

        if(key_entries.ContainsKey(value)) {
          key_entries[value].Timer.Stop();
        }

        entry = new Entry(key, value, ttl);
        key_entries[value] = entry;
      }

      if(entry != null) {
        entry.Timer = new SimpleTimer(EntryCallback, entry, 0, RETRY_TIMEOUT);
        entry.Timer.Start();
      }
      return true;
    }

Usage Example

Пример #1
0
    /// <summary>Uses the Dht for the bootstrap problem.</summary>
    /// <param name="node">The node needing remote tas.</param>
    /// <param name="dht">The dht for the shared overlay.</param>
    /// <param name="dht_proxy">A dht proxy for the shared overlay.</param>
    public DhtDiscovery(StructuredNode node, IDht dht, string shared_namespace,
        RpcDhtProxy dht_proxy) :
      base(node)
    {
      _dht = dht;
      _dht_proxy = dht_proxy;
      _node = node;
      _shared_namespace = shared_namespace;
      string skey = "PrivateOverlay:" + node.Realm;
      byte[] bkey = Encoding.UTF8.GetBytes(skey);
      _p2p_address = node.Address.ToMemBlock();
      _private_dht_key = MemBlock.Reference(bkey);

      _ongoing = 0;
      _steady_state = 0;
      _dht_proxy.Register(_private_dht_key, _p2p_address, PUT_DELAY_S);
    }
All Usage Examples Of Brunet.Services.Dht.RpcDhtProxy::Register