aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c58
1 files changed, 25 insertions, 33 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index fd8493e5f..1ff962544 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -159,6 +159,11 @@ struct GNUNET_ATS_Session
159 struct GNUNET_PeerIdentity target; 159 struct GNUNET_PeerIdentity target;
160 160
161 /** 161 /**
162 * Tokenizer for inbound messages.
163 */
164 struct GNUNET_MessageStreamTokenizer *mst;
165
166 /**
162 * Plugin this session belongs to. 167 * Plugin this session belongs to.
163 */ 168 */
164 struct Plugin *plugin; 169 struct Plugin *plugin;
@@ -626,6 +631,11 @@ free_session (struct GNUNET_ATS_Session *s)
626 GNUNET_free (s->frag_ctx); 631 GNUNET_free (s->frag_ctx);
627 s->frag_ctx = NULL; 632 s->frag_ctx = NULL;
628 } 633 }
634 if (NULL != s->mst)
635 {
636 GNUNET_MST_destroy (s->mst);
637 s->mst = NULL;
638 }
629 GNUNET_free (s); 639 GNUNET_free (s);
630} 640}
631 641
@@ -1271,10 +1281,7 @@ udp_plugin_check_address (void *cls,
1271 1281
1272 v6 = (const struct IPv6UdpAddress *) addr; 1282 v6 = (const struct IPv6UdpAddress *) addr;
1273 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) 1283 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1274 { 1284 return GNUNET_OK; /* plausible, if unlikely... */
1275 GNUNET_break_op (0);
1276 return GNUNET_SYSERR;
1277 }
1278 memset (&s6, 0, sizeof (s6)); 1285 memset (&s6, 0, sizeof (s6));
1279 s6.sin6_family = AF_INET6; 1286 s6.sin6_family = AF_INET6;
1280#if HAVE_SOCKADDR_IN_SIN_LEN 1287#if HAVE_SOCKADDR_IN_SIN_LEN
@@ -1338,10 +1345,7 @@ udp_nat_port_map_callback (void *cls,
1338 GNUNET_assert (sizeof(struct sockaddr_in) == addrlen); 1345 GNUNET_assert (sizeof(struct sockaddr_in) == addrlen);
1339 i4 = (const struct sockaddr_in *) addr; 1346 i4 = (const struct sockaddr_in *) addr;
1340 if (0 == ntohs (i4->sin_port)) 1347 if (0 == ntohs (i4->sin_port))
1341 { 1348 return; /* Port = 0 means unmapped, ignore these for UDP. */
1342 GNUNET_break (0);
1343 return;
1344 }
1345 memset (&u4, 1349 memset (&u4,
1346 0, 1350 0,
1347 sizeof(u4)); 1351 sizeof(u4));
@@ -1359,10 +1363,7 @@ udp_nat_port_map_callback (void *cls,
1359 GNUNET_assert (sizeof(struct sockaddr_in6) == addrlen); 1363 GNUNET_assert (sizeof(struct sockaddr_in6) == addrlen);
1360 i6 = (const struct sockaddr_in6 *) addr; 1364 i6 = (const struct sockaddr_in6 *) addr;
1361 if (0 == ntohs (i6->sin6_port)) 1365 if (0 == ntohs (i6->sin6_port))
1362 { 1366 return; /* Port = 0 means unmapped, ignore these for UDP. */
1363 GNUNET_break (0);
1364 return;
1365 }
1366 memset (&u6, 1367 memset (&u6,
1367 0, 1368 0,
1368 sizeof(u6)); 1369 sizeof(u6));
@@ -1632,7 +1633,7 @@ enqueue (struct Plugin *plugin,
1632 GNUNET_break (0); 1633 GNUNET_break (0);
1633 return; 1634 return;
1634 } 1635 }
1635 if (plugin->bytes_in_buffer + udpw->msg_size > INT64_MAX) 1636 if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size)
1636 { 1637 {
1637 GNUNET_break (0); 1638 GNUNET_break (0);
1638 } 1639 }
@@ -2060,7 +2061,7 @@ udp_plugin_send (void *cls,
2060 if ( (sizeof(struct IPv4UdpAddress) == s->address->address_length) && 2061 if ( (sizeof(struct IPv4UdpAddress) == s->address->address_length) &&
2061 (NULL == plugin->sockv4) ) 2062 (NULL == plugin->sockv4) )
2062 return GNUNET_SYSERR; 2063 return GNUNET_SYSERR;
2063 if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 2064 if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE)
2064 { 2065 {
2065 GNUNET_break (0); 2066 GNUNET_break (0);
2066 return GNUNET_SYSERR; 2067 return GNUNET_SYSERR;
@@ -2508,18 +2509,16 @@ read_process_ack (struct Plugin *plugin,
2508 * Message tokenizer has broken up an incomming message. Pass it on 2509 * Message tokenizer has broken up an incomming message. Pass it on
2509 * to the service. 2510 * to the service.
2510 * 2511 *
2511 * @param cls the `struct Plugin *` 2512 * @param cls the `struct GNUNET_ATS_Session *`
2512 * @param client the `struct GNUNET_ATS_Session *`
2513 * @param hdr the actual message 2513 * @param hdr the actual message
2514 * @return #GNUNET_OK (always) 2514 * @return #GNUNET_OK (always)
2515 */ 2515 */
2516static int 2516static int
2517process_inbound_tokenized_messages (void *cls, 2517process_inbound_tokenized_messages (void *cls,
2518 void *client,
2519 const struct GNUNET_MessageHeader *hdr) 2518 const struct GNUNET_MessageHeader *hdr)
2520{ 2519{
2521 struct Plugin *plugin = cls; 2520 struct GNUNET_ATS_Session *session = cls;
2522 struct GNUNET_ATS_Session *session = client; 2521 struct Plugin *plugin = session->plugin;
2523 2522
2524 if (GNUNET_YES == session->in_destroy) 2523 if (GNUNET_YES == session->in_destroy)
2525 return GNUNET_OK; 2524 return GNUNET_OK;
@@ -2635,6 +2634,8 @@ udp_plugin_create_session (void *cls,
2635 struct GNUNET_ATS_Session *s; 2634 struct GNUNET_ATS_Session *s;
2636 2635
2637 s = GNUNET_new (struct GNUNET_ATS_Session); 2636 s = GNUNET_new (struct GNUNET_ATS_Session);
2637 s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages,
2638 s);
2638 s->plugin = plugin; 2639 s->plugin = plugin;
2639 s->address = GNUNET_HELLO_address_copy (address); 2640 s->address = GNUNET_HELLO_address_copy (address);
2640 s->target = address->peer; 2641 s->target = address->peer;
@@ -2801,12 +2802,11 @@ process_udp_message (struct Plugin *plugin,
2801 GNUNET_free (address); 2802 GNUNET_free (address);
2802 2803
2803 s->rc++; 2804 s->rc++;
2804 GNUNET_SERVER_mst_receive (plugin->mst, 2805 GNUNET_MST_from_buffer (s->mst,
2805 s, 2806 (const char *) &msg[1],
2806 (const char *) &msg[1], 2807 ntohs (msg->header.size) - sizeof(struct UDPMessage),
2807 ntohs (msg->header.size) - sizeof(struct UDPMessage), 2808 GNUNET_YES,
2808 GNUNET_YES, 2809 GNUNET_NO);
2809 GNUNET_NO);
2810 s->rc--; 2810 s->rc--;
2811 if ( (0 == s->rc) && 2811 if ( (0 == s->rc) &&
2812 (GNUNET_YES == s->in_destroy) ) 2812 (GNUNET_YES == s->in_destroy) )
@@ -3999,8 +3999,6 @@ libgnunet_plugin_transport_udp_init (void *cls)
3999 p->sessions = GNUNET_CONTAINER_multipeermap_create (16, 3999 p->sessions = GNUNET_CONTAINER_multipeermap_create (16,
4000 GNUNET_NO); 4000 GNUNET_NO);
4001 p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 4001 p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
4002 p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages,
4003 p);
4004 GNUNET_BANDWIDTH_tracker_init (&p->tracker, 4002 GNUNET_BANDWIDTH_tracker_init (&p->tracker,
4005 NULL, 4003 NULL,
4006 NULL, 4004 NULL,
@@ -4017,7 +4015,6 @@ libgnunet_plugin_transport_udp_init (void *cls)
4017 _("Failed to create UDP network sockets\n")); 4015 _("Failed to create UDP network sockets\n"));
4018 GNUNET_CONTAINER_multipeermap_destroy (p->sessions); 4016 GNUNET_CONTAINER_multipeermap_destroy (p->sessions);
4019 GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); 4017 GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs);
4020 GNUNET_SERVER_mst_destroy (p->mst);
4021 if (NULL != p->nat) 4018 if (NULL != p->nat)
4022 GNUNET_NAT_unregister (p->nat); 4019 GNUNET_NAT_unregister (p->nat);
4023 GNUNET_free (p); 4020 GNUNET_free (p);
@@ -4129,11 +4126,6 @@ libgnunet_plugin_transport_udp_done (void *cls)
4129 GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); 4126 GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs);
4130 plugin->defrag_ctxs = NULL; 4127 plugin->defrag_ctxs = NULL;
4131 } 4128 }
4132 if (NULL != plugin->mst)
4133 {
4134 GNUNET_SERVER_mst_destroy (plugin->mst);
4135 plugin->mst = NULL;
4136 }
4137 while (NULL != (udpw = plugin->ipv4_queue_head)) 4129 while (NULL != (udpw = plugin->ipv4_queue_head))
4138 { 4130 {
4139 dequeue (plugin, 4131 dequeue (plugin,