GNUnet  0.10.x
Data Structures | Typedefs | Functions | Variables
gnunet-service-fs_cadet.h File Reference

non-anonymous file-transfer More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CadetQueryMessage
 Query from one peer, asking the other for CHK-data. More...
 
struct  CadetReplyMessage
 Reply to a CadetQueryMessage. More...
 

Typedefs

typedef 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. More...
 

Functions

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...
 
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...
 
void GSF_cadet_query_cancel (struct GSF_CadetRequest *sr)
 Cancel an active request; must not be called after 'proc' was calld. More...
 
void GSF_cadet_start_server (void)
 Initialize subsystem for non-anonymous file-sharing. More...
 
void GSF_cadet_stop_server (void)
 Shutdown subsystem for non-anonymous file-sharing. 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

Definition in file gnunet-service-fs_cadet.h.

Typedef Documentation

◆ GSF_CadetReplyProcessor

typedef 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.

Parameters
clsclosure
typetype of the block, ANY on error
expirationexpiration time for the block
data_sizenumber of bytes in data, 0 on error
datareply block data, NULL on error

Definition at line 45 of file gnunet-service-fs_cadet.h.

Function Documentation

◆ 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 627 of file gnunet-service-fs_cadet_client.c.

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

Referenced by cadet_reply_proc(), and GSF_cadet_lookup_().

632 {
633  struct CadetHandle *mh;
634  struct GSF_CadetRequest *sr;
635 
637  "Preparing to send query for %s via cadet to %s\n",
638  GNUNET_h2s(query),
639  GNUNET_i2s(target));
640  mh = get_cadet(target);
641  sr = GNUNET_new(struct GSF_CadetRequest);
642  sr->mh = mh;
643  sr->proc = proc;
644  sr->proc_cls = proc_cls;
645  sr->type = type;
646  sr->query = *query;
648  transmit_pending(mh);
649  return sr;
650 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
Handle for a cadet to another peer.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HashCode query
Query to transmit to the other peer.
void * proc_cls
Closure for proc.
Handle for a request that is going out via cadet API.
GSF_CadetReplyProcessor proc
Function to call with the result.
struct GSF_CadetRequest * pending_head
Head of DLL of pending requests on this cadet.
struct GSF_CadetRequest * pending_tail
Tail of DLL of pending requests on this cadet.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static void transmit_pending(void *cls)
Transmit pending requests via the cadet.
struct CadetHandle * mh
Which cadet is this request associated with?
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
enum GNUNET_BLOCK_Type type
Desired type for the reply.
static struct CadetHandle * get_cadet(const struct GNUNET_PeerIdentity *target)
Get (or create) a cadet to talk to the given peer.
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 700 of file gnunet-service-fs_cadet_client.c.

References CadetHandle::channel, GNUNET_CADET_channel_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_YES, GSF_CadetRequest::mh, CadetHandle::reset_task, CadetHandle::target, and value.

Referenced by GSF_cadet_stop_server().

703 {
704  struct CadetHandle *mh = value;
705 
707  "Timeout on cadet channel to %s\n",
708  GNUNET_i2s(&mh->target));
709  if (NULL != mh->channel)
710  {
711  struct GNUNET_CADET_Channel *channel = mh->channel;
712 
713  mh->channel = NULL;
715  }
716  if (NULL != mh->reset_task)
717  {
719  mh->reset_task = NULL;
720  }
721  return GNUNET_YES;
722 }
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
Handle for a cadet to another peer.
Opaque handle to a channel.
Definition: cadet_api.c:79
static char * value
Value of the record to add/remove.
struct GNUNET_PeerIdentity target
Which peer does this cadet go to?
struct GNUNET_SCHEDULER_Task * reset_task
Task to reset cadets that had errors (asynchronously, as we may not be able to do it immediately duri...
struct GNUNET_CADET_Channel * channel
Channel to the other peer.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:900
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 calld.

Parameters
srrequest to cancel

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

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, GSF_CadetRequest::mh, p, CadetHandle::pending_head, CadetHandle::pending_tail, GSF_CadetRequest::proc, GSF_CadetRequest::proc_cls, GSF_CadetRequest::query, CadetHandle::target, CadetHandle::timeout_task, CadetHandle::waiting_map, and GSF_CadetRequest::was_transmitted.

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

661 {
662  struct CadetHandle *mh = sr->mh;
664 
665  p = sr->proc;
666  sr->proc = NULL;
667  if (NULL != p)
668  {
669  /* signal failure / cancellation to callback */
671  }
673  "Cancelled query for %s via cadet to %s\n",
674  GNUNET_h2s(&sr->query),
675  GNUNET_i2s(&sr->mh->target));
676  if (GNUNET_YES == sr->was_transmitted)
678  GNUNET_OK ==
680  else
682  GNUNET_free(sr);
684  (NULL == mh->pending_head))
686  &cadet_timeout,
687  mh);
688 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
Any type of block, used as a wildcard when searching.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
Handle for a cadet to another peer.
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_HashCode query
Query to transmit to the other peer.
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
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
int was_transmitted
Did we transmit this request already? GNUNET_YES if we are in the 'waiting_map', GNUNET_NO if we are ...
int 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.
void * proc_cls
Closure for proc.
struct GNUNET_PeerIdentity target
Which peer does this cadet go to?
struct GNUNET_SCHEDULER_Task * timeout_task
Task to kill inactive cadets (we keep them around for a few seconds to give the application a chance ...
GSF_CadetReplyProcessor proc
Function to call with the result.
struct GSF_CadetRequest * pending_head
Head of DLL of pending requests on this cadet.
struct GSF_CadetRequest * pending_tail
Tail of DLL of pending requests on this cadet.
#define GNUNET_log(kind,...)
static void cadet_timeout(void *cls)
Task called when it is time to destroy an inactive cadet channel.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct CadetHandle * mh
Which cadet is this request associated with?
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GNUNET_CONTAINER_MultiHashMap * waiting_map
Map from query to struct GSF_CadetRequests waiting for a reply.
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.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_cadet_start_server()

void GSF_cadet_start_server ( void  )

Initialize subsystem for non-anonymous file-sharing.

Definition at line 482 of file gnunet-service-fs_cadet_server.c.

References cadet_handle, cadet_map, connect_cb(), disconnect_cb(), GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER, GNUNET_assert, GNUNET_CADET_connect(), GNUNET_CADET_open_port(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_FS_CADET_QUERY, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_YES, GSF_cfg, request, sc_count_max, and window_change_cb().

Referenced by main_init().

483 {
487  struct CadetQueryMessage,
488  NULL),
490  };
491  struct GNUNET_HashCode port;
492 
493  if (GNUNET_YES !=
495  "fs",
496  "MAX_CADET_CLIENTS",
497  &sc_count_max))
498  return;
500  "Initializing cadet FS server with a limit of %llu connections\n",
501  sc_count_max);
504  GNUNET_assert(NULL != cadet_handle);
507  &port);
509  &port,
510  &connect_cb,
511  NULL,
513  &disconnect_cb,
514  handlers);
515 }
static void * connect_cb(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator)
Functions of this type are called upon new cadet connection from other peers.
static struct GNUNET_CADET_Handle * cadet_handle
The handle to cadet.
Query from one peer, asking the other for CHK-data.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
static unsigned long long sc_count_max
Maximum allowed number of cadet clients.
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).
const struct GNUNET_CONFIGURATION_Handle * GSF_cfg
Our configuration.
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition: cadet_api.c:973
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_Port * GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *port, GNUNET_CADET_ConnectEventHandler connects, void *connects_cls, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Open a port to receive incomming MQ-based channels.
Definition: cadet_api.c:1007
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
struct GNUNET_CONTAINER_MultiPeerMap * cadet_map
Map from peer identities to 'struct CadetHandles' with cadet channels to those peers.
A 512-bit hashcode.
Message handler for a specific message type.
static void disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called by cadet when a client disconnects.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
#define GNUNET_MESSAGE_TYPE_FS_CADET_QUERY
P2P request for content (one FS to another via a cadet).
#define GNUNET_log(kind,...)
static struct GNUNET_CADET_Port * cadet_port
Listen port for incoming requests.
#define GNUNET_APPLICATION_PORT_FS_BLOCK_TRANSFER
Transfer of blocks for non-anonymmous file-sharing.
#define GNUNET_YES
Definition: gnunet_common.h:77
#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:

◆ GSF_cadet_stop_server()

void GSF_cadet_stop_server ( void  )

Shutdown subsystem for non-anonymous file-sharing.

Definition at line 522 of file gnunet-service-fs_cadet_server.c.

References cadet_handle, cadet_map, GNUNET_assert, GNUNET_CADET_close_port(), GNUNET_CADET_disconnect(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GSF_cadet_release_clients(), and sc_count.

Referenced by shutdown_task().

523 {
526  NULL);
528  cadet_map = NULL;
529  if (NULL != cadet_port)
530  {
532  cadet_port = NULL;
533  }
534  if (NULL != cadet_handle)
535  {
537  cadet_handle = NULL;
538  }
539  GNUNET_assert(NULL == sc_head);
540  GNUNET_assert(0 == sc_count);
541 }
static struct GNUNET_CADET_Handle * cadet_handle
The handle to cadet.
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:838
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct CadetClient * sc_head
Head of DLL of cadet clients.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GSF_cadet_release_clients(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Function called on each active cadets to shut them down.
static unsigned int sc_count
Number of active cadet clients in the 'sc_*'-DLL.
struct GNUNET_CONTAINER_MultiPeerMap * cadet_map
Map from peer identities to 'struct CadetHandles' with cadet channels to those peers.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_CADET_Port * cadet_port
Listen port for incoming requests.
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port().
Definition: cadet_api.c:871
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.

◆ 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 GSF_cadet_start_server(), and GSF_cadet_stop_server().