From: Christian Grothoff Date: Fri, 13 Dec 2013 12:48:34 +0000 (+0000) Subject: allow distance change to communicate changes in network of next hop as well, related... X-Git-Tag: initial-import-from-subversion-38251~5500 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=fdead2414ccf29e4542d17df5eb18b8bb1d9a878;p=oweals%2Fgnunet.git allow distance change to communicate changes in network of next hop as well, related to #3191, but not sure if it fixes it --- diff --git a/src/dv/dv.h b/src/dv/dv.h index b20e0b8ff..e791ed15c 100644 --- a/src/dv/dv.h +++ b/src/dv/dv.h @@ -37,7 +37,7 @@ GNUNET_NETWORK_STRUCT_BEGIN struct GNUNET_DV_ConnectMessage { /** - * Type: GNUNET_MESSAGE_TYPE_TRANSPORT_DV_CONNECT + * Type: #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_CONNECT */ struct GNUNET_MessageHeader header; @@ -47,14 +47,14 @@ struct GNUNET_DV_ConnectMessage uint32_t distance GNUNET_PACKED; /** - * The network the peer is in + * The other peer (at the given distance). */ - uint32_t network GNUNET_PACKED; + struct GNUNET_PeerIdentity peer; /** - * The other peer (at the given distance). + * The network the peer is in */ - struct GNUNET_PeerIdentity peer; + uint32_t network GNUNET_PACKED; }; @@ -69,7 +69,7 @@ struct GNUNET_DV_ConnectMessage struct GNUNET_DV_DisconnectMessage { /** - * Type: GNUNET_MESSAGE_TYPE_TRANSPORT_DV_DISCONNECT + * Type: #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_DISCONNECT */ struct GNUNET_MessageHeader header; @@ -96,7 +96,7 @@ struct GNUNET_DV_DisconnectMessage struct GNUNET_DV_ReceivedMessage { /** - * Type: GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECV + * Type: #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECV */ struct GNUNET_MessageHeader header; @@ -121,7 +121,7 @@ struct GNUNET_DV_ReceivedMessage struct GNUNET_DV_SendMessage { /** - * Type: GNUNET_MESSAGE_TYPE_DV_SEND + * Type: #GNUNET_MESSAGE_TYPE_DV_SEND */ struct GNUNET_MessageHeader header; @@ -145,8 +145,8 @@ struct GNUNET_DV_SendMessage struct GNUNET_DV_AckMessage { /** - * Type: GNUNET_MESSAGE_TYPE_DV_SEND_ACK or - * GNUNET_MESSAGE_TYPE_DV_SEND_NACK. + * Type: #GNUNET_MESSAGE_TYPE_DV_SEND_ACK or + * #GNUNET_MESSAGE_TYPE_DV_SEND_NACK. */ struct GNUNET_MessageHeader header; @@ -170,7 +170,7 @@ struct GNUNET_DV_AckMessage struct GNUNET_DV_DistanceUpdateMessage { /** - * Type: GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED. + * Type: #GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED. */ struct GNUNET_MessageHeader header; @@ -184,6 +184,11 @@ struct GNUNET_DV_DistanceUpdateMessage */ struct GNUNET_PeerIdentity peer; + /** + * The network the peer is in + */ + uint32_t network GNUNET_PACKED; + }; diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c index 229148ae4..13bd39afc 100644 --- a/src/dv/dv_api.c +++ b/src/dv/dv_api.c @@ -371,7 +371,8 @@ handle_message_receipt (void *cls, dum = (const struct GNUNET_DV_DistanceUpdateMessage *) msg; sh->distance_cb (sh->cls, &dum->peer, - ntohl (dum->distance)); + ntohl (dum->distance), + ntohl (dum->network)); break; case GNUNET_MESSAGE_TYPE_DV_DISCONNECT: if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DisconnectMessage)) diff --git a/src/dv/gnunet-dv.c b/src/dv/gnunet-dv.c index 7be154792..dc17e1a64 100644 --- a/src/dv/gnunet-dv.c +++ b/src/dv/gnunet-dv.c @@ -62,11 +62,13 @@ connect_cb (void *cls, * @param cls closure * @param peer connected peer * @param distance new distance to the peer + * @param network network used on first hop to peer */ static void change_cb (void *cls, const struct GNUNET_PeerIdentity *peer, - uint32_t distance) + uint32_t distance, + uint32_t network) { fprintf (stderr, "Change: %s at %u\n", GNUNET_i2s (peer), diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index d5eca28c7..8445ab1f5 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c @@ -512,10 +512,12 @@ send_ack_to_plugin (const struct GNUNET_PeerIdentity *target, * * @param peer peer with a changed distance * @param distance new distance to the peer + * @param network network used by the neighbor */ static void send_distance_change_to_plugin (const struct GNUNET_PeerIdentity *peer, - uint32_t distance) + uint32_t distance, + uint32_t network) { struct GNUNET_DV_DistanceUpdateMessage du_msg; @@ -526,6 +528,7 @@ send_distance_change_to_plugin (const struct GNUNET_PeerIdentity *peer, du_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED); du_msg.distance = htonl (distance); du_msg.peer = *peer; + du_msg.network = htonl (network); send_control_to_plugin (&du_msg.header); } @@ -1045,7 +1048,8 @@ check_possible_route (void *cls, move_route (route, ntohl (target->distance) + 1); route->next_hop = neighbor; send_distance_change_to_plugin (&target->peer, - ntohl (target->distance) + 1); + ntohl (target->distance) + 1, + neighbor->network); } return GNUNET_YES; /* got a route to this target already */ } @@ -1443,7 +1447,9 @@ check_target_added (void *cls, /* distance decreased, update route */ move_route (current_route, ntohl (target->distance) + 1); - send_distance_change_to_plugin (&target->peer, ntohl (target->distance) + 1); + send_distance_change_to_plugin (&target->peer, + ntohl (target->distance) + 1, + neighbor->network); } } return GNUNET_OK; @@ -1461,7 +1467,9 @@ check_target_added (void *cls, move_route (current_route, ntohl (target->distance) + 1); current_route->next_hop = neighbor; - send_distance_change_to_plugin (&target->peer, ntohl (target->distance) + 1); + send_distance_change_to_plugin (&target->peer, + ntohl (target->distance) + 1, + neighbor->network); return GNUNET_OK; } /* new route */ diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index 93792e0d9..f80c2aa33 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c @@ -296,6 +296,7 @@ handle_dv_connect (void *cls, struct Session *session; struct GNUNET_ATS_Information ats[2]; + GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network); /** * This requires transport plugin to be linked to libgnunetats. * If you remove it, also remove libgnunetats linkage from Makefile.am @@ -350,26 +351,28 @@ handle_dv_connect (void *cls, * @param cls closure with `struct Plugin *` * @param peer connected peer * @param distance new distance to the peer + * @param network network type used for the connection */ static void handle_dv_distance_changed (void *cls, const struct GNUNET_PeerIdentity *peer, - uint32_t distance) + uint32_t distance, + uint32_t network) { struct Plugin *plugin = cls; struct Session *session; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message for peer `%s': new distance %u\n", - "DV_DISTANCE_CHANGED", - GNUNET_i2s (peer), distance); - + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received `%s' message for peer `%s': new distance %u\n", + "DV_DISTANCE_CHANGED", + GNUNET_i2s (peer), + distance); session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, peer); if (NULL == session) { GNUNET_break (0); - /* FIXME */ - handle_dv_connect (plugin, peer, distance, 0); + handle_dv_connect (plugin, peer, distance, network); return; } session->distance = distance; diff --git a/src/include/gnunet_dv_service.h b/src/include/gnunet_dv_service.h index 9e49baf57..8ea9b1027 100644 --- a/src/include/gnunet_dv_service.h +++ b/src/include/gnunet_dv_service.h @@ -40,7 +40,8 @@ */ typedef void (*GNUNET_DV_ConnectCallback)(void *cls, const struct GNUNET_PeerIdentity *peer, - uint32_t distance, uint32_t network); + uint32_t distance, + uint32_t network); /** @@ -50,10 +51,12 @@ typedef void (*GNUNET_DV_ConnectCallback)(void *cls, * @param cls closure * @param peer connected peer * @param distance new distance to the peer + * @param network this network will be used to reach the next hop */ typedef void (*GNUNET_DV_DistanceChangedCallback)(void *cls, const struct GNUNET_PeerIdentity *peer, - uint32_t distance); + uint32_t distance, + uint32_t network); /**