aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-10-18 09:00:06 +0000
committerBart Polot <bart@net.in.tum.de>2011-10-18 09:00:06 +0000
commit97f036d35b9cc9ea11664d81bf05b783365cf20b (patch)
tree74d6fdac03436162af48ff2bdc7c0a0b8af29b6d /src/mesh/gnunet-service-mesh.c
parentde2b0525d627363de4c624a8b8ddc47e3bbd2f87 (diff)
downloadgnunet-97f036d35b9cc9ea11664d81bf05b783365cf20b.tar.gz
gnunet-97f036d35b9cc9ea11664d81bf05b783365cf20b.zip
Made multicast work for single peer tunnels
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r--src/mesh/gnunet-service-mesh.c105
1 files changed, 76 insertions, 29 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index d54a7022f..a9db45dde 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -811,6 +811,7 @@ send_client_peer_connected (const struct MeshTunnel *t, const GNUNET_PEER_Id id)
811static size_t 811static size_t
812send_core_create_path (void *cls, size_t size, void *buf); 812send_core_create_path (void *cls, size_t size, void *buf);
813 813
814
814/** 815/**
815 * Function called to notify a client about the socket 816 * Function called to notify a client about the socket
816 * being ready to queue more data. "buf" will be 817 * being ready to queue more data. "buf" will be
@@ -826,6 +827,7 @@ send_core_create_path (void *cls, size_t size, void *buf);
826static size_t 827static size_t
827send_core_data_multicast (void *cls, size_t size, void *buf); 828send_core_data_multicast (void *cls, size_t size, void *buf);
828 829
830
829/** 831/**
830 * Cancel a core transmission that was already requested and free all resources 832 * Cancel a core transmission that was already requested and free all resources
831 * associated to the request. 833 * associated to the request.
@@ -886,7 +888,12 @@ peer_info_cancel_transmission(struct MeshPeerInfo *peer, unsigned int i)
886 888
887 889
888/** 890/**
889 * 891 * Get a unused CORE slot to transmit a message to a peer. If all the slots
892 * are used, cancel one and return it's position.
893 *
894 * @param peer PeerInfo of the neighbor we want to transmit to.
895 *
896 * @return The index of an available slot to transmit to the neighbor.
890 */ 897 */
891static unsigned int 898static unsigned int
892peer_info_transmit_slot (struct MeshPeerInfo *peer) 899peer_info_transmit_slot (struct MeshPeerInfo *peer)
@@ -1627,7 +1634,7 @@ static int
1627tunnel_send_multicast (struct MeshTunnel *t, 1634tunnel_send_multicast (struct MeshTunnel *t,
1628 const struct GNUNET_MessageHeader *msg) 1635 const struct GNUNET_MessageHeader *msg)
1629{ 1636{
1630 struct GNUNET_PeerIdentity *neighbor; 1637 struct GNUNET_PeerIdentity neighbor;
1631 struct MeshDataDescriptor *info; 1638 struct MeshDataDescriptor *info;
1632 struct MeshTunnelTreeNode *n; 1639 struct MeshTunnelTreeNode *n;
1633 unsigned int *copies; 1640 unsigned int *copies;
@@ -1645,10 +1652,10 @@ tunnel_send_multicast (struct MeshTunnel *t,
1645 copies = GNUNET_malloc (sizeof (unsigned int)); 1652 copies = GNUNET_malloc (sizeof (unsigned int));
1646 for (*copies = 0; NULL != n; n = n->next) 1653 for (*copies = 0; NULL != n; n = n->next)
1647 (*copies)++; 1654 (*copies)++;
1648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (%u copies)\n", copies); 1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (%u copies)\n", *copies);
1649 n = t->tree->me->children_head; 1656 n = t->tree->me->children_head;
1650 data = GNUNET_malloc (size); 1657 data = GNUNET_malloc (size);
1651 memcpy (data, &msg, size); 1658 memcpy (data, msg, size);
1652 while (NULL != n) 1659 while (NULL != n)
1653 { 1660 {
1654 info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); 1661 info = GNUNET_malloc (sizeof (struct MeshDataDescriptor));
@@ -1656,30 +1663,21 @@ tunnel_send_multicast (struct MeshTunnel *t,
1656 info->data = data; 1663 info->data = data;
1657 info->size = size; 1664 info->size = size;
1658 info->copies = copies; 1665 info->copies = copies;
1659 if (NULL != t->client->handle) 1666 if (NULL != t->client)
1660 { 1667 {
1661 info->client = t->client->handle; 1668 info->client = t->client->handle;
1662
1663 info->timeout_task = GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT, 1669 info->timeout_task = GNUNET_SCHEDULER_add_delayed (UNACKNOWLEDGED_WAIT,
1664 &client_allow_send, 1670 &client_allow_send,
1665 t->client->handle); 1671 t->client->handle);
1666 } 1672 }
1667 info->destination = n->peer; 1673 info->destination = n->peer;
1668 neighbor = path_get_first_hop(t->tree, n->peer); 1674 GNUNET_PEER_resolve (n->peer, &neighbor);
1669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1670 "MESH: sending to %s...\n", 1676 "MESH: sending to %s...\n",
1671 GNUNET_i2s (neighbor)); 1677 GNUNET_i2s (&neighbor));
1672 info->peer = peer_info_get(neighbor); 1678 info->peer = peer_info_get(&neighbor);
1673 GNUNET_assert (NULL != info->peer); 1679 GNUNET_assert (NULL != info->peer);
1674 for (i = 0; NULL != info->peer->core_transmit[i]; i++) 1680 i = peer_info_transmit_slot(info->peer);
1675 {
1676 if (i == (CORE_QUEUE_SIZE - 1))
1677 {
1678 GNUNET_free (info);
1679 GNUNET_break (0);
1680 return GNUNET_OK;
1681 }
1682 }
1683 info->handler_n = i; 1681 info->handler_n = i;
1684 info->peer->infos[i] = info; 1682 info->peer->infos[i] = info;
1685 info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST; 1683 info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST;
@@ -1688,9 +1686,10 @@ tunnel_send_multicast (struct MeshTunnel *t,
1688 0, 1686 0,
1689 0, 1687 0,
1690 GNUNET_TIME_UNIT_FOREVER_REL, 1688 GNUNET_TIME_UNIT_FOREVER_REL,
1691 neighbor, 1689 &neighbor,
1692 size, 1690 size,
1693 &send_core_data_multicast, info); 1691 &send_core_data_multicast, info);
1692 n = n->next;
1694 } 1693 }
1695 return *copies; 1694 return *copies;
1696} 1695}
@@ -1942,9 +1941,9 @@ static size_t
1942send_core_data_multicast (void *cls, size_t size, void *buf) 1941send_core_data_multicast (void *cls, size_t size, void *buf)
1943{ 1942{
1944 struct MeshDataDescriptor *info = cls; 1943 struct MeshDataDescriptor *info = cls;
1945 struct GNUNET_MessageHeader *msg = buf;
1946 size_t total_size; 1944 size_t total_size;
1947 1945
1946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Multicast callback.\n");
1948 GNUNET_assert (NULL != info); 1947 GNUNET_assert (NULL != info);
1949 GNUNET_assert (NULL != info->peer); 1948 GNUNET_assert (NULL != info->peer);
1950 total_size = info->size; 1949 total_size = info->size;
@@ -1955,6 +1954,9 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
1955 /* Retry */ 1954 /* Retry */
1956 struct GNUNET_PeerIdentity id; 1955 struct GNUNET_PeerIdentity id;
1957 1956
1957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1958 "MESH: Multicast: retransmitting... (%u/%u)\n",
1959 size, total_size);
1958 GNUNET_PEER_resolve(info->peer->id, &id); 1960 GNUNET_PEER_resolve(info->peer->id, &id);
1959 info->peer->core_transmit[info->handler_n] = 1961 info->peer->core_transmit[info->handler_n] =
1960 GNUNET_CORE_notify_transmit_ready (core_handle, 1962 GNUNET_CORE_notify_transmit_ready (core_handle,
@@ -1969,19 +1971,55 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
1969 } 1971 }
1970 info->peer->core_transmit[info->handler_n] = NULL; 1972 info->peer->core_transmit[info->handler_n] = NULL;
1971 info->peer->infos[info->handler_n] = NULL; 1973 info->peer->infos[info->handler_n] = NULL;
1972 memcpy (&msg, info->data, total_size); 1974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: copying data...\n");
1975 memcpy (buf, info->data, total_size);
1976#if MESH_DEBUG
1977 {
1978 struct GNUNET_MESH_Multicast *mc;
1979 struct GNUNET_MessageHeader *mh;
1980
1981 mh = buf;
1982 if (ntohs (mh->type) == GNUNET_MESSAGE_TYPE_MESH_MULTICAST)
1983 {
1984 mc = (struct GNUNET_MESH_Multicast *) mh;
1985 mh = (struct GNUNET_MessageHeader *) &mc[1];
1986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1987 "MESH: multicast, payload type %u\n",
1988 ntohs (mh->type));
1989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1990 "MESH: multicast, payload size %u\n",
1991 ntohs (mh->size));
1992 }
1993 else
1994 {
1995 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1996 "MESH: type %u\n",
1997 ntohs (mh->type));
1998 }
1999 }
2000#endif
1973 if (0 == --(*info->copies)) 2001 if (0 == --(*info->copies))
1974 { 2002 {
2003 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Last copy!\n");
1975 if (NULL != info->client) 2004 if (NULL != info->client)
1976 { 2005 {
1977 if (GNUNET_SCHEDULER_NO_TASK != info->timeout_task) 2006 if (GNUNET_SCHEDULER_NO_TASK != info->timeout_task)
2007 {
2008 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2009 "MESH: cancelling client timeout (%u)...\n",
2010 info->timeout_task);
1978 GNUNET_SCHEDULER_cancel(info->timeout_task); 2011 GNUNET_SCHEDULER_cancel(info->timeout_task);
1979 GNUNET_SERVER_receive_done (info->client, GNUNET_OK); 2012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: notifying client...\n");
2013 GNUNET_SERVER_receive_done (info->client, GNUNET_OK);
2014 }
1980 } 2015 }
2016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: freeing memory...\n");
1981 GNUNET_free (info->data); 2017 GNUNET_free (info->data);
1982 GNUNET_free (info->copies); 2018 GNUNET_free (info->copies);
1983 } 2019 }
2020 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: freeing info...\n");
1984 GNUNET_free (info); 2021 GNUNET_free (info);
2022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: return %u\n", total_size);
1985 return total_size; 2023 return total_size;
1986} 2024}
1987 2025
@@ -2246,6 +2284,12 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2247 "MESH: It's for us!\n"); 2285 "MESH: It's for us!\n");
2248 path_add_to_origin (orig_peer_info, path); 2286 path_add_to_origin (orig_peer_info, path);
2287 t->peers = GNUNET_CONTAINER_multihashmap_create(4);
2288 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (
2289 t->peers,
2290 &my_full_id.hashPubKey,
2291 peer_info_get(&my_full_id),
2292 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
2249 info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); 2293 info = GNUNET_malloc (sizeof (struct MeshDataDescriptor));
2250 info->origin = &t->id; 2294 info->origin = &t->id;
2251 info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); 2295 info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey);
@@ -2369,8 +2413,9 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2370 "MESH: got a multicast packet from %s\n", 2414 "MESH: got a multicast packet from %s\n",
2371 GNUNET_i2s (peer)); 2415 GNUNET_i2s (peer));
2372 size = ntohs (message->size) - sizeof (struct GNUNET_MESH_Multicast); 2416 size = ntohs (message->size);
2373 if (size < sizeof (struct GNUNET_MessageHeader)) 2417 if (sizeof (struct GNUNET_MESH_Multicast) +
2418 sizeof (struct GNUNET_MessageHeader) > size)
2374 { 2419 {
2375 GNUNET_break_op (0); 2420 GNUNET_break_op (0);
2376 return GNUNET_OK; 2421 return GNUNET_OK;
@@ -2386,12 +2431,12 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2386 } 2431 }
2387 2432
2388 /* Transmit to locally interested clients */ 2433 /* Transmit to locally interested clients */
2389 if (GNUNET_CONTAINER_multihashmap_contains (t->peers, &my_full_id.hashPubKey)) 2434 if (NULL != t->peers &&
2435 GNUNET_CONTAINER_multihashmap_contains (t->peers, &my_full_id.hashPubKey))
2390 { 2436 {
2391 send_subscribed_clients (message, (struct GNUNET_MessageHeader *) &msg[1]); 2437 send_subscribed_clients (message, &msg[1].header);
2392 } 2438 }
2393 tunnel_send_multicast(t, message); 2439 tunnel_send_multicast(t, message);
2394
2395 return GNUNET_OK; 2440 return GNUNET_OK;
2396} 2441}
2397 2442
@@ -3561,7 +3606,8 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client,
3561 } 3606 }
3562 data_msg = (struct GNUNET_MESH_Multicast *) message; 3607 data_msg = (struct GNUNET_MESH_Multicast *) message;
3563 /* Sanity check for message size */ 3608 /* Sanity check for message size */
3564 if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (data_msg->header.size)) 3609 if (sizeof (struct GNUNET_MESH_Multicast) +
3610 sizeof (struct GNUNET_MessageHeader) > ntohs (data_msg->header.size))
3565 { 3611 {
3566 GNUNET_break (0); 3612 GNUNET_break (0);
3567 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3613 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -3607,7 +3653,8 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client,
3607 * Functions to handle messages from clients 3653 * Functions to handle messages from clients
3608 */ 3654 */
3609static struct GNUNET_SERVER_MessageHandler client_handlers[] = { 3655static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
3610 {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, 3656 {&handle_local_new_client, NULL,
3657 GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
3611 {&handle_local_tunnel_create, NULL, 3658 {&handle_local_tunnel_create, NULL,
3612 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, 3659 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE,
3613 sizeof (struct GNUNET_MESH_TunnelMessage)}, 3660 sizeof (struct GNUNET_MESH_TunnelMessage)},