GNUnet 0.22.2
gnunet-service-fs_cadet_client.c File Reference

non-anonymous file-transfer More...

Include dependency graph for gnunet-service-fs_cadet_client.c:

Go to the source code of this file.

Data Structures

struct  GSF_CadetRequest
 Handle for a request that is going out via cadet API. More...
 
struct  CadetHandle
 Handle for a cadet to another peer. More...
 
struct  HandleReplyClosure
 Closure for handle_reply(). More...
 

Macros

#define CLIENT_RETRY_TIMEOUT    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 After how long do we reset connections without replies? More...
 

Functions

static void transmit_pending (void *cls)
 Transmit pending requests via the cadet. More...
 
static int move_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator called on each entry in a waiting map to move it back to the pending list. More...
 
static int check_reply (void *cls, const struct CadetReplyMessage *srm)
 Functions with this signature are called whenever a complete reply is received. More...
 
static void reset_cadet_task (void *cls)
 Task called when it is time to reset an cadet. More...
 
static void reset_cadet_async (struct CadetHandle *mh)
 We had a serious error, tear down and re-create cadet from scratch, but do so asynchronously. More...
 
static int process_reply (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator called on each entry in a waiting map to process a result. More...
 
static int free_waiting_entry (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator called on each entry in a waiting map to call the 'proc' continuation and release associated resources. More...
 
static void handle_reply (void *cls, const struct CadetReplyMessage *srm)
 Functions with this signature are called whenever a complete reply is received. More...
 
static void disconnect_cb (void *cls, const struct GNUNET_CADET_Channel *channel)
 Function called by cadet when a client disconnects. More...
 
static void window_change_cb (void *cls, const struct GNUNET_CADET_Channel *channel, int window_size)
 Function called whenever an MQ-channel's transmission window size changes. More...
 
static void reset_cadet (struct CadetHandle *mh)
 We had a serious error, tear down and re-create cadet from scratch. More...
 
static void cadet_timeout (void *cls)
 Task called when it is time to destroy an inactive cadet channel. More...
 
static struct CadetHandleget_cadet (const struct GNUNET_PeerIdentity *target)
 Get (or create) a cadet to talk to the given peer. More...
 
struct GSF_CadetRequestGSF_cadet_query (const struct GNUNET_PeerIdentity *target, const struct GNUNET_HashCode *query, enum GNUNET_BLOCK_Type type, GSF_CadetReplyProcessor proc, void *proc_cls)
 Look for a block by directly contacting a particular peer. More...
 
void GSF_cadet_query_cancel (struct GSF_CadetRequest *sr)
 Cancel an active request; must not be called after 'proc' was called. More...
 
int GSF_cadet_release_clients (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Function called on each active cadets to shut them down. More...
 

Variables

struct GNUNET_CADET_Handlecadet_handle
 Cadet channel for creating outbound channels. More...
 
struct GNUNET_CONTAINER_MultiPeerMapcadet_map
 Map from peer identities to 'struct CadetHandles' with cadet channels to those peers. More...
 

Detailed Description

non-anonymous file-transfer

Author
Christian Grothoff

TODO:

  • PORT is set to old application type, unsure if we should keep it that way (fine for now)

Definition in file gnunet-service-fs_cadet_client.c.

Macro Definition Documentation

◆ CLIENT_RETRY_TIMEOUT

#define CLIENT_RETRY_TIMEOUT    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)

After how long do we reset connections without replies?

Definition at line 42 of file gnunet-service-fs_cadet_client.c.

Function Documentation

◆ transmit_pending()

static void transmit_pending ( void *  cls)
static

Transmit pending requests via the cadet.

Parameters
clsstruct CadetHandle to process

Definition at line 526 of file gnunet-service-fs_cadet_client.c.

527{
528 struct CadetHandle *mh = cls;
529 struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq (mh->channel);
530 struct GSF_CadetRequest *sr;
531 struct GNUNET_MQ_Envelope *env;
532 struct CadetQueryMessage *sqm;
533
534 if ((0 != GNUNET_MQ_get_length (mq)) || (NULL == (sr = mh->pending_head)))
535 return;
536 GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr);
538 mh->waiting_map,
539 &sr->query,
540 sr,
544 "Sending query for %s via cadet to %s\n",
545 GNUNET_h2s (&sr->query),
546 GNUNET_i2s (&mh->target));
552 sqm->type = htonl (sr->type);
553 sqm->query = sr->query;
556}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
static void transmit_pending(void *cls)
Transmit pending requests via the cadet.
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected channel.
Definition: cadet_api.c:1081
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
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.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_MQ_env_set_options(struct GNUNET_MQ_Envelope *env, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific options for this envelope.
Definition: mq.c:847
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:293
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(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
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:655
@ GNUNET_MQ_PREF_OUT_OF_ORDER
Flag to indicate that out-of-order delivery is OK.
@ GNUNET_MQ_PREF_CORK_ALLOWED
Flag to indicate that CORKing is acceptable.
@ GNUNET_MQ_PREF_GOODPUT
Flag to indicate that high bandwidth is desired.
#define GNUNET_MESSAGE_TYPE_FS_CADET_QUERY
P2P request for content (one FS to another via a cadet).
Handle for a cadet to another peer.
Query from one peer, asking the other for CHK-data.
struct GNUNET_HashCode query
Query hash from CHK (hash of encrypted block).
uint32_t type
Block type must be DBLOCK or IBLOCK.
Handle to a message queue.
Definition: mq.c:87
Handle for a request that is going out via cadet API.
enum GNUNET_BLOCK_Type type
Desired type for the reply.
int was_transmitted
Did we transmit this request already? GNUNET_YES if we are in the 'waiting_map', GNUNET_NO if we are ...
struct GNUNET_HashCode query
Query to transmit to the other peer.

References env, GNUNET_assert, GNUNET_CADET_get_mq(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY, GNUNET_MQ_env_set_options(), GNUNET_MQ_get_length(), GNUNET_MQ_msg, GNUNET_MQ_notify_sent(), GNUNET_MQ_PREF_CORK_ALLOWED, GNUNET_MQ_PREF_GOODPUT, GNUNET_MQ_PREF_OUT_OF_ORDER, GNUNET_MQ_send(), GNUNET_OK, GNUNET_YES, mh, mq, CadetQueryMessage::query, GSF_CadetRequest::query, transmit_pending(), CadetQueryMessage::type, GSF_CadetRequest::type, and GSF_CadetRequest::was_transmitted.

Referenced by GSF_cadet_query(), reset_cadet(), transmit_pending(), and window_change_cb().

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

◆ move_to_pending()

static int move_to_pending ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator called on each entry in a waiting map to move it back to the pending list.

Parameters
clsthe struct CadetHandle
keythe key of the entry in the map (the query)
valuethe struct GSF_CadetRequest to move to pending
Returns
GNUNET_YES (continue to iterate)

Definition at line 181 of file gnunet-service-fs_cadet_client.c.

182{
183 struct CadetHandle *mh = cls;
184 struct GSF_CadetRequest *sr = value;
185
187 GNUNET_YES ==
189 GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr);
191 return GNUNET_YES;
192}
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_NO

References GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_NO, GNUNET_YES, key, mh, value, and GSF_CadetRequest::was_transmitted.

Referenced by reset_cadet().

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

◆ check_reply()

static int check_reply ( void *  cls,
const struct CadetReplyMessage srm 
)
static

Functions with this signature are called whenever a complete reply is received.

Parameters
clsclosure with the struct CadetHandle
srmthe actual message
Returns
GNUNET_OK on success, GNUNET_SYSERR to stop further processing

Definition at line 204 of file gnunet-service-fs_cadet_client.c.

205{
206 /* We check later... */
207 return GNUNET_OK;
208}

References GNUNET_OK.

◆ reset_cadet_task()

static void reset_cadet_task ( void *  cls)
static

Task called when it is time to reset an cadet.

Parameters
clsthe struct CadetHandle to tear down

Definition at line 511 of file gnunet-service-fs_cadet_client.c.

512{
513 struct CadetHandle *mh = cls;
514
515 mh->reset_task = NULL;
516 reset_cadet (mh);
517}
static void reset_cadet(struct CadetHandle *mh)
We had a serious error, tear down and re-create cadet from scratch.

References mh, and reset_cadet().

Referenced by get_cadet(), and reset_cadet_async().

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

◆ reset_cadet_async()

static void reset_cadet_async ( struct CadetHandle mh)
static

We had a serious error, tear down and re-create cadet from scratch, but do so asynchronously.

Parameters
mhcadet to reset

Definition at line 227 of file gnunet-service-fs_cadet_client.c.

228{
229 if (NULL != mh->reset_task)
230 GNUNET_SCHEDULER_cancel (mh->reset_task);
232}
static void reset_cadet_task(void *cls)
Task called when it is time to reset an cadet.
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_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1304

References GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), mh, and reset_cadet_task().

Referenced by handle_reply().

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

◆ process_reply()

static int process_reply ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator called on each entry in a waiting map to process a result.

Parameters
clsthe struct HandleReplyClosure
keythe key of the entry in the map (the query)
valuethe struct GSF_CadetRequest to handle result for
Returns
GNUNET_YES (continue to iterate)

Definition at line 277 of file gnunet-service-fs_cadet_client.c.

278{
279 struct HandleReplyClosure *hrc = cls;
280 struct GSF_CadetRequest *sr = value;
281
282 sr->proc (sr->proc_cls,
283 hrc->type,
284 hrc->expiration,
285 hrc->data_size,
286 hrc->data);
287 sr->proc = NULL;
289 hrc->found = GNUNET_YES;
290 return GNUNET_YES;
291}
void GSF_cadet_query_cancel(struct GSF_CadetRequest *sr)
Cancel an active request; must not be called after 'proc' was called.
void * proc_cls
Closure for proc.
GSF_CadetReplyProcessor proc
Function to call with the result.
Closure for handle_reply().
enum GNUNET_BLOCK_Type type
Type of the block.
const void * data
Reply payload.
int found
Did we have a matching query?
size_t data_size
Number of bytes in data.
struct GNUNET_TIME_Absolute expiration
Expiration time for the block.

References HandleReplyClosure::data, HandleReplyClosure::data_size, HandleReplyClosure::expiration, HandleReplyClosure::found, GNUNET_YES, GSF_cadet_query_cancel(), GSF_CadetRequest::proc, GSF_CadetRequest::proc_cls, HandleReplyClosure::type, and value.

Referenced by handle_reply().

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

◆ free_waiting_entry()

static int free_waiting_entry ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Iterator called on each entry in a waiting map to call the 'proc' continuation and release associated resources.

Parameters
clsthe struct CadetHandle
keythe key of the entry in the map (the query)
valuethe struct GSF_CadetRequest to clean up
Returns
GNUNET_YES (continue to iterate)

Definition at line 305 of file gnunet-service-fs_cadet_client.c.

306{
307 struct GSF_CadetRequest *sr = value;
308
310 return GNUNET_YES;
311}

References GNUNET_YES, GSF_cadet_query_cancel(), and value.

Referenced by disconnect_cb().

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

◆ handle_reply()

static void handle_reply ( void *  cls,
const struct CadetReplyMessage srm 
)
static

Functions with this signature are called whenever a complete reply is received.

Parameters
clsclosure with the struct CadetHandle
srmthe actual message

Definition at line 322 of file gnunet-service-fs_cadet_client.c.

323{
324 struct CadetHandle *mh = cls;
325 struct HandleReplyClosure hrc;
326 uint16_t msize;
328 struct GNUNET_HashCode query;
329
330 msize = ntohs (srm->header.size) - sizeof(struct CadetReplyMessage);
331 type = ntohl (srm->type);
332 if (GNUNET_YES !=
333 GNUNET_BLOCK_get_key (GSF_block_ctx, type, &srm[1], msize, &query))
334 {
335 GNUNET_break_op (0);
336 GNUNET_log (
338 "Received bogus reply of type %u with %u bytes via cadet from peer %s\n",
339 type,
340 msize,
341 GNUNET_i2s (&mh->target));
343 return;
344 }
346 "Received reply `%s' via cadet from peer %s\n",
347 GNUNET_h2s (&query),
348 GNUNET_i2s (&mh->target));
349 GNUNET_CADET_receive_done (mh->channel);
351 gettext_noop ("# replies received via cadet"),
352 1,
353 GNUNET_NO);
354 hrc.data = &srm[1];
355 hrc.data_size = msize;
357 hrc.type = type;
358 hrc.found = GNUNET_NO;
360 &query,
362 &hrc);
363 if (GNUNET_NO == hrc.found)
364 {
367 "# replies received via cadet dropped"),
368 1,
369 GNUNET_NO);
370 }
371}
#define gettext_noop(String)
Definition: gettext.h:74
static uint32_t type
Type string converted to DNS type value.
struct GNUNET_BLOCK_Context * GSF_block_ctx
Our block context.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
static int process_reply(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator called on each entry in a waiting map to process a result.
static void reset_cadet_async(struct CadetHandle *mh)
We had a serious error, tear down and re-create cadet from scratch, but do so asynchronously.
enum GNUNET_GenericReturnValue GNUNET_BLOCK_get_key(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size, struct GNUNET_HashCode *key)
Function called to obtain the key for a block.
Definition: block.c:278
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Indicate readiness to receive the next message on a channel.
Definition: cadet_api.c:875
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_WARNING
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
Reply to a CadetQueryMessage.
struct GNUNET_TIME_AbsoluteNBO expiration
Expiration time for the block.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_FS_CADET_REPLY.
uint32_t type
Block type must be DBLOCK or IBLOCK.
A 512-bit hashcode.

References HandleReplyClosure::data, HandleReplyClosure::data_size, CadetReplyMessage::expiration, HandleReplyClosure::expiration, HandleReplyClosure::found, gettext_noop, GNUNET_BLOCK_get_key(), GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, GSF_block_ctx, GSF_stats, CadetReplyMessage::header, mh, process_reply(), reset_cadet_async(), GNUNET_MessageHeader::size, type, CadetReplyMessage::type, and HandleReplyClosure::type.

Here is the call graph for this function:

◆ disconnect_cb()

static void disconnect_cb ( void *  cls,
const struct GNUNET_CADET_Channel channel 
)
static

Function called by cadet when a client disconnects.

Cleans up our struct CadetClient of that channel.

Parameters
clsour struct CadetClient
channelchannel of the disconnecting client

Definition at line 382 of file gnunet-service-fs_cadet_client.c.

383{
384 struct CadetHandle *mh = cls;
385 struct GSF_CadetRequest *sr;
386
387 if (NULL == mh->channel)
388 return; /* being destroyed elsewhere */
389 GNUNET_assert (channel == mh->channel);
390 mh->channel = NULL;
391 while (NULL != (sr = mh->pending_head))
393 /* first remove `mh` from the `cadet_map`, so that if the
394 callback from `free_waiting_entry()` happens to re-issue
395 the request, we don't immediately have it back in the
396 `waiting_map`. */
398 &mh->target,
399 mh));
402 mh);
403 if (NULL != mh->timeout_task)
404 GNUNET_SCHEDULER_cancel (mh->timeout_task);
405 if (NULL != mh->reset_task)
406 GNUNET_SCHEDULER_cancel (mh->reset_task);
409 GNUNET_free (mh);
410}
struct GNUNET_CONTAINER_MultiPeerMap * cadet_map
Map from peer identities to 'struct CadetHandles' with cadet channels to those peers.
static int free_waiting_entry(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator called on each entry in a waiting map to call the 'proc' continuation and release associated...
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash 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.
#define GNUNET_free(ptr)
Wrapper around free.

References cadet_map, free_waiting_entry(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GSF_cadet_query_cancel(), and mh.

Referenced by get_cadet(), GNUNET_SERVICE_register_(), GNUNET_SERVICE_run_(), GNUNET_SERVICE_start(), and reset_cadet().

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

◆ window_change_cb()

static void window_change_cb ( void *  cls,
const struct GNUNET_CADET_Channel channel,
int  window_size 
)
static

Function called whenever an MQ-channel's transmission window size changes.

The first callback in an outgoing channel will be with a non-zero value and will mean the channel is connected to the destination.

For an incoming channel it will be called immediately after the GNUNET_CADET_ConnectEventHandler, also with a non-zero value.

Parameters
clsChannel closure.
channelConnection to the other end (henceforth invalid).
window_sizeNew window size. If the is more messages than buffer size this value will be negative..

Definition at line 428 of file gnunet-service-fs_cadet_client.c.

431{
432 /* FIXME: for flow control, implement? */
433#if 0
434 /* Something like this instead of the GNUNET_MQ_notify_sent() in
435 transmit_pending() might be good (once the window change CB works...) */
436 if (0 < window_size) /* test needed? */
438#endif
439}

References mh, and transmit_pending().

Referenced by get_cadet(), and reset_cadet().

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

◆ reset_cadet()

static void reset_cadet ( struct CadetHandle mh)
static

We had a serious error, tear down and re-create cadet from scratch.

Parameters
mhcadet to reset

Definition at line 448 of file gnunet-service-fs_cadet_client.c.

449{
451 "Resetting cadet channel to %s\n",
452 GNUNET_i2s (&mh->target));
453 if (NULL != mh->channel)
454 {
456 mh->channel = NULL;
457 }
459 {
461 { GNUNET_MQ_hd_var_size (reply,
463 struct CadetReplyMessage,
464 mh),
466 struct GNUNET_HashCode port;
467
470 &port);
472 mh,
473 &mh->target,
474 &port,
477 handlers);
478 }
480}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static uint16_t port
Port number.
Definition: gnunet-bcd.c:146
static void disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called by cadet when a client disconnects.
static void window_change_cb(void *cls, const struct GNUNET_CADET_Channel *channel, int window_size)
Function called whenever an MQ-channel's transmission window size changes.
struct GNUNET_CADET_Handle * cadet_handle
Cadet channel for creating outbound channels.
static int move_to_pending(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator called on each entry in a waiting map to move it back to the pending list.
#define GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER
Transfer of blocks for non-anonymmous file-sharing.
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:833
struct GNUNET_CADET_Channel * GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, void *channel_cls, const struct GNUNET_PeerIdentity *destination, const struct GNUNET_HashCode *port, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Create a new channel towards a remote peer.
Definition: cadet_api.c:1030
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_FS_CADET_REPLY
P2P answer for content (one FS to another via a cadet).
Message handler for a specific message type.

References cadet_handle, disconnect_cb(), GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, GNUNET_CADET_channel_create(), GNUNET_CADET_channel_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, handlers, mh, move_to_pending(), port, transmit_pending(), and window_change_cb().

Referenced by reset_cadet_task().

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

◆ cadet_timeout()

static void cadet_timeout ( void *  cls)
static

Task called when it is time to destroy an inactive cadet channel.

Parameters
clsthe struct CadetHandle to tear down

Definition at line 489 of file gnunet-service-fs_cadet_client.c.

490{
491 struct CadetHandle *mh = cls;
492 struct GNUNET_CADET_Channel *tun;
493
495 "Timeout on cadet channel to %s\n",
496 GNUNET_i2s (&mh->target));
497 mh->timeout_task = NULL;
498 tun = mh->channel;
499 mh->channel = NULL;
500 if (NULL != tun)
502}
Opaque handle to a channel.
Definition: cadet.h:116

References GNUNET_CADET_channel_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, and mh.

Referenced by GSF_cadet_query_cancel().

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

◆ get_cadet()

static struct CadetHandle * get_cadet ( const struct GNUNET_PeerIdentity target)
static

Get (or create) a cadet to talk to the given peer.

Parameters
targetpeer we want to communicate with

Definition at line 565 of file gnunet-service-fs_cadet_client.c.

566{
567 struct CadetHandle *mh;
568
570 if (NULL != mh)
571 {
572 if (NULL != mh->timeout_task)
573 {
574 GNUNET_SCHEDULER_cancel (mh->timeout_task);
575 mh->timeout_task = NULL;
576 }
577 return mh;
578 }
580 "Creating cadet channel to %s\n",
582 mh = GNUNET_new (struct CadetHandle);
583 mh->reset_task =
586 mh->target = *target;
589 cadet_map,
590 &mh->target,
591 mh,
593 {
595 { GNUNET_MQ_hd_var_size (reply,
597 struct CadetReplyMessage,
598 mh),
600 struct GNUNET_HashCode port;
601
604 &port);
606 mh,
607 &mh->target,
608 &port,
611 handlers);
612 }
613 return mh;
614}
#define CLIENT_RETRY_TIMEOUT
After how long do we reset connections without replies?
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.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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
struct GNUNET_PeerIdentity target
Which peer does this cadet go to?

References cadet_handle, cadet_map, CLIENT_RETRY_TIMEOUT, disconnect_cb(), GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, GNUNET_assert, GNUNET_CADET_channel_create(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, handlers, mh, port, reset_cadet_task(), CadetHandle::target, and window_change_cb().

Referenced by GSF_cadet_query().

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

◆ GSF_cadet_query()

struct GSF_CadetRequest * GSF_cadet_query ( const struct GNUNET_PeerIdentity target,
const struct GNUNET_HashCode query,
enum GNUNET_BLOCK_Type  type,
GSF_CadetReplyProcessor  proc,
void *  proc_cls 
)

Look for a block by directly contacting a particular peer.

Parameters
targetpeer that should have the block
queryhash to query for the block
typedesired type for the block
procfunction to call with result
proc_clsclosure for proc
Returns
handle to cancel the operation

Definition at line 628 of file gnunet-service-fs_cadet_client.c.

633{
634 struct CadetHandle *mh;
635 struct GSF_CadetRequest *sr;
636
638 "Preparing to send query for %s via cadet to %s\n",
640 GNUNET_i2s (target));
641 mh = get_cadet (target);
642 sr = GNUNET_new (struct GSF_CadetRequest);
643 sr->mh = mh;
644 sr->proc = proc;
645 sr->proc_cls = proc_cls;
646 sr->type = type;
647 sr->query = *query;
648 GNUNET_CONTAINER_DLL_insert (mh->pending_head, mh->pending_tail, sr);
650 return sr;
651}
static struct CadetHandle * get_cadet(const struct GNUNET_PeerIdentity *target)
Get (or create) a cadet to talk to the given peer.
struct CadetHandle * mh
Which cadet is this request associated with?

References get_cadet(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_new, mh, GSF_CadetRequest::mh, GSF_CadetRequest::proc, GSF_CadetRequest::proc_cls, GSF_CadetRequest::query, transmit_pending(), type, and GSF_CadetRequest::type.

Referenced by cadet_reply_proc(), and GSF_cadet_lookup_().

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

◆ GSF_cadet_query_cancel()

void GSF_cadet_query_cancel ( struct GSF_CadetRequest sr)

Cancel an active request; must not be called after 'proc' was called.

Parameters
srrequest to cancel

Definition at line 661 of file gnunet-service-fs_cadet_client.c.

662{
663 struct CadetHandle *mh = sr->mh;
665
666 p = sr->proc;
667 sr->proc = NULL;
668 if (NULL != p)
669 {
670 /* signal failure / cancellation to callback */
672 }
674 "Cancelled query for %s via cadet to %s\n",
675 GNUNET_h2s (&sr->query),
676 GNUNET_i2s (&sr->mh->target));
677 if (GNUNET_YES == sr->was_transmitted)
679 GNUNET_OK ==
680 GNUNET_CONTAINER_multihashmap_remove (mh->waiting_map, &sr->query, sr));
681 else
682 GNUNET_CONTAINER_DLL_remove (mh->pending_head, mh->pending_tail, sr);
683 GNUNET_free (sr);
684 if ((0 == GNUNET_CONTAINER_multihashmap_size (mh->waiting_map)) &&
685 (NULL == mh->pending_head))
688 mh);
689}
void(* GSF_CadetReplyProcessor)(void *cls, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute expiration, size_t data_size, const void *data)
Function called with a reply from the cadet.
static void cadet_timeout(void *cls)
Task called when it is time to destroy an inactive cadet channel.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:38
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.

References cadet_timeout(), GNUNET_assert, GNUNET_BLOCK_TYPE_ANY, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_UNIT_SECONDS, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_YES, mh, GSF_CadetRequest::mh, p, GSF_CadetRequest::proc, GSF_CadetRequest::proc_cls, GSF_CadetRequest::query, CadetHandle::target, and GSF_CadetRequest::was_transmitted.

Referenced by clean_request(), disconnect_cb(), free_waiting_entry(), GSF_pending_request_cancel_(), and process_reply().

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

◆ GSF_cadet_release_clients()

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

Function called on each active cadets to shut them down.

Parameters
clsNULL
keytarget peer, unused
valuethe struct CadetHandle to destroy
Returns
GNUNET_YES (continue to iterate)

Definition at line 701 of file gnunet-service-fs_cadet_client.c.

704{
705 struct CadetHandle *mh = value;
706
708 "Timeout on cadet channel to %s\n",
709 GNUNET_i2s (&mh->target));
710 if (NULL != mh->channel)
711 {
712 struct GNUNET_CADET_Channel *channel = mh->channel;
713
714 mh->channel = NULL;
716 }
717 if (NULL != mh->reset_task)
718 {
719 GNUNET_SCHEDULER_cancel (mh->reset_task);
720 mh->reset_task = NULL;
721 }
722 return GNUNET_YES;
723}

References GNUNET_CADET_channel_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_YES, mh, and value.

Referenced by GSF_cadet_stop_server().

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

Variable Documentation

◆ cadet_handle

struct GNUNET_CADET_Handle* cadet_handle

Cadet channel for creating outbound channels.

Cadet channel for creating outbound channels.

Definition at line 150 of file gnunet-service-fs_cadet_client.c.

Referenced by get_cadet(), and reset_cadet().

◆ cadet_map

struct GNUNET_CONTAINER_MultiPeerMap* cadet_map

Map from peer identities to 'struct CadetHandles' with cadet channels to those peers.

Definition at line 156 of file gnunet-service-fs_cadet_client.c.

Referenced by disconnect_cb(), get_cadet(), GSF_cadet_start_server(), and GSF_cadet_stop_server().