Ripples 1.0
High Performant Software Architecture For Transaction Processing
Loading...
Searching...
No Matches
Connection

Detailed Description

Connection object holds information about TCP and UDP connections. There is a connection object for each of the following:

TCP (established) connections are tracked in a Least Recently Used cache. LRU cache is used to check for various timeout conditions. Each TCP connection has a unique Id (connection ID) associated with it. The only purpose of this ID is to provide a unique key for LRU cache. LRU cache implementation uses UT HASH.

Listener connections are not tracked in LRU cache.

UDP listener and TCP connection objects have DNS query objects associated with them.

Data Structures

struct  conn_tcp_s
 
struct  conn_udp_s
 
struct  conn_s
 
struct  conn_fifo_queue_s
 

Macros

#define CONN_IS_UDP_LISTENER(conn)    conn->lc == 0 && conn->proto == 0
 
#define CONN_IS_TCP_LISTENER(conn)    conn->lc == 0 && conn->proto == 1
 
#define CONN_IS_TCP_CONN(conn)    conn->lc == 1 && conn->proto == 1
 

Typedefs

typedef enum listener_start_error_e listener_start_error_t
 
typedef enum conn_tcp_state_e conn_tcp_state_t
 
typedef struct conn_tcp_s conn_tcp_t
 
typedef struct conn_udp_s conn_udp_t
 
typedef struct conn_s conn_t
 
typedef struct conn_fifo_queue_s conn_fifo_queue_t
 

Enumerations

enum  listener_start_error_e {
  LISTENER_ERR_SOCKET = -1 , LISTENER_ERR_SOCKET_OPT_REUSEADDR = -2 , LISTENER_ERR_SOCKET_OPT_REUSEPORT = -3 , LISTENER_ERR_BIND = -4 ,
  LISTENER_ERR_LISTEN = -5 , LISTENER_ERR_SOCKET_OPT_IP_PKTINFO = -6 , LISTENER_ERR_SOCKET_OPT_IPV6_V6ONLY = -7 , LISTENER_ERR_SOCKET_OPT_IPV6_RECVPKTINFO = -8 ,
  LISTENER_ERR_SOCKET_OPT_RCVBUF = -9 , LISTENER_ERR_SOCKET_OPT_SNDBUF = -10
}
 
enum  conn_tcp_state_e {
  TCP_CONN_ST_ASSIGN_CONN_ID_ERR = 0 , TCP_CONN_ST_WAIT_FOR_QUERY , TCP_CONN_ST_WAIT_FOR_QUERY_DATA , TCP_CONN_ST_WAIT_FOR_WRITE ,
  TCP_CONN_ST_CLOSED_FOR_READ , TCP_CONN_ST_READ_ERR , TCP_CONN_ST_CLOSED_FOR_WRITE , TCP_CONN_ST_WRITE_ERR ,
  TCP_CONN_ST_QUERY_SIZE_TOOLARGE
}
 

Functions

void conn_fifo_enqueue_read (conn_fifo_queue_t *queue, conn_t *entry)
 
conn_tconn_fifo_dequeue_read (conn_fifo_queue_t *queue)
 
void conn_fifo_enqueue_write (conn_fifo_queue_t *queue, conn_t *entry)
 
conn_tconn_fifo_dequeue_write (conn_fifo_queue_t *queue)
 
void conn_fifo_enqueue_gen (conn_fifo_queue_t *queue, conn_t *conn)
 
conn_tconn_fifo_dequeue_gen (conn_fifo_queue_t *queue)
 
void conn_fifo_remove_from_read_queue (conn_fifo_queue_t *queue, conn_t *conn_rm)
 
void conn_fifo_remove_from_write_queue (conn_fifo_queue_t *queue, conn_t *conn_rm)
 
void conn_fifo_enqueue_release (conn_fifo_queue_t *queue, conn_t *conn)
 
conn_tconn_fifo_dequeue_release (conn_fifo_queue_t *queue)
 
void conn_tcp_release (conn_tcp_t *conn_tcp)
 
void conn_udp_release (conn_udp_t *conn_udp)
 
void conn_release (conn_t *conn)
 
void conn_udp_vectors_reset (conn_udp_t *conn_udp)
 
conn_udp_tconn_udp_new (config_t *cfg, int family)
 
conn_tconn_new_tcp (int fd, config_t *cfg, int ip_version, struct sockaddr_storage *client_ip, struct sockaddr_storage *local_ip)
 
conn_tconn_listener_provision (config_t *cfg, int family, int protocol, char *err_buf, size_t err_buf_len)
 
conn_tconn_lru_cache_get (conn_t **lru, uint64_t id)
 
bool conn_tcp_id_assign (uint64_t *id, conn_t **lru, uint64_t *base)
 
void conn_tcp_report_metrics (conn_tcp_t *conn_tcp, metrics_t *metrics)
 

Macro Definition Documentation

◆ CONN_IS_TCP_CONN

#define CONN_IS_TCP_CONN (   conn)     conn->lc == 1 && conn->proto == 1

Marco that returns true if conn (conn_t struct) is a TCP connection

◆ CONN_IS_TCP_LISTENER

#define CONN_IS_TCP_LISTENER (   conn)     conn->lc == 0 && conn->proto == 1

Marco that returns true if conn (conn_t struct) is a TCP listener

◆ CONN_IS_UDP_LISTENER

#define CONN_IS_UDP_LISTENER (   conn)     conn->lc == 0 && conn->proto == 0

Marco that returns true if conn (conn_t struct) is a UDP listener

Typedef Documentation

◆ conn_fifo_queue_t

Connection object FIFO queue. New objects are enqueued (added) to the tail of the queue, and objects are dequeued (removed) from head of the queue.

◆ conn_t

typedef struct conn_s conn_t

Structure holds data common to TCP and UDP connections.

◆ conn_tcp_state_t

Enumerated TCP connection states.

◆ conn_tcp_t

typedef struct conn_tcp_s conn_tcp_t

Structure holds data specific to TCP listener connection.

◆ conn_udp_t

typedef struct conn_udp_s conn_udp_t

Structure holds data specific to UDP listener connection.

◆ listener_start_error_t

Enumerated error returned by listener_start() function.

Enumeration Type Documentation

◆ conn_tcp_state_e

Enumerated TCP connection states.

Enumerator
TCP_CONN_ST_WAIT_FOR_QUERY 

Wait for query request (not first one).

TCP_CONN_ST_WAIT_FOR_WRITE 

Wait for epoll notification for socket to become "writable".

TCP_CONN_ST_CLOSED_FOR_READ 

TCP connection is closed for read (by far end), also known as half close.

TCP_CONN_ST_READ_ERR 

There was an error reading from connection socket. Socket is closed and no further reads nor writes are done.

TCP_CONN_ST_CLOSED_FOR_WRITE 

TCP connection is was closed for write.

TCP_CONN_ST_WRITE_ERR 

There was an error writing to connection socket. Socket is closed and no further reads nor writes are done.

TCP_CONN_ST_QUERY_SIZE_TOOLARGE 

Query size received over TCP connection exceeds RIP_NS_PACKETSZ.

◆ listener_start_error_e

Enumerated error returned by listener_start() function.

Enumerator
LISTENER_ERR_SOCKET 

Socket create error.

LISTENER_ERR_SOCKET_OPT_REUSEADDR 

Error setting socket option SO_REUSEADDR.

LISTENER_ERR_SOCKET_OPT_REUSEPORT 

Error setting socket option SO_REUSEPORT.

LISTENER_ERR_BIND 

Error binding socket.

LISTENER_ERR_LISTEN 

Error calling listen() on socket, applies to TCP only.

LISTENER_ERR_SOCKET_OPT_IP_PKTINFO 

Error setting socket option IP_PKTINFO.

LISTENER_ERR_SOCKET_OPT_IPV6_V6ONLY 

Error setting socket option IPV6_V6ONLY.

LISTENER_ERR_SOCKET_OPT_IPV6_RECVPKTINFO 

Error setting socket option IPV6_RECVPKTINFO.

LISTENER_ERR_SOCKET_OPT_RCVBUF 

Error setting socket option IPV6_RECVPKTINFO.

LISTENER_ERR_SOCKET_OPT_SNDBUF 

Error setting socket option IPV6_RECVPKTINFO.

Function Documentation

◆ conn_fifo_dequeue_gen()

conn_t * conn_fifo_dequeue_gen ( conn_fifo_queue_t queue)

Remove (dequeue) a connection object from generic fifo queue.

Parameters
queueQueue to remove connection object from.
Returns
On success returns object, otherwise there are no entries in the queue and returns NULL.
Here is the caller graph for this function:

◆ conn_fifo_dequeue_read()

conn_t * conn_fifo_dequeue_read ( conn_fifo_queue_t queue)

Remove (dequeue) a connection object from read fifo queue.

Parameters
queueRead queue to remove connection object from.
Returns
On success returns connection object, otherwise there are no entries in the queue and returns NULL.
Here is the caller graph for this function:

◆ conn_fifo_dequeue_release()

conn_t * conn_fifo_dequeue_release ( conn_fifo_queue_t queue)

Remove (dequeue) a generic object from fifo queue.

Parameters
queueQueue to remove connection object from.
Returns
On success returns object, otherwise there are no entries in the queue and returns NULL.
Here is the caller graph for this function:

◆ conn_fifo_dequeue_write()

conn_t * conn_fifo_dequeue_write ( conn_fifo_queue_t queue)

Remove (dequeue) a connection object from write fifo queue.

Parameters
queueWrite queue to remove connection object from.
Returns
On success returns connection object, otherwise there are no entries in the queue and returns NULL.
Here is the caller graph for this function:

◆ conn_fifo_enqueue_gen()

void conn_fifo_enqueue_gen ( conn_fifo_queue_t queue,
conn_t conn 
)

Add (enqueue) a connection object to generic fifo queue.

Parameters
queueQueue to add object to.
connObject to queue up.
Here is the caller graph for this function:

◆ conn_fifo_enqueue_read()

void conn_fifo_enqueue_read ( conn_fifo_queue_t queue,
conn_t conn 
)

Add (enqueue) a connection object to read fifo queue.

Parameters
queueRead queue to add connection object to.
connConnection object to queue up.
Here is the caller graph for this function:

◆ conn_fifo_enqueue_release()

void conn_fifo_enqueue_release ( conn_fifo_queue_t queue,
conn_t conn 
)

Add (enqueue) a connection object to release fifo queue.

Parameters
queueQueue to add object to.
connObject to queue up.
Here is the caller graph for this function:

◆ conn_fifo_enqueue_write()

void conn_fifo_enqueue_write ( conn_fifo_queue_t queue,
conn_t conn 
)

Add (enqueue) a connection object to write fifo queue.

Parameters
queueWrite queue to add connection object to.
connConnection object to queue up.
Here is the caller graph for this function:

◆ conn_fifo_remove_from_read_queue()

void conn_fifo_remove_from_read_queue ( conn_fifo_queue_t queue,
conn_t conn_rm 
)

Remove conn from read queue.

Parameters
queueRead queue to remove conn object from.
conn_rmConn object to remove from queue.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conn_fifo_remove_from_write_queue()

void conn_fifo_remove_from_write_queue ( conn_fifo_queue_t queue,
conn_t conn_rm 
)

Remove conn from write queue.

Parameters
queueWrite queue to remove conn object from.
conn_rmConn object to remove from queue.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conn_listener_provision()

conn_t * conn_listener_provision ( config_t cfg,
int  family,
int  protocol,
char *  err_buf,
size_t  err_buf_len 
)

Provision a new TCP or UDP listener and return the corresponding connection conn_t object.

Listener is started and associated with new connection object. New connection object is initialized meaning it has all necessary buffers allocated.

Parameters
cfgConfiguration object that has settings:
  • udp_conn_vector_len,
familyIP family to start a listener for, valid options are:
  • AF_INET,
  • AF_INET6.
protocolProtocol to start listener for, valid options are:
  • IPPROTO_TCP,
  • IPPROTO_UDP.
err_bufBuffer where to store error message if error was encountered. If NULL no message is stored.
err_buf_lenLength of error buffer.
Returns
On success returns a newly allocated and active connection object. On error returns NULL and message is populated into error buffer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conn_lru_cache_get()

conn_t * conn_lru_cache_get ( conn_t **  lru,
uint64_t  id 
)

Get entry in TCP connection LRU cache and also update LRU state (entry is set as MRU).

Parameters
lruPointer to LRU cache.
idEntry key to look for.
Returns
On success returns a pointer to connection in LRU cache. Entry place in LRU is updated. Otherwise returns NULL indicating that entry was not found in LRU cache.
Here is the caller graph for this function:

◆ conn_new_tcp()

conn_t * conn_new_tcp ( int  fd,
config_t cfg,
int  ip_version,
struct sockaddr_storage *  client_ip,
struct sockaddr_storage *  local_ip 
)

Create a new TCP connection object for an established TCP connection.

Parameters
fdSocket for TCP connection.
cfgApplication configuration to get various settings from.
ip_versionIP version this connection is for, 0=IPv4, 1=IPv6.
client_ipClient IP address.
local_ipLocal IP address.
Returns
Returns a newly allocated and initialized TCP connection object.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conn_release()

void conn_release ( conn_t conn)

Free memory associated with conn_t object and free object it self.

Parameters
connConnection object to release.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conn_tcp_id_assign()

bool conn_tcp_id_assign ( uint64_t *  id,
conn_t **  lru,
uint64_t *  base 
)

Assign a new TCP connection ID.

Parameters
idWhere to store newly assigned TCP connection ID.
lruTCP connection LRU cache, used to verify uniqueness of connection ID being assigned.
baseBase for connection ID. (Base is unique per Vectorloop object.
Returns
Returns true if connection ID was assigned, otherwise returns false.
Here is the caller graph for this function:

◆ conn_tcp_release()

void conn_tcp_release ( conn_tcp_t conn_tcp)

Free memory associated with conn_tcp_t object and free object it self.

Parameters
conn_tcpTCP connection object to release.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conn_tcp_report_metrics()

void conn_tcp_report_metrics ( conn_tcp_t conn_tcp,
metrics_t metrics 
)

Report TCP metrics for a query.

Parameters
conn_tcpTCP connection to report metrics for.
metricsMetrics object where to report metrics.
Here is the caller graph for this function:

◆ conn_udp_new()

conn_udp_t * conn_udp_new ( config_t cfg,
int  family 
)

Create a new UDP connection object

Parameters
cfgApplication configuration to get various settings from.
familyIP family: AF_INET or AF_INET6.
Returns
Returns a newly allocated and initialized UDP connection object.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conn_udp_release()

void conn_udp_release ( conn_udp_t conn_udp)

Free memory associated with conn_udp_t object and free object it self.

Parameters
conn_udpUDP connection object to release.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conn_udp_vectors_reset()

void conn_udp_vectors_reset ( conn_udp_t conn_udp)

Reset UDP connection vectors so the can be reused for next iteration of read/resolve/send of DNS queries.

Parameters
conn_udpUDP connection to reset vectors for.
Here is the call graph for this function:
Here is the caller graph for this function: