aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-08-31 22:21:25 +0000
committerBart Polot <bart@net.in.tum.de>2011-08-31 22:21:25 +0000
commit0f0f0759a16b5367757b78d9764902ac916fb689 (patch)
tree086805d374969d34f67a74819fcc92290e9edd58 /src
parent880b597b61d9b343d881edef2d42761e0407ebc3 (diff)
downloadgnunet-0f0f0759a16b5367757b78d9764902ac916fb689.tar.gz
gnunet-0f0f0759a16b5367757b78d9764902ac916fb689.zip
WiP
Diffstat (limited to 'src')
-rw-r--r--src/mesh/mesh_api.c39
-rw-r--r--src/mesh/mesh_api_new.c34
2 files changed, 42 insertions, 31 deletions
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 5ea4789b8..615593621 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -200,6 +200,7 @@ send_hello_message (void *cls, size_t size, void *buf)
200 200
201 struct peer_list_element *element = cls; 201 struct peer_list_element *element = cls;
202 struct GNUNET_MESH_Handle *handle = element->handle; 202 struct GNUNET_MESH_Handle *handle = element->handle;
203
203 element->hello = NULL; 204 element->hello = NULL;
204 struct GNUNET_MessageHeader *hdr = buf; 205 struct GNUNET_MessageHeader *hdr = buf;
205 206
@@ -216,22 +217,30 @@ send_hello_message (void *cls, size_t size, void *buf)
216 return sent; 217 return sent;
217} 218}
218 219
219void schedule_hello_message(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tctx) 220void
221schedule_hello_message (void *cls,
222 const struct GNUNET_SCHEDULER_TaskContext *tctx)
220{ 223{
221 struct peer_list_element *element = cls; 224 struct peer_list_element *element = cls;
225
222 element->sched = GNUNET_SCHEDULER_NO_TASK; 226 element->sched = GNUNET_SCHEDULER_NO_TASK;
223 227
224 if ((tctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 228 if ((tctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
225 return; 229 return;
226 230
227 if (element->hello == NULL) 231 if (element->hello == NULL)
228 element->hello = GNUNET_CORE_notify_transmit_ready (element->handle->core, GNUNET_NO, 42, 232 element->hello =
229 GNUNET_TIME_UNIT_SECONDS, &element->peer, 233 GNUNET_CORE_notify_transmit_ready (element->handle->core, GNUNET_NO, 42,
230 sizeof (struct GNUNET_MessageHeader) + 234 GNUNET_TIME_UNIT_SECONDS,
231 element->handle->hello_message_size, 235 &element->peer,
232 &send_hello_message, element); 236 sizeof (struct GNUNET_MessageHeader)
233 237 +
234 element->sched = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, schedule_hello_message, cls); 238 element->handle->hello_message_size,
239 &send_hello_message, element);
240
241 element->sched =
242 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
243 schedule_hello_message, cls);
235} 244}
236 245
237 246
@@ -257,7 +266,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
257 element->handle = handle; 266 element->handle = handle;
258 267
259 /* Send a hello to this peer */ 268 /* Send a hello to this peer */
260 element->sched = GNUNET_SCHEDULER_add_now(schedule_hello_message, element); 269 element->sched = GNUNET_SCHEDULER_add_now (schedule_hello_message, element);
261 270
262 if (NULL != atsi) 271 if (NULL != atsi)
263 memcpy (&element->atsi, atsi, 272 memcpy (&element->atsi, atsi,
@@ -327,8 +336,8 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
327 tail); 336 tail);
328 GNUNET_free (tail); 337 GNUNET_free (tail);
329 } 338 }
330 GNUNET_CORE_notify_transmit_ready_cancel(element->hello); 339 GNUNET_CORE_notify_transmit_ready_cancel (element->hello);
331 GNUNET_SCHEDULER_cancel(element->sched); 340 GNUNET_SCHEDULER_cancel (element->sched);
332 GNUNET_free (element); 341 GNUNET_free (element);
333 } 342 }
334 343
@@ -885,8 +894,8 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
885 tail); 894 tail);
886 GNUNET_free (tail); 895 GNUNET_free (tail);
887 } 896 }
888 GNUNET_CORE_notify_transmit_ready_cancel(element->hello); 897 GNUNET_CORE_notify_transmit_ready_cancel (element->hello);
889 GNUNET_SCHEDULER_cancel(element->sched); 898 GNUNET_SCHEDULER_cancel (element->sched);
890 GNUNET_free (element); 899 GNUNET_free (element);
891 element = next; 900 element = next;
892 } 901 }
@@ -912,4 +921,4 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
912 GNUNET_free (handle); 921 GNUNET_free (handle);
913} 922}
914 923
915/* end of mesh_api.c */ 924/* end of mesh_api.c */ \ No newline at end of file
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index 23ade2379..cd385b01d 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -651,8 +651,8 @@ send_raw (void *cls, size_t size, void *buf)
651 651
652/** 652/**
653 * Auxiliary function to send an already constructed packet to the service. 653 * Auxiliary function to send an already constructed packet to the service.
654 * Takes care of creating a new queue element and calling the tmt_rdy function 654 * Takes care of creating a new queue element, copying the message and
655 * if necessary. 655 * calling the tmt_rdy function if necessary.
656 * @param h mesh handle 656 * @param h mesh handle
657 * @param msg message to transmit 657 * @param msg message to transmit
658 */ 658 */
@@ -732,12 +732,14 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
732 h->message_handlers = handlers; 732 h->message_handlers = handlers;
733 h->applications = stypes; 733 h->applications = stypes;
734 h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; 734 h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_MARK;
735
735 /* count handlers and apps, calculate size */ 736 /* count handlers and apps, calculate size */
736 for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ; 737 for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
737 for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ; 738 for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ;
738 size = sizeof (struct GNUNET_MESH_ClientConnect); 739 size = sizeof (struct GNUNET_MESH_ClientConnect);
739 size += h->n_handlers * sizeof (uint16_t); 740 size += h->n_handlers * sizeof (uint16_t);
740 size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); 741 size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType);
742
741 { 743 {
742 char buf[size]; 744 char buf[size];
743 745
@@ -826,16 +828,16 @@ void
826GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun) 828GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun)
827{ 829{
828 struct GNUNET_MESH_Handle *h; 830 struct GNUNET_MESH_Handle *h;
829 struct GNUNET_MESH_TunnelMessage *msg; 831 struct GNUNET_MESH_TunnelMessage msg;
830 832
831 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); 833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
832 h = tun->mesh; 834 h = tun->mesh;
833 msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_TunnelMessage)); 835
834 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); 836 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
835 msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 837 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
836 msg->tunnel_id = htonl (tun->tid); 838 msg.tunnel_id = htonl (tun->tid);
837 GNUNET_free (tun); 839 GNUNET_free (tun);
838 send_packet (h, &msg->header); 840 send_packet (h, &msg.header);
839} 841}
840 842
841 843
@@ -852,7 +854,7 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
852 struct GNUNET_TIME_Relative timeout, 854 struct GNUNET_TIME_Relative timeout,
853 const struct GNUNET_PeerIdentity *peer) 855 const struct GNUNET_PeerIdentity *peer)
854{ 856{
855 struct GNUNET_MESH_PeerControl *msg; 857 struct GNUNET_MESH_PeerControl msg;
856 GNUNET_PEER_Id peer_id; 858 GNUNET_PEER_Id peer_id;
857 unsigned int i; 859 unsigned int i;
858 860
@@ -870,14 +872,14 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
870 tunnel->peers = 872 tunnel->peers =
871 GNUNET_realloc (tunnel->peers, tunnel->npeers * sizeof (GNUNET_PEER_Id)); 873 GNUNET_realloc (tunnel->peers, tunnel->npeers * sizeof (GNUNET_PEER_Id));
872 tunnel->peers[tunnel->npeers - 1] = peer_id; 874 tunnel->peers[tunnel->npeers - 1] = peer_id;
873 msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_PeerControl)); 875
874 msg->header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 876 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
875 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD); 877 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD);
876 msg->tunnel_id = htonl (tunnel->tid); 878 msg.tunnel_id = htonl (tunnel->tid);
877 msg->timeout = 879 msg.timeout =
878 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (timeout)); 880 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (timeout));
879 memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity)); 881 msg.peer = *peer;
880 send_packet (tunnel->mesh, &msg->header); 882 send_packet (tunnel->mesh, &msg.header);
881// tunnel->connect_handler (tunnel->cls, peer, NULL); FIXME call this later 883// tunnel->connect_handler (tunnel->cls, peer, NULL); FIXME call this later
882// TODO: remember timeout 884// TODO: remember timeout
883 return; 885 return;