override public void Start() { base.Start(); foreach(NodeMapping nm_from in Nodes.Values) { foreach(NodeMapping nm_to in Nodes.Values) { if(nm_from == nm_to) { continue; } ISender sender = null; if(Secure) { sender = nm_from.Sso.GetSecureSender(nm_to.Node.Address); } else { sender = new AHGreedySender(nm_from.Node, nm_to.Node.Address); } Channel q = new Channel(1); q.CloseEvent += Callback; try { nm_from.Node.Rpc.Invoke(sender, q, "sys:link.Ping", 0); _waiting_on++; } catch { _waiting_on--; } } } }
/// <summary> Attempts to crawl the next address.</summary> protected void CrawlNext(Address addr) { bool finished = false; if(_crawled.ContainsKey(addr)) { finished = true; } else { _crawled.Add(addr, true); try { ISender sender = null; if(Bso != null) { sender = Bso.GetSecureSender(addr); } else { sender = new AHGreedySender(Node, addr); } Channel q = new Channel(1); q.CloseEvent += CrawlHandler; Node.Rpc.Invoke(sender, q, "sys:link.GetNeighbors"); } catch { finished = true; } } if(finished) { Finished(); } }
/** * This dispatches the particular methods this class provides */ public void HandleRpc(ISender caller, string method, IList args, object req_state) { if( method == "GetRttTo" ) { ISender dest = new AHGreedySender(_node, AddressParser.Parse((string)args[0])); EchoSendHandler esh = new EchoSendHandler(_node, dest, req_state); //This will be garbage collected after the request is done: esh.SendEchoRequest(); } else if ( method == "GetRouteTo" ) { DoTraceRouteTo( (AHAddress)AddressParser.Parse((string)args[0]), req_state); } else if ( method == "RecursiveCall" ) { RecursiveCall(args, req_state); } else { throw new AdrException(-32601, "No Handler for method: " + method); } }
/** * Callback function that is invoked when TargetSelector fetches candidate scores in a range. * Initiates connection setup. * Node: All connection messages can be tagged with a token string. This token string is currenly being * used to keep the following information about a shortcut: * 1. The node who initiated the shortcut setup. * 2. The random target near which shortcut was chosen. * @param start address pointing to the start of range to query. * @param score_table list of candidate addresses sorted by score. * @param current currently selected optimal (nullable) */ protected void CreateShortcutCallback(Address start, SortedList score_table, Address current) { if (score_table.Count > 0) { /** * we remember our address and the start of range inside the token. * token is the concatenation of * (a) local node address * (b) random target for the range queried by target selector */ string token = _node.Address + start.ToString(); //connect to the min_target Address min_target = (Address)score_table.GetByIndex(0); ISender send = null; if (start.Equals(min_target)) { //looks like the target selector simply returned our random address #if TRACE if (ProtocolLog.SCO.Enabled) { ProtocolLog.Write(ProtocolLog.SCO, String.Format("SCO local: {0}, Connecting (shortcut) to min_target: {1} (greedy), random_target: {2}.", _node.Address, min_target, start)); } #endif //use a greedy sender send = new AHGreedySender(_node, min_target); } else { #if TRACE if (ProtocolLog.SCO.Enabled) { ProtocolLog.Write(ProtocolLog.SCO, String.Format("SCO local: {0}, Connecting (shortcut) to min_target: {1} (exact), random_target: {2}.", _node.Address, min_target, start)); } #endif //use exact sender send = new AHExactSender(_node, min_target); } ConnectTo(send, min_target, STRUC_SHORT, token); } }
/** * This dispatches the particular methods this class provides */ public void HandleRpc(ISender caller, string method, IList args, object req_state) { if (method == "GetRttTo") { ISender dest = new AHGreedySender(_node, AddressParser.Parse((string)args[0])); EchoSendHandler esh = new EchoSendHandler(_node, dest, req_state); //This will be garbage collected after the request is done: esh.SendEchoRequest(); } else if (method == "GetRouteTo") { DoTraceRouteTo((AHAddress)AddressParser.Parse((string)args[0]), req_state); } else if (method == "RecursiveCall") { RecursiveCall(args, req_state); } else { throw new AdrException(-32601, "No Handler for method: " + method); } }
/** * When a node is out of the range, this method is called. * This method tries to find the nearest node to the middle of range using greedty algorithm. * return list of MapReduceInfo */ private List<MapReduceInfo> GenerateTreeOutRange(AHAddress start, AHAddress end, MapReduceArgs mr_args) { List<MapReduceInfo> retval = new List<MapReduceInfo>(); BigInteger up = start.ToBigInteger(); BigInteger down = end.ToBigInteger(); BigInteger mid_range = (up + down) /2; if (mid_range % 2 == 1) {mid_range = mid_range -1; } AHAddress mid_addr = new AHAddress(mid_range); //if (!mid_addr.IsBetweenFromLeft(start, end) ) { if (!InRange(mid_addr, start, end) ) { mid_range += Address.Half; mid_addr = new AHAddress(mid_range); } ArrayList gen_arg = new ArrayList(); if (NextGreedyClosest(mid_addr) != null ) { AHGreedySender ags = new AHGreedySender(_node, mid_addr); string start_range = start.ToString(); string end_range = end.ToString(); gen_arg.Add(start_range); gen_arg.Add(end_range); MapReduceInfo mr_info = new MapReduceInfo( (ISender) ags, new MapReduceArgs(this.TaskName, mr_args.MapArg, gen_arg, mr_args.ReduceArg)); Log("{0}: {1}, out of range, moving to the closest node to mid_range: {2} to target node, range start: {3}, range end: {4}", this.TaskName, _node.Address, mid_addr, start, end); retval.Add(mr_info); } else { // cannot find a node in the range. } return retval; }
public void Start() { foreach(NodeMapping nm_from in _nodes.Values) { foreach(NodeMapping nm_to in _nodes.Values) { if(nm_from == nm_to) { continue; } ISender sender = null; if(_secure) { sender = nm_from.Sso.GetSecureSender(nm_to.Node.Address); } else { sender = new AHGreedySender(nm_from.Node, nm_to.Node.Address); } Channel q = new Channel(1); q.CloseEvent += Callback; try { nm_from.Node.Rpc.Invoke(sender, q, "sys:link.Ping", 0); _count++; _waiting_on++; } catch { // } catch(Exception e) { // Console.WriteLine(e); } } } }
protected void CrawlNext(Address addr) { bool finished = false; if(_log && _crawled.Count < _count) { Console.WriteLine("Current address: " + addr); } if(_crawled.ContainsKey(addr)) { finished = true; } else { _crawled.Add(addr, true); try { ISender sender = null; if(_bso != null) { sender = _bso.GetSecureSender(addr); } else { sender = new AHGreedySender(_node, addr); } Channel q = new Channel(1); q.CloseEvent += CrawlHandler; _node.Rpc.Invoke(sender, q, "sys:link.GetNeighbors"); } catch(Exception e) { if(_log) { Console.WriteLine("Crawl failed" + e); } finished = true; } } if(finished) { Interlocked.Exchange(ref _done, 1); if(_log) { Console.WriteLine("Crawl stats: {0}/{1}", _crawled.Count, _count); Console.WriteLine("Consistency: {0}/{1}", _consistency, _crawled.Count); Console.WriteLine("Finished in: {0}", (DateTime.UtcNow - _start)); } } }
/// <summary>Starts a test on the specified node.</summary> protected void Invoke(Address addr) { Channel q = new Channel(1); q.CloseEvent += delegate(object send, EventArgs ea) { RpcResult result = null; if(q.Count > 0) { result = q.Dequeue() as RpcResult; } ProcessResults(addr, result); }; AHSender sender = new AHGreedySender(_node, addr); _node.Rpc.Invoke(sender, q, "sys:link.GetNeighbors"); }
/** * Callback function that is invoked when TargetSelector fetches candidate scores in a range. * Initiates connection setup. * Node: All connection messages can be tagged with a token string. This token string is currenly being * used to keep the following information about a shortcut: * 1. The node who initiated the shortcut setup. * 2. The random target near which shortcut was chosen. * @param start address pointing to the start of range to query. * @param score_table list of candidate addresses sorted by score. * @param current currently selected optimal (nullable) */ protected void CreateShortcutCallback(Address start, SortedList score_table, Address current) { if (score_table.Count > 0) { /** * we remember our address and the start of range inside the token. * token is the concatenation of * (a) local node address * (b) random target for the range queried by target selector */ string token = _node.Address + start.ToString(); //connect to the min_target Address min_target = (Address) score_table.GetByIndex(0); ISender send = null; if (start.Equals(min_target)) { //looks like the target selector simply returned our random address if (LogEnabled) { ProtocolLog.Write(ProtocolLog.SCO, String.Format("SCO local: {0}, Connecting (shortcut) to min_target: {1} (greedy), random_target: {2}.", _node.Address, min_target, start)); } //use a greedy sender send = new AHGreedySender(_node, min_target); } else { if (LogEnabled) { ProtocolLog.Write(ProtocolLog.SCO, String.Format("SCO local: {0}, Connecting (shortcut) to min_target: {1} (exact), random_target: {2}.", _node.Address, min_target, start)); } //use exact sender send = new AHExactSender(_node, min_target); } ConnectTo(send, min_target, STRUC_SHORT, token); } }