GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
transport_api_application.c File Reference
Include dependency graph for transport_api_application.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_TRANSPORT_ApplicationSuggestHandle
 Handle for TRANSPORT address suggestion requests. More...
 
struct  GNUNET_TRANSPORT_ApplicationHandle
 Handle to the TRANSPORT subsystem for application management. More...
 

Macros

#define LOG(kind, ...)    GNUNET_log_from (kind, "transport-application-api", __VA_ARGS__)
 

Functions

static void reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
 Re-establish the connection to the TRANSPORT service.
 
static void reconnect_task (void *cls)
 Re-establish the connection to the TRANSPORT service.
 
static void force_reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
 Disconnect from TRANSPORT and then reconnect.
 
static void error_handler (void *cls, enum GNUNET_MQ_Error error)
 We encountered an error handling the MQ to the TRANSPORT service.
 
static int transmit_suggestion (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Transmit request for an address suggestion.
 
struct GNUNET_TRANSPORT_ApplicationHandleGNUNET_TRANSPORT_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Initialize the TRANSPORT application suggestion client handle.
 
static int free_sug_handle (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Function called to free all struct GNUNET_TRANSPORT_ApplicationSuggestHandles in the map.
 
void GNUNET_TRANSPORT_application_done (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
 Client is done with TRANSPORT application management, release resources.
 
struct GNUNET_TRANSPORT_ApplicationSuggestHandleGNUNET_TRANSPORT_application_suggest (struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_MQ_PriorityPreferences pk, struct GNUNET_BANDWIDTH_Value32NBO bw)
 An application would like TRANSPORT to connect to a peer.
 
void GNUNET_TRANSPORT_application_suggest_cancel (struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
 We no longer care about being connected to a peer.
 
void GNUNET_TRANSPORT_application_validate (struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_NetworkType nt, const char *addr)
 An application (or a communicator) has received a HELLO (or other address data of another peer) and wants TRANSPORT to validate that the address is correct.
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)     GNUNET_log_from (kind, "transport-application-api", __VA_ARGS__)

Definition at line 32 of file transport_api_application.c.

39{
44
49
54
59};
60
61
66{
70 const struct GNUNET_CONFIGURATION_Handle *cfg;
71
78
82 struct GNUNET_MQ_Handle *mq;
83
88
93};
94
95
101static void
103
104
110static void
111reconnect_task (void *cls)
112{
114
115 ch->task = NULL;
116 reconnect (ch);
117}
118
119
125static void
127{
128 if (NULL != ch->mq)
129 {
131 ch->mq = NULL;
132 }
133 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
134 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, &reconnect_task, ch);
135}
136
137
145static void
146error_handler (void *cls, enum GNUNET_MQ_Error error)
147{
149
151 "TRANSPORT connection died (code %d), reconnecting\n",
152 (int) error);
154}
155
156
166static int
167transmit_suggestion (void *cls,
168 const struct GNUNET_PeerIdentity *peer,
169 void *value)
170{
173 struct GNUNET_MQ_Envelope *ev;
175
176 if (NULL == ch->mq)
177 return GNUNET_SYSERR;
179 m->pk = htonl ((uint32_t) sh->pk);
180 m->bw = sh->bw;
181 m->peer = *peer;
182 GNUNET_MQ_send (ch->mq, ev);
183 return GNUNET_OK;
184}
185
186
192static void
194{
195 static const struct GNUNET_MQ_MessageHandler handlers[] = { { NULL, 0, 0 } };
196
197 GNUNET_assert (NULL == ch->mq);
198 ch->mq =
199 GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch);
200 if (NULL == ch->mq)
201 {
203 return;
204 }
207 ch);
208}
209
210
219 const struct GNUNET_CONFIGURATION_Handle *cfg)
220{
222
224 ch->cfg = cfg;
226 reconnect (ch);
227 return ch;
228}
229
230
240static int
241free_sug_handle (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
242{
244
245 GNUNET_free (cur);
246 return GNUNET_OK;
247}
248
249
255void
258{
259 if (NULL != ch->mq)
260 {
262 ch->mq = NULL;
263 }
264 if (NULL != ch->task)
265 {
267 ch->task = NULL;
268 }
271 NULL);
273 GNUNET_free (ch);
274}
275
276
290 const struct GNUNET_PeerIdentity *peer,
293{
295
297 s->ch = ch;
298 s->id = *peer;
299 s->pk = pk;
300 s->bw = bw;
302 ch->sug_requests,
303 &s->id,
304 s,
307 "Requesting TRANSPORT to suggest address for `%s'\n",
308 GNUNET_i2s (peer));
309 if (NULL == ch->mq)
310 return s;
312 return s;
313}
314
315
321void
324{
326 struct GNUNET_MQ_Envelope *ev;
328
330 "Telling TRANSPORT we no longer care for an address for `%s'\n",
331 GNUNET_i2s (&sh->id));
333 GNUNET_OK ==
334 GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, &sh->id, sh));
335 if (NULL == ch->mq)
336 {
337 GNUNET_free (sh);
338 return;
339 }
341 m->pk = htonl ((uint32_t) sh->pk);
342 m->bw = sh->bw;
343 m->peer = sh->id;
344 GNUNET_MQ_send (ch->mq, ev);
345 GNUNET_free (sh);
346}
347
348
364void
367 const struct GNUNET_PeerIdentity *peer,
369 const char *addr)
370{
371 struct GNUNET_MQ_Envelope *ev;
373 size_t alen;
374
375 if (NULL == ch->mq)
376 {
377 GNUNET_log (
379 "Address validation for %s:%s skipped as transport is not connected\n",
381 addr);
382 return;
383 }
384 alen = strlen (addr) + 1;
385 ev =
387 alen,
389 m->peer = *peer;
390 m->nt = htonl ((uint32_t) nt);
391 memcpy (&m[1], addr, alen);
392 GNUNET_MQ_send (ch->mq, ev);
393}
394
395
396/* end of transport_api2_application.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition gnunet-arm.c:103
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static struct GNUNET_CADET_Channel * ch
Channel handle.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static char * value
Value of the record to add/remove.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
struct GNUNET_TRANSPORT_ApplicationSuggestHandle * GNUNET_TRANSPORT_application_suggest(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_MQ_PriorityPreferences pk, struct GNUNET_BANDWIDTH_Value32NBO bw)
An application would like TRANSPORT to connect to a peer.
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Client is done with TRANSPORT application management, release resources.
void GNUNET_TRANSPORT_application_validate(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_NetworkType nt, const char *addr)
An application (or a communicator) has received a HELLO (or other address data of another peer) and w...
void GNUNET_TRANSPORT_application_suggest_cancel(struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
We no longer care about being connected to a peer.
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application suggestion client 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:1060
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash 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_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).
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.
enum GNUNET_GenericReturnValue 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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
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:305
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
GNUNET_MQ_PriorityPreferences
Per envelope preferences and priorities.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition mq.c:700
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION
Type of the 'struct RequestHelloValidationMessage' send by clients to TRANSPORT to trigger validation...
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL
Type of the 'struct ExpressPreferenceMessage' send by clients to TRANSPORT to abandon bandwidth prefe...
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST
Type of the 'struct ExpressPreferenceMessage' send by clients to TRANSPORT to establish bandwidth pre...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
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:1277
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static void reconnect(void)
Adjust exponential back-off and reconnect to the service.
Application client to TRANSPORT service: we would like to have address suggestions for this peer.
Definition transport.h:807
struct GNUNET_PeerIdentity peer
Peer to get address suggestions for.
Definition transport.h:824
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition cadet.h:142
Internal representation of the hash map.
Handle to a message queue.
Definition mq.c:87
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition scheduler.c:136
Time for relative time used by GNUnet, in microseconds.
Handle to the TRANSPORT subsystem for application management.
struct GNUNET_CONTAINER_MultiPeerMap * sug_requests
Map with the identities of all the peers for which we would like to have address suggestions.
struct GNUNET_SCHEDULER_Task * task
Task to trigger reconnect.
struct GNUNET_MQ_Handle * mq
Message queue for sending requests to the TRANSPORT service.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_TIME_Relative backoff
Reconnect backoff delay.
Handle for TRANSPORT address suggestion requests.
enum GNUNET_MQ_PriorityPreferences pk
What preference is being expressed?
struct GNUNET_TRANSPORT_ApplicationHandle * ch
Connecitivity handle this suggestion handle belongs to.
struct GNUNET_BANDWIDTH_Value32NBO bw
How much bandwidth does the client expect?
struct GNUNET_PeerIdentity id
ID of the peer for which address suggestion was requested.
We got an address of another peer, TRANSPORT service should validate it.
Definition transport.h:838
struct GNUNET_PeerIdentity peer
Peer to the address is presumably for.
Definition transport.h:853
static void force_reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Disconnect from TRANSPORT and then reconnect.
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error handling the MQ to the TRANSPORT service.
static int transmit_suggestion(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Transmit request for an address suggestion.
static int free_sug_handle(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Function called to free all struct GNUNET_TRANSPORT_ApplicationSuggestHandles in the map.
#define LOG(kind,...)
static void reconnect_task(void *cls)
Re-establish the connection to the TRANSPORT service.

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_TRANSPORT_ApplicationHandle ch)
static

Re-establish the connection to the TRANSPORT service.

Parameters
chhandle to use to re-connect.

Definition at line 194 of file transport_api_application.c.

195{
196 static const struct GNUNET_MQ_MessageHandler handlers[] = { { NULL, 0, 0 } };
197
198 GNUNET_assert (NULL == ch->mq);
199 ch->mq =
200 GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch);
201 if (NULL == ch->mq)
202 {
204 return;
205 }
208 ch);
209}

References ch, error_handler(), force_reconnect(), GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_CONTAINER_multipeermap_iterate(), handlers, GNUNET_CADET_Channel::mq, and transmit_suggestion().

Here is the call graph for this function:

◆ reconnect_task()

static void reconnect_task ( void *  cls)
static

Re-establish the connection to the TRANSPORT service.

Parameters
clshandle to use to re-connect.

Definition at line 112 of file transport_api_application.c.

113{
115
116 ch->task = NULL;
117 reconnect (ch);
118}

References ch, and reconnect().

Referenced by force_reconnect().

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

◆ force_reconnect()

static void force_reconnect ( struct GNUNET_TRANSPORT_ApplicationHandle ch)
static

Disconnect from TRANSPORT and then reconnect.

Parameters
chour handle

Definition at line 127 of file transport_api_application.c.

128{
129 if (NULL != ch->mq)
130 {
132 ch->mq = NULL;
133 }
134 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
135 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, &reconnect_task, ch);
136}

References ch, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, GNUNET_CADET_Channel::mq, and reconnect_task().

Referenced by error_handler(), and reconnect().

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

◆ error_handler()

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

We encountered an error handling the MQ to the TRANSPORT service.

Reconnect.

Parameters
clsthe struct GNUNET_TRANSPORT_ApplicationHandle
errordetails about the error

Definition at line 147 of file transport_api_application.c.

148{
150
152 "TRANSPORT connection died (code %d), reconnecting\n",
153 (int) error);
155}

References ch, force_reconnect(), GNUNET_ERROR_TYPE_DEBUG, and LOG.

Referenced by reconnect().

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

◆ transmit_suggestion()

static int transmit_suggestion ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Transmit request for an address suggestion.

Parameters
clsthe struct GNUNET_TRANSPORT_ApplicationHandle
peerpeer to ask for an address suggestion for
valuethe struct GNUNET_TRANSPORT_SuggestHandle
Returns
GNUNET_OK (continue to iterate), GNUNET_SYSERR on failure (message queue no longer exists)

Definition at line 168 of file transport_api_application.c.

171{
174 struct GNUNET_MQ_Envelope *ev;
176
177 if (NULL == ch->mq)
178 return GNUNET_SYSERR;
180 m->pk = htonl ((uint32_t) sh->pk);
181 m->bw = sh->bw;
182 m->peer = *peer;
183 GNUNET_MQ_send (ch->mq, ev);
184 return GNUNET_OK;
185}

References ch, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, m, GNUNET_CADET_Channel::mq, ExpressPreferenceMessage::peer, sh, and value.

Referenced by GNUNET_TRANSPORT_application_suggest(), and reconnect().

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

◆ free_sug_handle()

static int free_sug_handle ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Function called to free all struct GNUNET_TRANSPORT_ApplicationSuggestHandles in the map.

Parameters
clsNULL
keythe key
valuethe value to free
Returns
GNUNET_OK (continue to iterate)

Definition at line 242 of file transport_api_application.c.

243{
245
246 GNUNET_free (cur);
247 return GNUNET_OK;
248}

References GNUNET_free, GNUNET_OK, and value.

Referenced by GNUNET_TRANSPORT_application_done().

Here is the caller graph for this function: