aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-04-10 21:36:26 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-04-10 21:36:26 +0000
commitbf0c66911e342bc9ee6305fa8e039221041b27be (patch)
tree4d5e8fb47d6fda90c17a6ca52621d932b6d0ffd7 /src/mesh
parent0ed04623d2fff96b2093052330c8c92f1367ee7a (diff)
downloadgnunet-bf0c66911e342bc9ee6305fa8e039221041b27be.tar.gz
gnunet-bf0c66911e342bc9ee6305fa8e039221041b27be.zip
make the mock mesh perhaps not working, but not crashing either
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh_api.c52
1 files changed, 38 insertions, 14 deletions
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index fc92f9bb4..8b1655dde 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -142,6 +142,17 @@ send_self_connect(void* cls,
142} 142}
143 143
144static void 144static void
145call_connect_handler (void *cls,
146 const struct GNUNET_SCHEDULER_TaskContext *tc)
147{
148 struct GNUNET_MESH_Tunnel *tunnel = cls;
149
150 tunnel->connect_handler (tunnel->handler_cls, &tunnel->peer,
151 NULL);
152 GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
153}
154
155static void
145core_startup (void *cls, 156core_startup (void *cls,
146 struct GNUNET_CORE_Handle *core, 157 struct GNUNET_CORE_Handle *core,
147 const struct GNUNET_PeerIdentity *my_identity, 158 const struct GNUNET_PeerIdentity *my_identity,
@@ -171,8 +182,7 @@ send_hello_message (void *cls, size_t size, void *buf)
171/** 182/**
172 * Core calls this if we are connected to a new peer. 183 * Core calls this if we are connected to a new peer.
173 * 184 *
174 * If core tells us that we are connected to ourself, we ignore it. Otherwise, the 185 * The peer is added to the connected_peers-list.
175 * peer is added to the connected_peers-list.
176 * 186 *
177 */ 187 */
178static void 188static void
@@ -192,18 +202,14 @@ core_connect (void *cls,
192 &send_hello_message, 202 &send_hello_message,
193 cls); 203 cls);
194 204
195 /* Check for connect-to-self-message, which we ignore */
196 if (0 ==
197 memcmp (peer, &handle->myself, sizeof (struct GNUNET_PeerIdentity)))
198 return;
199
200
201 /* put the new peer into the list of connected peers */ 205 /* put the new peer into the list of connected peers */
202 struct peer_list_element *element = 206 struct peer_list_element *element =
203 GNUNET_malloc (sizeof (struct peer_list_element)); 207 GNUNET_malloc (sizeof (struct peer_list_element));
204 memcpy (&element->peer, peer, sizeof (struct GNUNET_PeerIdentity)); 208 memcpy (&element->peer, peer, sizeof (struct GNUNET_PeerIdentity));
205 memcpy (&element->atsi, atsi, 209
206 sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 210 if (NULL != atsi)
211 memcpy (&element->atsi, atsi,
212 sizeof (struct GNUNET_TRANSPORT_ATS_Information));
207 213
208 GNUNET_CONTAINER_DLL_insert_after (handle->connected_peers.head, 214 GNUNET_CONTAINER_DLL_insert_after (handle->connected_peers.head,
209 handle->connected_peers.tail, 215 handle->connected_peers.tail,
@@ -315,7 +321,6 @@ receive_hello (void *cls,
315 element = element->next; 321 element = element->next;
316 } 322 }
317 323
318 /* TODO: handle self */
319 /* TODO: add, not replace! */ 324 /* TODO: add, not replace! */
320 /* TODO: if this changes anything: send new hello */ 325 /* TODO: if this changes anything: send new hello */
321 element->num_types = *num; 326 element->num_types = *num;
@@ -517,7 +522,7 @@ GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle,
517 handle->established_tunnels.tail, 522 handle->established_tunnels.tail,
518 handle->established_tunnels.tail, 523 handle->established_tunnels.tail,
519 tunnel); 524 tunnel);
520 connect_handler (handler_cls, &element->peer, &element->atsi); 525 GNUNET_SCHEDULER_add_now(call_connect_handler, tunnel);
521 } 526 }
522 else if (0 == 527 else if (0 ==
523 memcmp (peers, &handle->myself, 528 memcmp (peers, &handle->myself,
@@ -540,7 +545,7 @@ GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle,
540 (void) GNUNET_CORE_peer_request_connect (handle->core, 545 (void) GNUNET_CORE_peer_request_connect (handle->core,
541 timeout, 546 timeout,
542 peers, 547 peers,
543 NULL, NULL); 548 NULL, NULL);
544 } 549 }
545 550
546 return &tunnel->tunnel; 551 return &tunnel->tunnel;
@@ -630,6 +635,23 @@ GNUNET_MESH_notify_transmit_ready (struct
630 return (struct GNUNET_MESH_TransmitHandle*) 1; 635 return (struct GNUNET_MESH_TransmitHandle*) 1;
631} 636}
632 637
638void build_hello_message(struct GNUNET_MESH_Handle* handle, int num)
639{
640 handle->hello_message_size = sizeof(uint16_t) + /* For the number of types */
641 num * sizeof(uint16_t); /* For the types */
642
643 uint16_t *nums = GNUNET_malloc(handle->hello_message_size);
644 uint16_t *types = nums + 1;
645
646 *nums = num;
647
648 unsigned int i;
649 for(i = 0; i < num; i++)
650 types[i] = handle->handlers[i].type;
651
652 handle->hello_message = nums;
653}
654
633 655
634struct GNUNET_MESH_Handle * 656struct GNUNET_MESH_Handle *
635GNUNET_MESH_connect (const struct 657GNUNET_MESH_connect (const struct
@@ -662,7 +684,7 @@ GNUNET_MESH_connect (const struct
662 memcpy (ret->handlers, handlers, 684 memcpy (ret->handlers, handlers,
663 len * sizeof (struct GNUNET_MESH_MessageHandler)); 685 len * sizeof (struct GNUNET_MESH_MessageHandler));
664 686
665 /* TODO: build hello */ 687 build_hello_message(ret, len);
666 688
667 const static struct GNUNET_CORE_MessageHandler core_handlers[] = { 689 const static struct GNUNET_CORE_MessageHandler core_handlers[] = {
668 {&core_receive, GNUNET_MESSAGE_TYPE_MESH, 0}, 690 {&core_receive, GNUNET_MESSAGE_TYPE_MESH, 0},
@@ -686,12 +708,14 @@ void
686GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) 708GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
687{ 709{
688 GNUNET_free (handle->handlers); 710 GNUNET_free (handle->handlers);
711 GNUNET_free (handle->hello_message);
689 GNUNET_CORE_disconnect (handle->core); 712 GNUNET_CORE_disconnect (handle->core);
690 713
691 struct peer_list_element *element = handle->connected_peers.head; 714 struct peer_list_element *element = handle->connected_peers.head;
692 while (element != NULL) 715 while (element != NULL)
693 { 716 {
694 struct peer_list_element *next = element->next; 717 struct peer_list_element *next = element->next;
718 GNUNET_free_non_null(element->types);
695 GNUNET_free (element); 719 GNUNET_free (element);
696 element = next; 720 element = next;
697 } 721 }