aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-11 12:16:22 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-11 12:16:22 +0000
commit0619087fbfdc6d93d421edee1a1320c494f18079 (patch)
treec7c8ad6c6d2dd820bf9ec2af5e8836987f4853f7 /src/mesh
parent15ec6e9eb5e1ec86c1db2135b62abe0ac36f8daf (diff)
downloadgnunet-0619087fbfdc6d93d421edee1a1320c494f18079.tar.gz
gnunet-0619087fbfdc6d93d421edee1a1320c494f18079.zip
- fix compile errors in local
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh_channel.c105
-rw-r--r--src/mesh/gnunet-service-mesh_channel.h18
-rw-r--r--src/mesh/gnunet-service-mesh_local.c37
3 files changed, 92 insertions, 68 deletions
diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c
index aa4ff0cc8..9019fb42c 100644
--- a/src/mesh/gnunet-service-mesh_channel.c
+++ b/src/mesh/gnunet-service-mesh_channel.c
@@ -853,47 +853,6 @@ channel_send_ack (struct MeshChannel *ch, int fwd)
853 853
854 854
855/** 855/**
856 * Iterator for deleting each channel whose client endpoint disconnected.
857 *
858 * @param cls Closure (client that has disconnected).
859 * @param key The local channel id (used to access the hashmap).
860 * @param value The value stored at the key (channel to destroy).
861 *
862 * @return GNUNET_OK, keep iterating.
863 */
864static int
865channel_destroy_iterator (void *cls,
866 uint32_t key,
867 void *value)
868{
869 struct MeshChannel *ch = value;
870 struct MeshClient *c = cls;
871 struct MeshTunnel3 *t;
872
873 LOG (GNUNET_ERROR_TYPE_DEBUG,
874 " Channel %X (%X / %X) destroy, due to client %s shutdown.\n",
875 ch->gid, ch->lid_root, ch->lid_dest, GML_2s (c));
876 GMCH_debug (ch);
877
878 if (c == ch->dest)
879 {
880 LOG (GNUNET_ERROR_TYPE_DEBUG, " Client %s is destination.\n", GML_2s (c));
881 }
882 if (c == ch->root)
883 {
884 LOG (GNUNET_ERROR_TYPE_DEBUG, " Client %s is owner.\n", GML_2s (c));
885 }
886
887 t = ch->t;
888 GMCH_send_destroy (ch);
889 channel_destroy (ch);
890 GMT_destroy_if_empty (t);
891
892 return GNUNET_OK;
893}
894
895
896/**
897 * Handle a loopback message: call the appropriate handler for the message type. 856 * Handle a loopback message: call the appropriate handler for the message type.
898 * 857 *
899 * @param ch Channel this message is on. 858 * @param ch Channel this message is on.
@@ -1277,34 +1236,29 @@ GMCH_handle_local_data (struct MeshChannel *ch,
1277 * 1236 *
1278 * @param ch Channel. 1237 * @param ch Channel.
1279 * @param c Client that requested the destruction (to avoid notifying him). 1238 * @param c Client that requested the destruction (to avoid notifying him).
1280 * @param chid Channel ID used.
1281 */ 1239 */
1282void 1240void
1283GMCH_handle_local_destroy (struct MeshChannel *ch, 1241GMCH_handle_local_destroy (struct MeshChannel *ch,
1284 struct MeshClient *c, 1242 struct MeshClient *c)
1285 MESH_ChannelNumber chid)
1286{ 1243{
1287 struct MeshTunnel3 *t; 1244 struct MeshTunnel3 *t;
1288 1245
1289 /* Cleanup after the tunnel */ 1246 /* Cleanup after the tunnel */
1290 GML_client_delete_channel (c, ch, chid); 1247 if (c == ch->dest)
1291 if (c == ch->dest && GNUNET_MESH_LOCAL_CHANNEL_ID_SERV <= chid)
1292 { 1248 {
1249 LOG (GNUNET_ERROR_TYPE_DEBUG, " Client %s is destination.\n", GML_2s (c));
1250 GML_client_delete_channel (c, ch, ch->lid_dest);
1293 ch->dest = NULL; 1251 ch->dest = NULL;
1294 } 1252 }
1295 else if (c == ch->root && GNUNET_MESH_LOCAL_CHANNEL_ID_SERV > chid) 1253 if (c == ch->root)
1296 { 1254 {
1255 LOG (GNUNET_ERROR_TYPE_DEBUG, " Client %s is owner.\n", GML_2s (c));
1256 GML_client_delete_channel (c, ch, ch->lid_root);
1297 ch->root = NULL; 1257 ch->root = NULL;
1298 } 1258 }
1299 else
1300 {
1301 LOG (GNUNET_ERROR_TYPE_ERROR,
1302 " channel %X client %p (%p, %p)\n",
1303 chid, c, ch->root, ch->dest);
1304 GNUNET_break (0);
1305 }
1306 1259
1307 t = ch->t; 1260 t = ch->t;
1261 GMCH_send_destroy (ch);
1308 channel_destroy (ch); 1262 channel_destroy (ch);
1309 GMT_destroy_if_empty (t); 1263 GMT_destroy_if_empty (t);
1310} 1264}
@@ -1317,8 +1271,10 @@ GMCH_handle_local_destroy (struct MeshChannel *ch,
1317 * 1271 *
1318 * @param c Client that requested the creation (will be the root). 1272 * @param c Client that requested the creation (will be the root).
1319 * @param msg Create Channel message. 1273 * @param msg Create Channel message.
1274 *
1275 * @return GNUNET_OK if everything went fine, GNUNET_SYSERR otherwise.
1320 */ 1276 */
1321void 1277int
1322GMCH_handle_local_create (struct MeshClient *c, 1278GMCH_handle_local_create (struct MeshClient *c,
1323 struct GNUNET_MESH_ChannelMessage *msg) 1279 struct GNUNET_MESH_ChannelMessage *msg)
1324{ 1280{
@@ -1335,15 +1291,14 @@ GMCH_handle_local_create (struct MeshClient *c,
1335 if (NULL != GML_channel_get (c, chid)) 1291 if (NULL != GML_channel_get (c, chid))
1336 { 1292 {
1337 GNUNET_break (0); 1293 GNUNET_break (0);
1338 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1294 return GNUNET_SYSERR;
1339 return;
1340 } 1295 }
1341 1296
1342 peer = GMP_get (&msg->peer); 1297 peer = GMP_get (&msg->peer);
1343 GMP_add_tunnel (peer); 1298 GMP_add_tunnel (peer);
1344 t = GMP_get_tunnel(peer); 1299 t = GMP_get_tunnel (peer);
1345 1300
1346 if (GMP_get_short_id(peer) == myid) 1301 if (GMP_get_short_id (peer) == myid)
1347 { 1302 {
1348 GMT_change_state (t, MESH_TUNNEL3_READY); 1303 GMT_change_state (t, MESH_TUNNEL3_READY);
1349 } 1304 }
@@ -1357,7 +1312,7 @@ GMCH_handle_local_create (struct MeshClient *c,
1357 if (NULL == ch) 1312 if (NULL == ch)
1358 { 1313 {
1359 GNUNET_break (0); 1314 GNUNET_break (0);
1360 return; 1315 return GNUNET_SYSERR;
1361 } 1316 }
1362 ch->port = ntohl (msg->port); 1317 ch->port = ntohl (msg->port);
1363 channel_set_options (ch, ntohl (msg->opt)); 1318 channel_set_options (ch, ntohl (msg->opt));
@@ -1368,7 +1323,7 @@ GMCH_handle_local_create (struct MeshClient *c,
1368 ch->root_rel->expected_delay = MESH_RETRANSMIT_TIME; 1323 ch->root_rel->expected_delay = MESH_RETRANSMIT_TIME;
1369 1324
1370 LOG (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n", 1325 LOG (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n",
1371 peer2s (t->peer), ch->gid, ch->port, ch->lid_root); 1326 GMT_2s (t), ch->gid, ch->port, ch->lid_root);
1372 1327
1373 /* Send create channel */ 1328 /* Send create channel */
1374 { 1329 {
@@ -1382,6 +1337,7 @@ GMCH_handle_local_create (struct MeshClient *c,
1382 1337
1383 GMT_queue_data (t, ch, &msgcc.header, GNUNET_YES); 1338 GMT_queue_data (t, ch, &msgcc.header, GNUNET_YES);
1384 } 1339 }
1340 return GNUNET_OK;
1385} 1341}
1386 1342
1387/** 1343/**
@@ -1618,14 +1574,19 @@ GMCH_handle_destroy (struct MeshChannel *ch,
1618 const struct GNUNET_MESH_ChannelManage *msg, 1574 const struct GNUNET_MESH_ChannelManage *msg,
1619 int fwd) 1575 int fwd)
1620{ 1576{
1577 struct MeshTunnel3 *t;
1578
1579 GMCH_debug (ch);
1621 if ( (fwd && NULL == ch->dest) || (!fwd && NULL == ch->root) ) 1580 if ( (fwd && NULL == ch->dest) || (!fwd && NULL == ch->root) )
1622 { 1581 {
1623 /* Not for us (don't destroy twice a half-open loopback channel) */ 1582 /* Not for us (don't destroy twice a half-open loopback channel) */
1624 return; 1583 return;
1625 } 1584 }
1626 1585
1586 t = ch->t;
1627 GMCH_send_destroy (ch); 1587 GMCH_send_destroy (ch);
1628 channel_destroy (ch); 1588 channel_destroy (ch);
1589 GMT_destroy_if_empty (t);
1629} 1590}
1630 1591
1631 1592
@@ -1661,3 +1622,25 @@ GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1661 1622
1662 GMT_send_prebuilt_message (message, ch->t, ch, fwd); 1623 GMT_send_prebuilt_message (message, ch->t, ch, fwd);
1663} 1624}
1625
1626
1627/**
1628 * Get the static string for identification of the channel.
1629 *
1630 * @param ch Channel.
1631 *
1632 * @return Static string with the channel IDs.
1633 */
1634const char *
1635GMCH_2s (const struct MeshChannel *ch)
1636{
1637 static char buf[64];
1638
1639 if (NULL == ch)
1640 return "(NULL Channel)";
1641
1642 sprintf (buf, "%s:%X (%X / %X)",
1643 GMT_2s (ch->t), ch->gid, ch->lid_root, ch->lid_dest);
1644
1645 return buf;
1646}
diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h
index 09f5fd3f0..3b6769132 100644
--- a/src/mesh/gnunet-service-mesh_channel.h
+++ b/src/mesh/gnunet-service-mesh_channel.h
@@ -192,12 +192,10 @@ GMCH_handle_local_data (struct MeshChannel *ch,
192 * 192 *
193 * @param ch Channel. 193 * @param ch Channel.
194 * @param c Client that requested the destruction (to avoid notifying him). 194 * @param c Client that requested the destruction (to avoid notifying him).
195 * @param chid Channel ID used.
196 */ 195 */
197void 196void
198GMCH_handle_local_destroy (struct MeshChannel *ch, 197GMCH_handle_local_destroy (struct MeshChannel *ch,
199 struct MeshClient *c, 198 struct MeshClient *c);
200 MESH_ChannelNumber chid);
201 199
202/** 200/**
203 * Handle a channel create requested by a client. 201 * Handle a channel create requested by a client.
@@ -206,8 +204,10 @@ GMCH_handle_local_destroy (struct MeshChannel *ch,
206 * 204 *
207 * @param c Client that requested the creation (will be the root). 205 * @param c Client that requested the creation (will be the root).
208 * @param msg Create Channel message. 206 * @param msg Create Channel message.
207 *
208 * @return GNUNET_OK if everything went fine, GNUNET_SYSERR otherwise.
209 */ 209 */
210void 210int
211GMCH_handle_local_create (struct MeshClient *c, 211GMCH_handle_local_create (struct MeshClient *c,
212 struct GNUNET_MESH_ChannelMessage *msg); 212 struct GNUNET_MESH_ChannelMessage *msg);
213 213
@@ -287,6 +287,16 @@ void
287GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, 287GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
288 struct MeshChannel *ch, int fwd); 288 struct MeshChannel *ch, int fwd);
289 289
290/**
291 * Get the static string for identification of the channel.
292 *
293 * @param ch Channel.
294 *
295 * @return Static string with the channel IDs.
296 */
297const char *
298GMCH_2s (const struct MeshChannel *ch);
299
290 300
291#if 0 /* keep Emacsens' auto-indent happy */ 301#if 0 /* keep Emacsens' auto-indent happy */
292{ 302{
diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c
index b77b7be8d..0fe98f448 100644
--- a/src/mesh/gnunet-service-mesh_local.c
+++ b/src/mesh/gnunet-service-mesh_local.c
@@ -192,6 +192,31 @@ handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
192 192
193 193
194/** 194/**
195 * Iterator for deleting each channel whose client endpoint disconnected.
196 *
197 * @param cls Closure (client that has disconnected).
198 * @param key The local channel id (used to access the hashmap).
199 * @param value The value stored at the key (channel to destroy).
200 *
201 * @return GNUNET_OK, keep iterating.
202 */
203static int
204channel_destroy_iterator (void *cls,
205 uint32_t key,
206 void *value)
207{
208 struct MeshChannel *ch = value;
209 struct MeshClient *c = cls;
210
211 LOG (GNUNET_ERROR_TYPE_DEBUG,
212 " Channel %s destroy, due to client %s shutdown.\n",
213 GMCH_2s (ch), GML_2s (c));
214
215 GMCH_handle_local_destroy (ch, c);
216 return GNUNET_OK;
217}
218
219/**
195 * Handler for client disconnection 220 * Handler for client disconnection
196 * 221 *
197 * @param cls closure 222 * @param cls closure
@@ -210,7 +235,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
210 return; 235 return;
211 } 236 }
212 237
213 c = client_get (client); 238 c = GML_client_get (client);
214 if (NULL != c) 239 if (NULL != c)
215 { 240 {
216 LOG (GNUNET_ERROR_TYPE_DEBUG, "matching client found (%u, %p)\n", 241 LOG (GNUNET_ERROR_TYPE_DEBUG, "matching client found (%u, %p)\n",
@@ -349,7 +374,13 @@ handle_channel_create (void *cls, struct GNUNET_SERVER_Client *client,
349 return; 374 return;
350 } 375 }
351 376
352 GMCH_handle_local_create (c, (struct GNUNET_MESH_ChannelMessage *) message); 377 if (GNUNET_OK !=
378 GMCH_handle_local_create (c,
379 (struct GNUNET_MESH_ChannelMessage *) message))
380 {
381 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
382 return;
383 }
353 384
354 GNUNET_SERVER_receive_done (client, GNUNET_OK); 385 GNUNET_SERVER_receive_done (client, GNUNET_OK);
355 return; 386 return;
@@ -405,7 +436,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
405 return; 436 return;
406 } 437 }
407 438
408 GMCH_handle_local_destroy (ch, c, chid); 439 GMCH_handle_local_destroy (ch, c);
409 440
410 GNUNET_SERVER_receive_done (client, GNUNET_OK); 441 GNUNET_SERVER_receive_done (client, GNUNET_OK);
411 return; 442 return;