aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-07-25 17:34:21 +0000
committerBart Polot <bart@net.in.tum.de>2012-07-25 17:34:21 +0000
commit2855795582ac050551da45a04a687e73c2c3d0d8 (patch)
treef612332cbe446da361e2bcfac9217cb2e8e395db /src
parenta79ea321245662f933dc8f9208b26d85d79cbe6c (diff)
downloadgnunet-2855795582ac050551da45a04a687e73c2c3d0d8.tar.gz
gnunet-2855795582ac050551da45a04a687e73c2c3d0d8.zip
- adapt callback to ack
Diffstat (limited to 'src')
-rw-r--r--src/mesh/mesh_api.c88
1 files changed, 70 insertions, 18 deletions
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 8117b9354..aee4c2a7b 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -23,6 +23,7 @@
23 * STRUCTURE: 23 * STRUCTURE:
24 * - CONSTANTS 24 * - CONSTANTS
25 * - DATA STRUCTURES 25 * - DATA STRUCTURES
26 * - DECLARATIONS
26 * - AUXILIARY FUNCTIONS 27 * - AUXILIARY FUNCTIONS
27 * - RECEIVE HANDLERS 28 * - RECEIVE HANDLERS
28 * - SEND FUNCTIONS 29 * - SEND FUNCTIONS
@@ -307,9 +308,9 @@ struct GNUNET_MESH_Tunnel
307 unsigned int npeers; 308 unsigned int npeers;
308 309
309 /** 310 /**
310 * Number of packets queued in this tunnel 311 * Size of packet queued in this tunnel
311 */ 312 */
312 unsigned int npackets; 313 unsigned int packet_size;
313 314
314 /** 315 /**
315 * Number of applications requested this tunnel 316 * Number of applications requested this tunnel
@@ -341,6 +342,24 @@ struct GNUNET_MESH_Tunnel
341 342
342 343
343/******************************************************************************/ 344/******************************************************************************/
345/*********************** DECLARATIONS *************************/
346/******************************************************************************/
347
348/**
349 * Function called to send a message to the service.
350 * "buf" will be NULL and "size" zero if the socket was closed for writing in
351 * the meantime.
352 *
353 * @param cls closure, the mesh handle
354 * @param size number of bytes available in buf
355 * @param buf where the callee should write the connect message
356 * @return number of bytes written to buf
357 */
358static size_t
359send_callback (void *cls, size_t size, void *buf);
360
361
362/******************************************************************************/
344/*********************** AUXILIARY FUNCTIONS *************************/ 363/*********************** AUXILIARY FUNCTIONS *************************/
345/******************************************************************************/ 364/******************************************************************************/
346 365
@@ -1079,6 +1098,11 @@ process_ack (struct GNUNET_MESH_Handle *h,
1079 ack = ntohl (msg->max_pid); 1098 ack = ntohl (msg->max_pid);
1080 if (ack > t->max_pid || PID_OVERFLOW (t->max_pid, ack)) 1099 if (ack > t->max_pid || PID_OVERFLOW (t->max_pid, ack))
1081 t->max_pid = ack; 1100 t->max_pid = ack;
1101 if (NULL == h->th && 0 < t->packet_size)
1102 h->th =
1103 GNUNET_CLIENT_notify_transmit_ready (h->client, t->packet_size,
1104 GNUNET_TIME_UNIT_FOREVER_REL,
1105 GNUNET_YES, &send_callback, h);
1082} 1106}
1083 1107
1084 1108
@@ -1157,6 +1181,8 @@ send_callback (void *cls, size_t size, void *buf)
1157{ 1181{
1158 struct GNUNET_MESH_Handle *h = cls; 1182 struct GNUNET_MESH_Handle *h = cls;
1159 struct GNUNET_MESH_TransmitHandle *th; 1183 struct GNUNET_MESH_TransmitHandle *th;
1184 struct GNUNET_MESH_TransmitHandle *next;
1185 struct GNUNET_MESH_Tunnel *t;
1160 char *cbuf = buf; 1186 char *cbuf = buf;
1161 size_t tsize; 1187 size_t tsize;
1162 size_t psize; 1188 size_t psize;
@@ -1170,11 +1196,18 @@ send_callback (void *cls, size_t size, void *buf)
1170 return 0; 1196 return 0;
1171 } 1197 }
1172 tsize = 0; 1198 tsize = 0;
1173 while ((NULL != (th = h->th_head)) && (size >= th->size)) 1199 while ((NULL != (th = next)) && (size >= th->size))
1174 { 1200 {
1201 t = th->tunnel;
1175 if (NULL != th->notify) 1202 if (NULL != th->notify)
1176 { 1203 {
1177 if (th->tunnel->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) 1204 if (t->max_pid < t->pid && ! PID_OVERFLOW (t->pid, t->max_pid)) {
1205 /* This tunnel is not ready to transmit yet, try next message */
1206 next = th->next;
1207 continue;
1208 }
1209 t->packet_size = 0;
1210 if (t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
1178 { 1211 {
1179 /* traffic to origin */ 1212 /* traffic to origin */
1180 struct GNUNET_MESH_ToOrigin to; 1213 struct GNUNET_MESH_ToOrigin to;
@@ -1191,7 +1224,8 @@ send_callback (void *cls, size_t size, void *buf)
1191 GNUNET_assert (size >= psize); 1224 GNUNET_assert (size >= psize);
1192 to.header.size = htons (psize); 1225 to.header.size = htons (psize);
1193 to.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN); 1226 to.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
1194 to.tid = htonl (th->tunnel->tid); 1227 to.tid = htonl (t->tid);
1228 // FIXME pid?
1195 memset (&to.oid, 0, sizeof (struct GNUNET_PeerIdentity)); 1229 memset (&to.oid, 0, sizeof (struct GNUNET_PeerIdentity));
1196 memset (&to.sender, 0, sizeof (struct GNUNET_PeerIdentity)); 1230 memset (&to.sender, 0, sizeof (struct GNUNET_PeerIdentity));
1197 memcpy (cbuf, &to, sizeof (to)); 1231 memcpy (cbuf, &to, sizeof (to));
@@ -1214,8 +1248,8 @@ send_callback (void *cls, size_t size, void *buf)
1214 GNUNET_assert (size >= psize); 1248 GNUNET_assert (size >= psize);
1215 mc.header.size = htons (psize); 1249 mc.header.size = htons (psize);
1216 mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); 1250 mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
1217 mc.tid = htonl (th->tunnel->tid); 1251 mc.tid = htonl (t->tid);
1218 mc.pid = 0; 1252 mc.pid = htonl (t->pid);
1219 mc.ttl = 0; 1253 mc.ttl = 0;
1220 memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); 1254 memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity));
1221 memcpy (cbuf, &mc, sizeof (mc)); 1255 memcpy (cbuf, &mc, sizeof (mc));
@@ -1238,12 +1272,14 @@ send_callback (void *cls, size_t size, void *buf)
1238 GNUNET_assert (size >= psize); 1272 GNUNET_assert (size >= psize);
1239 uc.header.size = htons (psize); 1273 uc.header.size = htons (psize);
1240 uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST); 1274 uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST);
1241 uc.tid = htonl (th->tunnel->tid); 1275 uc.tid = htonl (t->tid);
1276 uc.pid = htonl (t->pid);
1242 memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); 1277 memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity));
1243 GNUNET_PEER_resolve (th->target, &uc.destination); 1278 GNUNET_PEER_resolve (th->target, &uc.destination);
1244 memcpy (cbuf, &uc, sizeof (uc)); 1279 memcpy (cbuf, &uc, sizeof (uc));
1245 } 1280 }
1246 } 1281 }
1282 t->pid++;
1247 } 1283 }
1248 else 1284 else
1249 { 1285 {
@@ -1255,25 +1291,42 @@ send_callback (void *cls, size_t size, void *buf)
1255 } 1291 }
1256 if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1292 if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1257 GNUNET_SCHEDULER_cancel (th->timeout_task); 1293 GNUNET_SCHEDULER_cancel (th->timeout_task);
1258 if (NULL != th->notify)
1259 {
1260 th->tunnel->npackets--;
1261 }
1262 GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); 1294 GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th);
1263 GNUNET_free (th); 1295 GNUNET_free (th);
1296 next = h->th_head;
1264 cbuf += psize; 1297 cbuf += psize;
1265 size -= psize; 1298 size -= psize;
1266 tsize += psize; 1299 tsize += psize;
1267 } 1300 }
1268 LOG (GNUNET_ERROR_TYPE_DEBUG, " total size: %u\n", tsize); 1301 LOG (GNUNET_ERROR_TYPE_DEBUG, " total size: %u\n", tsize);
1269 if (NULL != (th = h->th_head)) 1302 if (NULL != h->th_head)
1270 { 1303 {
1271 LOG (GNUNET_ERROR_TYPE_DEBUG, " next size: %u\n", th->size); 1304 int request = GNUNET_NO;
1272 if (NULL == h->th) 1305
1306 for (th = h->th_head; NULL != th; th = th->next)
1307 {
1308 struct GNUNET_MESH_Tunnel *t = th->tunnel;
1309
1310 if (NULL != th->notify ||
1311 (t->max_pid >= t->pid || PID_OVERFLOW (t->pid, t->max_pid)))
1312 {
1313 request = GNUNET_YES;
1314 break;
1315 }
1316 }
1317
1318 if (GNUNET_YES == request)
1319 {
1320 LOG (GNUNET_ERROR_TYPE_DEBUG, " next size: %u\n", th->size);
1273 h->th = 1321 h->th =
1274 GNUNET_CLIENT_notify_transmit_ready (h->client, th->size, 1322 GNUNET_CLIENT_notify_transmit_ready (h->client, th->size,
1275 GNUNET_TIME_UNIT_FOREVER_REL, 1323 GNUNET_TIME_UNIT_FOREVER_REL,
1276 GNUNET_YES, &send_callback, h); 1324 GNUNET_YES, &send_callback, h);
1325 }
1326 else
1327 {
1328 LOG (GNUNET_ERROR_TYPE_DEBUG, " nothing left to transmit\n");
1329 }
1277 } 1330 }
1278 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send packet() END\n"); 1331 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send packet() END\n");
1279 if (GNUNET_NO == h->in_receive) 1332 if (GNUNET_NO == h->in_receive)
@@ -1863,8 +1916,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1863 else 1916 else
1864 LOG (GNUNET_ERROR_TYPE_DEBUG, " target multicast\n"); 1917 LOG (GNUNET_ERROR_TYPE_DEBUG, " target multicast\n");
1865 GNUNET_assert (NULL != notify); 1918 GNUNET_assert (NULL != notify);
1866 GNUNET_assert (0 == tunnel->npackets); 1919 GNUNET_assert (0 == tunnel->packet_size); // Only one data packet allowed
1867 tunnel->npackets++;
1868 th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle)); 1920 th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle));
1869 th->tunnel = tunnel; 1921 th->tunnel = tunnel;
1870 th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); 1922 th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
@@ -1875,7 +1927,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1875 overhead = sizeof (struct GNUNET_MESH_Multicast); 1927 overhead = sizeof (struct GNUNET_MESH_Multicast);
1876 else 1928 else
1877 overhead = sizeof (struct GNUNET_MESH_Unicast); 1929 overhead = sizeof (struct GNUNET_MESH_Unicast);
1878 th->size = notify_size + overhead; 1930 tunnel->packet_size = th->size = notify_size + overhead;
1879 th->notify = notify; 1931 th->notify = notify;
1880 th->notify_cls = notify_cls; 1932 th->notify_cls = notify_cls;
1881 add_to_queue (tunnel->mesh, th); 1933 add_to_queue (tunnel->mesh, th);