示例#1
0
        public LocalHT()
        {
            AHAddress addr = new AHAddress(new RNGCryptoServiceProvider());
              Node brunetNode = new StructuredNode(addr);
              RpcManager rpc = RpcManager.GetInstance(brunetNode);
              this._ts = new TableServer(brunetNode);
              this._node = brunetNode;

            #if FUSE_DEBUG
              //Having some init data isn't bad
              string key = FuseDhtUtil.GenDhtKey("testbasedir", "testkey1", "ipop_ns");
              this.Put(key, "testvalue1", 5000);
              this.Put(key, "testvalue2", 3000);
            #endif
        }
示例#2
0
    public void Init() {
      Console.WriteLine("Initializing...");
      ArrayList RemoteTA = new ArrayList();
      for(int i = 0; i < network_size; i++) {
        RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.udp://127.0.0.1:" + (base_port + i)));
      }

      for(int i = 0; i < network_size; i++) {
        Address addr = (Address) new AHAddress(new RNGCryptoServiceProvider());
        Node node = new StructuredNode((AHAddress) addr, brunet_namespace);
        nodes.Add(addr, node);
        node.AddEdgeListener(new UdpEdgeListener(base_port + i));
        node.RemoteTAs = RemoteTA;
        tables[addr] = new TableServer(node);
        (new Thread(node.Connect)).Start();
//        if(i < network_size / ((Dht)dhts.GetByIndex(i)).DEGREE) {
//          ((Dht)dhts.GetByIndex(i)).debug = true;
//        }
      }
      default_dht = new Dht((Node) nodes.GetByIndex(0), degree);
    }
示例#3
0
文件: Dht.cs 项目: xujyan/brunet
 /**
 <summary>A default Dht client provides a DEGREE of 1 and a sychronous wait
 time of up to 60 seconds.</summary>
 <param name ="node">The node to provide service for.</param>
 */
 public Dht(Node node) {
   this.node = node;
   _rpc = RpcManager.GetInstance(node);
   _table = new TableServer(node);
   DEGREE = 1;
   MAJORITY = 1;
   DELAY = 60000;
 }
      /**
      <summary>Begins a new transfer state to the neighbor connected via con.
      </summary>
      <param name="con">The connection to the neigbhor we will be transferring
      data to.</param>
      <param name="ts">The table server we're providing the transfer for.  C#
      does not allow sub-class objects to have access to their parent objects
      member variables, so we pass it in like this.</param>
      <remarks>
      Step 1:

      Get all the keys between me and my new neighbor.

      Step 2:

      Get all values for those keys, we copy so that we don't worry about
      changes to the dht during this interaction.  This is only a pointer
      copy and since we let the OS deal with removing the contents of an
      entry, we don't need to make copies of the actual entry.

      Step 3:

      Generate another list of keys of up to max parallel transfers and begin
      transferring, that way we do not need to lock access to the entry
      enumerator until non-constructor puts.

      Step 4:

      End constructor, results from puts, cause the next entry to be sent.
      */
      public TransferState(Connection con, TableServer ts) {
        this._ts = ts;
        this._con = con;
        // Get all keys between me and my new neighbor
        LinkedList<MemBlock> keys;
        lock(_ts._sync) {
          keys = _ts._data.GetKeysBetween((AHAddress) _ts._node.Address,
                                      (AHAddress) _con.Address);
        }
        if(Dht.DhtLog.Enabled) {
          ProtocolLog.Write(Dht.DhtLog, String.Format(
                            "Starting transfer from {0} to {1}", 
                            _ts._node.Address, _con.Address));
        }
        int total_entries = 0;
        /* Get all values for those keys, we copy so that we don't worry about
         * changes to the dht during this interaction.  This is only a pointer
         * copy and since we let the OS deal with removing the contents of an
         * entry, we don't need to make copies of the actual entry.
         */
        foreach(MemBlock key in keys) {
          Entry[] entries;
          lock(_ts._sync) {
            LinkedList<Entry> llentries = _ts._data.GetEntries(key);
            if(llentries == null) {
              continue;
            }
            entries = new Entry[llentries.Count];
            total_entries += llentries.Count;
            llentries.CopyTo(entries, 0);
          }
          key_entries.AddLast(entries);
        }
        if(Dht.DhtLog.Enabled) {
          ProtocolLog.Write(Dht.DhtLog, String.Format(
                            "Total keys: {0}, total entries: {1}.", 
                            key_entries.Count, total_entries));
        }
        _entry_enumerator = GetEntryEnumerator();

        /* Here we generate another list of keys that we would like to 
         * this is done here, so that we can lock up the _entry_enumerator
         * only during this stage and not during the RpcManager.Invoke
         */
        LinkedList<Entry> local_entries = new LinkedList<Entry>();
        for(int i = 0; i < MAX_PARALLEL_TRANSFERS && _entry_enumerator.MoveNext(); i++) {
          local_entries.AddLast((Entry) _entry_enumerator.Current);
        }

        foreach(Entry ent in local_entries) {
          Channel queue = new Channel();
          queue.CloseAfterEnqueue();
          queue.CloseEvent += this.NextTransfer;
          int ttl = (int) (ent.EndTime - DateTime.UtcNow).TotalSeconds;
          try {
            _ts._rpc.Invoke(_con.Edge, queue, "dht.PutHandler", ent.Key, ent.Value, ttl, false);
          }
          catch {
            if(_con.Edge.IsClosed) {
              _interrupted = true;
              Done();
              break;
            }
          }
        }
      }