Пример #1
0
 public Statistics(AnonymousRouter anonRouter, MMLC mmlc, ITcpListener tcp)
 {
     _sock = anonRouter.KeyBasedRouter.MessagingSocket;
     _tcp = tcp;
     Setup (_sock);
     Setup (anonRouter.KeyBasedRouter);
     Setup (anonRouter);
     Setup (mmlc);
 }
Пример #2
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);
 }
Пример #3
0
        void Setup(AnonymousRouter router)
        {
            router.MCRStatisticsNotice += delegate (object sender, StatisticsNoticeEventArgs args) {
                switch (args.Type) {
                    case StatisticsNoticeType.Success:
                        Interlocked.Increment (ref _mcrSuccess);
                        break;
                    case StatisticsNoticeType.Failure:
                        Interlocked.Increment (ref _mcrFailures);
                        break;
                    case StatisticsNoticeType.LifeTime:
                        _mcrLifeTime.AddSample ((float)args.TimeSpan.TotalSeconds);
                        break;
                }
            };

            router.ACStatisticsNotice += delegate (object sender, StatisticsNoticeEventArgs args) {
                switch (args.Type) {
                    case StatisticsNoticeType.Success:
                        Interlocked.Increment (ref _acSuccess);
                        break;
                    case StatisticsNoticeType.Failure:
                        Interlocked.Increment (ref _acFailures);
                        break;
                }
            };
        }