GNUnet  0.11.x
Data Structures | Functions
transport_api_hello_get.c File Reference

library to obtain our HELLO from our transport service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_arm_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_transport_hello_service.h"
#include "transport.h"
Include dependency graph for transport_api_hello_get.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_TRANSPORT_HelloGetHandle
 Functions to call with this peer's HELLO. More...
 

Functions

static int check_hello (void *cls, const struct GNUNET_MessageHeader *msg)
 Function we use for checking incoming HELLO messages. More...
 
static void handle_hello (void *cls, const struct GNUNET_MessageHeader *msg)
 Function we use for handling incoming HELLO messages. More...
 
static void schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
 Function that will schedule the job that will try to connect us again to the client. More...
 
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 creation of the message queue. More...
 
static void reconnect (void *cls)
 Try again to connect to transport service. More...
 
struct GNUNET_TRANSPORT_HelloGetHandleGNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_TRANSPORT_AddressClass ac, GNUNET_TRANSPORT_HelloUpdateCallback rec, void *rec_cls)
 Obtain the HELLO message for this peer. More...
 
void GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
 Stop receiving updates about changes to our HELLO message. More...
 

Detailed Description

library to obtain our HELLO from our transport service

Author
Christian Grothoff

Definition in file transport_api_hello_get.c.

Function Documentation

◆ check_hello()

static int check_hello ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Function we use for checking incoming HELLO messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_Handle *
msgmessage received
Returns
GNUNET_OK if message is well-formed

Definition at line 91 of file transport_api_hello_get.c.

93 {
94  struct GNUNET_PeerIdentity me;
95 
96  if (GNUNET_OK !=
98  &me))
99  {
100  GNUNET_break (0);
101  return GNUNET_SYSERR;
102  }
104  "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n",
105  (unsigned int) ntohs (msg->size),
106  GNUNET_i2s (&me));
107  return GNUNET_OK;
108 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
#define GNUNET_log(kind,...)
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
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:671
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
A HELLO message is used to exchange information about transports with other peers.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The identity of the host (wraps the signing key of the peer).

References GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_get_id(), GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_SYSERR, me, msg, and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ handle_hello()

static void handle_hello ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Function we use for handling incoming HELLO messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_HelloGetHandle *
msgmessage received

Definition at line 118 of file transport_api_hello_get.c.

120 {
121  struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
122 
123  ghh->rec (ghh->rec_cls,
124  msg);
125 }
static struct GNUNET_TRANSPORT_HelloGetHandle * ghh
Handle to get our current HELLO.
Functions to call with this peer's HELLO.
GNUNET_TRANSPORT_HelloUpdateCallback rec
Callback to call once we got our HELLO.

References ghh, msg, GNUNET_TRANSPORT_HelloGetHandle::rec, and GNUNET_TRANSPORT_HelloGetHandle::rec_cls.

◆ schedule_reconnect()

static void schedule_reconnect ( struct GNUNET_TRANSPORT_HelloGetHandle ghh)
static

Function that will schedule the job that will try to connect us again to the client.

Parameters
ghhtransport service to reconnect

Definition at line 206 of file transport_api_hello_get.c.

207 {
210  &reconnect,
211  ghh);
213 }
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:1269
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
static void reconnect(void *cls)
Try again to connect to transport service.

References ghh, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, reconnect(), GNUNET_TRANSPORT_HelloGetHandle::reconnect_delay, and GNUNET_TRANSPORT_HelloGetHandle::reconnect_task.

Referenced by mq_error_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_TRANSPORT_Handle *
errorerror code

Definition at line 148 of file transport_api_hello_get.c.

150 {
151  struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
152 
154  "Error receiving from transport service, disconnecting temporarily.\n");
156  ghh->mq = NULL;
158 }
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
struct GNUNET_MQ_Handle * mq
Transport handle.
static void schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
Function that will schedule the job that will try to connect us again to the client.

References ghh, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_TRANSPORT_HelloGetHandle::mq, and schedule_reconnect().

Referenced by reconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect()

static void reconnect ( void *  cls)
static

Try again to connect to transport service.

Parameters
clsthe handle to the transport service

Definition at line 167 of file transport_api_hello_get.c.

168 {
169  struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
171  GNUNET_MQ_hd_var_size (hello,
173  struct GNUNET_MessageHeader,
174  ghh),
176  };
177  struct GNUNET_MQ_Envelope *env;
178  struct StartMessage *s;
179 
180  ghh->reconnect_task = NULL;
182  "Connecting to transport service.\n");
183  GNUNET_assert (NULL == ghh->mq);
185  "transport",
186  handlers,
188  ghh);
189  if (NULL == ghh->mq)
190  return;
191  env = GNUNET_MQ_msg (s,
193  s->options = htonl (0);
195  env);
196 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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:1064
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:355
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_TRANSPORT_START
Message from the core saying that the transport server should start giving it messages.
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
Message handler for a specific message type.
Header for all communications.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Message from the transport service to the library asking to check if both processes agree about this ...
Definition: transport.h:92
uint32_t options
0: no options 1: The self field should be checked 2: this client is interested in payload traffic
Definition: transport.h:103
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...

References GNUNET_TRANSPORT_HelloGetHandle::cfg, env, ghh, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_HELLO, GNUNET_MESSAGE_TYPE_TRANSPORT_START, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), handlers, GNUNET_TRANSPORT_HelloGetHandle::mq, mq_error_handler(), StartMessage::options, and GNUNET_TRANSPORT_HelloGetHandle::reconnect_task.

Referenced by GNUNET_TRANSPORT_hello_get(), and schedule_reconnect().

Here is the call graph for this function:
Here is the caller graph for this function: