diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-01-26 13:40:14 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-01-26 13:40:14 +0000 |
commit | 9a072b194ac97acdf835bd917468664230d900ce (patch) | |
tree | cf30cecfa0b56aa629b6d8abfcdbe3e7964a2d67 /src | |
parent | c2bd55c1e68522d685c1ac539949918ad612ce16 (diff) | |
download | gnunet-9a072b194ac97acdf835bd917468664230d900ce.tar.gz gnunet-9a072b194ac97acdf835bd917468664230d900ce.zip |
transport plugin change from single MessageHeader to message buffer and size...
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 44 | ||||
-rw-r--r-- | src/transport/plugin_transport.h | 3 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 5 | ||||
-rw-r--r-- | src/transport/plugin_transport_template.c | 3 | ||||
-rw-r--r-- | 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) | |||
1110 | 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); | 1110 | 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); |
1111 | else | 1111 | else |
1112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer pre-send: at this point rl->neighbor->addr is NULL\n")); | 1112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer pre-send: at this point rl->neighbor->addr is NULL\n")); |
1113 | /* FIXME: Change MessageQueue to hold message buffer and size? */ | ||
1113 | rl->plugin->api->send (rl->plugin->api->cls, | 1114 | rl->plugin->api->send (rl->plugin->api->cls, |
1114 | &neighbor->id, | 1115 | &neighbor->id, |
1115 | mq->message, | 1116 | (char *)mq->message, |
1117 | ntohs(mq->message->size), | ||
1116 | mq->priority, | 1118 | mq->priority, |
1117 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1119 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1118 | rl->neighbor->addr, | 1120 | rl->neighbor->addr, |
@@ -1556,7 +1558,9 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1556 | GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello); | 1558 | GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello); |
1557 | n = find_neighbor (&pid, NULL, 0); | 1559 | n = find_neighbor (&pid, NULL, 0); |
1558 | if (NULL != n) | 1560 | if (NULL != n) |
1559 | try_transmission_to_peer (n); | 1561 | { |
1562 | try_transmission_to_peer (n); | ||
1563 | } | ||
1560 | GNUNET_free (hello); | 1564 | GNUNET_free (hello); |
1561 | while (NULL != (va = pos->addresses)) | 1565 | while (NULL != (va = pos->addresses)) |
1562 | { | 1566 | { |
@@ -1593,21 +1597,6 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1593 | } | 1597 | } |
1594 | 1598 | ||
1595 | 1599 | ||
1596 | static struct GNUNET_MessageHeader * | ||
1597 | createPingMessage (struct GNUNET_PeerIdentity * target, struct ValidationAddress *va) | ||
1598 | { | ||
1599 | |||
1600 | struct TransportPingMessage *ping; | ||
1601 | ping = GNUNET_malloc(sizeof(struct TransportPingMessage)); | ||
1602 | |||
1603 | ping->challenge = htonl(va->challenge); | ||
1604 | ping->header.size = sizeof(struct TransportPingMessage); | ||
1605 | ping->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); | ||
1606 | memcpy(&ping->target, target, sizeof(struct GNUNET_PeerIdentity)); | ||
1607 | |||
1608 | return &ping->header; | ||
1609 | } | ||
1610 | |||
1611 | /** | 1600 | /** |
1612 | * Function that will be called if we receive a validation | 1601 | * Function that will be called if we receive a validation |
1613 | * of an address challenge that we transmitted to another | 1602 | * of an address challenge that we transmitted to another |
@@ -1757,8 +1746,12 @@ run_validation (void *cls, | |||
1757 | struct TransportPlugin *tp; | 1746 | struct TransportPlugin *tp; |
1758 | struct ValidationAddress *va; | 1747 | struct ValidationAddress *va; |
1759 | struct GNUNET_PeerIdentity id; | 1748 | struct GNUNET_PeerIdentity id; |
1760 | struct GNUNET_MessageHeader *pingMessage; | 1749 | char *pingMessage; |
1761 | int sent; | 1750 | int sent; |
1751 | struct TransportPingMessage *ping; | ||
1752 | char * message_buf; | ||
1753 | int hello_size; | ||
1754 | |||
1762 | tp = find_transport (tname); | 1755 | tp = find_transport (tname); |
1763 | if (tp == NULL) | 1756 | if (tp == NULL) |
1764 | { | 1757 | { |
@@ -1786,13 +1779,22 @@ run_validation (void *cls, | |||
1786 | (unsigned int) -1); | 1779 | (unsigned int) -1); |
1787 | memcpy (&va[1], addr, addrlen); | 1780 | memcpy (&va[1], addr, addrlen); |
1788 | 1781 | ||
1789 | pingMessage = createPingMessage(&id, va); | 1782 | hello_size = GNUNET_HELLO_size(our_hello); |
1783 | message_buf = GNUNET_malloc(sizeof(struct TransportPingMessage) + hello_size); | ||
1784 | memcpy(message_buf, &our_hello, hello_size); | ||
1785 | |||
1786 | ping = GNUNET_malloc(sizeof(struct TransportPingMessage)); | ||
1787 | ping->challenge = htonl(va->challenge); | ||
1788 | ping->header.size = htons(sizeof(struct TransportPingMessage)); | ||
1789 | ping->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); | ||
1790 | memcpy(&ping->target, &id, sizeof(struct GNUNET_PeerIdentity)); | ||
1791 | memcpy(&message_buf[hello_size], ping, sizeof(struct TransportPingMessage)); | ||
1790 | 1792 | ||
1791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ping message to address `%s' via `%s' for `%4s'\n", | 1793 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ping message to address `%s' via `%s' for `%4s'\n", |
1792 | GNUNET_a2s (addr, addrlen), tname, GNUNET_i2s (&id)); | 1794 | GNUNET_a2s (addr, addrlen), tname, GNUNET_i2s (&id)); |
1793 | 1795 | ||
1794 | 1796 | ||
1795 | sent = tp->api->send(tp->api->cls, &id, pingMessage, GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1797 | sent = tp->api->send(tp->api->cls, &id, message_buf, sizeof(struct TransportPingMessage) + hello_size, GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1796 | TRANSPORT_DEFAULT_TIMEOUT, addr, addrlen, GNUNET_YES, NULL, NULL); | 1798 | TRANSPORT_DEFAULT_TIMEOUT, addr, addrlen, GNUNET_YES, NULL, NULL); |
1797 | 1799 | ||
1798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport returned %d from send!\n", sent); | 1800 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport returned %d from send!\n", sent); |
@@ -1814,6 +1816,8 @@ run_validation (void *cls, | |||
1814 | * the address via the transport plugin. If not validated, then | 1816 | * the address via the transport plugin. If not validated, then |
1815 | * do not count this as a good peer/address... | 1817 | * do not count this as a good peer/address... |
1816 | * | 1818 | * |
1819 | * Currently this function is not used, ping/pongs get sent from the | ||
1820 | * run_validation function. Haven't decided yet how to do this. | ||
1817 | */ | 1821 | */ |
1818 | static void | 1822 | static void |
1819 | validate_address (void *cls, struct ValidationAddress *va, | 1823 | 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 | |||
197 | (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, | 197 | (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, |
198 | const struct GNUNET_PeerIdentity * | 198 | const struct GNUNET_PeerIdentity * |
199 | target, | 199 | target, |
200 | const struct GNUNET_MessageHeader *msg, | 200 | char *msgbuf, |
201 | size_t msgbuf_size, | ||
201 | uint32_t priority, | 202 | uint32_t priority, |
202 | struct GNUNET_TIME_Relative timeout, | 203 | struct GNUNET_TIME_Relative timeout, |
203 | const void *addr, | 204 | 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) | |||
566 | static ssize_t | 566 | static ssize_t |
567 | tcp_plugin_send (void *cls, | 567 | tcp_plugin_send (void *cls, |
568 | const struct GNUNET_PeerIdentity *target, | 568 | const struct GNUNET_PeerIdentity *target, |
569 | const struct GNUNET_MessageHeader *msg, | 569 | char *msg, |
570 | size_t msgbuf_size, | ||
570 | uint32_t priority, | 571 | uint32_t priority, |
571 | struct GNUNET_TIME_Relative timeout, | 572 | struct GNUNET_TIME_Relative timeout, |
572 | const void *addr, | 573 | const void *addr, |
@@ -582,7 +583,7 @@ tcp_plugin_send (void *cls, | |||
582 | int af; | 583 | int af; |
583 | uint16_t mlen; | 584 | uint16_t mlen; |
584 | 585 | ||
585 | mlen = ntohs (msg->size); | 586 | mlen = msgbuf_size; |
586 | session = find_session_by_target (plugin, target); | 587 | session = find_session_by_target (plugin, target); |
587 | if ( (session != NULL) && ((GNUNET_YES == force_address) && | 588 | if ( (session != NULL) && ((GNUNET_YES == force_address) && |
588 | ( (session->connect_alen != addrlen) || | 589 | ( (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 | |||
148 | template_plugin_send (void *cls, | 148 | template_plugin_send (void *cls, |
149 | const struct GNUNET_PeerIdentity * | 149 | const struct GNUNET_PeerIdentity * |
150 | target, | 150 | target, |
151 | const struct GNUNET_MessageHeader *msg, | 151 | char *msgbuf, |
152 | size_t msgbuf_size, | ||
152 | unsigned int priority, | 153 | unsigned int priority, |
153 | struct GNUNET_TIME_Relative timeout, | 154 | struct GNUNET_TIME_Relative timeout, |
154 | const void *addr, | 155 | 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) | |||
183 | * | 183 | * |
184 | * @param cls closure | 184 | * @param cls closure |
185 | * @param target who should receive this message (ignored by UDP) | 185 | * @param target who should receive this message (ignored by UDP) |
186 | * @param msg the message to transmit | 186 | * @param msgbuf one or more GNUNET_MessageHeader(s) strung together |
187 | * @param msgbufsize the size of the msgbuf to send | ||
187 | * @param priority how important is the message (ignored by UDP) | 188 | * @param priority how important is the message (ignored by UDP) |
188 | * @param timeout when should we time out (give up) if we can not transmit? | 189 | * @param timeout when should we time out (give up) if we can not transmit? |
189 | * @param addr the addr to send the message to, needs to be a sockaddr for us | 190 | * @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) | |||
202 | static ssize_t | 203 | static ssize_t |
203 | udp_plugin_send (void *cls, | 204 | udp_plugin_send (void *cls, |
204 | const struct GNUNET_PeerIdentity *target, | 205 | const struct GNUNET_PeerIdentity *target, |
205 | const struct GNUNET_MessageHeader *msg, | 206 | char *msgbuf, |
207 | size_t msgbuf_size, | ||
206 | unsigned int priority, | 208 | unsigned int priority, |
207 | struct GNUNET_TIME_Relative timeout, | 209 | struct GNUNET_TIME_Relative timeout, |
208 | const void *addr, | 210 | const void *addr, |
@@ -228,8 +230,8 @@ udp_plugin_send (void *cls, | |||
228 | } | 230 | } |
229 | 231 | ||
230 | /* Build the message to be sent */ | 232 | /* Build the message to be sent */ |
231 | message = GNUNET_malloc (sizeof (struct UDPMessage) + ntohs (msg->size)); | 233 | message = GNUNET_malloc (sizeof (struct UDPMessage) + msgbuf_size); |
232 | ssize = sizeof (struct UDPMessage) + ntohs (msg->size); | 234 | ssize = sizeof (struct UDPMessage) + msgbuf_size; |
233 | 235 | ||
234 | #if DEBUG_UDP | 236 | #if DEBUG_UDP |
235 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | 237 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
@@ -239,7 +241,7 @@ udp_plugin_send (void *cls, | |||
239 | message->header.type = htons (0); | 241 | message->header.type = htons (0); |
240 | memcpy (&message->sender, plugin->env->my_identity, | 242 | memcpy (&message->sender, plugin->env->my_identity, |
241 | sizeof (struct GNUNET_PeerIdentity)); | 243 | sizeof (struct GNUNET_PeerIdentity)); |
242 | memcpy (&message[1], msg, ntohs (msg->size)); | 244 | memcpy (&message[1], msgbuf, msgbuf_size); |
243 | 245 | ||
244 | /* Actually send the message */ | 246 | /* Actually send the message */ |
245 | sent = | 247 | sent = |
@@ -353,6 +355,9 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
353 | socklen_t fromlen; | 355 | socklen_t fromlen; |
354 | struct sockaddr_storage addr; | 356 | struct sockaddr_storage addr; |
355 | ssize_t ret; | 357 | ssize_t ret; |
358 | int offset; | ||
359 | int count; | ||
360 | const struct GNUNET_MessageHeader *currhdr; | ||
356 | 361 | ||
357 | do | 362 | do |
358 | { | 363 | { |
@@ -419,8 +424,20 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
419 | ("msg reports message type of %d\n"), | 424 | ("msg reports message type of %d\n"), |
420 | ntohs (hdr->type)); | 425 | ntohs (hdr->type)); |
421 | #endif | 426 | #endif |
422 | plugin->env->receive (plugin->env->cls, | 427 | offset = 0; |
423 | sender, hdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen); | 428 | count = 0; |
429 | while (offset < (ntohs (msg->header.size) - sizeof(struct UDPMessage))) | ||
430 | { | ||
431 | currhdr = &hdr[offset]; | ||
432 | #if DEBUG_UDP | ||
433 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
434 | ("processing msg %d: type %d, size %d at offset %d\n"), | ||
435 | count, offset, ntohs(currhdr->size), ntohs(currhdr->type)); | ||
436 | #endif | ||
437 | plugin->env->receive (plugin->env->cls, | ||
438 | sender, currhdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen); | ||
439 | offset += ntohs(currhdr->size); | ||
440 | } | ||
424 | 441 | ||
425 | GNUNET_free (sender); | 442 | GNUNET_free (sender); |
426 | GNUNET_free (buf); | 443 | GNUNET_free (buf); |