예제 #1
0
파일: SimpleDHT.cs 프로젝트: kazuki/p2pncs
 public AsyncResult(Key key, int typeId, SimpleDHT dht, AsyncCallback callback, object state)
 {
     _callback = callback;
     _state = state;
     _dht = dht;
     _key = key;
     _typeId = typeId;
     _start = DateTime.Now;
     _getMethod = true;
     _getLock = new object ();
     _kbrAR = dht.KeyBasedRouter.BeginRoute (key, null, dht.NumberOfReplicas, dht.NumberOfSimultaneous, KBR_Callback, null);
 }
예제 #2
0
파일: SimpleDHT.cs 프로젝트: kazuki/p2pncs
 public AsyncResult(Key key, object value, TimeSpan lifetime, SimpleDHT dht, AsyncCallback callback, object state)
 {
     _callback = callback;
     _state = state;
     _dht = dht;
     _key = key;
     _start = DateTime.Now;
     _getMethod = false;
     _putReq = new PutRequest (key, value, lifetime);
     _kbrAR = dht.KeyBasedRouter.BeginRoute (key, null, dht.NumberOfReplicas, dht.NumberOfSimultaneous, KBR_Callback, null);
 }
예제 #3
0
 public void AddNodes(Key[] keys, ECKeyPair[] keyPairs)
 {
     for (int i = 0; i < keys.Length; i++) {
         IPAddress adrs = _ipGenerator.Next ();
         IPEndPoint ep = new IPEndPoint (adrs, 10000);
         VirtualDatagramEventSocket sock = new VirtualDatagramEventSocket (_network, adrs);
         sock.Bind (new IPEndPoint (IPAddress.Loopback, ep.Port));
         //IMessagingSocket msock = new MessagingSocket (sock, true, SymmetricKey.NoneKey, Serializer.Instance, null, _interrupter, TimeSpan.FromSeconds (1), 2, 1024);
         IMessagingSocket msock = new VirtualMessagingSocket (sock, true, _interrupter, _rtoAlgo, 2, 1024, 1024);
         _sockets.Add (msock);
         IKeyBasedRouter router = new SimpleIterativeRouter2 (keys[i], 0, msock, new SimpleRoutingAlgorithm (), Serializer.Instance, true);
         _routers.Add (router);
         if (_dhts != null) {
             IDistributedHashTable dht = new SimpleDHT (router, msock, new OnMemoryLocalHashTable (router, _dhtInt));
             _dhts.Add (dht);
             if (_anons != null) {
                 IAnonymousRouter anonRouter = new AnonymousRouter (dht, keyPairs[i], _anonInt);
                 _anons.Add (anonRouter);
             }
         }
         if (_endPoints.Count != 0) {
             if (_initEPs == null || _endPoints.Count < 3)
                 _initEPs = _endPoints.ToArray ();
             router.Join (_initEPs);
         }
         _endPoints.Add (ep);
         Thread.Sleep (5);
     }
     Thread.Sleep (500);
 }