/** Greedy routing. gen_arg is the Address of the destination */ public override void GenerateTree(Channel q, MapReduceArgs mr_args) { object gen_arg = mr_args.GenArg; Log("{0}: {1}, greedy generator called, arg: {2}.", this.TaskName, _node.Address, gen_arg); string address = gen_arg as string; AHAddress a = (AHAddress)AddressParser.Parse(address); ArrayList retval = new ArrayList(); ConnectionTable tab = _node.ConnectionTable; ConnectionList structs = tab.GetConnections(ConnectionType.Structured); Connection next_closest = structs.GetNearestTo((AHAddress)_node.Address, a); if (next_closest != null) { //arguments do not change at all MapReduceInfo mr_info = new MapReduceInfo(next_closest.Edge, mr_args); retval.Add(mr_info); } Log("{0}: {1}, greedy generator returning: {2} senders.", this.TaskName, _node.Address, retval.Count); //Send the result: q.Enqueue(retval.ToArray(typeof(MapReduceInfo))); }
/** * Recursive function to compute the latency of an Rpc call * by accumulating measured latencies of individual hops. * @param target address of the target */ public void ComputePathLatencyTo(AHAddress a, object req_state) { /* * First find the Connection pointing to the node closest to dest, if * there is one closer than us */ ConnectionTable tab = _node.ConnectionTable; ConnectionList structs = tab.GetConnections(ConnectionType.Structured); Connection next_closest = structs.GetNearestTo((AHAddress)_node.Address, a); //Okay, we have the next closest: ListDictionary my_entry = new ListDictionary(); my_entry["node"] = _node.Address.ToString(); if (next_closest != null) { my_entry["next_latency"] = GetMeasuredLatency(next_closest.Address); my_entry["next_contype"] = next_closest.ConType; Channel result = new Channel(); //We only want one result, so close the queue after we get the first result.CloseAfterEnqueue(); result.CloseEvent += delegate(object o, EventArgs args) { Channel q = (Channel)o; if (q.Count > 0) { try { RpcResult rres = (RpcResult)q.Dequeue(); IList l = (IList)rres.Result; ArrayList results = new ArrayList(l.Count + 1); results.Add(my_entry); results.AddRange(l); _rpc.SendResult(req_state, results); } catch (Exception x) { string m = String.Format("<node>{0}</node> trying <connection>{1}</connection> got <exception>{2}</exception>", _node.Address, next_closest, x); Exception nx = new Exception(m); _rpc.SendResult(req_state, nx); } } else { //We got no results. IList l = new ArrayList(1); l.Add(my_entry); _rpc.SendResult(req_state, l); } }; _rpc.Invoke(next_closest.Edge, result, "ncserver.ComputePathLatencyTo", a.ToString()); } else { //We are the end of the line, send the result: ArrayList l = new ArrayList(); l.Add(my_entry); _rpc.SendResult(req_state, l); } }
/// <summary>Returns our nearest neighbors to the specified address, which /// is in turn used to help communicate with tunnel peer.</summary> public static List <Address> GetNearest(Address addr, ConnectionList cons) { ConnectionList cons_near = cons.GetNearestTo(addr, 16); List <Address> addrs = new List <Address>(); foreach (Connection con in cons_near) { addrs.Add(con.Address); } return(addrs); }
protected Connection NextGreedyClosest(AHAddress dest) { /* * First find the Connection pointing to the node closest * from local to dest, * if there is one closer than us */ ConnectionTable tab = _node.ConnectionTable; ConnectionList structs = tab.GetConnections(ConnectionType.Structured); AHAddress local = (AHAddress)_node.Address; Connection next_closest = structs.GetNearestTo(local, dest); return(next_closest); }
/** * This is a recursive function over the network * It helps do a link-reliable procedure call on the * on the overlay network. */ protected void RecursiveCall(IList margs, object req_state) { //first argument is the target node. AHAddress a = (AHAddress)AddressParser.Parse((string)margs[0]); /* * First find the Connection pointing to the node closest to dest, if * there is one closer than us */ ConnectionTable tab = _node.ConnectionTable; ConnectionList structs = tab.GetConnections(ConnectionType.Structured); Connection next_closest = structs.GetNearestTo((AHAddress)_node.Address, a); //Okay, we have the next closest: if (next_closest != null) { Channel result = new Channel(); //We only want one result, so close the queue after we get the first result.CloseAfterEnqueue(); result.CloseEvent += delegate(object o, EventArgs args) { Channel q = (Channel)o; if (q.Count > 0) { try { RpcResult rres = (RpcResult)q.Dequeue(); _rpc.SendResult(req_state, rres.Result); } catch (Exception x) { string m = String.Format("<node>{0}</node> trying <connection>{1}</connection> got <exception>{2}</exception>", _node.Address, next_closest, x); Exception nx = new Exception(m); _rpc.SendResult(req_state, nx); } } else { //We got no results. _rpc.SendResult(req_state, null); } }; object [] new_args = new object[margs.Count]; margs.CopyTo(new_args, 0); _rpc.Invoke(next_closest.State.Edge, result, "trace.RecursiveCall", new_args); } else { //We are the end of the line, send the result: //Console.Error.WriteLine("Doing a local invocation"); Channel result = new Channel(); result.CloseAfterEnqueue(); result.CloseEvent += delegate(object o, EventArgs args) { Channel q = (Channel)o; if (q.Count > 0) { try { //Console.Error.WriteLine("Got result."); RpcResult rres = (RpcResult)q.Dequeue(); _rpc.SendResult(req_state, rres.Result); } catch (Exception x) { string m = String.Format("<node>{0}</node> local invocation got <exception>{1}</exception>", _node.Address, x); Exception nx = new Exception(m); _rpc.SendResult(req_state, nx); } } else { //We got no results. _rpc.SendResult(req_state, null); } }; string method_name = (string)margs[1]; object [] new_args = new object[margs.Count - 2]; margs.RemoveAt(0); //extract destination address margs.RemoveAt(0); //extract method name margs.CopyTo(new_args, 0); //Console.Error.WriteLine("Calling method: {0}, args_count: {1}", method_name, new_args.Length); //for (int i = 0; i < new_args.Length; i++) { //Console.Error.WriteLine(new_args[i]); //} _rpc.Invoke(_node, result, method_name, new_args); } }
/// <summary>Returns our nearest neighbors to the specified address, which /// is in turn used to help communicate with tunnel peer.</summary> public static List<Address> GetNearest(Address addr, ConnectionList cons) { ConnectionList cons_near = cons.GetNearestTo(addr, 16); List<Address> addrs = new List<Address>(); foreach(Connection con in cons_near) { addrs.Add(con.Address); } return addrs; }