- if(listen_socket[*sock].sa.sa.sa_family == AF_INET6) {
- if(localdiscovery_address.sa.sa_family == AF_INET6) {
- localdiscovery_address.in6.sin6_port = n->prevedge->address.in.sin_port;
- *sa = &localdiscovery_address;
- } else {
- broadcast_ipv6.in6.sin6_port = n->prevedge->address.in.sin_port;
- broadcast_ipv6.in6.sin6_scope_id = listen_socket[*sock].sa.in6.sin6_scope_id;
- *sa = &broadcast_ipv6;
- }
- } else {
- if(localdiscovery_address.sa.sa_family == AF_INET) {
- localdiscovery_address.in.sin_port = n->prevedge->address.in.sin_port;
- *sa = &localdiscovery_address;
- } else {
- broadcast_ipv4.in.sin_port = n->prevedge->address.in.sin_port;
- *sa = &broadcast_ipv4;
+ int i = 0;
+ int j = rand() % n->edge_tree->count;
+ edge_t *candidate = NULL;
+
+ for splay_each(edge_t, e, n->edge_tree) {
+ if(i++ == j) {
+ candidate = e;
+ break;