GNUnet  0.11.x
Data Structures | Macros | Functions
client.c File Reference

code for access to services More...

#include "platform.h"
#include "gnunet_protocols.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
#include "gnunet_socks.h"
Include dependency graph for client.c:

Go to the source code of this file.

Data Structures

struct  AddressProbe
 During connect, we try multiple possible IP addresses to find out which one might work. More...
 
struct  ClientState
 State we keep per client. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-client", __VA_ARGS__)
 
#define CONNECT_RETRY_TIMEOUT
 Timeout we use on TCP connect before trying another result from the DNS resolver. More...
 

Functions

static void start_connect (void *cls)
 Try to connect to the service. More...
 
static void connect_fail_continuation (struct ClientState *cstate)
 We've failed for good to establish a connection (timeout or no more addresses to try). More...
 
static void transmit_ready (void *cls)
 We are ready to send a message to the service. More...
 
static int recv_message (void *cls, const struct GNUNET_MessageHeader *msg)
 We have received a full message, pass to the MQ dispatcher. More...
 
static void cancel_aps (struct ClientState *cstate)
 Cancel all remaining connect attempts. More...
 
static void connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Implement the destruction of a message queue. More...
 
static void receive_ready (void *cls)
 This function is called once we have data ready to read. More...
 
static void connect_success_continuation (struct ClientState *cstate)
 We've succeeded in establishing a connection. More...
 
static struct GNUNET_NETWORK_Handletry_unixpath (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Try connecting to the server using UNIX domain sockets. More...
 
static void connect_probe_continuation (void *cls)
 Scheduler let us know that we're either ready to write on the socket OR connect timed out. More...
 
static void try_connect_using_address (void *cls, const struct sockaddr *addr, socklen_t addrlen)
 Try to establish a connection given the specified address. More...
 
static int test_service_configuration (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Test whether the configuration has proper values for connection (UNIXPATH || (PORT && HOSTNAME)). More...
 
static void connection_client_send_impl (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
 Implements the transmission functionality of a message queue. More...
 
static void connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Cancel the currently sent message. More...
 
int GNUNET_CLIENT_test (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name)
 Test if the port or UNIXPATH of the given service_name is in use and thus (most likely) the respective service is up. More...
 
struct GNUNET_MQ_HandleGNUNET_CLIENT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
 Create a message queue to connect to a GNUnet service. More...
 

Detailed Description

code for access to services

Author
Christian Grothoff

Generic TCP code for reliable, record-oriented TCP connections between clients and service providers.

Definition in file client.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-client", __VA_ARGS__)

◆ CONNECT_RETRY_TIMEOUT

#define CONNECT_RETRY_TIMEOUT
Value:
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:442

Timeout we use on TCP connect before trying another result from the DNS resolver.

Actual value used is this value divided by the number of address families. Default is 5s.

Definition at line 44 of file client.c.

Referenced by start_connect(), and try_connect_using_address().

Function Documentation

◆ start_connect()

static void start_connect ( void *  cls)
static

Try to connect to the service.

Parameters
clsthe struct ClientState to try to connect to the service

Definition at line 774 of file client.c.

References ClientState::attempts, ClientState::cfg, connect_fail_continuation(), CONNECT_RETRY_TIMEOUT, connect_success_continuation(), AddressProbe::cstate, ClientState::dns_active, GNUNET_RESOLVER_ip_get(), GNUNET_SOCKS_check_service(), GNUNET_YES, ClientState::hostname, ClientState::port, ClientState::retry_task, ClientState::service_name, ClientState::sock, try_connect_using_address(), and try_unixpath().

Referenced by connect_fail_continuation(), and GNUNET_CLIENT_connect().

775 {
776  struct ClientState *cstate = cls;
777 
778  cstate->retry_task = NULL;
779 #if 0
780  /* Never use a local source if a proxy is configured */
781  if (GNUNET_YES ==
783  cstate->cfg))
784  {
785  socks_connect (cstate);
786  return;
787  }
788 #endif
789 
790  if ((0 == (cstate->attempts++ % 2)) ||
791  (0 == cstate->port) ||
792  (NULL == cstate->hostname))
793  {
794  /* on even rounds, try UNIX first, or always
795  if we do not have a DNS name and TCP port. */
796  cstate->sock = try_unixpath (cstate->service_name,
797  cstate->cfg);
798  if (NULL != cstate->sock)
799  {
801  return;
802  }
803  }
804  if ((NULL == cstate->hostname) ||
805  (0 == cstate->port))
806  {
807  /* All options failed. Boo! */
808  connect_fail_continuation (cstate);
809  return;
810  }
811  cstate->dns_active
812  = GNUNET_RESOLVER_ip_get (cstate->hostname,
813  AF_UNSPEC,
816  cstate);
817 }
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request, NULL if DNS is finished.
Definition: client.c:110
State we keep per client.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: client.c:115
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
Definition: resolver_api.c:939
static struct GNUNET_NETWORK_Handle * try_unixpath(const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg)
Try connecting to the server using UNIX domain sockets.
Definition: client.c:499
char * service_name
Name of the service we interact with.
Definition: client.c:132
static void connect_success_continuation(struct ClientState *cstate)
We've succeeded in establishing a connection.
Definition: client.c:471
static void connect_fail_continuation(struct ClientState *cstate)
We've failed for good to establish a connection (timeout or no more addresses to try).
Definition: client.c:220
unsigned int attempts
How often have we tried to connect?
Definition: client.c:193
static void try_connect_using_address(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Try to establish a connection given the specified address.
Definition: client.c:626
int GNUNET_SOCKS_check_service(const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg)
Check if a SOCKS proxy is required by a service.
Definition: socks.c:593
unsigned long long port
TCP port (0 for disabled).
Definition: client.c:183
char * hostname
Hostname, if any.
Definition: client.c:137
#define CONNECT_RETRY_TIMEOUT
Timeout we use on TCP connect before trying another result from the DNS resolver. ...
Definition: client.c:44
struct GNUNET_NETWORK_Handle * sock
The connection handle, NULL if not live.
Definition: client.c:105
struct GNUNET_SCHEDULER_Task * retry_task
Task for trying to connect to the service.
Definition: client.c:147
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_fail_continuation()

static void connect_fail_continuation ( struct ClientState cstate)
static

We've failed for good to establish a connection (timeout or no more addresses to try).

Parameters
cstatethe connection we tried to establish

Definition at line 220 of file client.c.

References ClientState::ap_head, ClientState::ap_tail, ClientState::back_off, ClientState::dns_active, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, LOG, ClientState::recv_task, ClientState::retry_task, ClientState::send_task, ClientState::service_name, ClientState::sock, and start_connect().

Referenced by connect_probe_continuation(), start_connect(), and try_connect_using_address().

221 {
222  GNUNET_break (NULL == cstate->ap_head);
223  GNUNET_break (NULL == cstate->ap_tail);
224  GNUNET_break (NULL == cstate->dns_active);
225  GNUNET_break (NULL == cstate->sock);
226  GNUNET_assert (NULL == cstate->send_task);
227  GNUNET_assert (NULL == cstate->recv_task);
228  // GNUNET_assert (NULL == cstate->proxy_handshake);
229 
230  cstate->back_off = GNUNET_TIME_STD_BACKOFF (cstate->back_off);
232  "Failed to establish connection to `%s', no further addresses to try, will try again in %s.\n",
233  cstate->service_name,
235  GNUNET_YES));
236  cstate->retry_task
238  &start_connect,
239  cstate);
240 }
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request, NULL if DNS is finished.
Definition: client.c:110
#define LOG(kind,...)
Definition: client.c:36
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * service_name
Name of the service we interact with.
Definition: client.c:132
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:1253
struct GNUNET_SCHEDULER_Task * recv_task
Task for sending messages to the service.
Definition: client.c:157
struct GNUNET_SCHEDULER_Task * send_task
Task for sending messages to the service.
Definition: client.c:152
struct AddressProbe * ap_tail
Linked list of sockets we are currently trying out (during connect).
Definition: client.c:127
static void start_connect(void *cls)
Try to connect to the service.
Definition: client.c:774
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
Definition: client.c:121
struct GNUNET_TIME_Relative back_off
Current value for our incremental back-off (for connect re-tries).
Definition: client.c:178
struct GNUNET_NETWORK_Handle * sock
The connection handle, NULL if not live.
Definition: client.c:105
struct GNUNET_SCHEDULER_Task * retry_task
Task for trying to connect to the service.
Definition: client.c:147
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_ready()

static void transmit_ready ( void *  cls)
static

We are ready to send a message to the service.

Parameters
clsthe struct ClientState with the msg to transmit

Definition at line 249 of file client.c.

References AddressProbe::cstate, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_MQ_ERROR_WRITE, GNUNET_MQ_impl_send_continue(), GNUNET_MQ_impl_send_in_flight(), GNUNET_MQ_inject_error(), GNUNET_NETWORK_socket_send(), GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, ClientState::in_destroy, len, LOG, ClientState::mq, ClientState::msg, ClientState::msg_off, ret, RETRY, ClientState::send_task, GNUNET_MessageHeader::size, ClientState::sock, and GNUNET_MessageHeader::type.

Referenced by connect_success_continuation(), and connection_client_send_impl().

250 {
251  struct ClientState *cstate = cls;
252  ssize_t ret;
253  size_t len;
254  const char *pos;
255  int notify_in_flight;
256 
257  cstate->send_task = NULL;
258  if (GNUNET_YES == cstate->in_destroy)
259  return;
260  pos = (const char *) cstate->msg;
261  len = ntohs (cstate->msg->size);
262  GNUNET_assert (cstate->msg_off < len);
264  "message of type %u trying to send with socket %p (MQ: %p\n",
265  ntohs (cstate->msg->type),
266  cstate->sock,
267  cstate->mq);
268 
269 RETRY:
270  ret = GNUNET_NETWORK_socket_send (cstate->sock,
271  &pos[cstate->msg_off],
272  len - cstate->msg_off);
273  if (-1 == ret)
274  {
276  "Error during sending message of type %u\n",
277  ntohs (cstate->msg->type));
278  if (EINTR == errno)
279  {
281  "Retrying message of type %u\n",
282  ntohs (cstate->msg->type));
283  goto RETRY;
284  }
285  GNUNET_MQ_inject_error (cstate->mq,
287  return;
288  }
289  notify_in_flight = (0 == cstate->msg_off);
290  cstate->msg_off += ret;
291  if (cstate->msg_off < len)
292  {
294  "rescheduling message of type %u\n",
295  ntohs (cstate->msg->type));
296  cstate->send_task
298  cstate->sock,
300  cstate);
301  if (notify_in_flight)
303  return;
304  }
306  "sending message of type %u successful\n",
307  ntohs (cstate->msg->type));
308  cstate->msg = NULL;
310 }
State we keep per client.
void GNUNET_MQ_inject_error(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error error)
Call the error handler of a message queue with the given error code.
Definition: mq.c:300
#define RETRY
Return code we give on &#39;send&#39; if we failed to send right now but it makes sense to retry later...
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
Definition: network.c:816
struct GNUNET_MQ_Handle * mq
MQ to talk to client.
#define LOG(kind,...)
Definition: client.c:36
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1557
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int in_destroy
Are we supposed to die? GNUNET_SYSERR if destruction must be deferred, GNUNET_NO by default...
Definition: client.c:200
static void transmit_ready(void *cls)
We are ready to send a message to the service.
Definition: client.c:249
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_MQ_impl_send_in_flight(struct GNUNET_MQ_Handle *mq)
Call the send notification for the current message, but do not try to send the next message until #gn...
Definition: mq.c:519
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct GNUNET_SCHEDULER_Task * send_task
Task for sending messages to the service.
Definition: client.c:152
FIXME: document!
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
const struct GNUNET_MessageHeader * msg
Next message to transmit to the service.
Definition: client.c:142
size_t msg_off
Offset in the message where we are for transmission.
Definition: client.c:188
struct GNUNET_NETWORK_Handle * sock
The connection handle, NULL if not live.
Definition: client.c:105
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:486
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recv_message()

static int recv_message ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

We have received a full message, pass to the MQ dispatcher.

Called by the tokenizer via receive_ready().

Parameters
clsthe struct ClientState
msgmessage we received.
Returns
GNUNET_OK on success, GNUNET_NO to stop further processing due to disconnect (no error) GNUNET_SYSERR to stop further processing due to error

Definition at line 324 of file client.c.

References AddressProbe::cstate, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_inject_message(), GNUNET_NO, GNUNET_OK, GNUNET_YES, ClientState::in_destroy, LOG, ClientState::mq, ClientState::service_name, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by GNUNET_CLIENT_connect().

326 {
327  struct ClientState *cstate = cls;
328 
329  if (GNUNET_YES == cstate->in_destroy)
330  return GNUNET_NO;
332  "Received message of type %u and size %u from %s\n",
333  ntohs (msg->type),
334  ntohs (msg->size),
335  cstate->service_name);
336  GNUNET_MQ_inject_message (cstate->mq,
337  msg);
338  if (GNUNET_YES == cstate->in_destroy)
339  return GNUNET_NO;
340  return GNUNET_OK;
341 }
State we keep per client.
struct GNUNET_MQ_Handle * mq
MQ to talk to client.
#define LOG(kind,...)
Definition: client.c:36
int in_destroy
Are we supposed to die? GNUNET_SYSERR if destruction must be deferred, GNUNET_NO by default...
Definition: client.c:200
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
char * service_name
Name of the service we interact with.
Definition: client.c:132
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
void GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given m...
Definition: mq.c:202
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cancel_aps()

static void cancel_aps ( struct ClientState cstate)
static

Cancel all remaining connect attempts.

Parameters
cstatehandle of the client state to process

Definition at line 350 of file client.c.

References ClientState::ap_head, ClientState::ap_tail, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), AddressProbe::sock, and AddressProbe::task.

Referenced by connect_probe_continuation(), and connection_client_destroy_impl().

351 {
352  struct AddressProbe *pos;
353 
354  while (NULL != (pos = cstate->ap_head))
355  {
360  cstate->ap_tail,
361  pos);
362  GNUNET_free (pos);
363  }
364 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_SCHEDULER_Task * task
Task waiting for the connection to finish connecting.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct AddressProbe * ap_tail
Linked list of sockets we are currently trying out (during connect).
Definition: client.c:127
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket.
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
Definition: client.c:121
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
During connect, we try multiple possible IP addresses to find out which one might work...
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connection_client_destroy_impl()

static void connection_client_destroy_impl ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Implement the destruction of a message queue.

Implementations must not free mq, but should take care of impl_state.

Parameters
mqthe message queue to destroy
impl_stateour struct ClientState

Definition at line 375 of file client.c.

References cancel_aps(), AddressProbe::cstate, ClientState::dns_active, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_MST_destroy(), GNUNET_NETWORK_socket_close(), GNUNET_RESOLVER_request_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_YES, ClientState::hostname, ClientState::in_destroy, LOG, ClientState::mq, ClientState::mst, ClientState::recv_task, ClientState::retry_task, ClientState::send_task, ClientState::service_name, and ClientState::sock.

Referenced by GNUNET_CLIENT_connect(), and receive_ready().

377 {
378  struct ClientState *cstate = impl_state;
379 
380  (void) mq;
381  if (NULL != cstate->dns_active)
382  {
384  cstate->dns_active = NULL;
385  }
386  if (NULL != cstate->send_task)
387  {
389  cstate->send_task = NULL;
390  }
391  if (NULL != cstate->retry_task)
392  {
394  cstate->retry_task = NULL;
395  }
396  if (GNUNET_SYSERR == cstate->in_destroy)
397  {
398  /* defer destruction */
399  cstate->in_destroy = GNUNET_YES;
400  cstate->mq = NULL;
401  return;
402  }
403  if (NULL != cstate->recv_task)
404  {
406  cstate->recv_task = NULL;
407  }
408  if (NULL != cstate->sock)
409  {
411  "destroying socket: %p\n",
412  cstate->sock);
414  }
415  cancel_aps (cstate);
416  GNUNET_free (cstate->service_name);
417  GNUNET_free_non_null (cstate->hostname);
418  GNUNET_MST_destroy (cstate->mst);
419  GNUNET_free (cstate);
420 }
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request, NULL if DNS is finished.
Definition: client.c:110
State we keep per client.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
struct GNUNET_MQ_Handle * mq
MQ to talk to client.
#define LOG(kind,...)
Definition: client.c:36
static void cancel_aps(struct ClientState *cstate)
Cancel all remaining connect attempts.
Definition: client.c:350
int in_destroy
Are we supposed to die? GNUNET_SYSERR if destruction must be deferred, GNUNET_NO by default...
Definition: client.c:200
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
char * service_name
Name of the service we interact with.
Definition: client.c:132
struct GNUNET_SCHEDULER_Task * recv_task
Task for sending messages to the service.
Definition: client.c:157
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:411
struct GNUNET_SCHEDULER_Task * send_task
Task for sending messages to the service.
Definition: client.c:152
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MessageStreamTokenizer * mst
Tokenizer for inbound messages.
Definition: client.c:162
char * hostname
Hostname, if any.
Definition: client.c:137
struct GNUNET_NETWORK_Handle * sock
The connection handle, NULL if not live.
Definition: client.c:105
struct GNUNET_SCHEDULER_Task * retry_task
Task for trying to connect to the service.
Definition: client.c:147
#define GNUNET_YES
Definition: gnunet_common.h:77
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ receive_ready()

static void receive_ready ( void *  cls)
static

This function is called once we have data ready to read.

Parameters
clsstruct ClientState with connection to read from

Definition at line 429 of file client.c.

References connection_client_destroy_impl(), AddressProbe::cstate, GNUNET_MQ_ERROR_READ, GNUNET_MQ_inject_error(), GNUNET_MST_read(), GNUNET_NO, GNUNET_SCHEDULER_add_read_net(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, ClientState::in_destroy, ClientState::mq, ClientState::mst, ClientState::recv_task, ret, and ClientState::sock.

Referenced by connect_success_continuation().

430 {
431  struct ClientState *cstate = cls;
432  int ret;
433 
434  cstate->recv_task = NULL;
435  cstate->in_destroy = GNUNET_SYSERR;
436  ret = GNUNET_MST_read (cstate->mst,
437  cstate->sock,
438  GNUNET_NO,
439  GNUNET_NO);
440  if (GNUNET_SYSERR == ret)
441  {
442  if (NULL != cstate->mq)
443  GNUNET_MQ_inject_error (cstate->mq,
445  if (GNUNET_YES == cstate->in_destroy)
447  cstate);
448  return;
449  }
450  if (GNUNET_YES == cstate->in_destroy)
451  {
453  cstate);
454  return;
455  }
456  cstate->in_destroy = GNUNET_NO;
457  cstate->recv_task
459  cstate->sock,
460  &receive_ready,
461  cstate);
462 }
State we keep per client.
void GNUNET_MQ_inject_error(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error error)
Call the error handler of a message queue with the given error code.
Definition: mq.c:300
struct GNUNET_MQ_Handle * mq
MQ to talk to client.
static void connection_client_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implement the destruction of a message queue.
Definition: client.c:375
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
int in_destroy
Are we supposed to die? GNUNET_SYSERR if destruction must be deferred, GNUNET_NO by default...
Definition: client.c:200
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_SCHEDULER_Task * recv_task
Task for sending messages to the service.
Definition: client.c:157
Failed to read message from the network.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MessageStreamTokenizer * mst
Tokenizer for inbound messages.
Definition: client.c:162
int GNUNET_MST_read(struct GNUNET_MessageStreamTokenizer *mst, struct GNUNET_NETWORK_Handle *sock, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:345
struct GNUNET_NETWORK_Handle * sock
The connection handle, NULL if not live.
Definition: client.c:105
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1486
static void receive_ready(void *cls)
This function is called once we have data ready to read.
Definition: client.c:429
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_success_continuation()

static void connect_success_continuation ( struct ClientState cstate)
static

We've succeeded in establishing a connection.

Parameters
cstatethe connection we tried to establish

Definition at line 471 of file client.c.

References GNUNET_assert, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_UNIT_FOREVER_REL, ClientState::msg, receive_ready(), ClientState::recv_task, ClientState::send_task, ClientState::sock, and transmit_ready().

Referenced by connect_probe_continuation(), and start_connect().

472 {
473  GNUNET_assert (NULL == cstate->recv_task);
474  cstate->recv_task
476  cstate->sock,
477  &receive_ready,
478  cstate);
479  if (NULL != cstate->msg)
480  {
481  GNUNET_assert (NULL == cstate->send_task);
482  cstate->send_task
484  cstate->sock,
486  cstate);
487  }
488 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1557
static void transmit_ready(void *cls)
We are ready to send a message to the service.
Definition: client.c:249
struct GNUNET_SCHEDULER_Task * recv_task
Task for sending messages to the service.
Definition: client.c:157
struct GNUNET_SCHEDULER_Task * send_task
Task for sending messages to the service.
Definition: client.c:152
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
const struct GNUNET_MessageHeader * msg
Next message to transmit to the service.
Definition: client.c:142
struct GNUNET_NETWORK_Handle * sock
The connection handle, NULL if not live.
Definition: client.c:105
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1486
static void receive_ready(void *cls)
This function is called once we have data ready to read.
Definition: client.c:429
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_unixpath()

static struct GNUNET_NETWORK_Handle* try_unixpath ( const char *  service_name,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Try connecting to the server using UNIX domain sockets.

Parameters
service_namename of service to connect to
cfgconfiguration to use
Returns
NULL on error, socket connected to UNIX otherwise

Definition at line 499 of file client.c.

References _, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, GNUNET_NETWORK_shorten_unixpath(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_OK, GNUNET_strlcpy(), LOG, and AddressProbe::sock.

Referenced by start_connect().

501 {
502 #if AF_UNIX
503  struct GNUNET_NETWORK_Handle *sock;
504  char *unixpath;
505  struct sockaddr_un s_un;
506 
507  unixpath = NULL;
508  if ((GNUNET_OK ==
510  service_name,
511  "UNIXPATH",
512  &unixpath)) &&
513  (0 < strlen (unixpath)))
514  {
515  /* We have a non-NULL unixpath, need to validate it */
516  if (strlen (unixpath) >= sizeof(s_un.sun_path))
517  {
519  _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
520  unixpath,
521  (unsigned long long) sizeof(s_un.sun_path));
522  unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
524  _ ("Using `%s' instead\n"),
525  unixpath);
526  if (NULL == unixpath)
527  return NULL;
528  }
529  memset (&s_un,
530  0,
531  sizeof(s_un));
532  s_un.sun_family = AF_UNIX;
533  GNUNET_strlcpy (s_un.sun_path,
534  unixpath,
535  sizeof(s_un.sun_path));
536 #if HAVE_SOCKADDR_UN_SUN_LEN
537  s_un.sun_len = (u_char) sizeof(struct sockaddr_un);
538 #endif
539  sock = GNUNET_NETWORK_socket_create (AF_UNIX,
540  SOCK_STREAM,
541  0);
542  if ((NULL != sock) &&
543  ((GNUNET_OK ==
545  (struct sockaddr *) &s_un,
546  sizeof(s_un))) ||
547  (EINPROGRESS == errno)))
548  {
550  "Successfully connected to unixpath `%s'!\n",
551  unixpath);
552  GNUNET_free (unixpath);
553  return sock;
554  }
555  if (NULL != sock)
557  }
558  GNUNET_free_non_null (unixpath);
559 #endif
560  return NULL;
561 }
#define LOG(kind,...)
Definition: client.c:36
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition: network.c:658
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
handle to a socket
Definition: network.c:52
char * GNUNET_NETWORK_shorten_unixpath(char *unixpath)
Given a unixpath that is too long (larger than UNIX_PATH_MAX), shorten it to an acceptable length whi...
Definition: network.c:158
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
Definition: strings.c:219
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_probe_continuation()

static void connect_probe_continuation ( void *  cls)
static

Scheduler let us know that we're either ready to write on the socket OR connect timed out.

Do the right thing.

Parameters
clsthe struct AddressProbe * with the address that we are probing

Definition at line 571 of file client.c.

References ClientState::ap_head, ClientState::ap_tail, cancel_aps(), connect_fail_continuation(), connect_success_continuation(), AddressProbe::cstate, ClientState::dns_active, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_getsockopt(), GNUNET_OK, GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_WRITE_READY, len, LOG, GNUNET_SCHEDULER_TaskContext::reason, ClientState::service_name, ClientState::sock, AddressProbe::sock, AddressProbe::task, and tc.

Referenced by try_connect_using_address().

572 {
573  struct AddressProbe *ap = cls;
574  struct ClientState *cstate = ap->cstate;
575  const struct GNUNET_SCHEDULER_TaskContext *tc;
576  int error;
577  socklen_t len;
578 
579  ap->task = NULL;
580  GNUNET_assert (NULL != ap->sock);
582  cstate->ap_tail,
583  ap);
584  len = sizeof(error);
585  error = 0;
587  if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
588  (GNUNET_OK !=
590  SOL_SOCKET,
591  SO_ERROR,
592  &error,
593  &len)) ||
594  (0 != error))
595  {
598  GNUNET_free (ap);
599  if ((NULL == cstate->ap_head) &&
600  // (NULL == cstate->proxy_handshake) &&
601  (NULL == cstate->dns_active))
602  connect_fail_continuation (cstate);
603  return;
604  }
606  "Connection to `%s' succeeded!\n",
607  cstate->service_name);
608  /* trigger jobs that waited for the connection */
609  GNUNET_assert (NULL == cstate->sock);
610  cstate->sock = ap->sock;
611  GNUNET_free (ap);
612  cancel_aps (cstate);
614 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request, NULL if DNS is finished.
Definition: client.c:110
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:747
State we keep per client.
Context information passed to each scheduler task.
#define LOG(kind,...)
Definition: client.c:36
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:418
int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname, void *optval, socklen_t *optlen)
Get socket options.
Definition: network.c:683
static void cancel_aps(struct ClientState *cstate)
Cancel all remaining connect attempts.
Definition: client.c:350
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_SCHEDULER_Task * task
Task waiting for the connection to finish connecting.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * service_name
Name of the service we interact with.
Definition: client.c:132
static void connect_success_continuation(struct ClientState *cstate)
We&#39;ve succeeded in establishing a connection.
Definition: client.c:471
struct AddressProbe * ap_tail
Linked list of sockets we are currently trying out (during connect).
Definition: client.c:127
static void connect_fail_continuation(struct ClientState *cstate)
We&#39;ve failed for good to establish a connection (timeout or no more addresses to try).
Definition: client.c:220
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket.
The writing socket is ready.
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
Definition: client.c:121
struct GNUNET_NETWORK_Handle * sock
The connection handle, NULL if not live.
Definition: client.c:105
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
During connect, we try multiple possible IP addresses to find out which one might work...
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
struct ClientState * cstate
Connection for which we are probing.
Definition: client.c:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_connect_using_address()

static void try_connect_using_address ( void *  cls,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Try to establish a connection given the specified address.

This function is called by the resolver once we have a DNS reply.

Parameters
clsour struct ClientState *
addraddress to try, NULL for "last call"
addrlenlength of addr

Definition at line 626 of file client.c.

References AddressProbe::addr, AddressProbe::addrlen, ClientState::ap_head, ClientState::ap_tail, connect_fail_continuation(), connect_probe_continuation(), CONNECT_RETRY_TIMEOUT, AddressProbe::cstate, ClientState::dns_active, GNUNET_a2s(), GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log_strerror, GNUNET_malloc, GNUNET_memcpy, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_OK, GNUNET_SCHEDULER_add_write_net(), LOG, ClientState::port, ClientState::sock, AddressProbe::sock, and AddressProbe::task.

Referenced by start_connect().

629 {
630  struct ClientState *cstate = cls;
631  struct AddressProbe *ap;
632 
633  if (NULL == addr)
634  {
635  cstate->dns_active = NULL;
636  if ((NULL == cstate->ap_head) &&
637  // (NULL == cstate->proxy_handshake) &&
638  (NULL == cstate->sock))
639  connect_fail_continuation (cstate);
640  return;
641  }
642  if (NULL != cstate->sock)
643  return; /* already connected */
644  /* try to connect */
646  "Trying to connect using address `%s:%u'\n",
647  GNUNET_a2s (addr,
648  addrlen),
649  cstate->port);
650  ap = GNUNET_malloc (sizeof(struct AddressProbe) + addrlen);
651  ap->addr = (const struct sockaddr *) &ap[1];
652  GNUNET_memcpy (&ap[1],
653  addr,
654  addrlen);
655  ap->addrlen = addrlen;
656  ap->cstate = cstate;
657 
658  switch (ap->addr->sa_family)
659  {
660  case AF_INET:
661  ((struct sockaddr_in *) ap->addr)->sin_port = htons (cstate->port);
662  break;
663 
664  case AF_INET6:
665  ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (cstate->port);
666  break;
667 
668  default:
669  GNUNET_break (0);
670  GNUNET_free (ap);
671  return; /* not supported by us */
672  }
673  ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family,
674  SOCK_STREAM,
675  0);
676  if (NULL == ap->sock)
677  {
678  GNUNET_free (ap);
679  return; /* not supported by OS */
680  }
681  if ((GNUNET_OK !=
683  ap->addr,
684  ap->addrlen)) &&
685  (EINPROGRESS != errno))
686  {
687  /* maybe refused / unsupported address, try next */
689  "connect");
692  GNUNET_free (ap);
693  return;
694  }
696  cstate->ap_tail,
697  ap);
699  ap->sock,
701  ap);
702 }
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request, NULL if DNS is finished.
Definition: client.c:110
const struct sockaddr * addr
The address; do not free (allocated at the end of this struct).
State we keep per client.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define LOG(kind,...)
Definition: client.c:36
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1557
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_SCHEDULER_Task * task
Task waiting for the connection to finish connecting.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
int GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
Definition: network.c:658
struct AddressProbe * ap_tail
Linked list of sockets we are currently trying out (during connect).
Definition: client.c:127
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static void connect_fail_continuation(struct ClientState *cstate)
We&#39;ve failed for good to establish a connection (timeout or no more addresses to try).
Definition: client.c:220
socklen_t addrlen
Lenth of addr.
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket.
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
Definition: client.c:121
static void connect_probe_continuation(void *cls)
Scheduler let us know that we&#39;re either ready to write on the socket OR connect timed out...
Definition: client.c:571
unsigned long long port
TCP port (0 for disabled).
Definition: client.c:183
#define CONNECT_RETRY_TIMEOUT
Timeout we use on TCP connect before trying another result from the DNS resolver. ...
Definition: client.c:44
struct GNUNET_NETWORK_Handle * sock
The connection handle, NULL if not live.
Definition: client.c:105
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_malloc(size)
Wrapper around malloc.
During connect, we try multiple possible IP addresses to find out which one might work...
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
struct ClientState * cstate
Connection for which we are probing.
Definition: client.c:83
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_service_configuration()

static int test_service_configuration ( const char *  service_name,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Test whether the configuration has proper values for connection (UNIXPATH || (PORT && HOSTNAME)).

Parameters
service_namename of service to connect to
cfgconfiguration to use
Returns
GNUNET_OK if the configuration is valid, GNUNET_SYSERR if not

Definition at line 714 of file client.c.

References _, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free_non_null, GNUNET_log_config_invalid(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, hostname, port, and ret.

Referenced by GNUNET_CLIENT_connect().

716 {
717  int ret = GNUNET_SYSERR;
718  char *hostname = NULL;
719  unsigned long long port;
720 
721 #if AF_UNIX
722  char *unixpath = NULL;
723 
724  if ((GNUNET_OK ==
726  service_name,
727  "UNIXPATH",
728  &unixpath)) &&
729  (0 < strlen (unixpath)))
730  ret = GNUNET_OK;
731  else if ((GNUNET_OK ==
733  service_name,
734  "UNIXPATH")))
735  {
737  service_name,
738  "UNIXPATH",
739  _ ("not a valid filename"));
740  return GNUNET_SYSERR; /* UNIXPATH specified but invalid! */
741  }
742  GNUNET_free_non_null (unixpath);
743 #endif
744 
745  if ((GNUNET_YES ==
747  service_name,
748  "PORT")) &&
749  (GNUNET_OK ==
751  service_name,
752  "PORT",
753  &port)) &&
754  (port <= 65535) &&
755  (0 != port) &&
756  (GNUNET_OK ==
758  service_name,
759  "HOSTNAME",
760  &hostname)) &&
761  (0 != strlen (hostname)))
762  ret = GNUNET_OK;
763  GNUNET_free_non_null (hostname);
764  return ret;
765 }
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.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static char * hostname
Our hostname; we give this to all the peers we start.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connection_client_send_impl()

static void connection_client_send_impl ( struct GNUNET_MQ_Handle mq,
const struct GNUNET_MessageHeader msg,
void *  impl_state 
)
static

Implements the transmission functionality of a message queue.

Parameters
mqthe message queue
msgthe message to send
impl_stateour struct ClientState

Definition at line 828 of file client.c.

References AddressProbe::cstate, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_UNIT_FOREVER_REL, LOG, msg, ClientState::msg, ClientState::msg_off, ClientState::send_task, ClientState::sock, transmit_ready(), and GNUNET_MessageHeader::type.

Referenced by GNUNET_CLIENT_connect().

831 {
832  struct ClientState *cstate = impl_state;
833 
834  (void) mq;
835  /* only one message at a time allowed */
836  GNUNET_assert (NULL == cstate->msg);
837  GNUNET_assert (NULL == cstate->send_task);
838  cstate->msg = msg;
839  cstate->msg_off = 0;
840  if (NULL == cstate->sock)
841  {
843  "message of type %u waiting for socket\n",
844  ntohs (msg->type));
845  return; /* still waiting for connection */
846  }
847  cstate->send_task
849  cstate->sock,
851  cstate);
852 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
State we keep per client.
#define LOG(kind,...)
Definition: client.c:36
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1557
static void transmit_ready(void *cls)
We are ready to send a message to the service.
Definition: client.c:249
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct GNUNET_SCHEDULER_Task * send_task
Task for sending messages to the service.
Definition: client.c:152
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
const struct GNUNET_MessageHeader * msg
Next message to transmit to the service.
Definition: client.c:142
size_t msg_off
Offset in the message where we are for transmission.
Definition: client.c:188
struct GNUNET_NETWORK_Handle * sock
The connection handle, NULL if not live.
Definition: client.c:105
Here is the call graph for this function:
Here is the caller graph for this function:

◆ connection_client_cancel_impl()

static void connection_client_cancel_impl ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Cancel the currently sent message.

Parameters
mqmessage queue
impl_stateour struct ClientState

Definition at line 862 of file client.c.

References AddressProbe::cstate, GNUNET_assert, GNUNET_SCHEDULER_cancel(), ClientState::msg, ClientState::msg_off, and ClientState::send_task.

Referenced by GNUNET_CLIENT_connect().

864 {
865  struct ClientState *cstate = impl_state;
866 
867  (void) mq;
868  GNUNET_assert (NULL != cstate->msg);
869  GNUNET_assert (0 == cstate->msg_off);
870  cstate->msg = NULL;
871  if (NULL != cstate->send_task)
872  {
874  cstate->send_task = NULL;
875  }
876 }
State we keep per client.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * send_task
Task for sending messages to the service.
Definition: client.c:152
const struct GNUNET_MessageHeader * msg
Next message to transmit to the service.
Definition: client.c:142
size_t msg_off
Offset in the message where we are for transmission.
Definition: client.c:188
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function: