- add separate encryption enabled mesh to avoid breakage during developement
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_peer.c
index 70b88afe33de59621a5bd647787f594751e38028..515c4b4f0fdae87e218465702fca5530893d6019 100644 (file)
@@ -232,7 +232,7 @@ notify_broken (void *cls,
   struct MeshPeer *peer = cls;
   struct MeshConnection *c = value;
 
-  GMC_notify_broken (c, peer, &my_full_id);
+  GMC_notify_broken (c, peer);
 
   return GNUNET_YES;
 }
@@ -247,13 +247,13 @@ notify_broken (void *cls,
 static void
 core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
-  struct MeshPeer *pi;
+  struct MeshPeer *mp;
   struct MeshPeerPath *path;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer connected\n");
   LOG (GNUNET_ERROR_TYPE_DEBUG, "     %s\n", GNUNET_i2s (&my_full_id));
-  pi = GMP_get (peer);
-  if (myid == pi->id)
+  mp = GMP_get (peer);
+  if (myid == mp->id)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "     (self)\n");
     path = path_new (1);
@@ -262,15 +262,15 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "     %s\n", GNUNET_i2s (peer));
     path = path_new (2);
-    path->peers[1] = pi->id;
-    GNUNET_PEER_change_rc (pi->id, 1);
+    path->peers[1] = mp->id;
+    GNUNET_PEER_change_rc (mp->id, 1);
     GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO);
   }
   path->peers[0] = myid;
   GNUNET_PEER_change_rc (myid, 1);
-  peer_add_path (pi, path, GNUNET_YES);
+  GMP_add_path (mp, path, GNUNET_YES);
 
-  pi->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES);
+  mp->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES);
   return;
 }
 
@@ -332,8 +332,7 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
     sizeof (struct GNUNET_MESH_ACK)},
   {&GMC_handle_poll, GNUNET_MESSAGE_TYPE_MESH_POLL,
     sizeof (struct GNUNET_MESH_Poll)},
-  {&GMC_handle_fwd, GNUNET_MESSAGE_TYPE_MESH_FWD, 0},
-  {&GMC_handle_bck, GNUNET_MESSAGE_TYPE_MESH_BCK, 0},
+  {&GMC_handle_encrypted, GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED, 0},
   {NULL, 0, 0}
 };
 
@@ -774,8 +773,7 @@ queue_destroy (struct MeshPeerQueue *queue, int clear_cls)
       case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
         LOG (GNUNET_ERROR_TYPE_INFO, "destroying a DESTROY message\n");
         /* fall through */
-      case GNUNET_MESSAGE_TYPE_MESH_FWD:
-      case GNUNET_MESSAGE_TYPE_MESH_BCK:
+      case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
       case GNUNET_MESSAGE_TYPE_MESH_ACK:
       case GNUNET_MESSAGE_TYPE_MESH_POLL:
       case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
@@ -872,8 +870,7 @@ queue_send (void *cls, size_t size, void *buf)
     case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
     case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
     case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
-    case GNUNET_MESSAGE_TYPE_MESH_FWD:
-    case GNUNET_MESSAGE_TYPE_MESH_BCK:
+    case GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED:
     case GNUNET_MESSAGE_TYPE_MESH_ACK:
     case GNUNET_MESSAGE_TYPE_MESH_POLL:
       LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1164,6 +1161,7 @@ GMP_queue_unlock (struct MeshPeer *peer, struct MeshConnection *c)
 void
 GMP_init (const struct GNUNET_CONFIGURATION_Handle *c)
 {
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n");
   peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (c, "MESH", "MAX_PEERS",
@@ -1389,6 +1387,7 @@ GMP_is_neighbor (const struct MeshPeer *peer)
 
 /**
  * Create and initialize a new tunnel towards a peer, in case it has none.
+ * In case the peer already has a tunnel, nothing is done.
  *
  * Does not generate any traffic, just creates the local data structures.
  *
@@ -1588,6 +1587,45 @@ GMP_remove_connection (struct MeshPeer *peer,
                                                c);
 }
 
+/**
+ * Start the DHT search for new paths towards the peer: we don't have
+ * enough good connections.
+ *
+ * @param peer Destination peer.
+ */
+void
+GMP_start_search (struct MeshPeer *peer)
+{
+  if (NULL != peer->search_h)
+  {
+    GNUNET_break (0);
+    return;
+  }
+
+  peer->search_h = GMD_search (GMP_get_id (peer), &search_handler, peer);
+}
+
+
+/**
+ * Stop the DHT search for new paths towards the peer: we already have
+ * enough good connections.
+ *
+ * @param peer Destination peer.
+ */
+void
+GMP_stop_search (struct MeshPeer *peer)
+{
+  if (NULL == peer->search_h)
+  {
+    GNUNET_break (0);
+    return;
+  }
+
+  GMD_search_stop (peer->search_h);
+  peer->search_h = NULL;
+}
+
+
 /**
  * Get the Full ID of a peer.
  *