allow distance change to communicate changes in network of next hop as well, related...
authorChristian Grothoff <christian@grothoff.org>
Fri, 13 Dec 2013 12:48:34 +0000 (12:48 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 13 Dec 2013 12:48:34 +0000 (12:48 +0000)
src/dv/dv.h
src/dv/dv_api.c
src/dv/gnunet-dv.c
src/dv/gnunet-service-dv.c
src/dv/plugin_transport_dv.c
src/include/gnunet_dv_service.h

index b20e0b8ffe0a6ee611af2efc8e3271d7f267bf5e..e791ed15ccadcd81ed938a7d5a0969958e3de2b6 100644 (file)
@@ -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;
+
 };
 
 
index 229148ae4eae98c3bb804d23491322a71b5170bc..13bd39afcda022947feebb8e761e3f57b2052b2c 100644 (file)
@@ -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))
index 7be154792eceeac09d5d9a744395ac1fc1c3c9af..dc17e1a642569ed3867d279c29af2aede80e2e4d 100644 (file)
@@ -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),
index d5eca28c70715c65a4c494b97a3685052f7d14bb..8445ab1f57c6e89000aff865f2798dbcd0832043 100644 (file)
@@ -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 */
index 93792e0d99cda71a18f2fb7039cfec2970b70aa1..f80c2aa339d7d9676ec8d083dd97ab42a8989dc6 100644 (file)
@@ -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;
index 9e49baf5722b39b791544abc583d4a18b4dd0137..8ea9b10277216be610e08feaf1db405b201e797f 100644 (file)
@@ -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);
 
 
 /**