gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r12818 - in gnunet/src: include transport


From: gnunet
Subject: [GNUnet-SVN] r12818 - in gnunet/src: include transport
Date: Fri, 3 Sep 2010 17:28:43 +0200

Author: nevans
Date: 2010-09-03 17:28:43 +0200 (Fri, 03 Sep 2010)
New Revision: 12818

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/transport/gnunet-service-transport.c
   gnunet/src/transport/transport.h
   gnunet/src/transport/transport_api.c
Log:
making core request connect work

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2010-09-03 12:11:11 UTC (rev 
12817)
+++ gnunet/src/include/gnunet_protocols.h       2010-09-03 15:28:43 UTC (rev 
12818)
@@ -185,6 +185,12 @@
 #define GNUNET_MESSAGE_TYPE_TRANSPORT_PONG 33
 
 /**
+ * Message for TRANSPORT asking that a connection
+ * be initiated with a peer.
+ */
+#define GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT 34
+
+/**
  * Request update and listing of a peer.
  */
 #define GNUNET_MESSAGE_TYPE_PEERINFO_GET 37

Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2010-09-03 12:11:11 UTC 
(rev 12817)
+++ gnunet/src/transport/gnunet-service-transport.c     2010-09-03 15:28:43 UTC 
(rev 12818)
@@ -43,7 +43,7 @@
 
 #define DEBUG_PING_PONG GNUNET_NO
 
-#define DEBUG_TRANSPORT_HELLO GNUNET_NO
+#define DEBUG_TRANSPORT_HELLO GNUNET_YES
 
 /**
  * Should we do some additional checks (to validate behavior
@@ -2625,7 +2625,7 @@
   fal = find_peer_address (n, tname, NULL, addr, addrlen);
   if (fal == NULL)
     {
-#if DEBUG_TRANSPORT
+#if DEBUG_TRANSPORT_HELLO
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data 
for %llums.\n",
                  a2s (tname, addr, addrlen),
@@ -2656,7 +2656,7 @@
     }
   if (fal == NULL)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                  "Failed to add new address for `%4s'\n",
                  GNUNET_i2s (&n->id));
       return GNUNET_OK;
@@ -3028,13 +3028,16 @@
   n = find_neighbour(peer);
   if (n != NULL)
     {
-      cont (cont_cls, n);
+      if (cont != NULL)
+        cont (cont_cls, n);
       return;
     }
   if (bl_head == NULL)
     {
-      cont (cont_cls,
-           setup_new_neighbour (peer, do_hello));
+      if (cont != NULL)
+        cont (cont_cls, setup_new_neighbour (peer, do_hello));
+      else
+        setup_new_neighbour(peer, do_hello);
       return;
     }
   bc = GNUNET_malloc (sizeof (struct BlacklistCheck));
@@ -3414,7 +3417,7 @@
     }
 
 #if DEBUG_TRANSPORT
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Received message of type %u and size %u from `%4s', sending to 
all clients.\n",
              ntohs (message->type),
              ntohs (message->size),
@@ -4026,7 +4029,7 @@
                                             NULL);
          GNUNET_PEERINFO_add_peer (peerinfo, plain_hello);
          GNUNET_free (plain_hello);
-#if DEBUG_TRANSPORT
+#if DEBUG_TRANSPORT_HELLO
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                      "PEERINFO had no `%s' message for peer `%4s', full 
validation needed.\n",
                      "HELLO",
@@ -4060,7 +4063,7 @@
     }
   if (h == NULL)
     return;
-#if DEBUG_TRANSPORT
+#if DEBUG_TRANSPORT_HELLO
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "PEERINFO had `%s' message for peer `%4s', validating only new 
addresses.\n",
              "HELLO",
@@ -4070,6 +4073,11 @@
   n = find_neighbour (peer);
   if (n != NULL)
     {
+#if DEBUG_TRANSPORT_HELLO
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Calling hello_iterate_addresses for %s!\n",
+                  GNUNET_i2s (peer));
+#endif
       GNUNET_HELLO_iterate_addresses (h,
                                      GNUNET_NO,
                                      &add_to_foreign_address_list,
@@ -4078,6 +4086,11 @@
     }
   else
     {
+#if DEBUG_TRANSPORT_HELLO
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "No existing neighbor record for %s!\n",
+                  GNUNET_i2s (peer));
+#endif
       GNUNET_STATISTICS_update (stats,
                                gettext_noop ("# no existing neighbour record 
(validating HELLO)"),
                                1,
@@ -4159,6 +4172,13 @@
                       sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
                       &target.hashPubKey);
 
+#if DEBUG_TRANSPORT_HELLO
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received `%s' message for `%4s'\n",
+              "HELLO",
+              GNUNET_i2s (&target));
+#endif
+
   if (0 == memcmp (&my_identity,
                   &target,
                   sizeof (struct GNUNET_PeerIdentity)))
@@ -4952,13 +4972,13 @@
   obm = (const struct OutboundMessage *) message;
   obmm = (const struct GNUNET_MessageHeader *) &obm[1];
   msize = size - sizeof (struct OutboundMessage);
-#if DEBUG_TRANSPORT
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received `%s' request from client with target `%4s' and message 
of type %u and size %u\n",
               "SEND", GNUNET_i2s (&obm->peer),
               ntohs (obmm->type),
               msize);
-#endif
+
   tcmc = GNUNET_malloc (sizeof (struct TransmitClientMessageContext) + msize);
   tcmc->client = client;
   tcmc->priority = ntohl (obm->priority);
@@ -4974,6 +4994,31 @@
 
 
 /**
+ * Handle request connect message
+ *
+ * @param cls closure (always NULL)
+ * @param client identification of the client
+ * @param message the actual message
+ */
+static void
+handle_request_connect (void *cls,
+                        struct GNUNET_SERVER_Client *client,
+                        const struct GNUNET_MessageHeader *message)
+{
+  const struct TransportRequestConnectMessage *trcm =
+    (const struct TransportRequestConnectMessage *) message;
+
+  GNUNET_STATISTICS_update (stats,
+                            gettext_noop ("# REQUEST CONNECT messages 
received"),
+                            1,
+                            GNUNET_NO);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received a request connect message for 
peer %s\n", GNUNET_i2s(&trcm->peer));
+  setup_peer_check_blacklist (&trcm->peer, GNUNET_YES,
+                              NULL, NULL);
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+/**
  * Handle SET_QUOTA-message.
  *
  * @param cls closure (always NULL)
@@ -5373,6 +5418,8 @@
      GNUNET_MESSAGE_TYPE_HELLO, 0},
     {&handle_send, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
+    {&handle_request_connect, NULL,
+     GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof(struct 
TransportRequestConnectMessage)},
     {&handle_set_quota, NULL,
      GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
     {&handle_address_lookup, NULL,

Modified: gnunet/src/transport/transport.h
===================================================================
--- gnunet/src/transport/transport.h    2010-09-03 12:11:11 UTC (rev 12817)
+++ gnunet/src/transport/transport.h    2010-09-03 15:28:43 UTC (rev 12818)
@@ -127,7 +127,25 @@
 
 };
 
+/**
+ * Message type for sending a request connect message
+ * to the transport service.  Must be done before transport
+ * api will allow messages to be queued/sent to transport
+ * service for transmission to a peer.
+ */
+struct TransportRequestConnectMessage
+{
+  /**
+   *  Message header
+   */
+  struct GNUNET_MessageHeader header;
 
+  /**
+   * Identity of the peer we would like to connect to.
+   */
+  struct GNUNET_PeerIdentity peer;
+};
+
 /**
  * Message used to set a particular bandwidth quota.  Send TO the
  * service to set an incoming quota, send FROM the service to update

Modified: gnunet/src/transport/transport_api.c
===================================================================
--- gnunet/src/transport/transport_api.c        2010-09-03 12:11:11 UTC (rev 
12817)
+++ gnunet/src/transport/transport_api.c        2010-09-03 15:28:43 UTC (rev 
12818)
@@ -456,6 +456,9 @@
       next = n->next;
       if (n->transmit_stage != TS_QUEUED)
        continue; /* not eligible */
+      if (n->is_connected != GNUNET_YES)
+        continue;
+
       th = &n->transmit_handle;
       GNUNET_break (n == th->neighbour);
       /* check outgoing quota */
@@ -500,6 +503,7 @@
                  th->notify_size - sizeof (struct OutboundMessage),
                  GNUNET_i2s (&n->id));
 #endif 
+
       if ( (ret == NULL) ||
           (ret->priority < th->priority) )
        ret = th;
@@ -664,7 +668,7 @@
     return;
   if (h->client == NULL)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   _("Could not yet schedule transmission: we are not yet 
connected to the transport service!\n"));
       return;                   /* not yet connected */
     }
@@ -688,6 +692,10 @@
       size = th->notify_size;
       timeout = GNUNET_TIME_absolute_get_remaining (th->timeout);
     }
+#if DEBUG_TRANSPORT
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Calling notify_transmit_ready\n");
+#endif
   h->network_handle =
     GNUNET_CLIENT_notify_transmit_ready (h->client,
                                         size,
@@ -979,7 +987,7 @@
   if (buf == NULL)
     {
 #if DEBUG_TRANSPORT_TIMEOUT
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Timeout while trying to transmit `%s' request.\n",
                   "HELLO");
 #endif
@@ -1247,6 +1255,40 @@
 
 
 /**
+ * Send request connect message to the service.
+ *
+ * @param cls the TransportRequestConnectMessage
+ * @param size number of bytes available in buf
+ * @param buf where to copy the message
+ * @return number of bytes copied to buf
+ */
+static size_t
+send_transport_request_connect (void *cls, size_t size, void *buf)
+{
+  struct TransportRequestConnectMessage *trcm = cls;
+
+  if (buf == NULL)
+    {
+#if DEBUG_TRANSPORT
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Buffer null for %s\n",
+                  "REQUEST_CONNECT");
+#endif
+      GNUNET_free (trcm);
+      return 0;
+    }
+#if DEBUG_TRANSPORT
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Transmitting `%s' request for `%4s'.\n",
+              "REQUEST_CONNECT",
+              GNUNET_i2s (&trcm->peer));
+#endif
+  GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
+  memcpy(buf, trcm, sizeof(struct TransportRequestConnectMessage));
+  return sizeof(struct TransportRequestConnectMessage);
+}
+
+/**
  * Add neighbour to our list
  *
  * @return NULL if this API is currently disconnecting from the service
@@ -1256,6 +1298,7 @@
                const struct GNUNET_PeerIdentity *pid)
 {
   struct NeighbourList *n;
+  struct TransportRequestConnectMessage *trcm;
 
   if (GNUNET_YES == h->in_disconnect)
     return NULL;
@@ -1278,6 +1321,15 @@
   n->next = h->neighbours;
   n->h = h;
   h->neighbours = n;
+
+  trcm = GNUNET_malloc(sizeof(struct TransportRequestConnectMessage));
+  trcm->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT);
+  trcm->header.size = htons(sizeof(struct TransportRequestConnectMessage));
+  memcpy(&trcm->peer, pid, sizeof(struct GNUNET_PeerIdentity));
+  schedule_control_transmit (h,
+                             sizeof (struct TransportRequestConnectMessage),
+                             GNUNET_NO,
+                             GNUNET_TIME_UNIT_FOREVER_REL, 
&send_transport_request_connect, trcm);
   return n;
 }
 
@@ -1655,7 +1707,7 @@
   th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
   n = th->neighbour;
 #if DEBUG_TRANSPORT
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
              "Triggering timeout for request to transmit to `%4s' (%d)\n",
              GNUNET_i2s (&n->id),
              n->transmit_stage);
@@ -1729,18 +1781,24 @@
       GNUNET_break (0);
       return NULL;
     }
-#if DEBUG_TRANSPORT
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Asking transport service for transmission of %u bytes to peer 
`%4s' within %llu ms.\n",
               size, GNUNET_i2s (target),
              (unsigned long long) timeout.value);
-#endif
+
   n = neighbour_find (handle, target);
   if (n == NULL)
-    n = neighbour_add (handle, target);
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Created neighbour entry for peer `%s'\n",
+                  GNUNET_i2s (target));
+      n = neighbour_add (handle, target);
+
+    }
   if (n == NULL)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "Could not create neighbour entry for peer `%s'\n",
                  GNUNET_i2s (target));
       return NULL;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]