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); }
protected override void CreateMessagingSocket(int idx, SymmetricKey key, out IMessagingSocket socket, out EndPoint endPoint) { endPoint = new IPEndPoint (_adrsGen.Next (), 10000); VirtualDatagramEventSocket sock = new VirtualDatagramEventSocket (_net, ((IPEndPoint)endPoint).Address); sock.Bind (endPoint); socket = new VirtualMessagingSocket (sock, true, _interrupter, DefaultRTO, DefaultRetryCount, 1024, 1024); }
internal void AddVirtualMessagingSocketToVirtualNode(VirtualDatagramEventSocket sock, VirtualMessagingSocket msock) { using (_nodeLock.EnterReadLock ()) { VirtualNetworkNode node; if (_mapping.TryGetValue (sock.BindedPublicEndPoint, out node)) { node.MessagingSocket = msock; } } }