aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-10 13:52:37 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-10 13:52:37 +0000
commitbc69fd462df9e2e2ad795586400cba74e8327dcd (patch)
tree7c52759af819922c3f1fbe8cef727557a7261dc9 /src
parentaf56cd3fcb1fe3adf680ce90e1fbbefd7bd88d75 (diff)
downloadgnunet-bc69fd462df9e2e2ad795586400cba74e8327dcd.tar.gz
gnunet-bc69fd462df9e2e2ad795586400cba74e8327dcd.zip
- fixes
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh_channel.c24
-rw-r--r--src/mesh/gnunet-service-mesh_channel.h1
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c158
-rw-r--r--src/mesh/gnunet-service-mesh_connection.h1
-rw-r--r--src/mesh/gnunet-service-mesh_local.c2
-rw-r--r--src/mesh/gnunet-service-mesh_local.h2
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c2
7 files changed, 91 insertions, 99 deletions
diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c
index 5f2ce2f8d..f59519311 100644
--- a/src/mesh/gnunet-service-mesh_channel.c
+++ b/src/mesh/gnunet-service-mesh_channel.c
@@ -526,8 +526,8 @@ channel_retransmit_message (void *cls,
526 * is stalled. 526 * is stalled.
527 */ 527 */
528// FIXME access to queue elements is limited 528// FIXME access to queue elements is limited
529// payload = (struct GNUNET_MESH_Data *) &copy[1]; 529 payload = (struct GNUNET_MESH_Data *) &copy[1];
530// fwd = (rel == ch->root_rel); 530 fwd = (rel == ch->root_rel);
531// c = GMT_get_connection (ch->t, fwd); 531// c = GMT_get_connection (ch->t, fwd);
532// hop = connection_get_hop (c, fwd); 532// hop = connection_get_hop (c, fwd);
533// for (q = hop->queue_head; NULL != q; q = q->next) 533// for (q = hop->queue_head; NULL != q; q = q->next)
@@ -897,7 +897,7 @@ channel_destroy_iterator (void *cls,
897 */ 897 */
898void 898void
899handle_loopback (struct MeshChannel *ch, 899handle_loopback (struct MeshChannel *ch,
900 struct GNUNET_MessageHeader *msgh, 900 const struct GNUNET_MessageHeader *msgh,
901 int fwd) 901 int fwd)
902{ 902{
903 uint16_t type; 903 uint16_t type;
@@ -1200,8 +1200,6 @@ GMCH_handle_data (struct MeshChannel *ch,
1200 struct MeshChannelReliability *rel; 1200 struct MeshChannelReliability *rel;
1201 struct MeshClient *c; 1201 struct MeshClient *c;
1202 uint32_t mid; 1202 uint32_t mid;
1203 uint16_t type;
1204 size_t size;
1205 1203
1206 /* Initialize FWD/BCK data */ 1204 /* Initialize FWD/BCK data */
1207 c = fwd ? ch->dest : ch->root; 1205 c = fwd ? ch->dest : ch->root;
@@ -1360,7 +1358,7 @@ GMCH_handle_create (const struct GNUNET_MESH_ChannelCreate *msg,
1360 chid = ntohl (msg->chid); 1358 chid = ntohl (msg->chid);
1361 1359
1362 /* Create channel */ 1360 /* Create channel */
1363 ch = channel_new (NULL, NULL, 0); /* FIXME t */ 1361 ch = channel_new (NULL, NULL, 0); /* FIXME pass t */
1364 ch->gid = chid; 1362 ch->gid = chid;
1365 channel_set_options (ch, ntohl (msg->opt)); 1363 channel_set_options (ch, ntohl (msg->opt));
1366 1364
@@ -1372,11 +1370,11 @@ GMCH_handle_create (const struct GNUNET_MESH_ChannelCreate *msg,
1372 { 1370 {
1373 /* TODO send reject */ 1371 /* TODO send reject */
1374 LOG (GNUNET_ERROR_TYPE_DEBUG, " no client has port registered\n"); 1372 LOG (GNUNET_ERROR_TYPE_DEBUG, " no client has port registered\n");
1375 /* TODO free ch */ 1373 channel_destroy (ch);
1376 return; 1374 return NULL;
1377 } 1375 }
1378 1376
1379 channel_add_client (ch, c); 1377 GMCH_add_client (ch, c);
1380 if (GNUNET_YES == ch->reliable) 1378 if (GNUNET_YES == ch->reliable)
1381 LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! Reliable\n"); 1379 LOG (GNUNET_ERROR_TYPE_DEBUG, "!!! Reliable\n");
1382 1380
@@ -1416,10 +1414,6 @@ GMCH_handle_destroy (struct MeshChannel *ch,
1416 const struct GNUNET_MESH_ChannelManage *msg, 1414 const struct GNUNET_MESH_ChannelManage *msg,
1417 int fwd) 1415 int fwd)
1418{ 1416{
1419 MESH_ChannelNumber chid;
1420
1421 /* Check if channel exists */
1422 chid = ntohl (msg->chid);
1423 if ( (fwd && NULL == ch->dest) || (!fwd && NULL == ch->root) ) 1417 if ( (fwd && NULL == ch->dest) || (!fwd && NULL == ch->root) )
1424 { 1418 {
1425 /* Not for us (don't destroy twice a half-open loopback channel) */ 1419 /* Not for us (don't destroy twice a half-open loopback channel) */
@@ -1442,8 +1436,6 @@ void
1442GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message, 1436GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1443 struct MeshChannel *ch, int fwd) 1437 struct MeshChannel *ch, int fwd)
1444{ 1438{
1445 size_t size = ntohs (message->size);
1446
1447 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send on Channel %s:%X %s\n", 1439 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send on Channel %s:%X %s\n",
1448 GMT_2s (ch->t), ch->gid, fwd ? "FWD" : "BCK"); 1440 GMT_2s (ch->t), ch->gid, fwd ? "FWD" : "BCK");
1449 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", 1441 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n",
@@ -1451,7 +1443,7 @@ GMCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
1451 1443
1452 if (GMT_is_loopback (ch->t)) 1444 if (GMT_is_loopback (ch->t))
1453 { 1445 {
1454 handle_loopback (ch->t, message, fwd); 1446 handle_loopback (ch, message, fwd);
1455 return; 1447 return;
1456 } 1448 }
1457 1449
diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h
index a06319c34..1ea8c6d94 100644
--- a/src/mesh/gnunet-service-mesh_channel.h
+++ b/src/mesh/gnunet-service-mesh_channel.h
@@ -41,6 +41,7 @@ extern "C"
41#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
42 42
43#include "mesh_protocol_enc.h" 43#include "mesh_protocol_enc.h"
44#include "mesh_enc.h"
44 45
45/** 46/**
46 * Struct containing all information regarding a channel to a remote client. 47 * Struct containing all information regarding a channel to a remote client.
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index 86d241a82..7a27d3984 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -326,6 +326,64 @@ connection_get (const struct GNUNET_HashCode *cid)
326} 326}
327 327
328 328
329static void
330connection_change_state (struct MeshConnection* c,
331 enum MeshConnectionState state)
332{
333 LOG (GNUNET_ERROR_TYPE_DEBUG,
334 "Connection %s state was %s\n",
335 GNUNET_h2s (&c->id), GMC_state2s (c->state));
336 LOG (GNUNET_ERROR_TYPE_DEBUG,
337 "Connection %s state is now %s\n",
338 GNUNET_h2s (&c->id), GMC_state2s (state));
339 c->state = state;
340}
341
342
343/**
344 * Callback called when a queued message is sent.
345 *
346 * Calculates the average time
347 *
348 * @param cls Closure.
349 * @param c Connection this message was on.
350 * @param wait Time spent waiting for core (only the time for THIS message)
351 */
352static void
353message_sent (void *cls,
354 struct MeshConnection *c,
355 struct GNUNET_TIME_Relative wait)
356{
357 struct MeshConnectionPerformance *p;
358 size_t size = (size_t) cls;
359 double usecsperbyte;
360
361 if (NULL == c->perf)
362 return; /* Only endpoints are interested in this. */
363
364 p = c->perf;
365 usecsperbyte = ((double) wait.rel_value_us) / size;
366 if (p->size == AVG_MSGS)
367 {
368 /* Array is full. Substract oldest value, add new one and store. */
369 p->avg -= (p->usecsperbyte[p->idx] / AVG_MSGS);
370 p->usecsperbyte[p->idx] = usecsperbyte;
371 p->avg += (p->usecsperbyte[p->idx] / AVG_MSGS);
372 }
373 else
374 {
375 /* Array not yet full. Add current value to avg and store. */
376 p->usecsperbyte[p->idx] = usecsperbyte;
377 p->avg *= p->size;
378 p->avg += p->usecsperbyte[p->idx];
379 p->size++;
380 p->avg /= p->size;
381 }
382 p->idx = (p->idx + 1) % AVG_MSGS;
383}
384
385
386
329/** 387/**
330 * Send an ACK informing the predecessor about the available buffer space. 388 * Send an ACK informing the predecessor about the available buffer space.
331 * 389 *
@@ -407,7 +465,7 @@ send_connection_ack (struct MeshConnection *connection, int fwd)
407 sizeof (struct GNUNET_MESH_ConnectionACK), 465 sizeof (struct GNUNET_MESH_ConnectionACK),
408 connection, NULL, fwd, 466 connection, NULL, fwd,
409 &message_sent, sizeof (struct GNUNET_MESH_ConnectionACK)); 467 &message_sent, sizeof (struct GNUNET_MESH_ConnectionACK));
410 if (MESH_TUNNEL3_NEW == t->state) 468 if (MESH_TUNNEL3_NEW == GMT_get_state (t))
411 GMT_change_state (t, MESH_TUNNEL3_WAITING); 469 GMT_change_state (t, MESH_TUNNEL3_WAITING);
412 if (MESH_CONNECTION_READY != connection->state) 470 if (MESH_CONNECTION_READY != connection->state)
413 GMC_change_state (connection, MESH_CONNECTION_SENT); 471 GMC_change_state (connection, MESH_CONNECTION_SENT);
@@ -423,41 +481,26 @@ send_connection_ack (struct MeshConnection *connection, int fwd)
423static void 481static void
424send_connection_create (struct MeshConnection *connection) 482send_connection_create (struct MeshConnection *connection)
425{ 483{
426 struct MeshTunnel3 *t; 484enum MeshTunnel3State state;
485 size_t size;
427 486
428 t = connection->t; 487 size = sizeof (struct GNUNET_MESH_ConnectionCreate);
488 size += connection->path->length * sizeof (struct GNUNET_PeerIdentity);
429 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n"); 489 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
430 queue_add (NULL, 490 GMP_queue_add (NULL,
431 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, 491 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
432 sizeof (struct GNUNET_MESH_ConnectionCreate) + 492 size,
433 (connection->path->length * 493 connection,
434 sizeof (struct GNUNET_PeerIdentity)), 494 NULL,
435 connection, 495 GNUNET_YES, &message_sent, size);
436 NULL, 496 state = GMT_get_state (connection->t);
437 GNUNET_YES); 497 if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state)
438 if (NULL != t && 498 GMT_change_state (connection->t, MESH_TUNNEL3_WAITING);
439 (MESH_TUNNEL3_SEARCHING == t->state || MESH_TUNNEL3_NEW == t->state))
440 tunnel_change_state (t, MESH_TUNNEL3_WAITING);
441 if (MESH_CONNECTION_NEW == connection->state) 499 if (MESH_CONNECTION_NEW == connection->state)
442 connection_change_state (connection, MESH_CONNECTION_SENT); 500 connection_change_state (connection, MESH_CONNECTION_SENT);
443} 501}
444 502
445 503
446static void
447connection_change_state (struct MeshConnection* c,
448 enum MeshConnectionState state)
449{
450 LOG (GNUNET_ERROR_TYPE_DEBUG,
451 "Connection %s state was %s\n",
452 GNUNET_h2s (&c->id), GMC_state2s (c->state));
453 LOG (GNUNET_ERROR_TYPE_DEBUG,
454 "Connection %s state is now %s\n",
455 GNUNET_h2s (&c->id), GMC_state2s (state));
456 c->state = state;
457}
458
459
460
461/** 504/**
462 * Send keepalive packets for a connection. 505 * Send keepalive packets for a connection.
463 * 506 *
@@ -476,17 +519,15 @@ connection_keepalive (struct MeshConnection *c, int fwd)
476 GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE; 519 GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE;
477 520
478 LOG (GNUNET_ERROR_TYPE_DEBUG, 521 LOG (GNUNET_ERROR_TYPE_DEBUG,
479 "sending %s keepalive for connection %s[%d]\n", 522 "sending %s keepalive for connection %s[%d]\n",
480 fwd ? "FWD" : "BCK", 523 fwd ? "FWD" : "BCK", GMT_2s (c->t), c->id);
481 peer2s (c->t->peer),
482 c->id);
483 524
484 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf; 525 msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf;
485 msg->header.size = htons (size); 526 msg->header.size = htons (size);
486 msg->header.type = htons (type); 527 msg->header.type = htons (type);
487 msg->cid = c->id; 528 msg->cid = c->id;
488 529
489 send_prebuilt_message_connection (&msg->header, c, NULL, fwd); 530 GMC_send_prebuilt_message (&msg->header, c, NULL, fwd);
490} 531}
491 532
492 533
@@ -518,7 +559,7 @@ connection_recreate (struct MeshConnection *c, int fwd)
518static void 559static void
519connection_maintain (struct MeshConnection *c, int fwd) 560connection_maintain (struct MeshConnection *c, int fwd)
520{ 561{
521 if (MESH_TUNNEL3_SEARCHING == c->t->state) 562 if (MESH_TUNNEL3_SEARCHING == GMT_get_state (c->t))
522 { 563 {
523 /* TODO DHT GET with RO_BART */ 564 /* TODO DHT GET with RO_BART */
524 return; 565 return;
@@ -925,49 +966,6 @@ unregister_neighbors (struct MeshConnection *c)
925} 966}
926 967
927 968
928/**
929 * Callback called when a queued message is sent.
930 *
931 * Calculates the average time
932 *
933 * @param cls Closure.
934 * @param c Connection this message was on.
935 * @param wait Time spent waiting for core (only the time for THIS message)
936 */
937static void
938message_sent (void *cls,
939 struct MeshConnection *c,
940 struct GNUNET_TIME_Relative wait)
941{
942 struct MeshConnectionPerformance *p;
943 size_t size = (size_t) cls;
944 double usecsperbyte;
945
946 if (NULL == c->perf)
947 return; /* Only endpoints are interested in this. */
948
949 p = c->perf;
950 usecsperbyte = ((double) wait.rel_value_us) / size;
951 if (p->size == AVG_MSGS)
952 {
953 /* Array is full. Substract oldest value, add new one and store. */
954 p->avg -= (p->usecsperbyte[p->idx] / AVG_MSGS);
955 p->usecsperbyte[p->idx] = usecsperbyte;
956 p->avg += (p->usecsperbyte[p->idx] / AVG_MSGS);
957 }
958 else
959 {
960 /* Array not yet full. Add current value to avg and store. */
961 p->usecsperbyte[p->idx] = usecsperbyte;
962 p->avg *= p->size;
963 p->avg += p->usecsperbyte[p->idx];
964 p->size++;
965 p->avg /= p->size;
966 }
967 p->idx = (p->idx + 1) % AVG_MSGS;
968}
969
970
971/******************************************************************************/ 969/******************************************************************************/
972/******************************** API ***********************************/ 970/******************************** API ***********************************/
973/******************************************************************************/ 971/******************************************************************************/
@@ -2047,7 +2045,7 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2047 LOG (GNUNET_ERROR_TYPE_DEBUG, " poll %u\n", ntohl (pmsg->pid)); 2045 LOG (GNUNET_ERROR_TYPE_DEBUG, " poll %u\n", ntohl (pmsg->pid));
2048 break; 2046 break;
2049 2047
2050 case GNUNET_MESSAGE_TYPE_MESH_TUNNEL3_DESTROY: 2048 case GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY:
2051 dmsg = (struct GNUNET_MESH_ConnectionDestroy *) data; 2049 dmsg = (struct GNUNET_MESH_ConnectionDestroy *) data;
2052 dmsg->cid = c->id; 2050 dmsg->cid = c->id;
2053 dmsg->reserved = 0; 2051 dmsg->reserved = 0;
@@ -2089,7 +2087,7 @@ GMC_send_destroy (struct MeshConnection *c)
2089 return; 2087 return;
2090 2088
2091 msg.header.size = htons (sizeof (msg)); 2089 msg.header.size = htons (sizeof (msg));
2092 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL3_DESTROY);; 2090 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY);;
2093 msg.cid = c->id; 2091 msg.cid = c->id;
2094 LOG (GNUNET_ERROR_TYPE_DEBUG, 2092 LOG (GNUNET_ERROR_TYPE_DEBUG,
2095 " sending connection destroy for connection %s\n", 2093 " sending connection destroy for connection %s\n",
diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h
index 6b53b17cf..fafe0a59b 100644
--- a/src/mesh/gnunet-service-mesh_connection.h
+++ b/src/mesh/gnunet-service-mesh_connection.h
@@ -78,7 +78,6 @@ struct MeshConnection;
78 78
79 79
80 80
81
82/** 81/**
83 * Core handler for connection creation. 82 * Core handler for connection creation.
84 * 83 *
diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c
index 1e3bf1669..d4362d5e8 100644
--- a/src/mesh/gnunet-service-mesh_local.c
+++ b/src/mesh/gnunet-service-mesh_local.c
@@ -1054,7 +1054,7 @@ GML_send_ack (struct MeshChannel *ch, int fwd)
1054void 1054void
1055GML_send_channel_create (struct MeshClient *c, 1055GML_send_channel_create (struct MeshClient *c,
1056 uint32_t id, uint32_t port, uint32_t opt, 1056 uint32_t id, uint32_t port, uint32_t opt,
1057 struct GNUNET_PeerIdentity *peer) 1057 const struct GNUNET_PeerIdentity *peer)
1058{ 1058{
1059 struct GNUNET_MESH_ChannelMessage msg; 1059 struct GNUNET_MESH_ChannelMessage msg;
1060 1060
diff --git a/src/mesh/gnunet-service-mesh_local.h b/src/mesh/gnunet-service-mesh_local.h
index 4befb24ac..6f4507770 100644
--- a/src/mesh/gnunet-service-mesh_local.h
+++ b/src/mesh/gnunet-service-mesh_local.h
@@ -165,7 +165,7 @@ GML_send_ack (struct MeshChannel *ch, int fwd);
165void 165void
166GML_send_channel_create (struct MeshClient *c, 166GML_send_channel_create (struct MeshClient *c,
167 uint32_t id, uint32_t port, uint32_t opt, 167 uint32_t id, uint32_t port, uint32_t opt,
168 struct GNUNET_PeerIdentity *peer); 168 const struct GNUNET_PeerIdentity *peer);
169 169
170/** 170/**
171 * Notify a client that a channel is no longer valid. 171 * Notify a client that a channel is no longer valid.
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c
index 4e1373663..88a04eea6 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.c
+++ b/src/mesh/gnunet-service-mesh_tunnel.c
@@ -1003,6 +1003,8 @@ GMT_count_channels (struct MeshTunnel3 *t)
1003enum MeshTunnel3State 1003enum MeshTunnel3State
1004GMT_get_state (struct MeshTunnel3 *t) 1004GMT_get_state (struct MeshTunnel3 *t)
1005{ 1005{
1006 if (NULL == t)
1007 return (enum MeshTunnel3State) -1;
1006 return t->state; 1008 return t->state;
1007} 1009}
1008 1010