Exemplo n.º 1
0
        public SimpleIterativeRouter2(Key self, ushort tcpPort, IMessagingSocket sock, IKeyBasedRoutingAlgorithm algo, IFormatter formatter, bool isStrictMode)
        {
            _selfId = self;
            _tcpPort = tcpPort;
            _sock = sock;
            _algo = algo;
            _strict_mode = isStrictMode;

            // メッセージに含むことの出来る大体の最大NodeHandle数を計算
            int overhead, nodeHandleBytes;
            {
                using (MemoryStream ms = new MemoryStream ()) {
                    formatter.Serialize (ms, new NextHopResponse (self, _tcpPort, true, new NodeHandle[0]));
                    overhead = (int)ms.Length;
                }
                using (MemoryStream ms = new MemoryStream ()) {
                    formatter.Serialize (ms, new NodeHandle (self, new IPEndPoint (IPAddress.Loopback, 0), tcpPort));
                    nodeHandleBytes = (int)ms.Length;
                }
            }
            _maxNodeHandlesPerResponse = (dgramMaxSize - overhead) / nodeHandleBytes;

            algo.Setup (self, this);
            sock.AddInquiredHandler (typeof (NextHopQuery), MessagingSocket_Inquired_NextHopQuery);
            sock.AddInquiredHandler (typeof (CloseNodeQuery), MessagingSocket_Inquired_CloseNodeQuery);
        }
Exemplo n.º 2
0
 public SimpleDHT(IKeyBasedRouter kbr, IMessagingSocket sock, ILocalHashTable lht)
 {
     _kbr = kbr;
     _sock = sock;
     _lht = lht;
     sock.AddInquiredHandler (typeof (GetRequest), MessagingSocket_Inquired_GetRequest);
     sock.AddInquiredHandler (typeof (PutRequest), MessagingSocket_Inquired_PutRequest);
 }
Exemplo n.º 3
0
 public PortOpenChecker(IKeyBasedRouter kbr)
 {
     _msock = kbr.MessagingSocket;
     _kbr = kbr;
     _msock.AddInquiredHandler (typeof (PortCheckStartMessage), Inquired_PortCheckStartMessage);
     _msock.AddInquiredHandler (typeof (PortCheckRequest), Inquired_PortCheckRequest);
     _msock.AddInquiredHandler (typeof (PortCheckResponse), Inquired_PortCheckResponse);
 }
Exemplo n.º 4
0
 public MassKeyDeliverer(IDistributedHashTable dht, IMassKeyDelivererLocalStore store, IntervalInterrupter timer)
 {
     _router = dht.KeyBasedRouter;
     _dht = dht;
     _sock = _router.MessagingSocket;
     _store = store;
     _int = timer;
     timer.AddInterruption (Deliver);
     _values = new List<DHTEntry> [_router.RoutingAlgorithm.MaxRoutingLevel];
     for (int i = 0; i < _values.Length; i ++)
         _values[i] = new List<DHTEntry> ();
     _sock.AddInquiredHandler (typeof (Message), Messaging_Inquired);
 }