aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-10 18:08:42 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-10 18:08:42 +0000
commit25e99b83403ec04e691ed5543765e267705c125d (patch)
treebf17a58f1aadc8e6a19c5eb5c4c0ea79830d0dc8 /src/mesh
parent1295876120a61a26b35473a83162ed0e1e6aaf6c (diff)
downloadgnunet-25e99b83403ec04e691ed5543765e267705c125d.tar.gz
gnunet-25e99b83403ec04e691ed5543765e267705c125d.zip
- fix peer
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh_dht.c5
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c98
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.c41
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.h12
4 files changed, 81 insertions, 75 deletions
diff --git a/src/mesh/gnunet-service-mesh_dht.c b/src/mesh/gnunet-service-mesh_dht.c
index 4587041a4..067f7f4e1 100644
--- a/src/mesh/gnunet-service-mesh_dht.c
+++ b/src/mesh/gnunet-service-mesh_dht.c
@@ -91,11 +91,6 @@ static unsigned long long dht_replication_level;
91 */ 91 */
92static GNUNET_SCHEDULER_TaskIdentifier announce_id_task; 92static GNUNET_SCHEDULER_TaskIdentifier announce_id_task;
93 93
94/**
95 * Own private key.
96 */
97static struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
98
99 94
100/******************************************************************************/ 95/******************************************************************************/
101/******************************** STATIC ***********************************/ 96/******************************** STATIC ***********************************/
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c
index 2bba99319..bdc2fdd02 100644
--- a/src/mesh/gnunet-service-mesh_peer.c
+++ b/src/mesh/gnunet-service-mesh_peer.c
@@ -250,17 +250,17 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
250 struct MeshPeer *pi; 250 struct MeshPeer *pi;
251 struct MeshPeerPath *path; 251 struct MeshPeerPath *path;
252 252
253 LOG ("Peer connected\n"); 253 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer connected\n");
254 LOG (" %s\n", GNUNET_i2s (&my_full_id)); 254 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (&my_full_id));
255 pi = GMP_get (peer); 255 pi = GMP_get (peer);
256 if (myid == pi->id) 256 if (myid == pi->id)
257 { 257 {
258 LOG (" (self)\n"); 258 LOG (GNUNET_ERROR_TYPE_DEBUG, " (self)\n");
259 path = path_new (1); 259 path = path_new (1);
260 } 260 }
261 else 261 else
262 { 262 {
263 LOG (" %s\n", GNUNET_i2s (peer)); 263 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s\n", GNUNET_i2s (peer));
264 path = path_new (2); 264 path = path_new (2);
265 path->peers[1] = pi->id; 265 path->peers[1] = pi->id;
266 GNUNET_PEER_change_rc (pi->id, 1); 266 GNUNET_PEER_change_rc (pi->id, 1);
@@ -286,7 +286,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
286{ 286{
287 struct MeshPeer *pi; 287 struct MeshPeer *pi;
288 288
289 LOG ("Peer disconnected\n"); 289 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer disconnected\n");
290 pi = GNUNET_CONTAINER_multipeermap_get (peers, peer); 290 pi = GNUNET_CONTAINER_multipeermap_get (peers, peer);
291 if (NULL == pi) 291 if (NULL == pi)
292 { 292 {
@@ -304,7 +304,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
304 } 304 }
305 if (myid == pi->id) 305 if (myid == pi->id)
306 { 306 {
307 LOG (" (self)\n"); 307 LOG (GNUNET_ERROR_TYPE_DEBUG, " (self)\n");
308 } 308 }
309 GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO); 309 GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO);
310 310
@@ -417,7 +417,7 @@ send_core_connection_create (struct MeshConnection *c, size_t size, void *buf)
417{ 417{
418 struct GNUNET_MESH_ConnectionCreate *msg; 418 struct GNUNET_MESH_ConnectionCreate *msg;
419 struct GNUNET_PeerIdentity *peer_ptr; 419 struct GNUNET_PeerIdentity *peer_ptr;
420 struct MeshPeerPath *p = c->path; 420 const struct MeshPeerPath *p = GMC_get_path (c);
421 size_t size_needed; 421 size_t size_needed;
422 int i; 422 int i;
423 423
@@ -434,7 +434,7 @@ send_core_connection_create (struct MeshConnection *c, size_t size, void *buf)
434 msg = (struct GNUNET_MESH_ConnectionCreate *) buf; 434 msg = (struct GNUNET_MESH_ConnectionCreate *) buf;
435 msg->header.size = htons (size_needed); 435 msg->header.size = htons (size_needed);
436 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE); 436 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE);
437 msg->cid = c->id; 437 msg->cid = *GMC_get_id (c);
438 438
439 peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; 439 peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
440 for (i = 0; i < p->length; i++) 440 for (i = 0; i < p->length; i++)
@@ -442,8 +442,9 @@ send_core_connection_create (struct MeshConnection *c, size_t size, void *buf)
442 GNUNET_PEER_resolve (p->peers[i], peer_ptr++); 442 GNUNET_PEER_resolve (p->peers[i], peer_ptr++);
443 } 443 }
444 444
445 LOG (GNUNET_ERROR_TYPE_DEBUG, 445 LOG (GNUNET_ERROR_TYPE_DEBUG,
446 "CONNECTION CREATE (%u bytes long) sent!\n", size_needed); 446 "CONNECTION CREATE (%u bytes long) sent!\n",
447 size_needed);
447 return size_needed; 448 return size_needed;
448} 449}
449 450
@@ -461,10 +462,8 @@ static size_t
461send_core_connection_ack (struct MeshConnection *c, size_t size, void *buf) 462send_core_connection_ack (struct MeshConnection *c, size_t size, void *buf)
462{ 463{
463 struct GNUNET_MESH_ConnectionACK *msg = buf; 464 struct GNUNET_MESH_ConnectionACK *msg = buf;
464 struct MeshTunnel3 *t = c->t;
465 465
466 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CONNECTION ACK...\n"); 466 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CONNECTION ACK...\n");
467 GNUNET_assert (NULL != t);
468 if (sizeof (struct GNUNET_MESH_ConnectionACK) > size) 467 if (sizeof (struct GNUNET_MESH_ConnectionACK) > size)
469 { 468 {
470 GNUNET_break (0); 469 GNUNET_break (0);
@@ -472,7 +471,7 @@ send_core_connection_ack (struct MeshConnection *c, size_t size, void *buf)
472 } 471 }
473 msg->header.size = htons (sizeof (struct GNUNET_MESH_ConnectionACK)); 472 msg->header.size = htons (sizeof (struct GNUNET_MESH_ConnectionACK));
474 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK); 473 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK);
475 msg->cid = c->id; 474 msg->cid = *GMC_get_id (c);
476 msg->reserved = 0; 475 msg->reserved = 0;
477 476
478 /* TODO add signature */ 477 /* TODO add signature */
@@ -534,21 +533,21 @@ peer_destroy (struct MeshPeer *peer)
534 LOG (GNUNET_ERROR_TYPE_WARNING, 533 LOG (GNUNET_ERROR_TYPE_WARNING,
535 "removing peer %s, not in peermap\n", GNUNET_i2s (&id)); 534 "removing peer %s, not in peermap\n", GNUNET_i2s (&id));
536 } 535 }
537 if (NULL != peer->search_h) 536 if (NULL != peer->search_h)
538 { 537 {
539 GMD_search_stop (peer->search_h); 538 GMD_search_stop (peer->search_h);
540 } 539 }
541 p = peer->path_head; 540 p = peer->path_head;
542 while (NULL != p) 541 while (NULL != p)
543 { 542 {
544 nextp = p->next; 543 nextp = p->next;
545 GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, p); 544 GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, p);
546 path_destroy (p); 545 path_destroy (p);
547 p = nextp; 546 p = nextp;
548 } 547 }
549 tunnel_destroy_empty (peer->tunnel); 548 GMT_destroy_empty (peer->tunnel);
550 GNUNET_free (peer); 549 GNUNET_free (peer);
551 return GNUNET_OK; 550 return GNUNET_OK;
552} 551}
553 552
554 553
@@ -647,47 +646,6 @@ peer_delete_oldest (void)
647 646
648 647
649/** 648/**
650 * Get a cost of a path for a peer considering existing tunnel connections.
651 *
652 * @param peer Peer towards which the path is considered.
653 * @param path Candidate path.
654 *
655 * @return Cost of the path (path length + number of overlapping nodes)
656 */
657static unsigned int
658peer_get_path_cost (const struct MeshPeer *peer,
659 const struct MeshPeerPath *path)
660{
661 struct MeshConnection *c;
662 unsigned int overlap;
663 unsigned int i;
664 unsigned int j;
665
666 if (NULL == path)
667 return 0;
668
669 overlap = 0;
670 GNUNET_assert (NULL != peer->tunnel);
671
672 for (i = 0; i < path->length; i++)
673 {
674 for (c = peer->tunnel->connection_head; NULL != c; c = c->next)
675 {
676 for (j = 0; j < c->path->length; j++)
677 {
678 if (path->peers[i] == c->path->peers[j])
679 {
680 overlap++;
681 break;
682 }
683 }
684 }
685 }
686 return (path->length + overlap) * (path->score * -1);
687}
688
689
690/**
691 * Choose the best path towards a peer considering the tunnel properties. 649 * Choose the best path towards a peer considering the tunnel properties.
692 * 650 *
693 * @param peer The destination peer. 651 * @param peer The destination peer.
@@ -709,7 +667,7 @@ peer_get_best_path (const struct MeshPeer *peer)
709 if (GNUNET_YES == GMT_is_path_used (peer->tunnel, p)) 667 if (GNUNET_YES == GMT_is_path_used (peer->tunnel, p))
710 continue; /* If path is already in use, skip it. */ 668 continue; /* If path is already in use, skip it. */
711 669
712 if ((cost = peer_get_path_cost (peer, p)) < best_cost) 670 if ((cost = GMT_get_path_cost (peer->tunnel, p)) < best_cost)
713 { 671 {
714 best_cost = cost; 672 best_cost = cost;
715 best_p = p; 673 best_p = p;
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c
index 9341e0eaf..8b8085658 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.c
+++ b/src/mesh/gnunet-service-mesh_tunnel.c
@@ -1191,6 +1191,47 @@ GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p)
1191 1191
1192 1192
1193/** 1193/**
1194 * Get a cost of a path for a tunnel considering existing connections.
1195 *
1196 * @param t Tunnel.
1197 * @param path Candidate path.
1198 *
1199 * @return Cost of the path (path length + number of overlapping nodes)
1200 */
1201unsigned int
1202GMT_get_path_cost (const struct MeshTunnel3 *t,
1203 const struct MeshPeerPath *path)
1204{
1205 struct MeshTConnection *iter;
1206 unsigned int overlap;
1207 unsigned int i;
1208 unsigned int j;
1209
1210 if (NULL == path)
1211 return 0;
1212
1213 overlap = 0;
1214 GNUNET_assert (NULL != t);
1215
1216 for (i = 0; i < path->length; i++)
1217 {
1218 for (iter = t->connection_head; NULL != iter; iter = iter->next)
1219 {
1220 for (j = 0; j < GMC_get_path (iter->c)->length; j++)
1221 {
1222 if (path->peers[i] == GMC_get_path (iter->c)->peers[j])
1223 {
1224 overlap++;
1225 break;
1226 }
1227 }
1228 }
1229 }
1230 return (path->length + overlap) * (path->score * -1);
1231}
1232
1233
1234/**
1194 * Get the static string for the peer this tunnel is directed. 1235 * Get the static string for the peer this tunnel is directed.
1195 * 1236 *
1196 * @param t Tunnel. 1237 * @param t Tunnel.
diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h
index 89c8a1462..49533edf6 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.h
+++ b/src/mesh/gnunet-service-mesh_tunnel.h
@@ -332,6 +332,18 @@ int
332GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p); 332GMT_is_path_used (const struct MeshTunnel3 *t, const struct MeshPeerPath *p);
333 333
334/** 334/**
335 * Get a cost of a path for a tunnel considering existing connections.
336 *
337 * @param t Tunnel.
338 * @param path Candidate path.
339 *
340 * @return Cost of the path (path length + number of overlapping nodes)
341 */
342unsigned int
343GMT_get_path_cost (const struct MeshTunnel3 *t,
344 const struct MeshPeerPath *path);
345
346/**
335 * Get the static string for the peer this tunnel is directed. 347 * Get the static string for the peer this tunnel is directed.
336 * 348 *
337 * @param t Tunnel. 349 * @param t Tunnel.