/** * Installs the network coordinate service on a given node. * NCService instance can be installed on atmost one node. * Each node is allowed to have only one NCService instance. * @param node node for installing the service instance. * @param InitialPoint a starting place for the NCService to use */ public NCService(Node node, Point InitialPoint) { _sync = new object(); _node = null; _last_sample_instant = DateTime.MinValue; _samples = new Hashtable(); _vivaldi_state = new VivaldiState(); _vivaldi_state.WeightedError = INITIAL_WEIGHTED_ERROR; _vivaldi_state.Position = new Point(); _vivaldi_state.DistanceDelta = 0.0f; if (InitialPoint == null) { InitialPoint = new Point(); } _vivaldi_state.Position = InitialPoint; if (node != null) { _node = node; #if NC_DEBUG Console.Error.WriteLine("[NCService] {0} Starting an instance of NCService.", node.Address); #endif lock (_sync) { _rpc = _node.Rpc; _rpc.AddHandler("ncserver", this); _node.HeartBeatEvent += GetNextSample; } } }
/** * This method packages the current state of the network coordinates * into a Hashtable than can be sent back as Brunet-Rpc result. * @returns hashtable representing the network coordinate state. */ public Hashtable EchoVivaldiState() { #if NC_DEBUG if (_node != null) { //Console.Error.WriteLine("[NCService] {0} EchoVivaldiState() method invoked.", _node.Address); } #endif //get snapshot of the local vivaldi state VivaldiState v_state = State; // // Hashtable containing the Vivaldi state. // Hashtable ht = new Hashtable(); //error ht["error"] = v_state.WeightedError; //local coordinates Hashtable ht_position = new Hashtable(); ht_position["side"] = new ArrayList(v_state.Position.Side); ht_position["height"] = v_state.Position.Height; ht["position"] = ht_position; ht["hostname"] = _hostname; #if NC_DEBUG if (_node != null) { //Console.Error.WriteLine("[NCService] {0} EchoVivaldiState() returning.", _node.Address); } #endif return(ht); }
/** * Installs the network coordinate service on a given node. * NCService instance can be installed on atmost one node. * Each node is allowed to have only one NCService instance. * @param node node for installing the service instance. * @param InitialPoint a starting place for the NCService to use */ public NCService(Node node, Point InitialPoint) { _sync = new object(); _node = null; _last_sample_instant = DateTime.MinValue; _samples = new Hashtable(); _vivaldi_state = new VivaldiState(); _vivaldi_state.WeightedError = INITIAL_WEIGHTED_ERROR; _vivaldi_state.Position = new Point(); _vivaldi_state.DistanceDelta = 0.0f; if(InitialPoint == null) { InitialPoint = new Point(); } _vivaldi_state.Position = InitialPoint; if(node != null) { _node = node; #if NC_DEBUG Console.Error.WriteLine("[NCService] {0} Starting an instance of NCService.", node.Address); #endif lock(_sync) { _rpc = _node.Rpc; _rpc.AddHandler("ncserver", this); _node.HeartBeatEvent += GetNextSample; } } }