/** * 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); } }
// Provides an Exact AH Secure Sender using the default SPI given an address public SecurityAssociation GetSecureSender(Address target) { SecurityAssociation sa = null; bool new_sa = false; lock(_sync) { if(_address_to_sa.ContainsKey(target)) { sa = _address_to_sa[target]; } else { AHSender sender = new AHExactSender(_node, target); sa = base.CreateSecurityAssociation(sender, SecurityPolicy.DefaultSPI); _address_to_sa[target] = sa; _sa_to_address[sa] = target; new_sa = true; } } if(new_sa) { StartSA(sa); } return sa; }
protected void CreateSecurityAssociation() { var sender = new AHExactSender(Node0.Node, Node1.Node.Address); var sa = Node0.Sso.CreateSecurityAssociation(sender); SecurityAssociation.StateChangeHandler callback = delegate(SecurityAssociation in_sa, SecurityAssociation.States state) { if(state == SecurityAssociation.States.Active) { SecurityAssociationEstablished(); } else if(state == SecurityAssociation.States.Closed) { Finished(); } else { Console.WriteLine(state); } }; if(sa.State != SecurityAssociation.States.Waiting) { callback(sa, sa.State); } else { sa.StateChangeEvent += callback; } }
/** * 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); } }