From 9a072b194ac97acdf835bd917468664230d900ce Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Tue, 26 Jan 2010 13:40:14 +0000 Subject: [PATCH] transport plugin change from single MessageHeader to message buffer and size... --- src/transport/gnunet-service-transport.c | 44 ++++++++++++----------- src/transport/plugin_transport.h | 3 +- src/transport/plugin_transport_tcp.c | 5 +-- src/transport/plugin_transport_template.c | 3 +- src/transport/plugin_transport_udp.c | 31 ++++++++++++---- 5 files changed, 55 insertions(+), 31 deletions(-) diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 95ab96919..d239ce0ce 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -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, diff --git a/src/transport/plugin_transport.h b/src/transport/plugin_transport.h index 2b3a87f3b..5fa630483 100644 --- a/src/transport/plugin_transport.h +++ b/src/transport/plugin_transport.h @@ -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, diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 3107e2792..4d936279d 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -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) || diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c index 3572c7837..ab4149c90 100644 --- a/src/transport/plugin_transport_template.c +++ b/src/transport/plugin_transport_template.c @@ -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, diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 75b8c6e56..68e519f3e 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -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); -- 2.25.1