+ if(n->status.udp_confirmed) {
+ /* Address of this node is confirmed, so use it. */
+ sa = &n->address;
+ sock = n->sock;
+ } else {
+ /* Otherwise, go through the list of known addresses of
+ this node. The first address we try is always the
+ one in n->address; that could be set to the node's
+ reflexive UDP address discovered during key
+ exchange. The other known addresses are those found
+ in edges to this node. */
+
+ static unsigned int i;
+ int j = 0;
+ edge_t *candidate = NULL;
+
+ if(i) {
+ for splay_each(edge_t, e, edge_weight_tree) {
+ if(e->to != n)
+ continue;
+ j++;
+ if(!candidate || j == i)
+ candidate = e;
+ }
+ }
+
+ if(!candidate) {
+ sa = &n->address;
+ sock = n->sock;
+ } else {
+ sa = &candidate->address;
+ sock = rand() % listen_sockets;
+ }
+
+ if(i++)
+ if(i > j)
+ i = 0;
+ }