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 632 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_().

637 {
638  struct CadetHandle *mh;
639  struct GSF_CadetRequest *sr;
640 
642  "Preparing to send query for %s via cadet to %s\n",
643  GNUNET_h2s (query),
644  GNUNET_i2s (target));
645  mh = get_cadet (target);
646  sr = GNUNET_new (struct GSF_CadetRequest);
647  sr->mh = mh;
648  sr->proc = proc;
649  sr->proc_cls = proc_cls;
650  sr->type = type;
651  sr->query = *query;
653  transmit_pending (mh);
654  return sr;
655 }
#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 705 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().

708 {
709  struct CadetHandle *mh = value;
710 
712  "Timeout on cadet channel to %s\n",
713  GNUNET_i2s (&mh->target));
714  if (NULL != mh->channel)
715  {
716  struct GNUNET_CADET_Channel *channel = mh->channel;
717 
718  mh->channel = NULL;
720  }
721  if (NULL != mh->reset_task)
722  {
724  mh->reset_task = NULL;
725  }
726  return GNUNET_YES;
727 }
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:80
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:80
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:905
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:965
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 665 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().

666 {
667  struct CadetHandle *mh = sr->mh;
669 
670  p = sr->proc;
671  sr->proc = NULL;
672  if (NULL != p)
673  {
674  /* signal failure / cancellation to callback */
676  }
678  "Cancelled query for %s via cadet to %s\n",
679  GNUNET_h2s (&sr->query),
680  GNUNET_i2s (&sr->mh->target));
681  if (GNUNET_YES == sr->was_transmitted)
682  GNUNET_assert (
683  GNUNET_OK ==
685  else
687  GNUNET_free (sr);
689  (NULL == mh->pending_head))
691  &cadet_timeout,
692  mh);
693 }
#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:78
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:1246
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:80
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 485 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, sc_count_max, and window_change_cb().

Referenced by main_init().

486 {
490  struct CadetQueryMessage,
491  NULL),
493  };
494  struct GNUNET_HashCode port;
495 
496  if (GNUNET_YES !=
498  "fs",
499  "MAX_CADET_CLIENTS",
500  &sc_count_max))
501  return;
503  "Initializing cadet FS server with a limit of %llu connections\n",
504  sc_count_max);
507  GNUNET_assert (NULL != cadet_handle);
510  &port);
512  &port,
513  &connect_cb,
514  NULL,
516  &disconnect_cb,
517  handlers);
518 }
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.
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:977
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:1011
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:79
#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:80
#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 525 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().

526 {
529  NULL);
531  cadet_map = NULL;
532  if (NULL != cadet_port)
533  {
535  cadet_port = NULL;
536  }
537  if (NULL != cadet_handle)
538  {
540  cadet_handle = NULL;
541  }
542  GNUNET_assert (NULL == sc_head);
543  GNUNET_assert (0 == sc_count);
544 }
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:843
#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:876
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 153 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 159 of file gnunet-service-fs_cadet_client.c.

Referenced by GSF_cadet_start_server(), and GSF_cadet_stop_server().