예제 #1
0
 public RpcDht(IDht dht, Node node) {
   LocalUseOnly = true;
   _bqs = new Cache(100);
   _node = node;
   _dht = dht;
   _node.Rpc.AddHandler("DhtClient", this);
 }
예제 #2
0
  /**
   * Protected constructor, we want to control ReqrepManager instances
   * running on a node. 
   * @param node The Node we work for
   */
  public ReqrepManager(string info) {
    _info = info;

    _rand = new Random();
    _req_handler_table = new Hashtable();
    _req_state_table = new Hashtable();
    _rep_handler_table = new Hashtable();

    /**
     * We keep a list of the most recent 1000 replies until they
     * get too old.  If the reply gets older than reptimeout, we
     * remove it
     */
    _reply_cache = new Cache(1000);
    /*
     * Here we set the timeout mechanisms.  There is a default
     * value, but this is now dynamic based on the observed
     * RTT of the network
     */
    //resend the request after 5 seconds.
    _edge_reqtimeout = new TimeSpan(0,0,0,0,5000);
    _nonedge_reqtimeout = new TimeSpan(0,0,0,0,5000);
    //Start with 50 sec timeout
    _acked_reqtimeout = new TimeSpan(0,0,0,0,50000);
    //Here we track the statistics to improve the timeouts:
    _nonedge_rtt_stats = new TimeStats(_nonedge_reqtimeout.TotalMilliseconds, 0.98);
    _edge_rtt_stats = new TimeStats(_edge_reqtimeout.TotalMilliseconds, 0.98);
    _acked_rtt_stats = new TimeStats(_acked_reqtimeout.TotalMilliseconds, 0.98);
    _last_check = DateTime.UtcNow;
  }
예제 #3
0
 public AHRouter(AHAddress local)
 {
   _local = local;
   _sync = new object();
   /*
    * Store the 100 most commonly used routes.
    * Since this may cause us to keep an extra 100
    * AHAddress objects in memory, each of which requires
    * about 20 bytes, this costs on the order of 10-100 KB
    */
   _route_cache = new Cache(100);
 }
    /// <summary>Creates a new SymmetricEncryption handler for the passed in
    /// SymmetricAlgorithm.</summary>
    public SymmetricEncryption(SymmetricAlgorithm Algorithm)
    {
      if(Algorithm.Mode != CipherMode.CBC) {
        throw new Exception("SymmetricEncryption requires the symmetric algorithm to use CBC.");
      }

      rng = new RNGCryptoServiceProvider();
      _sa = Algorithm;
      // We take care of PKCS7 padding here due to issues in the underlying implementations...
      _sa.Padding = PaddingMode.None;
      BlockSizeByte = _sa.BlockSize / 8;
      // Match the same size as our Window size...
      _decryptors = new Cache(64);
      _enc_iv = new byte[BlockSizeByte];
      rng.GetBytes(_enc_iv);
      _enc = _sa.CreateEncryptor(_sa.Key, _enc_iv);
      _temp = new byte[BlockSizeByte];
    }
예제 #5
0
  public RpcManager(ReqrepManager rrm) {
    _sync = new Object();
    _rrman = rrm;
    _method_cache = new Cache(CACHE_SIZE);
    _method_handlers = new Hashtable();

#if DAVID_ASYNC_INVOKE
    _rpc_command = new BlockingQueue();
    _rpc_thread = new Thread(RpcCommandRun);
    _rpc_thread.IsBackground = true;
    _rpc_thread.Start();
#endif
  }
예제 #6
0
 public ReflectionRpcHandler(RpcManager rpc, object handler, bool use_sender) {
   _rpc = rpc;
   _handler = handler;
   _type = _handler.GetType();
   _use_sender = use_sender;
   _sync = new object();
   //Cache the 10 most used methods:
   _method_cache = new Cache(10);
 }
예제 #7
0
파일: Cache.cs 프로젝트: xujyan/brunet
  public void TestEviction() {
    const int MAX_SIZE = 1000;
    Random r = new Random();
    Cache c = new Cache(MAX_SIZE);
    Hashtable ht = new Hashtable();
    Hashtable ht_evicted = new Hashtable();
    EventHandler eh = delegate(object o, EventArgs args) {
      Cache.EvictionArgs a = (Cache.EvictionArgs)args;
      ht_evicted[a.Key] = a.Value;
    };
    c.EvictionEvent += eh;

    int i = 0;
    for(i = 0; i < 50 * MAX_SIZE; i++) {
      int v = r.Next();
      ht[i] = v;
      c[i] = v;
      int exp_size = Math.Min(i+1, MAX_SIZE);
      Assert.AreEqual(c.Count, exp_size, "Size check");
      Assert.AreEqual(ht[i], c[i], "equivalence check");
      //Keep the zero'th element in the cache:
      object v_0 = c[0];
      Assert.IsNotNull(v_0, "0th element still in the cache");
    }
    Assert.AreEqual(c.Count, MAX_SIZE, "Full cache"); 
    //Now check that everything is either in the Cache or was evicted:
    IDictionaryEnumerator ide = ht.GetEnumerator();
    while(ide.MoveNext()) {
      int key = (int)ide.Key;
      int val = (int)ide.Value;
      object c_val = c[key];
      if( !c.Contains(key) ) {
        Assert.IsNull(c_val, "Evicted entry is null");
        c_val = ht_evicted[key];
        Assert.AreEqual(c_val, val, "Evicted lookup");
      }
      else {
        //Not in the cache:
        Assert.AreEqual(c_val, val, "Cache lookup");
      }
    }
    //Let's remove from the Cache and see if that worked:
    int s0 = c.Count;
    object rv = c.Remove(0);
    Assert.AreEqual( rv, ht[0], "Removed value matches");
    Assert.IsNull(c[0], "Remove really removed");
    Assert.AreEqual( s0 - 1, c.Count, "Removed decreased size");

  }
예제 #8
0
파일: Cache.cs 프로젝트: xujyan/brunet
 public void TestEnumeration() {
   const int MAX_SIZE = 100;
   Random r = new Random();
   Cache c = new Cache(MAX_SIZE);
   Hashtable ht = new Hashtable();
   for(int i = 0; i < MAX_SIZE; i++) {
     int k = r.Next();
     int v = r.Next();
     ht[k] = v;
     c[k] = v;
   }
   int enum_count = 0;
   foreach(DictionaryEntry de in c) {
     Assert.IsNotNull( c[de.Key], "Enumeration");
     enum_count++;
   }
   Assert.AreEqual(enum_count, c.Count, "Enumeration count");
   //Remove a bunch at random:
   ArrayList removed = new ArrayList();
   for(int i = 0; i < MAX_SIZE / 2; i++) {
     object k = r.Next(0, MAX_SIZE);
     removed.Add( k );
     c.Remove( k );
   }
   //Make sure they are really gone:
   enum_count = 0;
   foreach(DictionaryEntry de in c) {
     Assert.IsNotNull( c[de.Key], "Enumeration after remove");
     enum_count++;
   }
   Assert.AreEqual(enum_count, c.Count, "Enumeration count after remove");
   foreach(object k in removed) {
     Assert.IsNull(c[k], "removed objects removed");
   }
   //Let's enumerate and removed:
   foreach(DictionaryEntry de in c) {
     c.Remove(de.Key);
     Assert.IsNull( c[de.Key], "Removing with enumeration");
   }
   Assert.AreEqual(0, c.Count, "Removed everything");
 }
예제 #9
0
파일: Cache.cs 프로젝트: xujyan/brunet
 public void TestRecall() {
   const int MAX_SIZE = 100;
   Random r = new Random();
   Cache c = new Cache(MAX_SIZE);
   Hashtable ht = new Hashtable();
   for(int i = 0; i < MAX_SIZE; i++) {
     int k = r.Next();
     int v = r.Next();
     ht[k] = v;
     c[k] = v;
   }
   IDictionaryEnumerator ide = ht.GetEnumerator();
   while(ide.MoveNext()) {
     int key = (int)ide.Key;
     int val = (int)ide.Value;
     object c_val = c[key];
     Assert.AreEqual(c_val, val, "Test lookup");
   }
 }
예제 #10
0
 public void TestUpdate() {
   Cache c = new Cache(16);
   object entry = new object();
   object first = new object();
   object second = new object();
   c[entry] = first;
   c[entry] = second;
   Assert.IsTrue(c[entry].Equals(second), "Entry equals second");
 }
예제 #11
0
 static AddressParser() {
   _address_cache = new Cache(CACHE_SIZE);
   _mb_cache = new Address[ UInt16.MaxValue + 1 ];
 }
예제 #12
0
 static TransportAddressFactory() {
   _string_to_type = new Hashtable();
   _ta_cache = new Cache(CACHE_SIZE);
 }