GNUnet  0.10.x
transport_api_core.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009-2013, 2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_arm_service.h"
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_protocols.h"
33 #include "transport.h"
34 
35 #define LOG(kind, ...) GNUNET_log_from(kind, "transport-api-core", __VA_ARGS__)
36 
41 #define UNREADY_WARN_TIME GNUNET_TIME_UNIT_MINUTES
42 
46 #define STARTING_NEIGHBOURS_SIZE 16
47 
48 
52 struct Neighbour {
57 
61  struct GNUNET_MQ_Handle *mq;
62 
66  struct GNUNET_MQ_Envelope *env;
67 
71  void *handlers_cls;
72 
76  struct GNUNET_PeerIdentity id;
77 
82 
92 
98 
103  unsigned long long traffic_overhead;
104 
108  int is_ready;
109 
113  uint16_t env_size;
114 };
115 
116 
125  void *cls;
126 
132 
137 
142 
147 
151  struct GNUNET_MQ_Handle *mq;
152 
156  const struct GNUNET_CONFIGURATION_Handle *cfg;
157 
163 
167  struct GNUNET_PeerIdentity self;
168 
173 
177  struct GNUNET_TIME_Relative reconnect_delay;
178 
186  unsigned int rom_pending;
187 
192  int check_self;
193 };
194 
195 
202 static void
204 
205 
213 static struct Neighbour *
215  const struct GNUNET_PeerIdentity *peer)
216 {
218 }
219 
220 
227 static void
229 {
230  struct Neighbour *n = cls;
231  struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
232 
234  "Notifying CORE that more bandwidth is available for %s\n",
235  GNUNET_i2s(&n->id));
236 
237  if (NULL != h->neb_cb)
238  h->neb_cb(h->cls, &n->id, n->handlers_cls);
239 }
240 
241 
252 static int
253 neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
254 {
256  struct Neighbour *n = value;
257 
259  "Dropping entry for neighbour `%s'.\n",
260  GNUNET_i2s(key));
262  if (NULL != handle->nd_cb)
263  handle->nd_cb(handle->cls, &n->id, n->handlers_cls);
264  if (NULL != n->timeout_task)
265  {
267  n->timeout_task = NULL;
268  }
269  if (NULL != n->env)
270  {
272  n->env = NULL;
273  }
274  GNUNET_MQ_destroy(n->mq);
275  GNUNET_assert(NULL == n->mq);
277  GNUNET_YES ==
279  GNUNET_free(n);
280  return GNUNET_YES;
281 }
282 
283 
293 static void
294 mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
295 {
297 
299  "Error receiving from transport service (%d), disconnecting temporarily.\n",
300  error);
302 }
303 
304 
312 static int
314 {
315  struct GNUNET_PeerIdentity me;
316 
317  if (GNUNET_OK !=
318  GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg, &me))
319  {
320  GNUNET_break(0);
321  return GNUNET_SYSERR;
322  }
323  return GNUNET_OK;
324 }
325 
326 
333 static void
334 handle_hello(void *cls, const struct GNUNET_MessageHeader *msg)
335 {
336  /* we do not care => FIXME: signal in options to NEVER send HELLOs! */
337 }
338 
339 
348 static void
350 {
351  struct Neighbour *n = cls;
352 
353  n->timeout_task = NULL;
354  n->is_ready = GNUNET_YES;
356 }
357 
358 
367 static void
369 {
370  struct Neighbour *n = cls;
371  struct GNUNET_TIME_Relative delay;
372 
373  n->timeout_task = NULL;
374  if (NULL != n->env)
375  {
377  n->env_size + n->traffic_overhead);
378  n->env = NULL;
379  n->traffic_overhead = 0;
380  }
382  if (0 == delay.rel_value_us)
383  {
384  n->is_ready = GNUNET_YES;
386  return;
387  }
389  /* cannot send even a small message without violating
390  quota, wait a before allowing MQ to send next message */
391  n->timeout_task =
393 }
394 
395 
406 static void
408  const struct GNUNET_MessageHeader *msg,
409  void *impl_state)
410 {
411  struct Neighbour *n = impl_state;
412  struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
413  struct OutboundMessage *obm;
414  uint16_t msize;
415 
417  msize = ntohs(msg->size);
418  if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm))
419  {
420  GNUNET_break(0);
422  return;
423  }
424  GNUNET_assert(NULL == n->env);
425  n->env =
427  {
428  struct GNUNET_MQ_Envelope *env;
429 
431  obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env));
432  }
434  GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */
435  obm->peer = n->id;
436  GNUNET_assert(NULL == n->timeout_task);
437  n->is_ready = GNUNET_NO;
438  n->env_size = ntohs(msg->size);
440  GNUNET_MQ_send(h->mq, n->env);
442  "Queued message of type %u for neighbour `%s'.\n",
443  ntohs(msg->type),
444  GNUNET_i2s(&n->id));
445 }
446 
447 
455 static void
456 mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
457 {
458  struct Neighbour *n = impl_state;
459 
460  GNUNET_assert(mq == n->mq);
461  n->mq = NULL;
462 }
463 
464 
472 static void
473 mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
474 {
475  struct Neighbour *n = impl_state;
476 
478  if (NULL != n->env)
479  {
481  n->env = NULL;
482  }
483 
484  n->is_ready = GNUNET_YES;
485 }
486 
487 
496 static void
498 {
499  /* struct Neighbour *n = cls; */
500 
501  GNUNET_break_op(0);
502 }
503 
504 
511 static void
513 {
514  struct Neighbour *n = cls;
515  struct GNUNET_TIME_Relative delay;
516 
517  if (NULL == n->timeout_task)
518  return;
522 }
523 
524 
531 static void
532 handle_connect(void *cls, const struct ConnectInfoMessage *cim)
533 {
535  struct Neighbour *n;
536 
538  "Receiving CONNECT message for `%s' with quota %u\n",
539  GNUNET_i2s(&cim->id),
540  ntohl(cim->quota_out.value__));
541  n = neighbour_find(h, &cim->id);
542  if (NULL != n)
543  {
544  GNUNET_break(0); /* FIXME: this assertion seems to fail sometimes!? */
546  return;
547  }
548  n = GNUNET_new(struct Neighbour);
549  n->id = cim->id;
550  n->h = h;
551  n->is_ready = GNUNET_YES;
552  n->traffic_overhead = 0;
555  n,
559  n);
562  h->neighbours,
563  &n->id,
564  n,
566 
571  n,
572  h->handlers,
574  n);
575  if (NULL != h->nc_cb)
576  {
577  n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq);
579  }
580 }
581 
582 
589 static void
590 handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim)
591 {
593  struct Neighbour *n;
594 
595  GNUNET_break(ntohl(dim->reserved) == 0);
597  "Receiving DISCONNECT message for `%s'.\n",
598  GNUNET_i2s(&dim->peer));
599  n = neighbour_find(h, &dim->peer);
600  if (NULL == n)
601  {
602  GNUNET_break(0);
604  return;
605  }
607 }
608 
609 
616 static void
617 handle_send_ok(void *cls, const struct SendOkMessage *okm)
618 {
620  struct Neighbour *n;
621  uint32_t bytes_msg;
622  uint32_t bytes_physical;
623 
624  bytes_msg = ntohl(okm->bytes_msg);
625  bytes_physical = ntohl(okm->bytes_physical);
627  "Receiving SEND_OK message, transmission to %s %s.\n",
628  GNUNET_i2s(&okm->peer),
629  ntohl(okm->success) == GNUNET_OK ? "succeeded" : "failed");
630  n = neighbour_find(h, &okm->peer);
631  if (NULL == n)
632  {
633  /* We should never get a 'SEND_OK' for a peer that we are not
634  connected to */
635  GNUNET_break(0);
637  return;
638  }
639  if (bytes_physical > bytes_msg)
640  {
642  "Overhead for %u byte message was %u\n",
643  bytes_msg,
644  bytes_physical - bytes_msg);
645  n->traffic_overhead += bytes_physical - bytes_msg;
646  }
647 }
648 
649 
656 static int
657 check_recv(void *cls, const struct InboundMessage *im)
658 {
659  const struct GNUNET_MessageHeader *imm;
660  uint16_t size;
661 
662  size = ntohs(im->header.size) - sizeof(*im);
663  if (size < sizeof(struct GNUNET_MessageHeader))
664  {
665  GNUNET_break(0);
666  return GNUNET_SYSERR;
667  }
668  imm = (const struct GNUNET_MessageHeader *)&im[1];
669  if (ntohs(imm->size) != size)
670  {
671  GNUNET_break(0);
672  return GNUNET_SYSERR;
673  }
674  return GNUNET_OK;
675 }
676 
677 
684 static void
685 handle_recv(void *cls, const struct InboundMessage *im)
686 {
688  const struct GNUNET_MessageHeader *imm =
689  (const struct GNUNET_MessageHeader *)&im[1];
690  struct Neighbour *n;
691 
693  "Received message of type %u with %u bytes from `%s'.\n",
694  (unsigned int)ntohs(imm->type),
695  (unsigned int)ntohs(imm->size),
696  GNUNET_i2s(&im->peer));
697  n = neighbour_find(h, &im->peer);
698  if (NULL == n)
699  {
700  GNUNET_break(0);
702  return;
703  }
704  h->rom_pending++;
705  GNUNET_MQ_inject_message(n->mq, imm);
706 }
707 
708 
715 static void
716 handle_set_quota(void *cls, const struct QuotaSetMessage *qm)
717 {
719  struct Neighbour *n;
720 
722  "Receiving SET_QUOTA message for `%s' with quota %u\n",
723  GNUNET_i2s(&qm->peer),
724  ntohl(qm->quota.value__));
725  n = neighbour_find(h, &qm->peer);
726  if (NULL == n)
727  {
728  GNUNET_break(
729  0); /* FIXME: julius reports this assertion fails sometimes? */
731  return;
732  }
734 }
735 
736 
742 static void
743 reconnect(void *cls)
744 {
746  struct GNUNET_MQ_MessageHandler handlers[] =
747  { GNUNET_MQ_hd_var_size(hello,
749  struct GNUNET_MessageHeader,
750  h),
751  GNUNET_MQ_hd_fixed_size(connect,
753  struct ConnectInfoMessage,
754  h),
757  struct DisconnectInfoMessage,
758  h),
759  GNUNET_MQ_hd_fixed_size(send_ok,
761  struct SendOkMessage,
762  h),
765  struct InboundMessage,
766  h),
767  GNUNET_MQ_hd_fixed_size(set_quota,
769  struct QuotaSetMessage,
770  h),
772  struct GNUNET_MQ_Envelope *env;
773  struct StartMessage *s;
774  uint32_t options;
775 
776  h->reconnect_task = NULL;
777  LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
778  GNUNET_assert(NULL == h->mq);
779  h->mq =
780  GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h);
781  if (NULL == h->mq)
782  return;
784  options = 0;
785  if (h->check_self)
786  options |= 1;
787  if (NULL != h->handlers)
788  options |= 2;
789  s->options = htonl(options);
790  s->self = h->self;
791  GNUNET_MQ_send(h->mq, env);
792 }
793 
794 
801 static void
803 {
804  GNUNET_assert(NULL == h->reconnect_task);
805  /* Forget about all neighbours that we used to be connected to */
807  if (NULL != h->mq)
808  {
809  GNUNET_MQ_destroy(h->mq);
810  h->mq = NULL;
811  }
813  "Scheduling task to reconnect to transport service in %s.\n",
815  h->reconnect_task =
818 }
819 
820 
828 struct GNUNET_MQ_Handle *
830  const struct GNUNET_PeerIdentity *peer)
831 {
832  struct Neighbour *n;
833 
834  n = neighbour_find(handle, peer);
835  if (NULL == n)
836  return NULL;
837  return n->mq;
838 }
839 
840 
857  const struct GNUNET_PeerIdentity *self,
858  const struct GNUNET_MQ_MessageHandler *handlers,
859  void *cls,
863 {
865  unsigned int i;
866 
868  if (NULL != self)
869  {
870  h->self = *self;
871  h->check_self = GNUNET_YES;
872  }
873  h->cfg = cfg;
874  h->cls = cls;
875  h->nc_cb = nc;
876  h->nd_cb = nd;
877  h->neb_cb = neb;
879  if (NULL != handlers)
880  {
881  for (i = 0; NULL != handlers[i].cb; i++)
882  ;
885  handlers,
886  i * sizeof(struct GNUNET_MQ_MessageHandler));
887  }
888  LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n");
889  reconnect(h);
890  if (NULL == h->mq)
891  {
893  GNUNET_free(h);
894  return NULL;
895  }
896  h->neighbours =
898  return h;
899 }
900 
901 
908 void
910 {
911  LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
912  /* this disconnects all neighbours... */
913  if (NULL == handle->reconnect_task)
915  /* and now we stop trying to connect again... */
916  if (NULL != handle->reconnect_task)
917  {
919  handle->reconnect_task = NULL;
920  }
922  handle->neighbours = NULL;
924  handle->handlers = NULL;
925  GNUNET_free(handle);
926 }
927 
928 
949 void
950 GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch,
951  const struct GNUNET_PeerIdentity *pid)
952 {
953  struct RecvOkMessage *rom;
954  struct GNUNET_MQ_Envelope *env;
955 
956  GNUNET_assert(ch->rom_pending > 0);
957  ch->rom_pending--;
959  rom->increase_window_delta = htonl(1);
960  rom->peer = *pid;
961  GNUNET_MQ_send(ch->mq, env);
962 }
963 
964 
965 /* end of transport_api_core.c */
struct GNUNET_MQ_MessageHandler * handlers
Functions to call for received data (template for new message queues).
A connected controller which is not our child.
struct GNUNET_PeerIdentity id
Identity of the new neighbour.
Definition: transport.h:139
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:662
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static void disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
Function that will schedule the job that will try to connect us again to the client.
static struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Map from PIDs to struct Neighbour entries.
A HELLO message is used to exchange information about transports with other peers.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
int GNUNET_BANDWIDTH_tracker_consume(struct GNUNET_BANDWIDTH_Tracker *av, ssize_t size)
Notify the tracker that a certain number of bytes of bandwidth have been consumed.
Definition: bandwidth.c:402
void * cls
Closure for the callbacks.
uint64_t rel_value_us
The actual value.
#define LOG(kind,...)
Message used to notify the transport API that it can send another message to the transport service...
Definition: transport.h:254
uint32_t priority
An enum GNUNET_MQ_PriorityPreferences in NBO.
Definition: transport.h:286
common internal definitions for transport service
void * handlers_cls
Closure for mq handlers.
GNUNET_TRANSPORT_NotifyDisconnect nd_cb
function to call on disconnect events
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK
Message telling transport to limit its receive rate.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:900
static void handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim)
Function we use for handling incoming disconnect messages.
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct...
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_TRANSPORT_CoreHandle * h
Overall transport handle.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
void GNUNET_BANDWIDTH_tracker_update_quota(struct GNUNET_BANDWIDTH_Tracker *av, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit)
Update quota of bandwidth tracker.
Definition: bandwidth.c:526
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
const struct GNUNET_CONFIGURATION_Handle * cfg
My configuration.
struct GNUNET_PeerIdentity peer
Which peer should receive the message?
Definition: transport.h:300
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_BANDWIDTH_Value32NBO quota_out
Current outbound quota for this peer.
Definition: transport.h:133
struct GNUNET_MQ_Handle * mq
My client connection to the transport service.
struct GNUNET_PeerIdentity peer
Which peer can CORE handle more from now?
Definition: transport.h:269
static void notify_excess_cb(void *cls)
Function called by the bandwidth tracker if we have excess bandwidth.
GNUNET_TRANSPORT_NotifyExcessBandwidth neb_cb
function to call on excess bandwidth events
static int neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries, for deleting state of a neighbour.
static void handle_set_quota(void *cls, const struct QuotaSetMessage *qm)
Function we use for handling incoming set quota messages.
GNUNET_TRANSPORT_NotifyConnect nc_cb
function to call on connect events
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Struct to track available bandwidth.
#define GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
Bandwidth (in/out) to assume initially (before either peer has communicated any particular preference...
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_NO
Definition: gnunet_common.h:78
uint32_t increase_window_delta
Number of messages by which to increase the window, greater or equal to one.
Definition: transport.h:264
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_PeerIdentity self
Identity we think we have.
Definition: transport.h:108
void *(* GNUNET_TRANSPORT_NotifyConnect)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Function called to notify transport users that another peer connected to us.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_PeerIdentity self
Peer identity as assumed by this process, or all zeros.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
static void notify_send_done_fin(void *cls)
A message from the handler&#39;s message queue to a neighbour was transmitted.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map of the current connected neighbours of this peer.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
Request to TRANSPORT to transmit a message.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
Message from TRANSPORT notifying about a client that connected to us.
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, GNUNET_TRANSPORT_NotifyExcessBandwidth neb)
Connect to the transport service.
uint32_t value__
The actual value (bytes per second).
#define STARTING_NEIGHBOURS_SIZE
How large to start with for the hashmap of neighbours.
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get performance preferences set for this envelope.
Definition: mq.c:1017
unsigned int rom_pending
Internal counter to check how many more receive OK messages this CORE service is allowed to send in t...
uint16_t env_size
Size of the message in env.
void GNUNET_MQ_set_handlers_closure(struct GNUNET_MQ_Handle *mq, void *handlers_cls)
Change the closure argument in all of the handlers of the mq.
Definition: mq.c:581
struct GNUNET_PeerIdentity peer
About which peer are we talking here?
Definition: transport.h:186
void(* GNUNET_TRANSPORT_NotifyDisconnect)(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
Function called to notify transport users that another peer disconnected from us. ...
static void peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We had an error processing a message we forwarded from a peer to the CORE service.
uint16_t success
GNUNET_OK if the transmission succeeded, GNUNET_SYSERR if it failed (i.e.
Definition: transport.h:228
void GNUNET_MQ_impl_send_in_flight(struct GNUNET_MQ_Handle *mq)
Call the send notification for the current message, but do not try to send the next message until #gn...
Definition: mq.c:517
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1237
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
static int check_hello(void *cls, const struct GNUNET_MessageHeader *msg)
Function we use for checking incoming HELLO messages.
uint32_t reserved
Reserved, always zero.
Definition: transport.h:156
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition: mq.c:550
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:772
static char * value
Value of the record to add/remove.
struct GNUNET_SCHEDULER_Task * timeout_task
Task to trigger MQ when we have enough bandwidth for the next transmission.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
static void handle_recv(void *cls, const struct InboundMessage *im)
Function we use for handling incoming messages.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static void mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void handle_hello(void *cls, const struct GNUNET_MessageHeader *msg)
Function we use for handling incoming HELLO messages.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
uint32_t bytes_physical
Size of message sent over wire.
Definition: transport.h:239
uint32_t options
0: no options 1: The self field should be checked 2: this client is interested in payload traffic ...
Definition: transport.h:102
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
static void disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the peerstore service.
Message from the transport service to the library informing about neighbors.
Definition: transport.h:116
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_TIME_RelativeNBO timeout
Allowed delay.
Definition: transport.h:294
int check_self
Should we check that self matches what the service thinks? (if GNUNET_NO, then self is all zeros!)...
GNUNET_MQ_MessageCallback cb
Callback, called every time a new message of the specified type has been receied. ...
#define GNUNET_MESSAGE_TYPE_TRANSPORT_START
Message from the core saying that the transport server should start giving it messages.
void GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given m...
Definition: mq.c:200
Internal representation of the hash map.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
static void reconnect(void *cls)
Try again to connect to transport service.
static void reconnect_task(void *cls)
Re-establish the connection to the ATS service.
Message used to set a particular bandwidth quota.
Definition: transport.h:172
void GNUNET_BANDWIDTH_tracker_init2(struct GNUNET_BANDWIDTH_Tracker *av, GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb, void *update_cb_cls, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, uint32_t max_carry_s, GNUNET_BANDWIDTH_ExcessNotificationCallback excess_cb, void *excess_cb_cls)
Initialize bandwidth tracker.
Definition: bandwidth.c:259
Message handler for a specific message type.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
Message from TRANSPORT notifying about a client that disconnected from us.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
Node in the heap.
Message used to notify the transport service about a message to be transmitted to another peer...
Definition: transport.h:277
#define MAX_BANDWIDTH_CARRY_S
Number of seconds that available bandwidth carries over (can accumulate).
struct GNUNET_TIME_Relative GNUNET_BANDWIDTH_tracker_get_delay(struct GNUNET_BANDWIDTH_Tracker *av, size_t size)
Compute how long we should wait until consuming size bytes of bandwidth in order to stay within the g...
Definition: bandwidth.c:458
static int check_recv(void *cls, const struct InboundMessage *im)
Function we use for checking incoming "inbound" messages.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
Message from the transport service to the library asking to check if both processes agree about this ...
Definition: transport.h:91
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_PeerIdentity peer
Which peer sent the message?
Definition: transport.h:203
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:623
Message from the transport service to the library informing about disconnects.
Definition: transport.h:147
static struct Neighbour * neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
Get the neighbour list entry for the given peer.
int is_ready
Is this peer currently ready to receive a message?
uint16_t bytes_msg
Size of message sent.
Definition: transport.h:233
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
Confirmation from TRANSPORT that message for transmission has been queued (and that the next message ...
unsigned long long traffic_overhead
Sending consumed more bytes on wire than payload was announced This overhead is added to the delay of...
static void handle_send_ok(void *cls, const struct SendOkMessage *okm)
Function we use for handling incoming send-ok messages.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_BANDWIDTH_Tracker out_tracker
Outbound bandwidh tracker.
static void mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Handle destruction of a message queue.
static void notify_send_done(void *cls)
A message from the handler&#39;s message queue to a neighbour was transmitted.
Handle to a message queue.
Definition: mq.c:84
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_HeapNode * hn
Entry in our readyness heap (which is sorted by next_ready value).
The identity of the host (wraps the signing key of the peer).
Message used to notify the transport API that it can send another message to the transport service...
Definition: transport.h:211
struct GNUNET_PeerIdentity peer
Which peer can send more now?
Definition: transport.h:245
static void handle_connect(void *cls, const struct ConnectInfoMessage *cim)
Function we use for handling incoming connect messages.
void(* GNUNET_TRANSPORT_NotifyExcessBandwidth)(void *cls, const struct GNUNET_PeerIdentity *neighbour, void *handlers_cls)
Function called if we have "excess" bandwidth to a peer.
configuration data
Definition: configuration.c:83
#define GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
Message from TRANSPORT notifying about a message that was received.
struct GNUNET_BANDWIDTH_Value32NBO quota
Quota.
Definition: transport.h:181
struct GNUNET_PeerIdentity peer
Who got disconnected?
Definition: transport.h:161
void GNUNET_BANDWIDTH_tracker_notification_stop(struct GNUNET_BANDWIDTH_Tracker *av)
Stop notifying about tracker updates and excess notifications.
Definition: bandwidth.c:325
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
Entry in list of pending tasks.
Definition: scheduler.c:131
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
Message telling transport to limit its receive rate.
Header for all communications.
struct GNUNET_MQ_Envelope * GNUNET_MQ_get_current_envelope(struct GNUNET_MQ_Handle *mq)
Function to obtain the current envelope from within GNUNET_MQ_SendImpl implementations.
Definition: mq.c:971
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:351
static void outbound_bw_tracker_update(void *cls)
The outbound quota has changed in a way that may require us to reset the timeout. ...
struct GNUNET_MQ_Handle * GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, const struct GNUNET_PeerIdentity *peer)
Checks if a given peer is connected to us and get the message queue.
struct GNUNET_MQ_Envelope * env
Envelope with the message we are currently transmitting (or NULL).
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV.
Definition: transport.h:198
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
static void mq_send_impl(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Implement sending functionality of a message queue.
Handle for the transport service (includes all of the state for the transport service).
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:484
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition: mq.c:913
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Message used to notify the transport API about a message received from the network.
Definition: transport.h:194
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_PeerIdentity pid
Which peer is this about?
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956