GNUnet  0.11.x
Data Structures | Macros | Functions
tcp_connection_legacy.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
Include dependency graph for tcp_connection_legacy.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_CONNECTION_TransmitHandle
 Transmission handle. More...
 
struct  AddressProbe
 During connect, we try multiple possible IP addresses to find out which one might work. More...
 
struct  GNUNET_CONNECTION_Handle
 handle for a network connection More...
 

Macros

#define CONNECT_RETRY_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 Timeout we use on TCP connect before trying another result from the DNS resolver. More...
 
#define LOG_STRERROR(kind, syscall)   GNUNET_log_from_strerror (kind, "util-connection", syscall)
 

Functions

void GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection)
 Set the persist option on this connection handle. More...
 
int GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection)
 Disable the "CORK" feature for communication with the given connection, forcing the OS to immediately flush the buffer on transmission instead of potentially buffering multiple messages. More...
 
struct GNUNET_CONNECTION_HandleGNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket)
 Create a connection handle by boxing an existing OS socket. More...
 
struct GNUNET_CONNECTION_HandleGNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, void *access_cb_cls, struct GNUNET_NETWORK_Handle *lsock)
 Create a connection handle by accepting on a listen socket. More...
 
int GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, void **addr, size_t *addrlen)
 Obtain the network address of the other party. More...
 
static void signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode)
 Tell the receiver callback that we had an IO error. More...
 
static void signal_receive_timeout (struct GNUNET_CONNECTION_Handle *connection)
 Tell the receiver callback that a timeout was reached. More...
 
static void signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, int ecode)
 We failed to transmit data to the service, signal the error. More...
 
static void connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection)
 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 transmit (or got a timeout). More...
 
static void receive_ready (void *cls)
 This function is called once we either timeout or have data ready to read. More...
 
static void connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
 We've succeeded in establishing a connection. 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...
 
struct GNUNET_CONNECTION_HandleGNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *hostname, uint16_t port)
 Create a connection handle by (asynchronously) connecting to a host. More...
 
struct GNUNET_CONNECTION_HandleGNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *unixpath)
 Create a connection handle by connecting to a UNIX domain service. More...
 
struct GNUNET_CONNECTION_HandleGNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s, const struct sockaddr *serv_addr, socklen_t addrlen)
 Create a connection handle by (asynchronously) connecting to a host. More...
 
struct GNUNET_CONNECTION_HandleGNUNET_CONNECTION_create_from_sockaddr (int af_family, const struct sockaddr *serv_addr, socklen_t addrlen)
 Create a connection handle by creating a socket and (asynchronously) connecting to a host. More...
 
int GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection)
 Check if connection is valid (no fatal errors have happened so far). More...
 
void GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
 Close the connection and free associated resources. More...
 
int GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, size_t max, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_Receiver receiver, void *receiver_cls)
 Receive data from the given connection. More...
 
void * GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection)
 Cancel receive job on the given connection. More...
 
static int process_notify (struct GNUNET_CONNECTION_Handle *connection)
 Try to call the transmit notify method (check if we do have enough space available first)! More...
 
static void transmit_timeout (void *cls)
 Task invoked by the scheduler when a call to transmit is timing out (we never got enough buffer space to call the callback function before the specified timeout expired). More...
 
static void connect_error (void *cls)
 Task invoked by the scheduler when we failed to connect at the time of being asked to transmit. More...
 
struct GNUNET_CONNECTION_TransmitHandleGNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, size_t size, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify notify, void *notify_cls)
 Ask the connection to call us once the specified number of bytes are free in the transmission buffer. More...
 
void GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_TransmitHandle *th)
 Cancel the specified transmission-ready notification. More...
 
struct GNUNET_CONNECTION_HandleGNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph)
 Create a connection to be proxied using a given connection. More...
 
void GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied)
 Activate proxied connection and destroy initial proxy handshake connection. More...
 

Macro Definition Documentation

◆ CONNECT_RETRY_TIMEOUT

#define CONNECT_RETRY_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)

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 tcp_connection_legacy.c.

Referenced by GNUNET_CONNECTION_create_from_connect(), and try_connect_using_address().

◆ LOG_STRERROR

#define LOG_STRERROR (   kind,
  syscall 
)    GNUNET_log_from_strerror (kind, "util-connection", syscall)

Function Documentation

◆ GNUNET_CONNECTION_persist_()

void GNUNET_CONNECTION_persist_ ( struct GNUNET_CONNECTION_Handle connection)

Set the persist option on this connection handle.

Indicates that the underlying socket or fd should never really be closed. Used for indicating process death.

Parameters
connectionthe connection to set persistent

Definition at line 274 of file tcp_connection_legacy.c.

References GNUNET_YES, and GNUNET_CONNECTION_Handle::persist.

Referenced by GNUNET_SERVER_client_disconnect().

275 {
276  connection->persist = GNUNET_YES;
277 }
int8_t persist
When shutdown, do not ever actually close the socket, but free resources.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_disable_corking()

int GNUNET_CONNECTION_disable_corking ( struct GNUNET_CONNECTION_Handle connection)

Disable the "CORK" feature for communication with the given connection, forcing the OS to immediately flush the buffer on transmission instead of potentially buffering multiple messages.

Essentially reduces the OS send buffers to zero. Used to make sure that the last messages sent through the connection reach the other side before the process is terminated.

Parameters
connectionthe connection to make flushing and blocking
Returns
GNUNET_OK on success

Definition at line 292 of file tcp_connection_legacy.c.

References GNUNET_NETWORK_socket_disable_corking(), and GNUNET_CONNECTION_Handle::sock.

Referenced by GNUNET_SERVER_client_disable_corking().

293 {
294  return GNUNET_NETWORK_socket_disable_corking (connection->sock);
295 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS's socket, set to NULL after fatal errors.
int GNUNET_NETWORK_socket_disable_corking(struct GNUNET_NETWORK_Handle *desc)
Disable the "CORK" feature for communication with the given socket, forcing the OS to immediately flu...
Definition: network.c:961
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_create_from_existing()

struct GNUNET_CONNECTION_Handle* GNUNET_CONNECTION_create_from_existing ( struct GNUNET_NETWORK_Handle osSocket)

Create a connection handle by boxing an existing OS socket.

The OS socket should henceforth be no longer used directly. #GNUNET_connection_destroy() will close it.

Parameters
osSocketexisting socket to box
Returns
the boxed connection handle

Definition at line 307 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_malloc, GNUNET_MIN_MESSAGE_SIZE, GNUNET_new, GNUNET_CONNECTION_Handle::sock, GNUNET_CONNECTION_Handle::write_buffer, and GNUNET_CONNECTION_Handle::write_buffer_size.

Referenced by GNUNET_CONNECTION_connect_socket(), and GNUNET_CONNECTION_create_proxied_from_handshake().

308 {
309  struct GNUNET_CONNECTION_Handle *connection;
310 
311  connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
313  connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
314  connection->sock = osSocket;
315  return connection;
316 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS's socket, set to NULL after fatal errors.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
size_t write_buffer_size
Current size of our write_buffer.
#define GNUNET_MIN_MESSAGE_SIZE
Smallest supported message.
char * write_buffer
Pointer to our write buffer.
handle for a network connection
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_create_from_accept()

struct GNUNET_CONNECTION_Handle* GNUNET_CONNECTION_create_from_accept ( GNUNET_CONNECTION_AccessCheck  access_cb,
void *  access_cb_cls,
struct GNUNET_NETWORK_Handle lsock 
)

Create a connection handle by accepting on a listen socket.

This function may block if the listen socket has no connection ready.

Parameters
access_cbfunction to use to check if access is allowed
access_cb_clsclosure for access_cb
lsocklisten socket
Returns
the connection handle, NULL on error

Definition at line 329 of file tcp_connection_legacy.c.

References _, GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::addrlen, GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_CONNECTION_Credentials::gid, GNUNET_a2s(), GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_MIN_MESSAGE_SIZE, GNUNET_NETWORK_get_fd(), GNUNET_NETWORK_socket_accept(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_shutdown(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_YES, LOG, LOG_STRERROR, GNUNET_CONNECTION_Handle::sock, uc, GNUNET_CONNECTION_Credentials::uid, GNUNET_CONNECTION_Handle::write_buffer, and GNUNET_CONNECTION_Handle::write_buffer_size.

Referenced by process_listen_socket().

332 {
333  struct GNUNET_CONNECTION_Handle *connection;
334  char addr[128];
335  socklen_t addrlen;
336  struct GNUNET_NETWORK_Handle *sock;
337  int aret;
338  struct sockaddr_in *v4;
339  struct sockaddr_in6 *v6;
340  struct sockaddr *sa;
341  void *uaddr;
342 
343 #ifdef SO_PEERCRED
344  struct ucred uc;
345  socklen_t olen;
346 #endif
347  struct GNUNET_CONNECTION_Credentials *gcp;
348 #if HAVE_GETPEEREID || defined(SO_PEERCRED) || HAVE_GETPEERUCRED
350 
351  gc.uid = 0;
352  gc.gid = 0;
353 #endif
354 
355  addrlen = sizeof(addr);
356  sock =
357  GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
358  if (NULL == sock)
359  {
360  if (EAGAIN != errno)
362  return NULL;
363  }
364  if ((addrlen > sizeof(addr)) || (addrlen < sizeof(sa_family_t)))
365  {
366  GNUNET_break (0);
368  return NULL;
369  }
370 
371  sa = (struct sockaddr *) addr;
372  v6 = (struct sockaddr_in6 *) addr;
373  if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)))
374  {
375  /* convert to V4 address */
376  v4 = GNUNET_new (struct sockaddr_in);
377  memset (v4, 0, sizeof(struct sockaddr_in));
378  v4->sin_family = AF_INET;
379 #if HAVE_SOCKADDR_IN_SIN_LEN
380  v4->sin_len = (u_char) sizeof(struct sockaddr_in);
381 #endif
382  GNUNET_memcpy (&v4->sin_addr,
383  &((char *) &v6->sin6_addr)[sizeof(struct in6_addr)
384  - sizeof(struct in_addr)],
385  sizeof(struct in_addr));
386  v4->sin_port = v6->sin6_port;
387  uaddr = v4;
388  addrlen = sizeof(struct sockaddr_in);
389  }
390  else
391  {
392  uaddr = GNUNET_malloc (addrlen);
393  GNUNET_memcpy (uaddr, addr, addrlen);
394  }
395  gcp = NULL;
396  if (AF_UNIX == sa->sa_family)
397  {
398 #if HAVE_GETPEEREID
399  /* most BSDs */
400  if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
401  gcp = &gc;
402 #else
403 #ifdef SO_PEERCRED
404  /* largely traditional GNU/Linux */
405  olen = sizeof(uc);
406  if ((0 == getsockopt (GNUNET_NETWORK_get_fd (sock),
407  SOL_SOCKET,
408  SO_PEERCRED,
409  &uc,
410  &olen)) &&
411  (olen == sizeof(uc)))
412  {
413  gc.uid = uc.uid;
414  gc.gid = uc.gid;
415  gcp = &gc;
416  }
417 #else
418 #if HAVE_GETPEERUCRED
419  /* this is for Solaris 10 */
420  ucred_t *uc;
421 
422  uc = NULL;
423  if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc))
424  {
425  gc.uid = ucred_geteuid (uc);
426  gc.gid = ucred_getegid (uc);
427  gcp = &gc;
428  }
429  ucred_free (uc);
430 #endif
431 #endif
432 #endif
433  }
434 
435  if ((NULL != access_cb) &&
436  (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen))))
437  {
438  if (GNUNET_NO == aret)
440  _ ("Access denied to `%s'\n"),
441  GNUNET_a2s (uaddr, addrlen));
443  GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
445  GNUNET_free (uaddr);
446  return NULL;
447  }
448  connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
450  connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
451  connection->addr = uaddr;
452  connection->addrlen = addrlen;
453  connection->sock = sock;
455  _ ("Accepting connection from `%s': %p\n"),
456  GNUNET_a2s (uaddr, addrlen),
457  connection);
458  return connection;
459 }
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
Definition: network.c:1080
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
#define LOG(kind,...)
Definition: abd_api.c:38
uid_t uid
UID of the other end of the connection.
static struct GNUNET_FS_UnindexContext * uc
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
int GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc, int how)
Shut down socket operations.
Definition: network.c:940
size_t write_buffer_size
Current size of our write_buffer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
Definition: network.c:430
struct sockaddr * addr
Network address of the other end-point, may be NULL.
#define GNUNET_MIN_MESSAGE_SIZE
Smallest supported message.
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)...
Credentials for UNIX domain sockets.
handle to a socket
Definition: network.c:52
#define GNUNET_YES
Definition: gnunet_common.h:77
socklen_t addrlen
Length of addr.
char * write_buffer
Pointer to our write buffer.
handle for a network connection
#define LOG_STRERROR(kind, syscall)
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_get_address()

int GNUNET_CONNECTION_get_address ( struct GNUNET_CONNECTION_Handle connection,
void **  addr,
size_t *  addrlen 
)

Obtain the network address of the other party.

Parameters
connectionthe client to get the address for
addrwhere to store the address
addrlenwhere to store the length of the addr
Returns
GNUNET_OK on success

Definition at line 471 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::addrlen, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, and GNUNET_OK.

Referenced by GNUNET_SERVER_client_get_address().

474 {
475  if ((NULL == connection->addr) || (0 == connection->addrlen))
476  return GNUNET_NO;
477  *addr = GNUNET_malloc (connection->addrlen);
478  GNUNET_memcpy (*addr, connection->addr, connection->addrlen);
479  *addrlen = connection->addrlen;
480  return GNUNET_OK;
481 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct sockaddr * addr
Network address of the other end-point, may be NULL.
socklen_t addrlen
Length of addr.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the caller graph for this function:

◆ signal_receive_error()

static void signal_receive_error ( struct GNUNET_CONNECTION_Handle connection,
int  errcode 
)
static

Tell the receiver callback that we had an IO error.

Parameters
connectionconnection to signal error
errcodeerror code to send

Definition at line 491 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::addrlen, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, LOG, GNUNET_CONNECTION_Handle::receiver, and GNUNET_CONNECTION_Handle::receiver_cls.

Referenced by connect_fail_continuation(), and receive_ready().

492 {
494 
496  "Receive encounters error (%s), connection closed (%p)\n",
497  strerror (errcode),
498  connection);
499  GNUNET_assert (NULL != (receiver = connection->receiver));
500  connection->receiver = NULL;
501  receiver (connection->receiver_cls,
502  NULL,
503  0,
504  connection->addr,
505  connection->addrlen,
506  errcode);
507 }
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void(* GNUNET_CONNECTION_Receiver)(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback function for data received from the network.
struct sockaddr * addr
Network address of the other end-point, may be NULL.
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
socklen_t addrlen
Length of addr.
void * receiver_cls
Closure for receiver.
Here is the caller graph for this function:

◆ signal_receive_timeout()

static void signal_receive_timeout ( struct GNUNET_CONNECTION_Handle connection)
static

Tell the receiver callback that a timeout was reached.

Parameters
connectionconnection to signal for

Definition at line 516 of file tcp_connection_legacy.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, LOG, GNUNET_CONNECTION_Handle::receiver, and GNUNET_CONNECTION_Handle::receiver_cls.

Referenced by receive_ready(), and signal_transmit_error().

517 {
519 
521  "Connection signals timeout to receiver (%p)!\n",
522  connection);
523  GNUNET_assert (NULL != (receiver = connection->receiver));
524  connection->receiver = NULL;
525  receiver (connection->receiver_cls, NULL, 0, NULL, 0, 0);
526 }
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void(* GNUNET_CONNECTION_Receiver)(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback function for data received from the network.
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
void * receiver_cls
Closure for receiver.
Here is the caller graph for this function:

◆ signal_transmit_error()

static void signal_transmit_error ( struct GNUNET_CONNECTION_Handle connection,
int  ecode 
)
static

We failed to transmit data to the service, signal the error.

Parameters
connectionhandle that had trouble
ecodeerror code (errno)

Definition at line 536 of file tcp_connection_legacy.c.

References GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_shutdown(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), LOG, notify, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_TransmitHandle::notify_ready_cls, GNUNET_CONNECTION_Handle::nth, GNUNET_CONNECTION_Handle::read_task, signal_receive_timeout(), GNUNET_CONNECTION_Handle::sock, and GNUNET_CONNECTION_Handle::write_task.

Referenced by connect_fail_continuation(), and transmit_ready().

537 {
539 
541  "Transmission encounterd error (%s), connection closed (%p)\n",
542  strerror (ecode),
543  connection);
544  if (NULL != connection->sock)
545  {
546  (void) GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR);
548  connection->sock = NULL;
549  GNUNET_assert (NULL == connection->write_task);
550  }
551  if (NULL != connection->read_task)
552  {
553  /* send errors trigger read errors... */
554  GNUNET_SCHEDULER_cancel (connection->read_task);
555  connection->read_task = NULL;
556  signal_receive_timeout (connection);
557  return;
558  }
559  if (NULL == connection->nth.notify_ready)
560  return; /* nobody to tell about it */
561  notify = connection->nth.notify_ready;
562  connection->nth.notify_ready = NULL;
563  notify (connection->nth.notify_ready_cls, 0, NULL);
564 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc, int how)
Shut down socket operations.
Definition: network.c:940
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
size_t(* GNUNET_CONNECTION_TransmitReadyNotify)(void *cls, size_t size, void *buf)
Function called to notify a client about the connection begin ready to queue more data...
void * notify_ready_cls
Closure for notify_ready.
struct GNUNET_SCHEDULER_Task * read_task
Read task that we may need to wait for.
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we&#39;ve connected to it).
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
static void signal_receive_timeout(struct GNUNET_CONNECTION_Handle *connection)
Tell the receiver callback that a timeout was reached.
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
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:

◆ connect_fail_continuation()

static void connect_fail_continuation ( struct GNUNET_CONNECTION_Handle connection)
static

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

Parameters
connectionthe connection we tried to establish

Definition at line 574 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::ap_head, GNUNET_CONNECTION_Handle::ap_tail, GNUNET_CONNECTION_Handle::destroy_later, GNUNET_CONNECTION_Handle::dns_active, GNUNET_assert, GNUNET_break, GNUNET_CONNECTION_destroy(), GNUNET_ERROR_TYPE_INFO, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_CONNECTION_Handle::hostname, LOG, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_Handle::nth, GNUNET_CONNECTION_Handle::port, GNUNET_CONNECTION_Handle::proxy_handshake, receive_ready(), GNUNET_CONNECTION_Handle::receiver, signal_receive_error(), signal_transmit_error(), GNUNET_CONNECTION_Handle::sock, GNUNET_CONNECTION_TransmitHandle::timeout_task, transmit_ready(), and GNUNET_CONNECTION_Handle::write_task.

Referenced by connect_probe_continuation(), and try_connect_using_address().

575 {
577  "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n",
578  connection->hostname,
579  connection->port);
580  GNUNET_break (NULL == connection->ap_head);
581  GNUNET_break (NULL == connection->ap_tail);
582  GNUNET_break (GNUNET_NO == connection->dns_active);
583  GNUNET_break (NULL == connection->sock);
584  GNUNET_assert (NULL == connection->write_task);
585  GNUNET_assert (NULL == connection->proxy_handshake);
586 
587  /* signal errors for jobs that used to wait on the connection */
588  connection->destroy_later = 1;
589  if (NULL != connection->receiver)
590  signal_receive_error (connection, ECONNREFUSED);
591  if (NULL != connection->nth.notify_ready)
592  {
593  GNUNET_assert (NULL != connection->nth.timeout_task);
595  connection->nth.timeout_task = NULL;
596  signal_transmit_error (connection, ECONNREFUSED);
597  }
598  if (-1 == connection->destroy_later)
599  {
600  /* do it now */
601  connection->destroy_later = 0;
602  GNUNET_CONNECTION_destroy (connection);
603  return;
604  }
605  connection->destroy_later = 0;
606 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void signal_receive_error(struct GNUNET_CONNECTION_Handle *connection, int errcode)
Tell the receiver callback that we had an IO error.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct AddressProbe * ap_tail
Linked list of sockets we are currently trying out (during connect).
uint16_t port
Port to connect to.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * hostname
Pointer to the hostname if connection was created using DNS lookup, otherwise NULL.
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
void GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection)
Close the connection and free associated resources.
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
static void signal_transmit_error(struct GNUNET_CONNECTION_Handle *connection, int ecode)
We failed to transmit data to the service, signal the error.
struct GNUNET_SCHEDULER_Task * timeout_task
Task called on timeout.
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:

◆ transmit_ready()

static void transmit_ready ( void *  cls)
static

We are ready to transmit (or got a timeout).

Parameters
clsour connection handle

Definition at line 1348 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::addrlen, GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_a2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NETWORK_fdset_isset(), GNUNET_NETWORK_socket_send(), GNUNET_realloc, GNUNET_SCHEDULER_add_write_net(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_TIMEOUT, GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_REL, LOG, notify, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_TransmitHandle::notify_ready_cls, GNUNET_CONNECTION_TransmitHandle::notify_size, GNUNET_CONNECTION_Handle::nth, process_notify(), GNUNET_SCHEDULER_TaskContext::reason, ret, RETRY, signal_transmit_error(), GNUNET_CONNECTION_Handle::sock, tc, GNUNET_CONNECTION_TransmitHandle::timeout_task, GNUNET_CONNECTION_TransmitHandle::transmit_timeout, GNUNET_CONNECTION_Handle::write_buffer, GNUNET_CONNECTION_Handle::write_buffer_off, GNUNET_CONNECTION_Handle::write_buffer_pos, GNUNET_CONNECTION_Handle::write_buffer_size, GNUNET_SCHEDULER_TaskContext::write_ready, and GNUNET_CONNECTION_Handle::write_task.

Referenced by connect_fail_continuation(), connect_success_continuation(), and GNUNET_CONNECTION_notify_transmit_ready().

1349 {
1350  struct GNUNET_CONNECTION_Handle *connection = cls;
1352  const struct GNUNET_SCHEDULER_TaskContext *tc;
1353  ssize_t ret;
1354  size_t have;
1355 
1356  LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection);
1357  GNUNET_assert (NULL != connection->write_task);
1358  connection->write_task = NULL;
1359  GNUNET_assert (NULL == connection->nth.timeout_task);
1361  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1362  {
1364  "Transmit to `%s' fails, time out reached (%p).\n",
1365  GNUNET_a2s (connection->addr, connection->addrlen),
1366  connection);
1367  notify = connection->nth.notify_ready;
1368  GNUNET_assert (NULL != notify);
1369  connection->nth.notify_ready = NULL;
1370  notify (connection->nth.notify_ready_cls, 0, NULL);
1371  return;
1372  }
1373  GNUNET_assert (NULL != connection->sock);
1374  if (NULL == tc->write_ready)
1375  {
1376  /* special circumstances (in particular, PREREQ_DONE after
1377  * connect): not yet ready to write, but no "fatal" error either.
1378  * Hence retry. */
1379  goto SCHEDULE_WRITE;
1380  }
1381  if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock))
1382  {
1383  GNUNET_assert (NULL == connection->write_task);
1384  /* special circumstances (in particular, shutdown): not yet ready
1385  * to write, but no "fatal" error either. Hence retry. */
1386  goto SCHEDULE_WRITE;
1387  }
1388  GNUNET_assert (connection->write_buffer_off >= connection->write_buffer_pos);
1389  if ((NULL != connection->nth.notify_ready) &&
1390  (connection->write_buffer_size < connection->nth.notify_size))
1391  {
1392  connection->write_buffer =
1393  GNUNET_realloc (connection->write_buffer, connection->nth.notify_size);
1394  connection->write_buffer_size = connection->nth.notify_size;
1395  }
1396  process_notify (connection);
1397  have = connection->write_buffer_off - connection->write_buffer_pos;
1398  if (0 == have)
1399  {
1400  /* no data ready for writing, terminate write loop */
1401  return;
1402  }
1403  GNUNET_assert (have <= connection->write_buffer_size);
1404  GNUNET_assert (have + connection->write_buffer_pos <=
1405  connection->write_buffer_size);
1406  GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size);
1407 RETRY:
1408  ret =
1409  GNUNET_NETWORK_socket_send (connection->sock,
1410  &connection
1411  ->write_buffer[connection->write_buffer_pos],
1412  have);
1413  if (-1 == ret)
1414  {
1415  if (EINTR == errno)
1416  goto RETRY;
1417  if (NULL != connection->write_task)
1418  {
1419  GNUNET_SCHEDULER_cancel (connection->write_task);
1420  connection->write_task = NULL;
1421  }
1422  signal_transmit_error (connection, errno);
1423  return;
1424  }
1426  "Connection transmitted %u/%u bytes to `%s' (%p)\n",
1427  (unsigned int) ret,
1428  have,
1429  GNUNET_a2s (connection->addr, connection->addrlen),
1430  connection);
1431  connection->write_buffer_pos += ret;
1432  if (connection->write_buffer_pos == connection->write_buffer_off)
1433  {
1434  /* transmitted all pending data */
1435  connection->write_buffer_pos = 0;
1436  connection->write_buffer_off = 0;
1437  }
1438  if ((0 == connection->write_buffer_off) &&
1439  (NULL == connection->nth.notify_ready))
1440  return; /* all data sent! */
1441  /* not done writing, schedule more */
1442 SCHEDULE_WRITE:
1444  "Re-scheduling transmit_ready (more to do) (%p).\n",
1445  connection);
1446  have = connection->write_buffer_off - connection->write_buffer_pos;
1447  GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0));
1448  if (NULL == connection->write_task)
1449  connection->write_task =
1450  GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == NULL)
1453  connection->nth.transmit_timeout),
1454  connection->sock,
1455  &transmit_ready,
1456  connection);
1457 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:747
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
#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
static int process_notify(struct GNUNET_CONNECTION_Handle *connection)
Try to call the transmit notify method (check if we do have enough space available first)! ...
Context information passed to each scheduler task.
#define LOG(kind,...)
Definition: abd_api.c:38
#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
const struct GNUNET_NETWORK_FDSet * write_ready
Set of file descriptors ready for writing; note that additional bits may be set that were not in the ...
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
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
size_t write_buffer_size
Current size of our write_buffer.
size_t(* GNUNET_CONNECTION_TransmitReadyNotify)(void *cls, size_t size, void *buf)
Function called to notify a client about the connection begin ready to queue more data...
void * notify_ready_cls
Closure for notify_ready.
struct sockaddr * addr
Network address of the other end-point, may be NULL.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we&#39;ve connected to it).
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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)...
size_t write_buffer_off
Current write-offset in write_buffer (where would we write next).
static void transmit_ready(void *cls)
We are ready to transmit (or got a timeout).
size_t write_buffer_pos
Current read-offset in write_buffer (how many bytes have already been sent).
The specified timeout has expired.
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
size_t notify_size
At what number of bytes available in the write buffer should the notify method be called...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
struct GNUNET_TIME_Absolute transmit_timeout
Timeout for receiving (in absolute time).
socklen_t addrlen
Length of addr.
char * write_buffer
Pointer to our write buffer.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
Definition: network.c:1029
handle for a network connection
static void signal_transmit_error(struct GNUNET_CONNECTION_Handle *connection, int ecode)
We failed to transmit data to the service, signal the error.
struct GNUNET_SCHEDULER_Task * timeout_task
Task called on timeout.
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 either timeout or have data ready to read.

Parameters
clsconnection to read from

Definition at line 1105 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::addrlen, GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_a2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NETWORK_fdset_isset(), GNUNET_NETWORK_socket_recv(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_TIMEOUT, GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, LOG, GNUNET_CONNECTION_Handle::max, GNUNET_SCHEDULER_TaskContext::read_ready, GNUNET_CONNECTION_Handle::read_task, GNUNET_SCHEDULER_TaskContext::reason, GNUNET_CONNECTION_Handle::receive_timeout, GNUNET_CONNECTION_Handle::receiver, GNUNET_CONNECTION_Handle::receiver_cls, ret, RETRY, signal_receive_error(), signal_receive_timeout(), GNUNET_CONNECTION_Handle::sock, and tc.

Referenced by connect_fail_continuation(), connect_success_continuation(), and GNUNET_CONNECTION_receive().

1106 {
1107  struct GNUNET_CONNECTION_Handle *connection = cls;
1108  const struct GNUNET_SCHEDULER_TaskContext *tc;
1109  char buffer[connection->max];
1110  ssize_t ret;
1111  GNUNET_CONNECTION_Receiver receiver;
1112 
1113  connection->read_task = NULL;
1115  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1116  {
1118  "Receive from `%s' encounters error: timeout (%s, %p)\n",
1119  GNUNET_a2s (connection->addr, connection->addrlen),
1122  connection->receive_timeout),
1123  GNUNET_YES),
1124  connection);
1125  signal_receive_timeout (connection);
1126  return;
1127  }
1128  if (NULL == connection->sock)
1129  {
1130  /* connect failed for good */
1131  signal_receive_error (connection, ECONNREFUSED);
1132  return;
1133  }
1135 RETRY:
1136  ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max);
1137  if (-1 == ret)
1138  {
1139  if (EINTR == errno)
1140  goto RETRY;
1141  signal_receive_error (connection, errno);
1142  return;
1143  }
1145  "receive_ready read %u/%u bytes from `%s' (%p)!\n",
1146  (unsigned int) ret,
1147  connection->max,
1148  GNUNET_a2s (connection->addr, connection->addrlen),
1149  connection);
1150  GNUNET_assert (NULL != (receiver = connection->receiver));
1151  connection->receiver = NULL;
1152  receiver (connection->receiver_cls,
1153  buffer,
1154  ret,
1155  connection->addr,
1156  connection->addrlen,
1157  0);
1158 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:747
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
#define RETRY
Return code we give on &#39;send&#39; if we failed to send right now but it makes sense to retry later...
Context information passed to each scheduler task.
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:787
#define LOG(kind,...)
Definition: abd_api.c:38
#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
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void signal_receive_error(struct GNUNET_CONNECTION_Handle *connection, int errcode)
Tell the receiver callback that we had an IO error.
const struct GNUNET_NETWORK_FDSet * read_ready
Set of file descriptors ready for reading; note that additional bits may be set that were not in the ...
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
void(* GNUNET_CONNECTION_Receiver)(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback function for data received from the network.
struct GNUNET_SCHEDULER_Task * read_task
Read task that we may need to wait for.
struct sockaddr * addr
Network address of the other end-point, may be NULL.
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
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)...
struct GNUNET_TIME_Absolute receive_timeout
Timeout for receiving (in absolute time).
The specified timeout has expired.
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
static void signal_receive_timeout(struct GNUNET_CONNECTION_Handle *connection)
Tell the receiver callback that a timeout was reached.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:375
size_t max
Maximum number of bytes to read (for receiving).
#define GNUNET_YES
Definition: gnunet_common.h:77
socklen_t addrlen
Length of addr.
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
Definition: network.c:1029
handle for a network connection
void * receiver_cls
Closure for receiver.
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 GNUNET_CONNECTION_Handle connection)
static

We've succeeded in establishing a connection.

Parameters
connectionthe connection we tried to establish

Definition at line 634 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::addrlen, GNUNET_a2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_write_net(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_absolute_get_remaining(), LOG, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_Handle::nth, GNUNET_CONNECTION_Handle::read_task, receive_ready(), GNUNET_CONNECTION_Handle::receive_timeout, GNUNET_CONNECTION_Handle::receiver, GNUNET_CONNECTION_Handle::sock, GNUNET_CONNECTION_TransmitHandle::timeout_task, transmit_ready(), GNUNET_CONNECTION_TransmitHandle::transmit_timeout, and GNUNET_CONNECTION_Handle::write_task.

Referenced by connect_probe_continuation(), GNUNET_CONNECTION_acivate_proxied(), and GNUNET_CONNECTION_create_from_connect_to_unixpath().

635 {
637  "Connection to `%s' succeeded! (%p)\n",
638  GNUNET_a2s (connection->addr, connection->addrlen),
639  connection);
640  /* trigger jobs that waited for the connection */
641  if (NULL != connection->receiver)
642  {
644  "Connection succeeded, starting with receiving data (%p)\n",
645  connection);
646  GNUNET_assert (NULL == connection->read_task);
647  connection->read_task =
649  connection->receive_timeout),
650  connection->sock,
651  &receive_ready,
652  connection);
653  }
654  if (NULL != connection->nth.notify_ready)
655  {
657  "Connection succeeded, starting with sending data (%p)\n",
658  connection);
659  GNUNET_assert (connection->nth.timeout_task != NULL);
661  connection->nth.timeout_task = NULL;
662  GNUNET_assert (connection->write_task == NULL);
663  connection->write_task =
665  connection->nth.transmit_timeout),
666  connection->sock,
668  connection);
669  }
670 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
#define LOG(kind,...)
Definition: abd_api.c:38
#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
struct GNUNET_SCHEDULER_Task * read_task
Read task that we may need to wait for.
struct sockaddr * addr
Network address of the other end-point, may be NULL.
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)...
struct GNUNET_TIME_Absolute receive_timeout
Timeout for receiving (in absolute time).
static void transmit_ready(void *cls)
We are ready to transmit (or got a timeout).
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
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
struct GNUNET_TIME_Absolute transmit_timeout
Timeout for receiving (in absolute time).
socklen_t addrlen
Length of addr.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
static void receive_ready(void *cls)
This function is called once we either timeout or have data ready to read.
struct GNUNET_SCHEDULER_Task * timeout_task
Task called on timeout.
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:

◆ 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 680 of file tcp_connection_legacy.c.

References AddressProbe::addr, GNUNET_CONNECTION_Handle::addr, AddressProbe::addrlen, GNUNET_CONNECTION_Handle::addrlen, GNUNET_CONNECTION_Handle::ap_head, GNUNET_CONNECTION_Handle::ap_tail, connect_fail_continuation(), connect_success_continuation(), GNUNET_CONNECTION_TransmitHandle::connection, AddressProbe::connection, GNUNET_CONNECTION_Handle::dns_active, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_getsockopt(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_WRITE_READY, len, GNUNET_CONNECTION_Handle::proxy_handshake, GNUNET_SCHEDULER_TaskContext::reason, AddressProbe::sock, GNUNET_CONNECTION_Handle::sock, AddressProbe::task, and tc.

Referenced by try_connect_using_address().

681 {
682  struct AddressProbe *ap = cls;
683  struct GNUNET_CONNECTION_Handle *connection = ap->connection;
684  const struct GNUNET_SCHEDULER_TaskContext *tc;
685  struct AddressProbe *pos;
686  int error;
687  socklen_t len;
688 
689  GNUNET_assert (NULL != ap->sock);
690  GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap);
691  len = sizeof(error);
692  errno = 0;
693  error = 0;
695  if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
697  SOL_SOCKET,
698  SO_ERROR,
699  &error,
700  &len)) ||
701  (0 != error))
702  {
704  GNUNET_free (ap);
705  if ((NULL == connection->ap_head) &&
706  (GNUNET_NO == connection->dns_active) &&
707  (NULL == connection->proxy_handshake))
708  connect_fail_continuation (connection);
709  return;
710  }
711  GNUNET_assert (NULL == connection->sock);
712  connection->sock = ap->sock;
713  GNUNET_assert (NULL == connection->addr);
714  connection->addr = GNUNET_malloc (ap->addrlen);
715  GNUNET_memcpy (connection->addr, ap->addr, ap->addrlen);
716  connection->addrlen = ap->addrlen;
717  GNUNET_free (ap);
718  /* cancel all other attempts */
719  while (NULL != (pos = connection->ap_head))
720  {
723  GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
724  GNUNET_free (pos);
725  }
726  connect_success_continuation (connection);
727 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:747
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
const struct sockaddr * addr
The address; do not free (allocated at the end of this struct).
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
Context information passed to each scheduler task.
#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
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct AddressProbe * ap_tail
Linked list of sockets we are currently trying out (during connect).
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...
static void connect_fail_continuation(struct GNUNET_CONNECTION_Handle *connection)
We&#39;ve failed for good to establish a connection (timeout or no more addresses to try).
struct sockaddr * addr
Network address of the other end-point, may be NULL.
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
socklen_t addrlen
Lenth of addr.
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket.
The writing socket is ready.
static void connect_success_continuation(struct GNUNET_CONNECTION_Handle *connection)
We&#39;ve succeeded in establishing a connection.
socklen_t addrlen
Length of addr.
handle for a network connection
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.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
struct GNUNET_CONNECTION_Handle * connection
Connection for which we are probing.
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:

◆ 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 GNUNET_CONNECTION_Handle *
addraddress to try, NULL for "last call"
addrlenlength of addr

Definition at line 739 of file tcp_connection_legacy.c.

References AddressProbe::addr, GNUNET_CONNECTION_Handle::addr, AddressProbe::addrlen, GNUNET_CONNECTION_Handle::ap_head, GNUNET_CONNECTION_Handle::ap_tail, connect_fail_continuation(), connect_probe_continuation(), CONNECT_RETRY_TIMEOUT, GNUNET_CONNECTION_TransmitHandle::connection, AddressProbe::connection, GNUNET_CONNECTION_Handle::dns_active, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_OK, GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_min(), GNUNET_CONNECTION_Handle::hostname, LOG, LOG_STRERROR, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_Handle::nth, GNUNET_CONNECTION_Handle::port, GNUNET_CONNECTION_Handle::proxy_handshake, GNUNET_CONNECTION_Handle::receive_timeout, GNUNET_CONNECTION_Handle::receiver, AddressProbe::sock, GNUNET_CONNECTION_Handle::sock, AddressProbe::task, and GNUNET_CONNECTION_TransmitHandle::transmit_timeout.

Referenced by GNUNET_CONNECTION_create_from_connect().

742 {
743  struct GNUNET_CONNECTION_Handle *connection = cls;
744  struct AddressProbe *ap;
746 
747  if (NULL == addr)
748  {
749  connection->dns_active = NULL;
750  if ((NULL == connection->ap_head) && (NULL == connection->sock) &&
751  (NULL == connection->proxy_handshake))
752  connect_fail_continuation (connection);
753  return;
754  }
755  if (NULL != connection->sock)
756  return; /* already connected */
757  GNUNET_assert (NULL == connection->addr);
758  /* try to connect */
760  "Trying to connect using address `%s:%u/%s:%u'\n",
761  connection->hostname,
762  connection->port,
763  GNUNET_a2s (addr, addrlen),
764  connection->port);
765  ap = GNUNET_malloc (sizeof(struct AddressProbe) + addrlen);
766  ap->addr = (const struct sockaddr *) &ap[1];
767  GNUNET_memcpy (&ap[1], addr, addrlen);
768  ap->addrlen = addrlen;
769  ap->connection = connection;
770 
771  switch (ap->addr->sa_family)
772  {
773  case AF_INET:
774  ((struct sockaddr_in *) ap->addr)->sin_port = htons (connection->port);
775  break;
776 
777  case AF_INET6:
778  ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (connection->port);
779  break;
780 
781  default:
782  GNUNET_break (0);
783  GNUNET_free (ap);
784  return; /* not supported by us */
785  }
786  ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
787  if (NULL == ap->sock)
788  {
789  GNUNET_free (ap);
790  return; /* not supported by OS */
791  }
793  "Trying to connect to `%s' (%p)\n",
794  GNUNET_a2s (ap->addr, ap->addrlen),
795  connection);
796  if ((GNUNET_OK !=
797  GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
798  (EINPROGRESS != errno))
799  {
800  /* maybe refused / unsupported address, try next */
803  GNUNET_free (ap);
804  return;
805  }
806  GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap);
808  if (NULL != connection->nth.notify_ready)
811  connection->nth.transmit_timeout));
812  if (NULL != connection->receiver)
815  connection->receive_timeout));
817  ap->sock,
819  ap);
820 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
const struct sockaddr * addr
The address; do not free (allocated at the end of this struct).
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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...
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
#define LOG(kind,...)
Definition: abd_api.c:38
#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
#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 AddressProbe * ap_tail
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_SCHEDULER_Task * task
Task waiting for the connection to finish connecting.
uint16_t port
Port to connect to.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void connect_fail_continuation(struct GNUNET_CONNECTION_Handle *connection)
We&#39;ve failed for good to establish a connection (timeout or no more addresses to try).
char * hostname
Pointer to the hostname if connection was created using DNS lookup, otherwise NULL.
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 sockaddr * addr
Network address of the other end-point, may be NULL.
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
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)...
socklen_t addrlen
Lenth of addr.
struct GNUNET_TIME_Absolute receive_timeout
Timeout for receiving (in absolute time).
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:272
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_TIME_Absolute transmit_timeout
Timeout for receiving (in absolute time).
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
handle for a network connection
#define LOG_STRERROR(kind, syscall)
#define CONNECT_RETRY_TIMEOUT
Timeout we use on TCP connect before trying another result from the DNS resolver. ...
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.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_CONNECTION_Handle * connection
Connection for which we are probing.
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:

◆ GNUNET_CONNECTION_create_from_connect()

struct GNUNET_CONNECTION_Handle* GNUNET_CONNECTION_create_from_connect ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  hostname,
uint16_t  port 
)

Create a connection handle by (asynchronously) connecting to a host.

This function returns immediately, even if the connection has not yet been established. This function only creates TCP connections.

Parameters
cfgconfiguration to use
hostnamename of the host to connect to
portport to connect to
Returns
the connection handle

Definition at line 834 of file tcp_connection_legacy.c.

References cfg, GNUNET_CONNECTION_Handle::cfg, CONNECT_RETRY_TIMEOUT, GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_CONNECTION_Handle::dns_active, GNUNET_assert, GNUNET_malloc, GNUNET_MIN_MESSAGE_SIZE, GNUNET_new, GNUNET_RESOLVER_ip_get(), GNUNET_strdup, GNUNET_CONNECTION_Handle::hostname, port, GNUNET_CONNECTION_Handle::port, try_connect_using_address(), GNUNET_CONNECTION_Handle::write_buffer, and GNUNET_CONNECTION_Handle::write_buffer_size.

Referenced by GNUNET_SOCKS_do_connect().

838 {
839  struct GNUNET_CONNECTION_Handle *connection;
840 
841  GNUNET_assert (0 < strlen (hostname)); /* sanity check */
842  connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
843  connection->cfg = cfg;
845  connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
846  connection->port = port;
847  connection->hostname = GNUNET_strdup (hostname);
848  connection->dns_active = GNUNET_RESOLVER_ip_get (connection->hostname,
849  AF_UNSPEC,
852  connection);
853  return connection;
854 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint16_t port
Port to connect to.
size_t write_buffer_size
Current size of our write_buffer.
char * hostname
Pointer to the hostname if connection was created using DNS lookup, otherwise NULL.
#define GNUNET_MIN_MESSAGE_SIZE
Smallest supported message.
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
static char * hostname
Our hostname; we give this to all the peers we start.
static void try_connect_using_address(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Try to establish a connection given the specified address.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
char * write_buffer
Pointer to our write buffer.
handle for a network connection
#define CONNECT_RETRY_TIMEOUT
Timeout we use on TCP connect before trying another result from the DNS resolver. ...
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_create_from_connect_to_unixpath()

struct GNUNET_CONNECTION_Handle* GNUNET_CONNECTION_create_from_connect_to_unixpath ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  unixpath 
)

Create a connection handle by connecting to a UNIX domain service.

This function returns immediately, even if the connection has not yet been established. This function only creates UNIX connections.

Parameters
cfgconfiguration to use
unixpathpath to connect to
Returns
the connection handle, NULL on systems without UNIX support

Definition at line 867 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::addrlen, cfg, GNUNET_CONNECTION_Handle::cfg, connect_success_continuation(), GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_free, GNUNET_malloc, GNUNET_MIN_MESSAGE_SIZE, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_new, GNUNET_OK, GNUNET_strlcpy(), GNUNET_YES, GNUNET_CONNECTION_Handle::hostname, GNUNET_CONNECTION_Handle::port, GNUNET_CONNECTION_Handle::sock, GNUNET_CONNECTION_Handle::write_buffer, and GNUNET_CONNECTION_Handle::write_buffer_size.

870 {
871 #ifdef AF_UNIX
872  struct GNUNET_CONNECTION_Handle *connection;
873  struct sockaddr_un *un;
874 
875  GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
876  un = GNUNET_new (struct sockaddr_un);
877  un->sun_family = AF_UNIX;
878  GNUNET_strlcpy (un->sun_path, unixpath, sizeof(un->sun_path));
879 #ifdef LINUX
880  {
881  int abstract;
882 
883  abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
884  "TESTING",
885  "USE_ABSTRACT_SOCKETS");
886  if (GNUNET_YES == abstract)
887  un->sun_path[0] = '\0';
888  }
889 #endif
890 #if HAVE_SOCKADDR_UN_SUN_LEN
891  un->sun_len = (u_char) sizeof(struct sockaddr_un);
892 #endif
893  connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
894  connection->cfg = cfg;
896  connection->write_buffer = GNUNET_malloc (connection->write_buffer_size);
897  connection->port = 0;
898  connection->hostname = NULL;
899  connection->addr = (struct sockaddr *) un;
900  connection->addrlen = sizeof(struct sockaddr_un);
901  connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
902  if (NULL == connection->sock)
903  {
904  GNUNET_free (connection->addr);
905  GNUNET_free (connection->write_buffer);
906  GNUNET_free (connection);
907  return NULL;
908  }
909  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (connection->sock,
910  connection->addr,
911  connection->addrlen)) &&
912  (EINPROGRESS != errno))
913  {
914  /* Just return; we expect everything to work eventually so don't fail HARD */
916  connection->sock = NULL;
917  return connection;
918  }
919  connect_success_continuation (connection);
920  return connection;
921 #else
922  return NULL;
923 #endif
924 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint16_t port
Port to connect to.
size_t write_buffer_size
Current size of our write_buffer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * hostname
Pointer to the hostname if connection was created using DNS lookup, otherwise NULL.
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 sockaddr * addr
Network address of the other end-point, may be NULL.
#define GNUNET_MIN_MESSAGE_SIZE
Smallest supported message.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
static void connect_success_continuation(struct GNUNET_CONNECTION_Handle *connection)
We&#39;ve succeeded in establishing a connection.
#define GNUNET_YES
Definition: gnunet_common.h:77
socklen_t addrlen
Length of addr.
char * write_buffer
Pointer to our write buffer.
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
handle for a network connection
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_malloc(size)
Wrapper around malloc.
#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:

◆ GNUNET_CONNECTION_connect_socket()

struct GNUNET_CONNECTION_Handle* GNUNET_CONNECTION_connect_socket ( struct GNUNET_NETWORK_Handle s,
const struct sockaddr *  serv_addr,
socklen_t  addrlen 
)

Create a connection handle by (asynchronously) connecting to a host.

This function returns immediately, even if the connection has not yet been established. This function only creates TCP connections.

Parameters
ssocket to connect
serv_addrserver address
addrlenlength of serv_addr
Returns
the connection handle

Definition at line 938 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::addrlen, GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_a2s(), GNUNET_break, GNUNET_CONNECTION_create_from_existing(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_malloc, GNUNET_memcpy, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_OK, LOG, and LOG_STRERROR.

Referenced by GNUNET_CONNECTION_create_from_sockaddr(), and tcp_plugin_get_session().

941 {
942  struct GNUNET_CONNECTION_Handle *connection;
943 
944  if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) &&
945  (EINPROGRESS != errno))
946  {
947  /* maybe refused / unsupported address, try next */
950  "Attempt to connect to `%s' failed\n",
951  GNUNET_a2s (serv_addr, addrlen));
953  return NULL;
954  }
956  connection->addr = GNUNET_malloc (addrlen);
957  GNUNET_memcpy (connection->addr, serv_addr, addrlen);
958  connection->addrlen = addrlen;
960  "Trying to connect to `%s' (%p)\n",
961  GNUNET_a2s (serv_addr, addrlen),
962  connection);
963  return connection;
964 }
#define LOG(kind,...)
Definition: abd_api.c:38
#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_CONNECTION_Handle * GNUNET_CONNECTION_create_from_existing(struct GNUNET_NETWORK_Handle *osSocket)
Create a connection handle by boxing an existing OS socket.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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 sockaddr * addr
Network address of the other end-point, may be NULL.
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)...
socklen_t addrlen
Length of addr.
handle for a network connection
#define LOG_STRERROR(kind, syscall)
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_create_from_sockaddr()

struct GNUNET_CONNECTION_Handle* GNUNET_CONNECTION_create_from_sockaddr ( int  af_family,
const struct sockaddr *  serv_addr,
socklen_t  addrlen 
)

Create a connection handle by creating a socket and (asynchronously) connecting to a host.

This function returns immediately, even if the connection has not yet been established. This function only creates TCP connections.

Parameters
af_familyaddress family to use
serv_addrserver address
addrlenlength of serv_addr
Returns
the connection handle

Definition at line 979 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_connect_socket(), GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_WARNING, GNUNET_NETWORK_socket_create(), and LOG_STRERROR.

Referenced by tcp_plugin_get_session(), and try_connection_reversal().

982 {
983  struct GNUNET_NETWORK_Handle *s;
984 
985  s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
986  if (NULL == s)
987  {
989  return NULL;
990  }
991  return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen);
992 }
struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_connect_socket(struct GNUNET_NETWORK_Handle *s, const struct sockaddr *serv_addr, socklen_t addrlen)
Create a connection handle by (asynchronously) connecting to a host.
socklen_t addrlen
Number of bytes in addr.
Definition: network.c:69
handle to a socket
Definition: network.c:52
#define LOG_STRERROR(kind, syscall)
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:

◆ GNUNET_CONNECTION_check()

int GNUNET_CONNECTION_check ( struct GNUNET_CONNECTION_Handle connection)

Check if connection is valid (no fatal errors have happened so far).

Note that a connection that is still trying to connect is considered valid.

Parameters
connectionconnection to check
Returns
GNUNET_YES if valid, GNUNET_NO otherwise

Definition at line 1004 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::ap_head, GNUNET_CONNECTION_Handle::destroy_later, GNUNET_CONNECTION_Handle::dns_active, GNUNET_NO, GNUNET_YES, GNUNET_CONNECTION_Handle::proxy_handshake, and GNUNET_CONNECTION_Handle::sock.

Referenced by process_incoming().

1005 {
1006  if ((NULL != connection->ap_head) || (NULL != connection->dns_active) ||
1007  (NULL != connection->proxy_handshake))
1008  return GNUNET_YES; /* still trying to connect */
1009  if ((0 != connection->destroy_later) || (NULL == connection->sock))
1010  return GNUNET_NO;
1011  return GNUNET_YES;
1012 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_destroy()

void GNUNET_CONNECTION_destroy ( struct GNUNET_CONNECTION_Handle connection)

Close the connection and free associated resources.

There must not be any pending requests for reading or writing to the connection at this time.

Parameters
connectionconnection to destroy

Definition at line 1023 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::ap_head, GNUNET_CONNECTION_Handle::ap_tail, GNUNET_CONNECTION_Handle::destroy_later, GNUNET_CONNECTION_Handle::dns_active, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_non_null, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_free_memory_only_(), GNUNET_NETWORK_socket_shutdown(), GNUNET_OK, GNUNET_RESOLVER_request_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, GNUNET_CONNECTION_Handle::hostname, LOG, LOG_STRERROR, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_Handle::nth, GNUNET_CONNECTION_Handle::persist, GNUNET_CONNECTION_Handle::proxy_handshake, GNUNET_CONNECTION_Handle::read_task, GNUNET_CONNECTION_Handle::receiver, AddressProbe::sock, GNUNET_CONNECTION_Handle::sock, AddressProbe::task, GNUNET_CONNECTION_TransmitHandle::timeout_task, GNUNET_CONNECTION_Handle::write_buffer, GNUNET_CONNECTION_Handle::write_buffer_off, and GNUNET_CONNECTION_Handle::write_task.

Referenced by connect_fail_continuation(), GNUNET_CONNECTION_acivate_proxied(), GNUNET_SERVER_client_disconnect(), libgnunet_plugin_transport_tcp_done(), and notify_send_probe().

1024 {
1025  struct AddressProbe *pos;
1026 
1027  if (0 != connection->destroy_later)
1028  {
1029  connection->destroy_later = -1;
1030  return;
1031  }
1032  LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection);
1033  GNUNET_assert (NULL == connection->nth.notify_ready);
1034  GNUNET_assert (NULL == connection->receiver);
1035  if (NULL != connection->write_task)
1036  {
1037  GNUNET_SCHEDULER_cancel (connection->write_task);
1038  connection->write_task = NULL;
1039  connection->write_buffer_off = 0;
1040  }
1041  if (NULL != connection->read_task)
1042  {
1043  GNUNET_SCHEDULER_cancel (connection->read_task);
1044  connection->read_task = NULL;
1045  }
1046  if (NULL != connection->nth.timeout_task)
1047  {
1049  connection->nth.timeout_task = NULL;
1050  }
1051  connection->nth.notify_ready = NULL;
1052  if (NULL != connection->dns_active)
1053  {
1055  connection->dns_active = NULL;
1056  }
1057  if (NULL != connection->proxy_handshake)
1058  {
1059  /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */
1060  connection->proxy_handshake->destroy_later = -1;
1061  connection->proxy_handshake = NULL; /* Not leaked ??? */
1062  }
1063  while (NULL != (pos = connection->ap_head))
1064  {
1067  GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
1068  GNUNET_free (pos);
1069  }
1070  if ((NULL != connection->sock) && (GNUNET_YES != connection->persist))
1071  {
1072  if ((GNUNET_OK !=
1073  GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) &&
1074  (ENOTCONN != errno) && (ECONNRESET != errno))
1076  }
1077  if (NULL != connection->sock)
1078  {
1079  if (GNUNET_YES != connection->persist)
1080  {
1082  GNUNET_NETWORK_socket_close (connection->sock));
1083  }
1084  else
1085  {
1087  connection->sock); /* at least no memory leak (we deliberately
1088  * leak the socket in this special case) ... */
1089  }
1090  }
1091  GNUNET_free_non_null (connection->addr);
1092  GNUNET_free_non_null (connection->hostname);
1093  GNUNET_free (connection->write_buffer);
1094  GNUNET_free (connection);
1095 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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.
struct AddressProbe * ap_tail
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_SCHEDULER_Task * task
Task waiting for the connection to finish connecting.
int GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc, int how)
Shut down socket operations.
Definition: network.c:940
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_NETWORK_socket_free_memory_only_(struct GNUNET_NETWORK_Handle *desc)
Only free memory of a socket, keep the file descriptor untouched.
Definition: network.c:622
char * hostname
Pointer to the hostname if connection was created using DNS lookup, otherwise NULL.
struct GNUNET_SCHEDULER_Task * read_task
Read task that we may need to wait for.
struct sockaddr * addr
Network address of the other end-point, may be NULL.
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
size_t write_buffer_off
Current write-offset in write_buffer (where would we write next).
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket.
int8_t persist
When shutdown, do not ever actually close the socket, but free resources.
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
#define GNUNET_YES
Definition: gnunet_common.h:77
char * write_buffer
Pointer to our write buffer.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
#define LOG_STRERROR(kind, syscall)
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.
struct GNUNET_SCHEDULER_Task * timeout_task
Task called on timeout.
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:

◆ GNUNET_CONNECTION_receive()

int GNUNET_CONNECTION_receive ( struct GNUNET_CONNECTION_Handle connection,
size_t  max,
struct GNUNET_TIME_Relative  timeout,
GNUNET_CONNECTION_Receiver  receiver,
void *  receiver_cls 
)

Receive data from the given connection.

Note that this function will call receiver asynchronously using the scheduler. It will "immediately" return. Note that there MUST only be one active receive call per connection at any given point in time (so do not call receive again until the receiver callback has been invoked).

Parameters
connectionconnection handle
maxmaximum number of bytes to read
timeoutmaximum amount of time to wait
receiverfunction to call with received data
receiver_clsclosure for receiver
Returns
GNUNET_SYSERR if connection died (receiver was called with error)

Definition at line 1177 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::ap_head, GNUNET_CONNECTION_Handle::dns_active, GNUNET_assert, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_to_absolute(), GNUNET_CONNECTION_Handle::max, GNUNET_CONNECTION_Handle::proxy_handshake, GNUNET_CONNECTION_Handle::read_task, receive_ready(), GNUNET_CONNECTION_Handle::receive_timeout, GNUNET_CONNECTION_Handle::receiver, GNUNET_CONNECTION_Handle::receiver_cls, and GNUNET_CONNECTION_Handle::sock.

Referenced by GNUNET_SERVER_connect_socket(), process_incoming(), process_mst(), register_reciever(), and restart_processing().

1182 {
1183  GNUNET_assert ((NULL == connection->read_task) &&
1184  (NULL == connection->receiver));
1185  GNUNET_assert (NULL != receiver);
1186  connection->receiver = receiver;
1187  connection->receiver_cls = receiver_cls;
1188  connection->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1189  connection->max = max;
1190  if (NULL != connection->sock)
1191  {
1192  connection->read_task =
1194  connection->receive_timeout),
1195  connection->sock,
1196  &receive_ready,
1197  connection);
1198  return GNUNET_OK;
1199  }
1200  if ((NULL == connection->dns_active) && (NULL == connection->ap_head) &&
1201  (NULL == connection->proxy_handshake))
1202  {
1203  connection->receiver = NULL;
1204  receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
1205  return GNUNET_SYSERR;
1206  }
1207  return GNUNET_OK;
1208 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_SCHEDULER_Task * read_task
Read task that we may need to wait for.
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
struct GNUNET_TIME_Absolute receive_timeout
Timeout for receiving (in absolute time).
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
size_t max
Maximum number of bytes to read (for receiving).
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
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
void * receiver_cls
Closure for receiver.
static void receive_ready(void *cls)
This function is called once we either timeout or have data ready to read.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_receive_cancel()

void* GNUNET_CONNECTION_receive_cancel ( struct GNUNET_CONNECTION_Handle connection)

Cancel receive job on the given connection.

Note that the receiver callback must not have been called yet in order for the cancellation to be valid.

Parameters
connectionconnection handle
Returns
closure of the original receiver callback closure

Definition at line 1220 of file tcp_connection_legacy.c.

References GNUNET_assert, GNUNET_SCHEDULER_cancel(), GNUNET_CONNECTION_Handle::read_task, GNUNET_CONNECTION_Handle::receiver, and GNUNET_CONNECTION_Handle::receiver_cls.

Referenced by GNUNET_SERVER_client_disconnect().

1221 {
1222  if (NULL != connection->read_task)
1223  {
1224  GNUNET_assert (connection ==
1225  GNUNET_SCHEDULER_cancel (connection->read_task));
1226  connection->read_task = NULL;
1227  }
1228  connection->receiver = NULL;
1229  return connection->receiver_cls;
1230 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * read_task
Read task that we may need to wait for.
GNUNET_CONNECTION_Receiver receiver
Function to call on data received, NULL if no receive is pending.
void * receiver_cls
Closure for receiver.
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:

◆ process_notify()

static int process_notify ( struct GNUNET_CONNECTION_Handle connection)
static

Try to call the transmit notify method (check if we do have enough space available first)!

Parameters
connectionconnection for which we should do this processing
Returns
GNUNET_YES if we were able to call notify

Definition at line 1241 of file tcp_connection_legacy.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_YES, LOG, notify, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_TransmitHandle::notify_ready_cls, GNUNET_CONNECTION_TransmitHandle::notify_size, GNUNET_CONNECTION_Handle::nth, size, GNUNET_CONNECTION_Handle::write_buffer, GNUNET_CONNECTION_Handle::write_buffer_off, GNUNET_CONNECTION_Handle::write_buffer_pos, GNUNET_CONNECTION_Handle::write_buffer_size, and GNUNET_CONNECTION_Handle::write_task.

Referenced by transmit_ready().

1242 {
1243  size_t used;
1244  size_t avail;
1245  size_t size;
1247 
1248  LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n");
1249  GNUNET_assert (NULL == connection->write_task);
1250  if (NULL == (notify = connection->nth.notify_ready))
1251  {
1252  LOG (GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n");
1253  return GNUNET_NO;
1254  }
1255  used = connection->write_buffer_off - connection->write_buffer_pos;
1256  avail = connection->write_buffer_size - used;
1257  size = connection->nth.notify_size;
1258  if (size > avail)
1259  {
1260  LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n");
1261  return GNUNET_NO;
1262  }
1263  connection->nth.notify_ready = NULL;
1264  if (connection->write_buffer_size - connection->write_buffer_off < size)
1265  {
1266  /* need to compact */
1267  memmove (connection->write_buffer,
1268  &connection->write_buffer[connection->write_buffer_pos],
1269  used);
1270  connection->write_buffer_off -= connection->write_buffer_pos;
1271  connection->write_buffer_pos = 0;
1272  }
1273  avail = connection->write_buffer_size - connection->write_buffer_off;
1274  GNUNET_assert (avail >= size);
1275  size = notify (connection->nth.notify_ready_cls,
1276  avail,
1277  &connection->write_buffer[connection->write_buffer_off]);
1278  GNUNET_assert (size <= avail);
1279  if (0 != size)
1280  connection->write_buffer_off += size;
1281  return GNUNET_YES;
1282 }
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
size_t write_buffer_size
Current size of our write_buffer.
size_t(* GNUNET_CONNECTION_TransmitReadyNotify)(void *cls, size_t size, void *buf)
Function called to notify a client about the connection begin ready to queue more data...
void * notify_ready_cls
Closure for notify_ready.
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we&#39;ve connected to it).
size_t write_buffer_off
Current write-offset in write_buffer (where would we write next).
size_t write_buffer_pos
Current read-offset in write_buffer (how many bytes have already been sent).
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
size_t notify_size
At what number of bytes available in the write buffer should the notify method be called...
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
#define GNUNET_YES
Definition: gnunet_common.h:77
char * write_buffer
Pointer to our write buffer.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
Here is the caller graph for this function:

◆ transmit_timeout()

static void transmit_timeout ( void *  cls)
static

Task invoked by the scheduler when a call to transmit is timing out (we never got enough buffer space to call the callback function before the specified timeout expired).

This task notifies the client about the timeout.

Parameters
clsthe struct GNUNET_CONNECTION_Handle

Definition at line 1296 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::addr, GNUNET_CONNECTION_Handle::addrlen, GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_a2s(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_CONNECTION_Handle::hostname, LOG, notify, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_TransmitHandle::notify_ready_cls, GNUNET_CONNECTION_Handle::nth, GNUNET_CONNECTION_Handle::port, and GNUNET_CONNECTION_TransmitHandle::timeout_task.

1297 {
1298  struct GNUNET_CONNECTION_Handle *connection = cls;
1300 
1301  connection->nth.timeout_task = NULL;
1303  "Transmit to `%s:%u/%s' fails, time out reached (%p).\n",
1304  connection->hostname,
1305  connection->port,
1306  GNUNET_a2s (connection->addr, connection->addrlen),
1307  connection);
1308  notify = connection->nth.notify_ready;
1309  GNUNET_assert (NULL != notify);
1310  connection->nth.notify_ready = NULL;
1311  notify (connection->nth.notify_ready_cls, 0, NULL);
1312 }
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t port
Port to connect to.
size_t(* GNUNET_CONNECTION_TransmitReadyNotify)(void *cls, size_t size, void *buf)
Function called to notify a client about the connection begin ready to queue more data...
void * notify_ready_cls
Closure for notify_ready.
char * hostname
Pointer to the hostname if connection was created using DNS lookup, otherwise NULL.
struct sockaddr * addr
Network address of the other end-point, may be NULL.
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we&#39;ve connected to it).
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)...
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
socklen_t addrlen
Length of addr.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
handle for a network connection
struct GNUNET_SCHEDULER_Task * timeout_task
Task called on timeout.
Here is the call graph for this function:

◆ connect_error()

static void connect_error ( void *  cls)
static

Task invoked by the scheduler when we failed to connect at the time of being asked to transmit.

This task notifies the client about the error.

Parameters
clsthe struct GNUNET_CONNECTION_Handle

Definition at line 1324 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_ERROR_TYPE_DEBUG, GNUNET_CONNECTION_Handle::hostname, LOG, notify, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_TransmitHandle::notify_ready_cls, GNUNET_CONNECTION_TransmitHandle::notify_size, GNUNET_CONNECTION_Handle::nth, GNUNET_CONNECTION_Handle::port, and GNUNET_CONNECTION_Handle::write_task.

Referenced by GNUNET_CONNECTION_notify_transmit_ready().

1325 {
1326  struct GNUNET_CONNECTION_Handle *connection = cls;
1328 
1330  "Transmission request of size %u fails (%s/%u), connection failed (%p).\n",
1331  connection->nth.notify_size,
1332  connection->hostname,
1333  connection->port,
1334  connection);
1335  connection->write_task = NULL;
1336  notify = connection->nth.notify_ready;
1337  connection->nth.notify_ready = NULL;
1338  notify (connection->nth.notify_ready_cls, 0, NULL);
1339 }
#define LOG(kind,...)
Definition: abd_api.c:38
uint16_t port
Port to connect to.
size_t(* GNUNET_CONNECTION_TransmitReadyNotify)(void *cls, size_t size, void *buf)
Function called to notify a client about the connection begin ready to queue more data...
void * notify_ready_cls
Closure for notify_ready.
char * hostname
Pointer to the hostname if connection was created using DNS lookup, otherwise NULL.
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we&#39;ve connected to it).
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
size_t notify_size
At what number of bytes available in the write buffer should the notify method be called...
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
handle for a network connection
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_notify_transmit_ready()

struct GNUNET_CONNECTION_TransmitHandle* GNUNET_CONNECTION_notify_transmit_ready ( struct GNUNET_CONNECTION_Handle connection,
size_t  size,
struct GNUNET_TIME_Relative  timeout,
GNUNET_CONNECTION_TransmitReadyNotify  notify,
void *  notify_cls 
)

Ask the connection to call us once the specified number of bytes are free in the transmission buffer.

Will never call the notify callback in this task, but always first go into the scheduler.

Parameters
connectionconnection
sizenumber of bytes to send
timeoutafter how long should we give up (and call notify with buf NULL and size 0)?
notifyfunction to call
notify_clsclosure for notify
Returns
non-NULL if the notify callback was queued, NULL if we are already going to notify someone else (busy)

Definition at line 1475 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_Handle::ap_head, connect_error(), GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_CONNECTION_Handle::dns_active, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MAX_MESSAGE_SIZE, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_write_net(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_to_absolute(), LOG, notify, GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_TransmitHandle::notify_ready_cls, GNUNET_CONNECTION_TransmitHandle::notify_size, GNUNET_CONNECTION_Handle::nth, GNUNET_CONNECTION_Handle::proxy_handshake, size, GNUNET_CONNECTION_Handle::sock, GNUNET_CONNECTION_TransmitHandle::timeout_task, transmit_ready(), GNUNET_CONNECTION_TransmitHandle::transmit_timeout, GNUNET_CONNECTION_Handle::write_buffer_off, GNUNET_CONNECTION_Handle::write_buffer_pos, GNUNET_CONNECTION_Handle::write_buffer_size, and GNUNET_CONNECTION_Handle::write_task.

Referenced by GNUNET_SERVER_notify_transmit_ready(), register_sender(), and try_connection_reversal().

1481 {
1482  if (NULL != connection->nth.notify_ready)
1483  {
1484  GNUNET_assert (0);
1485  return NULL;
1486  }
1487  GNUNET_assert (NULL != notify);
1489  GNUNET_assert (connection->write_buffer_off <= connection->write_buffer_size);
1490  GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size);
1491  GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_off);
1492  connection->nth.notify_ready = notify;
1493  connection->nth.notify_ready_cls = notify_cls;
1494  connection->nth.connection = connection;
1495  connection->nth.notify_size = size;
1496  connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1497  GNUNET_assert (NULL == connection->nth.timeout_task);
1498  if ((NULL == connection->sock) && (NULL == connection->ap_head) &&
1499  (NULL == connection->dns_active) && (NULL == connection->proxy_handshake))
1500  {
1501  if (NULL != connection->write_task)
1502  GNUNET_SCHEDULER_cancel (connection->write_task);
1503  connection->write_task =
1504  GNUNET_SCHEDULER_add_now (&connect_error, connection);
1505  return &connection->nth;
1506  }
1507  if (NULL != connection->write_task)
1508  return &connection->nth; /* previous transmission still in progress */
1509  if (NULL != connection->sock)
1510  {
1511  /* connected, try to transmit now */
1513  "Scheduling transmission (%p).\n",
1514  connection);
1515  connection->write_task =
1517  connection->nth.transmit_timeout),
1518  connection->sock,
1519  &transmit_ready,
1520  connection);
1521  return &connection->nth;
1522  }
1523  /* not yet connected, wait for connection */
1525  "Need to wait to schedule transmission for connection, adding timeout task (%p).\n",
1526  connection);
1527  connection->nth.timeout_task =
1528  GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection);
1529  return &connection->nth;
1530 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
struct AddressProbe * ap_head
Linked list of sockets we are currently trying out (during connect).
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
static void connect_error(void *cls)
Task invoked by the scheduler when we failed to connect at the time of being asked to transmit...
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define LOG(kind,...)
Definition: abd_api.c:38
#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_timeout(void *cls)
Task invoked by the scheduler when a call to transmit is timing out (we never got enough buffer space...
size_t write_buffer_size
Current size of our write_buffer.
void * notify_ready_cls
Closure for notify_ready.
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 * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we&#39;ve connected to it).
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
size_t write_buffer_off
Current write-offset in write_buffer (where would we write next).
static void transmit_ready(void *cls)
We are ready to transmit (or got a timeout).
size_t write_buffer_pos
Current read-offset in write_buffer (how many bytes have already been sent).
struct GNUNET_CONNECTION_Handle * connection
Our connection handle.
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_CONNECTION_TransmitHandle nth
The handle we return for GNUNET_CONNECTION_notify_transmit_ready().
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
size_t notify_size
At what number of bytes available in the write buffer should the notify method be called...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
struct GNUNET_TIME_Absolute transmit_timeout
Timeout for receiving (in absolute time).
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
struct GNUNET_SCHEDULER_Task * timeout_task
Task called on timeout.
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:

◆ GNUNET_CONNECTION_notify_transmit_ready_cancel()

void GNUNET_CONNECTION_notify_transmit_ready_cancel ( struct GNUNET_CONNECTION_TransmitHandle th)

Cancel the specified transmission-ready notification.

Parameters
thnotification to cancel

Definition at line 1539 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_TransmitHandle::connection, GNUNET_assert, GNUNET_SCHEDULER_cancel(), GNUNET_CONNECTION_TransmitHandle::notify_ready, GNUNET_CONNECTION_TransmitHandle::timeout_task, and GNUNET_CONNECTION_Handle::write_task.

Referenced by GNUNET_SERVER_notify_transmit_ready_cancel().

1541 {
1542  GNUNET_assert (NULL != th->notify_ready);
1543  th->notify_ready = NULL;
1544  if (NULL != th->timeout_task)
1545  {
1547  th->timeout_task = NULL;
1548  }
1549  if (NULL != th->connection->write_task)
1550  {
1552  th->connection->write_task = NULL;
1553  }
1554 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONNECTION_Handle * connection
Our connection handle.
struct GNUNET_SCHEDULER_Task * write_task
Write task that we may need to wait for.
GNUNET_CONNECTION_TransmitReadyNotify notify_ready
Function to call if the send buffer has notify_size bytes available.
struct GNUNET_SCHEDULER_Task * timeout_task
Task called on timeout.
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:

◆ GNUNET_CONNECTION_create_proxied_from_handshake()

struct GNUNET_CONNECTION_Handle* GNUNET_CONNECTION_create_proxied_from_handshake ( struct GNUNET_CONNECTION_Handle cph)

Create a connection to be proxied using a given connection.

Parameters
cphconnection to proxy server
Returns
connection to be proxied

Definition at line 1564 of file tcp_connection_legacy.c.

References GNUNET_CONNECTION_create_from_existing(), and GNUNET_CONNECTION_Handle::proxy_handshake.

Referenced by GNUNET_SOCKS_run_handshake().

1566 {
1567  struct GNUNET_CONNECTION_Handle *proxied =
1569 
1570  proxied->proxy_handshake = cph;
1571  return proxied;
1572 }
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_existing(struct GNUNET_NETWORK_Handle *osSocket)
Create a connection handle by boxing an existing OS socket.
handle for a network connection
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_CONNECTION_acivate_proxied()

void GNUNET_CONNECTION_acivate_proxied ( struct GNUNET_CONNECTION_Handle proxied)

Activate proxied connection and destroy initial proxy handshake connection.

There must not be any pending requests for reading or writing to the proxy hadshake connection at this time.

Parameters
proxiedconnection connection to proxy server

Definition at line 1583 of file tcp_connection_legacy.c.

References connect_success_continuation(), GNUNET_assert, GNUNET_CONNECTION_destroy(), GNUNET_CONNECTION_Handle::proxy_handshake, and GNUNET_CONNECTION_Handle::sock.

Referenced by SOCKS5_handshake_done().

1584 {
1585  struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake;
1586 
1587  GNUNET_assert (NULL != cph);
1588  GNUNET_assert (NULL == proxied->sock);
1589  GNUNET_assert (NULL != cph->sock);
1590  proxied->sock = cph->sock;
1591  cph->sock = NULL;
1593  connect_success_continuation (proxied);
1594 }
struct GNUNET_NETWORK_Handle * sock
Underlying OS&#39;s socket, set to NULL after fatal errors.
struct GNUNET_CONNECTION_Handle * proxy_handshake
Handle to subsequent connection after proxy handshake completes,.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection)
Close the connection and free associated resources.
static void connect_success_continuation(struct GNUNET_CONNECTION_Handle *connection)
We&#39;ve succeeded in establishing a connection.
handle for a network connection
Here is the call graph for this function:
Here is the caller graph for this function: