private static void testLookupPerformance(ChordNode node, ILogger logger) { // initialize random number generator using (var rng = new RNGCryptoServiceProvider()) { // send random key lookup messages for testing the chord network while (true) { // generate a random key byte[] bytes = new byte[20]; rng.GetBytes(bytes); // send a lookup request for the generated key node.LookupKey(new BigInteger(bytes)) .ContinueWith(e => logger.LogInformation( $"Lookup: key '{ HexString.Deserialize(bytes) }' " + $"is managed by node with id '{ HexString.Deserialize(e.Result.NodeId.ToByteArray()) }'")) .Wait(); // sleep for 1 sec Thread.Sleep(1000); } } }
private static ChordNode initChord(ILogger logger) { // retrieve the node's IP address and port from the local IP configuration var local = new IPEndPoint(IpSettings.GetChordIpv4Address(), IpSettings.GetChordPort()); logger.LogInformation($"Initializing: endpoint={ local.Address }:{ local.Port }, " + $"node id={ HexString.Deserialize(HashingHelper.GetSha1Hash(local)) }"); var netId = IpSettings.GetIpv4NetworkId(); var broadcast = IpSettings.GetIpv4Broadcast(); // connect the chord node to the chord network var node = new ChordNode(local, logger); node.FindBootstrapNode(netId, broadcast) .ContinueWith(x => node.JoinNetwork(x.Result)).Wait(); // write initialization success message to console logger.LogInformation($"Initializing: successful! Going into idle state ..."); return(node); }