transport plugin change from single MessageHeader to message buffer and size...
authorNathan S. Evans <evans@in.tum.de>
Tue, 26 Jan 2010 13:40:14 +0000 (13:40 +0000)
committerNathan S. Evans <evans@in.tum.de>
Tue, 26 Jan 2010 13:40:14 +0000 (13:40 +0000)
src/transport/gnunet-service-transport.c
src/transport/plugin_transport.h
src/transport/plugin_transport_tcp.c
src/transport/plugin_transport_template.c
src/transport/plugin_transport_udp.c

index 95ab969197bf047183b09220b208a5765a29b3d1..d239ce0ce7f9e6995414d33bc8a5a242aac611cb 100644 (file)
@@ -1110,9 +1110,11 @@ try_transmission_to_peer (struct NeighborList *neighbor)
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer pre-send: at this point rl->neighbor->addr is NOT NULL, addrlen is %d\n"), rl->neighbor->addr_len);
   else
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer pre-send: at this point rl->neighbor->addr is NULL\n"));
+  /* FIXME: Change MessageQueue to hold message buffer and size? */
   rl->plugin->api->send (rl->plugin->api->cls,
                          &neighbor->id,
-                         mq->message,
+                         (char *)mq->message,
+                         ntohs(mq->message->size),
                          mq->priority,
                          GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
                          rl->neighbor->addr,
@@ -1556,7 +1558,9 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
           GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello);
           n = find_neighbor (&pid, NULL, 0);
           if (NULL != n)
-            try_transmission_to_peer (n);
+            {
+              try_transmission_to_peer (n);
+            }
           GNUNET_free (hello);
           while (NULL != (va = pos->addresses))
             {
@@ -1593,21 +1597,6 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
-static struct GNUNET_MessageHeader *
-createPingMessage (struct GNUNET_PeerIdentity * target, struct ValidationAddress *va)
-{
-
-  struct TransportPingMessage *ping;
-  ping = GNUNET_malloc(sizeof(struct TransportPingMessage));
-
-  ping->challenge = htonl(va->challenge);
-  ping->header.size = sizeof(struct TransportPingMessage);
-  ping->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
-  memcpy(&ping->target, target, sizeof(struct GNUNET_PeerIdentity));
-
-  return &ping->header;
-}
-
 /**
  * Function that will be called if we receive a validation
  * of an address challenge that we transmitted to another
@@ -1757,8 +1746,12 @@ run_validation (void *cls,
   struct TransportPlugin *tp;
   struct ValidationAddress *va;
   struct GNUNET_PeerIdentity id;
-  struct GNUNET_MessageHeader *pingMessage;
+  char *pingMessage;
   int sent;
+  struct TransportPingMessage *ping;
+  char * message_buf;
+  int hello_size;
+
   tp = find_transport (tname);
   if (tp == NULL)
     {
@@ -1786,13 +1779,22 @@ run_validation (void *cls,
                                             (unsigned int) -1);
   memcpy (&va[1], addr, addrlen);
 
-  pingMessage = createPingMessage(&id, va);
+  hello_size = GNUNET_HELLO_size(our_hello);
+  message_buf = GNUNET_malloc(sizeof(struct TransportPingMessage) + hello_size);
+  memcpy(message_buf, &our_hello, hello_size);
+
+  ping = GNUNET_malloc(sizeof(struct TransportPingMessage));
+  ping->challenge = htonl(va->challenge);
+  ping->header.size = htons(sizeof(struct TransportPingMessage));
+  ping->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
+  memcpy(&ping->target, &id, sizeof(struct GNUNET_PeerIdentity));
+  memcpy(&message_buf[hello_size], ping, sizeof(struct TransportPingMessage));
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ping message to address `%s' via `%s' for `%4s'\n",
                 GNUNET_a2s (addr, addrlen), tname, GNUNET_i2s (&id));
 
 
-  sent = tp->api->send(tp->api->cls, &id, pingMessage, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+  sent = tp->api->send(tp->api->cls, &id, message_buf, sizeof(struct TransportPingMessage) + hello_size, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                 TRANSPORT_DEFAULT_TIMEOUT, addr, addrlen, GNUNET_YES, NULL, NULL);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport returned %d from send!\n", sent);
@@ -1814,6 +1816,8 @@ run_validation (void *cls,
  * the address via the transport plugin.  If not validated, then
  * do not count this as a good peer/address...
  *
+ * Currently this function is not used, ping/pongs get sent from the
+ * run_validation function.  Haven't decided yet how to do this.
  */
 static void
 validate_address (void *cls, struct ValidationAddress *va,
index 2b3a87f3b838417fd09374fddd0f1123b7d66162..5fa6304830fa601fd68377abcd4da40c257b045f 100644 (file)
@@ -197,7 +197,8 @@ typedef ssize_t
   (*GNUNET_TRANSPORT_TransmitFunction) (void *cls,
                                         const struct GNUNET_PeerIdentity *
                                         target,
-                                        const struct GNUNET_MessageHeader *msg,
+                                        char *msgbuf,
+                                        size_t msgbuf_size,
                                         uint32_t priority,
                                         struct GNUNET_TIME_Relative timeout,
                                         const void *addr,
index 3107e2792945b0526dca5918bd575fd33d026d00..4d936279dfbdee9e2b50aa501a7c99e4b1b9fbe9 100644 (file)
@@ -566,7 +566,8 @@ disconnect_session (struct Session *session)
 static ssize_t
 tcp_plugin_send (void *cls,
                  const struct GNUNET_PeerIdentity *target,
-                 const struct GNUNET_MessageHeader *msg,
+                 char *msg,
+                 size_t msgbuf_size,
                  uint32_t priority,
                  struct GNUNET_TIME_Relative timeout,
                 const void *addr,
@@ -582,7 +583,7 @@ tcp_plugin_send (void *cls,
   int af;
   uint16_t mlen;
 
-  mlen = ntohs (msg->size);
+  mlen = msgbuf_size;
   session = find_session_by_target (plugin, target);
   if ( (session != NULL) && ((GNUNET_YES == force_address) &&
        ( (session->connect_alen != addrlen) ||
index 3572c7837204c07136cdb1975fbf98e50ee95080..ab4149c900e281914c7a5e5a5617a2762c6e7fdc 100644 (file)
@@ -148,7 +148,8 @@ static ssize_t
 template_plugin_send (void *cls,
                       const struct GNUNET_PeerIdentity *
                       target,
-                      const struct GNUNET_MessageHeader *msg,
+                      char *msgbuf,
+                      size_t msgbuf_size,
                       unsigned int priority,
                       struct GNUNET_TIME_Relative timeout,
                       const void *addr,
index 75b8c6e56a4c0bfcfe6fa0a218a548f38b1733c6..68e519f3eab05214236b7c3e9a8bbfa8cb850bf3 100644 (file)
@@ -183,7 +183,8 @@ udp_transport_server_stop (void *cls)
  *
  * @param cls closure
  * @param target who should receive this message (ignored by UDP)
- * @param msg the message to transmit
+ * @param msgbuf one or more GNUNET_MessageHeader(s) strung together
+ * @param msgbufsize the size of the msgbuf to send
  * @param priority how important is the message (ignored by UDP)
  * @param timeout when should we time out (give up) if we can not transmit?
  * @param addr the addr to send the message to, needs to be a sockaddr for us
@@ -202,7 +203,8 @@ udp_transport_server_stop (void *cls)
 static ssize_t
 udp_plugin_send (void *cls,
                  const struct GNUNET_PeerIdentity *target,
-                 const struct GNUNET_MessageHeader *msg,
+                 char *msgbuf,
+                 size_t msgbuf_size,
                  unsigned int priority,
                  struct GNUNET_TIME_Relative timeout,
                  const void *addr,
@@ -228,8 +230,8 @@ udp_plugin_send (void *cls,
     }
 
   /* Build the message to be sent */
-  message = GNUNET_malloc (sizeof (struct UDPMessage) + ntohs (msg->size));
-  ssize = sizeof (struct UDPMessage) + ntohs (msg->size);
+  message = GNUNET_malloc (sizeof (struct UDPMessage) + msgbuf_size);
+  ssize = sizeof (struct UDPMessage) + msgbuf_size;
 
 #if DEBUG_UDP
   GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
@@ -239,7 +241,7 @@ udp_plugin_send (void *cls,
   message->header.type = htons (0);
   memcpy (&message->sender, plugin->env->my_identity,
           sizeof (struct GNUNET_PeerIdentity));
-  memcpy (&message[1], msg, ntohs (msg->size));
+  memcpy (&message[1], msgbuf, msgbuf_size);
 
   /* Actually send the message */
   sent =
@@ -353,6 +355,9 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   socklen_t fromlen;
   struct sockaddr_storage addr;
   ssize_t ret;
+  int offset;
+  int count;
+  const struct GNUNET_MessageHeader *currhdr;
 
   do
     {
@@ -419,8 +424,20 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                        ("msg reports message type of %d\n"),
                        ntohs (hdr->type));
 #endif
-      plugin->env->receive (plugin->env->cls,
-          sender, hdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen);
+      offset = 0;
+      count = 0;
+      while (offset < (ntohs (msg->header.size) - sizeof(struct UDPMessage)))
+        {
+          currhdr = &hdr[offset];
+#if DEBUG_UDP
+      GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
+                       ("processing msg %d: type %d, size %d at offset %d\n"),
+                       count, offset, ntohs(currhdr->size), ntohs(currhdr->type));
+#endif
+          plugin->env->receive (plugin->env->cls,
+              sender, currhdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen);
+          offset += ntohs(currhdr->size);
+        }
 
       GNUNET_free (sender);
       GNUNET_free (buf);