public override Pair<Connection, bool> NextConnection(Edge from, AHHeader head) {
Address dest = head.Destination;
int d_idx = _structs.IndexOf(dest);
Connection next_con;
if( d_idx >= 0 ) {
//We have a direct connection:
next_con = _structs[d_idx];
}
else {
//We have to check the right and the left:
var ah_dest = (AHAddress)dest;
int left_idx = ~d_idx;
Connection l_c = _structs[left_idx];
int right_idx = left_idx - 1;
Connection r_c = _structs[right_idx];
if( ah_dest.IsCloserToFirst((AHAddress)l_c.Address, (AHAddress)r_c.Address) ) {
next_con = l_c;
}
else {
next_con = r_c;
}
/*
* Note, DO NOT DO COMPARISONS WITH INDEX VALUES!!!!!
* do the the wrap around, _structs[x] == _structs[y]
* when x = y + k * _structs.Count for all k, so equality
* of Connection is not the same as equality of index
*/
if( head.Hops >= head.Ttl ) {
//Only deliver if we are the closest or last mode:
bool local = next_con == _local_con || head.Opts == AHHeader.Options.Last;
if( local ) {
return _LOCAL;
}
else {
return _NO_ONE;
}
}
}
return next_con == _local_con ? _LOCAL : new Pair<Connection, bool>(next_con, false);
}
}