aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transport/plugin_transport_udp.c82
1 files changed, 58 insertions, 24 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index bf8220164..a08edbade 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -254,10 +254,42 @@ struct FragmentationContext
254 254
255struct UDPMessageWrapper 255struct UDPMessageWrapper
256{ 256{
257 /**
258 * Session this message belongs to
259 */
257 struct Session *session; 260 struct Session *session;
261
262 /**
263 * DLL of messages
264 * previous element
265 */
258 struct UDPMessageWrapper *prev; 266 struct UDPMessageWrapper *prev;
267
268 /**
269 * DLL of messages
270 * previous element
271 */
259 struct UDPMessageWrapper *next; 272 struct UDPMessageWrapper *next;
260 char *udp; 273
274 /**
275 * Message with size msg_size including UDP specific overhead
276 */
277 char *msg_buf;
278
279 /**
280 * Size of UDP message to send including UDP specific overhead
281 */
282 size_t msg_size;
283
284 /**
285 * Amount of bytes used on wire to send this message
286 */
287 size_t payload_size;
288
289 /**
290 * Message timeout
291 */
292 struct GNUNET_TIME_Absolute timeout;
261 293
262 /** 294 /**
263 * Function to call upon completion of the transmission. 295 * Function to call upon completion of the transmission.
@@ -269,11 +301,12 @@ struct UDPMessageWrapper
269 */ 301 */
270 void *cont_cls; 302 void *cont_cls;
271 303
304 /**
305 * Fragmentation context
306 * frag_ctx == NULL if transport <= MTU
307 * frag_ctx != NULL if transport > MTU
308 */
272 struct FragmentationContext *frag_ctx; 309 struct FragmentationContext *frag_ctx;
273
274 size_t msg_size;
275
276 struct GNUNET_TIME_Absolute timeout;
277}; 310};
278 311
279 312
@@ -630,7 +663,8 @@ call_continuation (struct UDPMessageWrapper *udpw, int result)
630 (GNUNET_OK == result) ? "OK" : "SYSERR"); 663 (GNUNET_OK == result) ? "OK" : "SYSERR");
631 if (NULL != udpw->cont) 664 if (NULL != udpw->cont)
632 { 665 {
633 udpw->cont (udpw->cont_cls, &udpw->session->target,result); 666 /* FIXME: add bytes used on wire here */
667 udpw->cont (udpw->cont_cls, &udpw->session->target, result);
634 } 668 }
635 669
636} 670}
@@ -1157,14 +1191,14 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
1157 "Enqueuing fragment with %u bytes %u\n", msg_len , sizeof (struct UDPMessageWrapper)); 1191 "Enqueuing fragment with %u bytes %u\n", msg_len , sizeof (struct UDPMessageWrapper));
1158 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + msg_len); 1192 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + msg_len);
1159 udpw->session = frag_ctx->session; 1193 udpw->session = frag_ctx->session;
1160 udpw->udp = (char *) &udpw[1]; 1194 udpw->msg_buf = (char *) &udpw[1];
1161 1195
1162 udpw->msg_size = msg_len; 1196 udpw->msg_size = msg_len;
1163 udpw->cont = &send_next_fragment; 1197 udpw->cont = &send_next_fragment;
1164 udpw->cont_cls = udpw; 1198 udpw->cont_cls = udpw;
1165 udpw->timeout = frag_ctx->timeout; 1199 udpw->timeout = frag_ctx->timeout;
1166 udpw->frag_ctx = frag_ctx; 1200 udpw->frag_ctx = frag_ctx;
1167 memcpy (udpw->udp, msg, msg_len); 1201 memcpy (udpw->msg_buf, msg, msg_len);
1168 enqueue (plugin, udpw); 1202 enqueue (plugin, udpw);
1169 schedule_select (plugin); 1203 schedule_select (plugin);
1170} 1204}
@@ -1206,10 +1240,10 @@ udp_plugin_send (void *cls,
1206 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 1240 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1207{ 1241{
1208 struct Plugin *plugin = cls; 1242 struct Plugin *plugin = cls;
1209 size_t mlen = msgbuf_size + sizeof (struct UDPMessage); 1243 size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage);
1210 struct UDPMessageWrapper * udpw; 1244 struct UDPMessageWrapper * udpw;
1211 struct UDPMessage *udp; 1245 struct UDPMessage *udp;
1212 char mbuf[mlen]; 1246 char mbuf[udpmlen];
1213 GNUNET_assert (plugin != NULL); 1247 GNUNET_assert (plugin != NULL);
1214 GNUNET_assert (s != NULL); 1248 GNUNET_assert (s != NULL);
1215 1249
@@ -1217,7 +1251,7 @@ udp_plugin_send (void *cls,
1217 return GNUNET_SYSERR; 1251 return GNUNET_SYSERR;
1218 if ((s->addrlen == sizeof (struct sockaddr_in)) && (plugin->sockv4 == NULL)) 1252 if ((s->addrlen == sizeof (struct sockaddr_in)) && (plugin->sockv4 == NULL))
1219 return GNUNET_SYSERR; 1253 return GNUNET_SYSERR;
1220 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1254 if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1221 { 1255 {
1222 GNUNET_break (0); 1256 GNUNET_break (0);
1223 return GNUNET_SYSERR; 1257 return GNUNET_SYSERR;
@@ -1229,7 +1263,7 @@ udp_plugin_send (void *cls,
1229 } 1263 }
1230 LOG (GNUNET_ERROR_TYPE_DEBUG, 1264 LOG (GNUNET_ERROR_TYPE_DEBUG,
1231 "UDP transmits %u-byte message to `%s' using address `%s'\n", 1265 "UDP transmits %u-byte message to `%s' using address `%s'\n",
1232 mlen, 1266 udpmlen,
1233 GNUNET_i2s (&s->target), 1267 GNUNET_i2s (&s->target),
1234 GNUNET_a2s(s->sock_addr, s->addrlen)); 1268 GNUNET_a2s(s->sock_addr, s->addrlen));
1235 1269
@@ -1243,24 +1277,24 @@ udp_plugin_send (void *cls,
1243 1277
1244 /* Message */ 1278 /* Message */
1245 udp = (struct UDPMessage *) mbuf; 1279 udp = (struct UDPMessage *) mbuf;
1246 udp->header.size = htons (mlen); 1280 udp->header.size = htons (udpmlen);
1247 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); 1281 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE);
1248 udp->reserved = htonl (0); 1282 udp->reserved = htonl (0);
1249 udp->sender = *plugin->env->my_identity; 1283 udp->sender = *plugin->env->my_identity;
1250 1284
1251 reschedule_session_timeout(s); 1285 reschedule_session_timeout(s);
1252 if (mlen <= UDP_MTU) 1286 if (udpmlen <= UDP_MTU)
1253 { 1287 {
1254 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + mlen); 1288 udpw = GNUNET_malloc (sizeof (struct UDPMessageWrapper) + udpmlen);
1255 udpw->session = s; 1289 udpw->session = s;
1256 udpw->udp = (char *) &udpw[1]; 1290 udpw->msg_buf = (char *) &udpw[1];
1257 udpw->msg_size = mlen; 1291 udpw->msg_size = udpmlen;
1258 udpw->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); 1292 udpw->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to);
1259 udpw->cont = cont; 1293 udpw->cont = cont;
1260 udpw->cont_cls = cont_cls; 1294 udpw->cont_cls = cont_cls;
1261 udpw->frag_ctx = NULL; 1295 udpw->frag_ctx = NULL;
1262 memcpy (udpw->udp, udp, sizeof (struct UDPMessage)); 1296 memcpy (udpw->msg_buf, udp, sizeof (struct UDPMessage));
1263 memcpy (&udpw->udp[sizeof (struct UDPMessage)], msgbuf, msgbuf_size); 1297 memcpy (&udpw->msg_buf[sizeof (struct UDPMessage)], msgbuf, msgbuf_size);
1264 enqueue (plugin, udpw); 1298 enqueue (plugin, udpw);
1265 } 1299 }
1266 else 1300 else
@@ -1277,7 +1311,7 @@ udp_plugin_send (void *cls,
1277 frag_ctx->cont = cont; 1311 frag_ctx->cont = cont;
1278 frag_ctx->cont_cls = cont_cls; 1312 frag_ctx->cont_cls = cont_cls;
1279 frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); 1313 frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to);
1280 frag_ctx->bytes_to_send = mlen; 1314 frag_ctx->bytes_to_send = udpmlen;
1281 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, 1315 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
1282 UDP_MTU, 1316 UDP_MTU,
1283 &plugin->tracker, 1317 &plugin->tracker,
@@ -1289,7 +1323,7 @@ udp_plugin_send (void *cls,
1289 s->frag_ctx = frag_ctx; 1323 s->frag_ctx = frag_ctx;
1290 } 1324 }
1291 schedule_select (plugin); 1325 schedule_select (plugin);
1292 return mlen; 1326 return udpmlen;
1293} 1327}
1294 1328
1295 1329
@@ -1577,8 +1611,8 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
1577 udpw->msg_size = msize; 1611 udpw->msg_size = msize;
1578 udpw->session = s; 1612 udpw->session = s;
1579 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 1613 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
1580 udpw->udp = (char *)&udpw[1]; 1614 udpw->msg_buf = (char *)&udpw[1];
1581 udp_ack = (struct UDP_ACK_Message *) udpw->udp; 1615 udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf;
1582 udp_ack->header.size = htons ((uint16_t) msize); 1616 udp_ack->header.size = htons ((uint16_t) msize);
1583 udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); 1617 udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK);
1584 udp_ack->delay = htonl (delay); 1618 udp_ack->delay = htonl (delay);
@@ -1945,7 +1979,7 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
1945 return 0; 1979 return 0;
1946 } 1980 }
1947 1981
1948 sent = GNUNET_NETWORK_socket_sendto (sock, udpw->udp, udpw->msg_size, sa, slen); 1982 sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, sa, slen);
1949 1983
1950 if (GNUNET_SYSERR == sent) 1984 if (GNUNET_SYSERR == sent)
1951 { 1985 {