Exemplo n.º 1
0
        static ChordController()
        {
            // determine the local chord endpoint's IP address and port
            string localIp   = IpSettingUtils.GetChordIpv4Address().ToString();
            string localPort = IpSettingUtils.GetChordPort().ToString();

            // define a function callback for finding bootstrap nodes
            Func <Task <IChordEndpoint> > bootstrapFunc =
                () => { return(Task.Run(() => findBootstrapNode())); };

            // join the chord network using a bootstrap node
            node = new ChordNode(sendRequest, localIp, localPort);
            node.JoinNetwork(bootstrapFunc).Wait();
        }
Exemplo n.º 2
0
        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);
        }