Improve UDP address selection.
We don't need to search the whole edge tree, we can use the node's own edge tree since each edge has a pointer to its reverse. Also, we do need to make sure we try the reflexive address often.
This commit is contained in:
parent
f57129ce34
commit
3c1b704733
1 changed files with 16 additions and 12 deletions
|
|
@ -447,24 +447,28 @@ static void choose_udp_address(const node_t *n, const sockaddr_t **sa, int *sock
|
||||||
if(n->status.udp_confirmed)
|
if(n->status.udp_confirmed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Otherwise, go through the list of known addresses of
|
/* Send every third packet to n->address; that could be set
|
||||||
this node. The first address we try is always the
|
to the node's reflexive UDP address discovered during key
|
||||||
one in n->address; that could be set to the node's
|
exchange. */
|
||||||
reflexive UDP address discovered during key
|
|
||||||
exchange. The other known addresses are those found
|
|
||||||
in edges to this node. */
|
|
||||||
|
|
||||||
|
static int x = 0;
|
||||||
|
if(++x >= 3) {
|
||||||
|
x = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, address are found in edges to this node.
|
||||||
|
So we pick a random edge and a random socket. */
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = rand() % n->edge_tree->count;
|
int j = rand() % n->edge_tree->count;
|
||||||
edge_t *candidate = NULL;
|
edge_t *candidate = NULL;
|
||||||
|
|
||||||
for splay_each(edge_t, e, edge_weight_tree) {
|
for splay_each(edge_t, e, n->edge_tree) {
|
||||||
if(e->to != n)
|
if(i++ == j) {
|
||||||
continue;
|
candidate = e->reverse;
|
||||||
i++;
|
break;
|
||||||
if(!candidate || i == j)
|
}
|
||||||
candidate = e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(candidate) {
|
if(candidate) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue