GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-service-fs_cadet_server.c File Reference

non-anonymous file-transfer More...

#include "platform.h"
#include "gnunet_constants.h"
#include "gnunet_util_lib.h"
#include "gnunet_cadet_service.h"
#include "gnunet_protocols.h"
#include "gnunet_applications.h"
#include "gnunet-service-fs.h"
#include "gnunet-service-fs_indexing.h"
#include "gnunet-service-fs_cadet.h"
Include dependency graph for gnunet-service-fs_cadet_server.c:

Go to the source code of this file.

Data Structures

struct  WriteQueueItem
 A message in the queue to be written to the cadet. More...
 
struct  CadetClient
 Struct containing information about a client of the service. More...
 

Macros

#define IDLE_TIMEOUT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
 After how long do we termiante idle connections? More...
 

Functions

static void timeout_cadet_task (void *cls)
 Task run to asynchronously terminate the cadet due to timeout. More...
 
static void refresh_timeout_task (struct CadetClient *sc)
 Reset the timeout for the cadet client (due to activity). More...
 
static void continue_writing (void *cls)
 Check if we are done with the write queue, and if so tell CADET that we are ready to read more. More...
 
static void handle_datastore_reply (void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
 Process a datum that was stored in the datastore. More...
 
static void handle_request (void *cls, const struct CadetQueryMessage *sqm)
 Functions with this signature are called whenever a complete query message is received. More...
 
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. 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...
 
void GSF_cadet_start_server ()
 Initialize subsystem for non-anonymous file-sharing. More...
 
void GSF_cadet_stop_server ()
 Shutdown subsystem for non-anonymous file-sharing. More...
 

Variables

static struct GNUNET_CADET_Portcadet_port
 Listen port for incoming requests. More...
 
static struct CadetClientsc_head
 Head of DLL of cadet clients. More...
 
static struct CadetClientsc_tail
 Tail of DLL of cadet clients. More...
 
static unsigned int sc_count
 Number of active cadet clients in the 'sc_*'-DLL. More...
 
static unsigned long long sc_count_max
 Maximum allowed number of cadet clients. More...
 

Detailed Description

non-anonymous file-transfer

Author
Christian Grothoff

TODO:

Definition in file gnunet-service-fs_cadet_server.c.

Macro Definition Documentation

◆ IDLE_TIMEOUT

After how long do we termiante idle connections?

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

Referenced by refresh_timeout_task().

Function Documentation

◆ timeout_cadet_task()

static void timeout_cadet_task ( void *  cls)
static

Task run to asynchronously terminate the cadet due to timeout.

Parameters
clsthe 'struct CadetClient'

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

References CadetClient::channel, GNUNET_CADET_channel_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, sc, and CadetClient::timeout_task.

Referenced by refresh_timeout_task().

152 {
153  struct CadetClient *sc = cls;
154  struct GNUNET_CADET_Channel *tun;
155 
156  sc->timeout_task = NULL;
157  tun = sc->channel;
158  sc->channel = NULL;
160  "Timeout for inactive cadet client %p\n",
161  sc);
163 }
struct GNUNET_SCHEDULER_Task * timeout_task
Task that is scheduled to terminate idle connections.
Opaque handle to a channel.
Definition: cadet_api.c:79
Struct containing information about a client of the service.
struct GNUNET_CADET_Channel * channel
Channel for communication.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define GNUNET_log(kind,...)
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:900
Here is the call graph for this function:
Here is the caller graph for this function:

◆ refresh_timeout_task()

static void refresh_timeout_task ( struct CadetClient sc)
static

Reset the timeout for the cadet client (due to activity).

Parameters
scclient handle to reset timeout for

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

References GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), IDLE_TIMEOUT, timeout_cadet_task(), and CadetClient::timeout_task.

Referenced by connect_cb(), continue_writing(), and handle_request().

173 {
174  if (NULL != sc->timeout_task)
178  sc);
179 }
struct GNUNET_SCHEDULER_Task * timeout_task
Task that is scheduled to terminate idle connections.
#define IDLE_TIMEOUT
After how long do we termiante idle connections?
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 void timeout_cadet_task(void *cls)
Task run to asynchronously terminate the cadet due to timeout.
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:

◆ continue_writing()

static void continue_writing ( void *  cls)
static

Check if we are done with the write queue, and if so tell CADET that we are ready to read more.

Parameters
clswhere to process the write queue

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

References CadetClient::channel, GNUNET_CADET_get_mq(), GNUNET_CADET_receive_done(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_get_length(), mq, refresh_timeout_task(), and sc.

Referenced by handle_datastore_reply(), and handle_request().

190 {
191  struct CadetClient *sc = cls;
192  struct GNUNET_MQ_Handle *mq;
193 
194  mq = GNUNET_CADET_get_mq(sc->channel);
195  if (0 != GNUNET_MQ_get_length(mq))
196  {
198  "Write pending, waiting for it to complete\n");
199  return;
200  }
203  "Finished processing cadet request from client %p, ready to receive the next one\n",
204  sc);
206 }
static void refresh_timeout_task(struct CadetClient *sc)
Reset the timeout for the cadet client (due to activity).
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:333
Struct containing information about a client of the service.
struct GNUNET_CADET_Channel * channel
Channel for communication.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Handle to a message queue.
Definition: mq.c:84
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:951
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
Definition: cadet_api.c:1116
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_datastore_reply()

static void handle_datastore_reply ( void *  cls,
const struct GNUNET_HashCode key,
size_t  size,
const void *  data,
enum GNUNET_BLOCK_Type  type,
uint32_t  priority,
uint32_t  anonymity,
uint32_t  replication,
struct GNUNET_TIME_Absolute  expiration,
uint64_t  uid 
)
static

Process a datum that was stored in the datastore.

Parameters
clsclosure with the struct CadetClient which sent the query
keykey for the content
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationreplication-level for the content
expirationexpiration time for the content
uidunique identifier for the datum; maybe 0 if no unique identifier is available

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

References CadetClient::channel, continue_writing(), env, CadetReplyMessage::expiration, gettext_noop, GNUNET_BLOCK_TYPE_ANY, GNUNET_BLOCK_TYPE_FS_ONDEMAND, GNUNET_break, GNUNET_CADET_get_mq(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_FS_handle_on_demand_block(), GNUNET_h2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_FS_CADET_REPLY, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), GSF_stats, WriteQueueItem::msize, CadetClient::qe, sc, and CadetReplyMessage::type.

Referenced by handle_request().

235 {
236  struct CadetClient *sc = cls;
237  size_t msize = size + sizeof(struct CadetReplyMessage);
238  struct GNUNET_MQ_Envelope *env;
239  struct CadetReplyMessage *srm;
240 
241  sc->qe = NULL;
242  if (NULL == data)
243  {
244  /* no result, this should not really happen, as for
245  non-anonymous routing only peers that HAVE the
246  answers should be queried; OTOH, this is not a
247  hard error as we might have had the answer in the
248  past and the user might have unindexed it. Hence
249  we log at level "INFO" for now. */
250  if (NULL == key)
251  {
253  "Have no answer and the query was NULL\n");
254  }
255  else
256  {
258  "Have no answer for query `%s'\n",
259  GNUNET_h2s(key));
260  }
262  gettext_noop("# queries received via CADET not answered"),
263  1,
264  GNUNET_NO);
265  continue_writing(sc);
266  return;
267  }
269  {
271  "Performing on-demand encoding for query %s\n",
272  GNUNET_h2s(key));
273  if (GNUNET_OK !=
275  size,
276  data,
277  type,
278  priority,
279  anonymity,
280  replication,
281  expiration,
282  uid,
284  sc))
285  {
287  "On-demand encoding request failed\n");
288  continue_writing(sc);
289  }
290  return;
291  }
292  if (msize > GNUNET_MAX_MESSAGE_SIZE)
293  {
294  GNUNET_break(0);
295  continue_writing(sc);
296  return;
297  }
300  "Starting transmission of %u byte reply of type %d for query `%s' via cadet to %p\n",
301  (unsigned int)size,
302  (unsigned int)type,
303  GNUNET_h2s(key),
304  sc);
305  env = GNUNET_MQ_msg_extra(srm,
306  size,
308  srm->type = htonl(type);
309  srm->expiration = GNUNET_TIME_absolute_hton(expiration);
310  GNUNET_memcpy(&srm[1],
311  data,
312  size);
315  sc);
317  gettext_noop("# Blocks transferred via cadet"),
318  1,
319  GNUNET_NO);
321  env);
322 }
#define GNUNET_MESSAGE_TYPE_FS_CADET_REPLY
P2P answer for content (one FS to another via a cadet).
static void handle_datastore_reply(void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
Process a datum that was stored in the datastore.
Any type of block, used as a wildcard when searching.
static unsigned int replication
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
Definition: gnunet_common.h:78
#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).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Type of a block representing a block to be encoded on demand from disk.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
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:772
static void continue_writing(void *cls)
Check if we are done with the write queue, and if so tell CADET that we are ready to read more...
Struct containing information about a client of the service.
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_CADET_Channel * channel
Channel for communication.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_TIME_AbsoluteNBO expiration
Expiration time for the block.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
static unsigned int anonymity
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
uint32_t type
Block type must be DBLOCK or IBLOCK.
int GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid, GNUNET_DATASTORE_DatumProcessor cont, void *cont_cls)
We've received an on-demand encoded block from the datastore.
uint32_t data
The data value.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:655
Reply to a CadetQueryMessage.
struct GNUNET_DATASTORE_QueueEntry * qe
Current active request to the datastore, if we have one pending.
#define gettext_noop(String)
Definition: gettext.h:69
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
Definition: cadet_api.c:1116
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_request()

static void handle_request ( void *  cls,
const struct CadetQueryMessage sqm 
)
static

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

Parameters
clsclosure with the struct CadetClient
sqmthe actual message

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

References continue_writing(), gettext_noop, GNUNET_DATASTORE_get_key(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GSF_datastore_queue_size, GSF_dsh, GSF_stats, handle_datastore_reply(), CadetClient::qe, CadetQueryMessage::query, refresh_timeout_task(), sc, and CadetQueryMessage::type.

335 {
336  struct CadetClient *sc = cls;
337 
339  "Received query for `%s' via cadet from client %p\n",
340  GNUNET_h2s(&sqm->query),
341  sc);
343  gettext_noop("# queries received via cadet"),
344  1,
345  GNUNET_NO);
348  0 /* next_uid */,
349  false /* random */,
350  &sqm->query,
351  ntohl(sqm->type),
352  0 /* priority */,
355  sc);
356  if (NULL == sc->qe)
357  {
359  "Queueing request with datastore failed (queue full?)\n");
360  continue_writing(sc);
361  }
362 }
static void handle_datastore_reply(void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
Process a datum that was stored in the datastore.
uint32_t type
Block type must be DBLOCK or IBLOCK.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
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).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static void refresh_timeout_task(struct CadetClient *sc)
Reset the timeout for the cadet client (due to activity).
struct GNUNET_HashCode query
Query hash from CHK (hash of encrypted block).
static void continue_writing(void *cls)
Check if we are done with the write queue, and if so tell CADET that we are ready to read more...
unsigned int GSF_datastore_queue_size
Size of the datastore queue we assume for common requests.
struct GNUNET_DATASTORE_Handle * GSF_dsh
Our connection to the datastore.
Struct containing information about a client of the service.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define GNUNET_log(kind,...)
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_get_key(struct GNUNET_DATASTORE_Handle *h, uint64_t next_uid, bool random, const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
Get a result for a particular key from the datastore.
struct GNUNET_DATASTORE_QueueEntry * qe
Current active request to the datastore, if we have one pending.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ connect_cb()

static void* connect_cb ( void *  cls,
struct GNUNET_CADET_Channel channel,
const struct GNUNET_PeerIdentity initiator 
)
static

Functions of this type are called upon new cadet connection from other peers.

Parameters
clsthe closure from GNUNET_CADET_connect
channelthe channel representing the cadet
initiatorthe identity of the peer who wants to establish a cadet with us; NULL on binding error
Returns
initial channel context (our struct CadetClient)

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

References CadetClient::channel, gettext_noop, GNUNET_assert, GNUNET_CADET_channel_destroy(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), GSF_stats, refresh_timeout_task(), sc, sc_count, and sc_count_max.

Referenced by GNUNET_SERVICE_run_(), GNUNET_SERVICE_start(), and GSF_cadet_start_server().

378 {
379  struct CadetClient *sc;
380 
381  GNUNET_assert(NULL != channel);
382  if (sc_count >= sc_count_max)
383  {
385  gettext_noop("# cadet client connections rejected"),
386  1,
387  GNUNET_NO);
389  return NULL;
390  }
392  gettext_noop("# cadet connections active"),
393  1,
394  GNUNET_NO);
395  sc = GNUNET_new(struct CadetClient);
396  sc->channel = channel;
398  sc_tail,
399  sc);
400  sc_count++;
403  "Accepting inbound cadet connection from `%s' as client %p\n",
404  GNUNET_i2s(initiator),
405  sc);
406  return sc;
407 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct CadetClient * sc_head
Head of DLL of cadet clients.
static unsigned long long sc_count_max
Maximum allowed number of cadet clients.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static void refresh_timeout_task(struct CadetClient *sc)
Reset the timeout for the cadet client (due to activity).
static unsigned int sc_count
Number of active cadet clients in the 'sc_*'-DLL.
Struct containing information about a client of the service.
struct GNUNET_CADET_Channel * channel
Channel for communication.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define GNUNET_log(kind,...)
static struct CadetClient * sc_tail
Tail of DLL of cadet clients.
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).
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller 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
channel_ctx

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

References CadetClient::channel, gettext_noop, GNUNET_CONTAINER_DLL_remove, GNUNET_DATASTORE_cancel(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GSF_stats, CadetClient::qe, sc, sc_count, CadetClient::terminate_task, CadetClient::timeout_task, CadetClient::wqi_head, and CadetClient::wqi_tail.

Referenced by GSF_cadet_start_server().

421 {
422  struct CadetClient *sc = cls;
423  struct WriteQueueItem *wqi;
424 
425  if (NULL == sc)
426  return;
427  sc->channel = NULL;
429  "Terminating cadet connection with client %p\n",
430  sc);
432  gettext_noop("# cadet connections active"), -1,
433  GNUNET_NO);
434  if (NULL != sc->terminate_task)
436  if (NULL != sc->timeout_task)
438  if (NULL != sc->qe)
440  while (NULL != (wqi = sc->wqi_head))
441  {
443  sc->wqi_tail,
444  wqi);
445  GNUNET_free(wqi);
446  }
448  sc_tail,
449  sc);
450  sc_count--;
451  GNUNET_free(sc);
452 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_SCHEDULER_Task * timeout_task
Task that is scheduled to terminate idle connections.
struct GNUNET_SCHEDULER_Task * terminate_task
Task that is scheduled to asynchronously terminate the connection.
static struct CadetClient * sc_head
Head of DLL of cadet clients.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static unsigned int sc_count
Number of active cadet clients in the 'sc_*'-DLL.
struct WriteQueueItem * wqi_head
Head of write queue.
Struct containing information about a client of the service.
struct GNUNET_CADET_Channel * channel
Channel for communication.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
struct WriteQueueItem * wqi_tail
Tail of write queue.
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
#define GNUNET_log(kind,...)
static struct CadetClient * sc_tail
Tail of DLL of cadet clients.
struct GNUNET_DATASTORE_QueueEntry * qe
Current active request to the datastore, if we have one pending.
A message in the queue to be written to the cadet.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
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:

◆ 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 470 of file gnunet-service-fs_cadet_server.c.

Referenced by GSF_cadet_start_server().

473 {
474  /* FIXME: could do flow control here... */
475 }
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_port

struct GNUNET_CADET_Port* cadet_port
static

Listen port for incoming requests.

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

◆ sc_head

struct CadetClient* sc_head
static

Head of DLL of cadet clients.

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

◆ sc_tail

struct CadetClient* sc_tail
static

Tail of DLL of cadet clients.

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

◆ sc_count

unsigned int sc_count
static

Number of active cadet clients in the 'sc_*'-DLL.

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

Referenced by connect_cb(), disconnect_cb(), and GSF_cadet_stop_server().

◆ sc_count_max

unsigned long long sc_count_max
static

Maximum allowed number of cadet clients.

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

Referenced by connect_cb(), and GSF_cadet_start_server().