GNUnet  0.10.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 90 of file transport_api_hello_get.c.

References GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_get_id(), GNUNET_i2s(), GNUNET_log, GNUNET_OK, and GNUNET_SYSERR.

92 {
93  struct GNUNET_PeerIdentity me;
94 
95  if (GNUNET_OK !=
96  GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg,
97  &me))
98  {
99  GNUNET_break(0);
100  return GNUNET_SYSERR;
101  }
103  "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n",
104  (unsigned int)ntohs(msg->size),
105  GNUNET_i2s(&me));
106  return GNUNET_OK;
107 }
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 GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
A HELLO message is used to exchange information about transports with other peers.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
The identity of the host (wraps the signing key of the peer).
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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 117 of file transport_api_hello_get.c.

References ghh, GNUNET_TRANSPORT_HelloGetHandle::rec, GNUNET_TRANSPORT_HelloGetHandle::rec_cls, and schedule_reconnect().

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

◆ 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 205 of file transport_api_hello_get.c.

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

Referenced by handle_hello(), and mq_error_handler().

206 {
207  ghh->reconnect_task =
209  &reconnect,
210  ghh);
212 }
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
#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.
static void reconnect(void *cls)
Try again to connect to transport service.
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
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 147 of file transport_api_hello_get.c.

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

Referenced by reconnect().

149 {
150  struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
151 
153  "Error receiving from transport service, disconnecting temporarily.\n");
154  GNUNET_MQ_destroy(ghh->mq);
155  ghh->mq = NULL;
156  schedule_reconnect(ghh);
157 }
struct GNUNET_MQ_Handle * mq
Transport handle.
static struct GNUNET_TRANSPORT_HelloGetHandle * ghh
Handle to get our current HELLO.
#define GNUNET_log(kind,...)
Functions to call with this peer's HELLO.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
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.
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 166 of file transport_api_hello_get.c.

References GNUNET_TRANSPORT_HelloGetHandle::cfg, env, 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(), GNUNET_TRANSPORT_HelloGetHandle::mq, mq_error_handler(), StartMessage::options, and GNUNET_TRANSPORT_HelloGetHandle::reconnect_task.

Referenced by GNUNET_TRANSPORT_hello_get(), and schedule_reconnect().

167 {
168  struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
170  GNUNET_MQ_hd_var_size(hello,
172  struct GNUNET_MessageHeader,
173  ghh),
175  };
176  struct GNUNET_MQ_Envelope *env;
177  struct StartMessage *s;
178 
179  ghh->reconnect_task = NULL;
181  "Connecting to transport service.\n");
182  GNUNET_assert(NULL == ghh->mq);
183  ghh->mq = GNUNET_CLIENT_connect(ghh->cfg,
184  "transport",
185  handlers,
187  ghh);
188  if (NULL == ghh->mq)
189  return;
190  env = GNUNET_MQ_msg(s,
192  s->options = htonl(0);
193  GNUNET_MQ_send(ghh->mq,
194  env);
195 }
struct GNUNET_MQ_Handle * mq
Transport handle.
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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
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_MESSAGE_TYPE_TRANSPORT_START
Message from the core saying that the transport server should start giving it messages.
Message handler for a specific message type.
Message from the transport service to the library asking to check if both processes agree about this ...
Definition: transport.h:91
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_TRANSPORT_HelloGetHandle * ghh
Handle to get our current HELLO.
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...
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
#define GNUNET_log(kind,...)
Functions to call with this peer's HELLO.
Header for all communications.
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
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Here is the call graph for this function:
Here is the caller graph for this function: