add code to enable checking if transport's idea of our peer identity matches that...
authorChristian Grothoff <christian@grothoff.org>
Wed, 21 Jul 2010 20:48:40 +0000 (20:48 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 21 Jul 2010 20:48:40 +0000 (20:48 +0000)
15 files changed:
TODO
src/core/gnunet-service-core.c
src/core/test_core_api.c
src/core/test_core_api_reliability.c
src/dht/gnunet-service-dht.c
src/hostlist/hostlist-client.c
src/hostlist/test_gnunet_daemon_hostlist.c
src/include/gnunet_transport_service.h
src/testing/testing.c
src/topology/gnunet-daemon-topology.c
src/transport/gnunet-service-transport.c
src/transport/test_transport_api.c
src/transport/test_transport_api_reliability.c
src/transport/transport.h
src/transport/transport_api.c

diff --git a/TODO b/TODO
index 747548f232b83d0e975831740fc3db882eea1e59..4511ae209cfade802c7227d16c55eeeccc904ce1 100644 (file)
--- a/TODO
+++ b/TODO
 * DHT: [Nate]
   - implement DHT service 
   - implement performance tests
-* FS: [CG]
-  - service:
-    + trust: do not charge when "idle" / load considerations (migration, routing)
-    + artificial delays
-    + active reply route caching design & implementation; gap extension!
-  - non-anonymous FS service (needs DHT)
-    + DHT integration for search
-    + CS-DHT-functions (DHT-put of LOC)
-    + P2P-functions (DHT-get)
 * GNUNET-GTK: [CG]
   - implement publish dialog details:
     + open (import directory structure)
   - datacache
   - datastore
 * FS: [CG]
-  - reconstruct IBLOCKS from DBLOCKS if possible (during download; see FIXME in fs_download)
-  - add support for pushing "already seen" search results to FS service for bloomfilter (can wait)
-  - use different 'priority' for probe downloads vs. normal downloads
+  - library:
+    + reconstruct IBLOCKS from DBLOCKS if possible (during download; see FIXME in fs_download)
+    + add support for pushing "already seen" search results to FS service for bloomfilter (can wait)
+    + use different 'priority' for probe downloads vs. normal downloads
+  - service:
+    + trust: do not charge when "idle" / load considerations (migration, routing)
+    + artificial delays
+    + active reply route caching design & implementation; gap extension!
+  - non-anonymous FS service (needs DHT)
+    + DHT integration for search
+    + CS-DHT-functions (DHT-put of LOC)
+    + P2P-functions (DHT-get)
   - implement FS performance tests
     + insert
     + download
index df3342ce061ad14291b7d040918d4c05ad78cc21..2ad197e58c15b3258b340b117c7d2e3212b8b623 100644 (file)
@@ -3878,6 +3878,7 @@ run (void *cls,
   /* setup transport connection */
   transport = GNUNET_TRANSPORT_connect (sched,
                                         cfg,
+                                       &my_identity,
                                         NULL,
                                         &handle_transport_receive,
                                         &handle_transport_notify_connect,
index ad82d0a1da0c4171c7316a1a82ab74b3f46a0475..b04430eea6d74eb6464df22c3c2561d675351359 100644 (file)
@@ -297,7 +297,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
                                         "-c", cfgname, NULL);
 #endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
-  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, NULL, NULL);
+  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, NULL, p, NULL, NULL, NULL);
   GNUNET_assert (p->th != NULL);
   GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
 }
index e8e1ad0f60feeb9d7d54dda63a0a7572f42c666b..b9fba21c62e9e2e04a8c776da3a2a378bb121999 100644 (file)
@@ -444,7 +444,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
                                         "-c", cfgname, NULL);
 #endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
-  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, NULL, NULL);
+  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, NULL, p, NULL, NULL, NULL);
   GNUNET_assert (p->th != NULL);
   GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
 }
index 9cd4c2909b542f85d196d3bc45cdb558cd3ac4c4..31ceff7735475b7a50ad4c6e3e9c898e067063bf 100644 (file)
@@ -2445,7 +2445,8 @@ run (void *cls,
 
   if (coreAPI == NULL)
     return;
-  transport_handle = GNUNET_TRANSPORT_connect(sched, cfg, NULL, NULL, NULL, NULL);
+  transport_handle = GNUNET_TRANSPORT_connect(sched, cfg, 
+                                             NULL, NULL, NULL, NULL, NULL);
   if (transport_handle != NULL)
     GNUNET_TRANSPORT_get_hello (transport_handle, &process_hello, NULL);
   else
index 26b68390cc289ef436894897c5f61f04b14a2a07..b4d86e052d8ae12db91bde90e1b768bf4ed4e196 100644 (file)
@@ -1528,7 +1528,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c,
       GNUNET_break (0);
       return GNUNET_SYSERR;
     }
-  transport = GNUNET_TRANSPORT_connect (s, c, NULL, NULL, NULL, NULL);
+  transport = GNUNET_TRANSPORT_connect (s, c, NULL, NULL, NULL, NULL, NULL);
   if (NULL == transport)
     {
       curl_global_cleanup ();
index 85138ebf11e05bc727efbcc63dbf1ec2a6d9ef08..899a2eb44fca6b7313303da755ef5d960d5e8170 100644 (file)
@@ -143,7 +143,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
                                         "-c", cfgname, NULL);
 #endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
-  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, 
+  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, NULL, p, NULL, 
                                    &notify_connect, NULL);
   GNUNET_assert (p->th != NULL);
   GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
index 7cb4df5a69c3ddec0ac971b00ce84ad4e0ceca61..2ee9fb71810cf3054aba1590f35a0d4c2561923f 100644 (file)
@@ -120,6 +120,8 @@ typedef void
  *
  * @param sched scheduler to use
  * @param cfg configuration to use
+ * @param self our own identity (API should check that it matches
+ *             the identity found by transport), or NULL (no check)
  * @param cls closure for the callbacks
  * @param rec receive function to call
  * @param nc function to call on connect events
@@ -131,7 +133,9 @@ struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (struct
                                                           *sched,
                                                           const struct
                                                           GNUNET_CONFIGURATION_Handle
-                                                          *cfg, void *cls,
+                                                          *cfg, 
+                                                         const struct GNUNET_PeerIdentity *self,
+                                                         void *cls,
                                                           GNUNET_TRANSPORT_ReceiveCallback
                                                           rec,
                                                           GNUNET_TRANSPORT_NotifyConnect
index d12892fcc1b2c60efa90814566aef1294ab99b7a..3bc6c98da00d6b8e5029e9707abc77beb8ec5f95 100644 (file)
@@ -161,7 +161,9 @@ testing_init (void *cls,
 
 
   d->th = GNUNET_TRANSPORT_connect (d->sched,
-                                    d->cfg, d, NULL, NULL, NULL);
+                                    d->cfg, 
+                                   &d->id,
+                                   d, NULL, NULL, NULL);
   if (d->th == NULL)
     {
       if (GNUNET_YES == d->dead)
@@ -1402,7 +1404,9 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
 #endif
 
   ctx->d2th = GNUNET_TRANSPORT_connect (d2->sched,
-                                        d2->cfg, d2, NULL, NULL, NULL);
+                                        d2->cfg, 
+                                       &d2->id,
+                                       d2, NULL, NULL, NULL);
   if (ctx->d2th == NULL)
     {
       GNUNET_CORE_disconnect(ctx->d1core);
@@ -1455,7 +1459,9 @@ reattempt_daemons_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext
     }
 
   ctx->d2th = GNUNET_TRANSPORT_connect (ctx->d2->sched,
-                                        ctx->d2->cfg, ctx->d2, NULL, NULL, NULL);
+                                        ctx->d2->cfg, 
+                                       &ctx->d2->id,
+                                       ctx->d2, NULL, NULL, NULL);
   if (ctx->d2th == NULL)
     {
       GNUNET_CORE_disconnect(ctx->d1core);
index d39c89d36514ccc5b12ca3fdede0f44d2fcebc65..3686f20184ad053b1b715a1827c94a6a17eef7e8 100644 (file)
@@ -1395,6 +1395,7 @@ run (void *cls,
                                        NULL,
                                        NULL,
                                        NULL,
+                                       NULL,
                                        NULL);
   handle = GNUNET_CORE_connect (sched,
                                cfg,
index 0d33ac5ca6ad27e7dd62c14e7fcd22f28039afaf..c1dc60fd0e699d5c5f598e2f98f69f0b7c0cf858 100644 (file)
@@ -4673,10 +4673,12 @@ handle_start (void *cls,
               struct GNUNET_SERVER_Client *client,
               const struct GNUNET_MessageHeader *message)
 {
+  const struct StartMessage *start;
   struct TransportClient *c;
   struct ConnectInfoMessage cim;
   struct NeighbourList *n;
 
+  start = (const struct StartMessage*) message;
 #if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received `%s' request from client\n", "START");
@@ -4693,6 +4695,17 @@ handle_start (void *cls,
         }
       c = c->next;
     }
+  if ( (GNUNET_NO != ntohl (start->do_check)) &&
+       (0 != memcmp (&start->self,
+                    &my_identity,
+                    sizeof (struct GNUNET_PeerIdentity))) )
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 _("Rejecting control connection from peer `%s', which is not me!\n"),
+                 GNUNET_i2s (&start->self));
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+      return;      
+    }
   c = GNUNET_malloc (sizeof (struct TransportClient));
   c->next = clients;
   clients = c;
@@ -5239,7 +5252,7 @@ run (void *cls,
 {
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
     {&handle_start, NULL,
-     GNUNET_MESSAGE_TYPE_TRANSPORT_START, 0},
+     GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
     {&handle_hello, NULL,
      GNUNET_MESSAGE_TYPE_HELLO, 0},
     {&handle_send, NULL,
index 52b9282deda2fc2064cc049fa13fe2a4442d8f36..7aa81bff860982b3c99190310b67bb44d9d29832 100644 (file)
@@ -220,7 +220,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
 
   p->th = GNUNET_TRANSPORT_connect (sched, p->cfg,
-                                    p,
+                                    NULL, p,
                                     &notify_receive,
                                     &notify_connect, &notify_disconnect);
   GNUNET_assert (p->th != NULL);
index dc4867f84312b9aba587526bcc33eb3a424597c0..c86b582b9ac41c00ecc9a0f461e42a8c9ca14a2d 100644 (file)
@@ -366,7 +366,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
                                         "-c", cfgname, NULL);
 #endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
-  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg,
+  p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, NULL,
                                     p,
                                     &notify_receive,
                                     &notify_connect, 
index 0f2d5c6c9acf3d52553fc80647089358ea624f2a..aa934c944e9dac8c4eebca1a8887e40003a30463 100644 (file)
  */
 #define MIN_QUOTA_REFRESH_TIME 2000
 
+/**
+ * Message from the transport service to the library
+ * asking to check if both processes agree about this
+ * peers identity.
+ */
+struct StartMessage
+{
+
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_START
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Should the 'self' field be checked?
+   */
+  uint32_t do_check;
+
+  /**
+   * Identity we think we have.  If it does not match, the
+   * receiver should print out an error message and disconnect.
+   */
+  struct GNUNET_PeerIdentity self;
+
+};
+
+
 /**
  * Message from the transport service to the library
  * informing about neighbors.
index eb8868d9861008da3e29b30fb2f75ac791dc1548..db96d1800d5786af8ccc8c8300986d8c23f250af 100644 (file)
@@ -278,7 +278,7 @@ struct GNUNET_TRANSPORT_Handle
   /**
    * Closure for the callbacks.
    */
-  void *cls;
+  void *cls;  
 
   /**
    * Function to call for received data.
@@ -341,6 +341,11 @@ struct GNUNET_TRANSPORT_Handle
    */
   struct NeighbourList *neighbours;
 
+  /**
+   * Peer identity as assumed by this process, or all zeros.
+   */
+  struct GNUNET_PeerIdentity self;
+
   /**
    * ID of the task trying to reconnect to the service.
    */
@@ -363,6 +368,11 @@ struct GNUNET_TRANSPORT_Handle
    */
   int in_disconnect;
 
+  /**
+   * Should we check that 'self' matches what the service thinks?
+   * (if GNUNET_NO, then 'self' is all zeros!).
+   */
+  int check_self;
 };
 
 
@@ -1038,7 +1048,8 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
 static size_t
 send_start (void *cls, size_t size, void *buf)
 {
-  struct GNUNET_MessageHeader *s = buf;
+  struct GNUNET_TRANSPORT_Handle *h = cls;
+  struct StartMessage s;
 
   if (buf == NULL)
     {
@@ -1054,10 +1065,13 @@ send_start (void *cls, size_t size, void *buf)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Transmitting `%s' request.\n", "START");
 #endif
-  GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
-  s->size = htons (sizeof (struct GNUNET_MessageHeader));
-  s->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START);
-  return sizeof (struct GNUNET_MessageHeader);
+  GNUNET_assert (size >= sizeof (struct StartMessage));
+  s.header.size = htons (sizeof (struct StartMessage));
+  s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START);
+  s.do_check = htonl (h->check_self);
+  s.self = h->self;
+  memcpy (buf, &s, sizeof (struct StartMessage));
+  return sizeof (struct StartMessage);
 }
 
 
@@ -1192,9 +1206,9 @@ reconnect (void *cls,
       pos = pos->next;
     }
   schedule_control_transmit (h,
-                             sizeof (struct GNUNET_MessageHeader),
+                             sizeof (struct StartMessage),
                              GNUNET_YES,
-                             GNUNET_TIME_UNIT_FOREVER_REL, &send_start, NULL);
+                             GNUNET_TIME_UNIT_FOREVER_REL, &send_start, h);
   GNUNET_CLIENT_receive (h->client,
                          &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL);
 }
@@ -1274,6 +1288,8 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
  *
  * @param sched scheduler to use
  * @param cfg configuration to use
+ * @param self our own identity (API should check that it matches
+ *             the identity found by transport), or NULL (no check)
  * @param cls closure for the callbacks
  * @param rec receive function to call
  * @param nc function to call on connect events
@@ -1282,6 +1298,7 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
 struct GNUNET_TRANSPORT_Handle *
 GNUNET_TRANSPORT_connect (struct GNUNET_SCHEDULER_Handle *sched,
                           const struct GNUNET_CONFIGURATION_Handle *cfg,
+                         const struct GNUNET_PeerIdentity *self,
                           void *cls,
                           GNUNET_TRANSPORT_ReceiveCallback rec,
                           GNUNET_TRANSPORT_NotifyConnect nc,
@@ -1290,6 +1307,11 @@ GNUNET_TRANSPORT_connect (struct GNUNET_SCHEDULER_Handle *sched,
   struct GNUNET_TRANSPORT_Handle *ret;
 
   ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle));
+  if (self != NULL)
+    {
+      ret->self = *self;
+      ret->check_self = GNUNET_YES;
+    }
   ret->sched = sched;
   ret->cfg = cfg;
   ret->cls = cls;