|
|
|
@ -1,3 +1,16 @@
|
|
|
|
|
/*
|
|
|
|
|
* Secure Network Transport Layer Library v2 implementation.
|
|
|
|
|
* (sntllv2) it superseed all versions before due to the:
|
|
|
|
|
* - memory consumption
|
|
|
|
|
* - new features such as pulse emitting
|
|
|
|
|
* - performance optimization
|
|
|
|
|
*
|
|
|
|
|
* This is a proprietary software. See COPYING for further details.
|
|
|
|
|
*
|
|
|
|
|
* (c) Askele Group 2013-2015 <http://askele.com>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* File: connection.h
|
|
|
|
|
* Author: vdo
|
|
|
|
@ -22,7 +35,7 @@
|
|
|
|
|
|
|
|
|
|
#include <sntl/pth_queue.h>
|
|
|
|
|
|
|
|
|
|
/* error codes */
|
|
|
|
|
/* TODO: remove to the special separate file - error codes */
|
|
|
|
|
#define ESXOREPLYREQ 44 /* protocol require reply with expression,
|
|
|
|
|
* or expression return for the request */
|
|
|
|
|
#define ESXOTIMEDOUT 45 /* timedout */
|
|
|
|
@ -43,12 +56,7 @@
|
|
|
|
|
typedef struct __perm_context_type {
|
|
|
|
|
char *login;
|
|
|
|
|
char *passwd;
|
|
|
|
|
ulong_t certid;
|
|
|
|
|
ulong_t uid;
|
|
|
|
|
ulong_t gid;
|
|
|
|
|
ulong_t *gids;
|
|
|
|
|
int n_gids;
|
|
|
|
|
int p_attr;
|
|
|
|
|
uint64_t certid;
|
|
|
|
|
struct in_addr *addr;
|
|
|
|
|
void *priv;
|
|
|
|
|
} perm_ctx_t;
|
|
|
|
@ -58,32 +66,50 @@ typedef struct __perm_context_type {
|
|
|
|
|
#define CXCONN_ESTABL (1 << 3)
|
|
|
|
|
#define CXCONN_BROKEN (1 << 4)
|
|
|
|
|
|
|
|
|
|
/* 8 byte header */
|
|
|
|
|
typedef struct __sntllv2_head_type {
|
|
|
|
|
uint16_t msgid;
|
|
|
|
|
uint16_t payload_length;
|
|
|
|
|
uint8_t attr;
|
|
|
|
|
uint8_t opcode;
|
|
|
|
|
uint16_t reserve;
|
|
|
|
|
}__attribute__((packed)) sntllv2_head_t;
|
|
|
|
|
|
|
|
|
|
struct __connections_subsys_type;
|
|
|
|
|
struct __channel_t;
|
|
|
|
|
struct __message_t;
|
|
|
|
|
/*
|
|
|
|
|
* älä jätä kommentteja omalla kielellä! yksinkertaisia englanti sijaan!
|
|
|
|
|
* i found somebody who write comments and messages in non-english,
|
|
|
|
|
* itäs a fucking practice - forget it.
|
|
|
|
|
* it's a fucking practice - forget it.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct __connection_t {
|
|
|
|
|
/* General section */
|
|
|
|
|
struct __connections_subsys_type *ssys; /* < connections subsystem */
|
|
|
|
|
char *uuid; /** < uuid of the connection */
|
|
|
|
|
/* Channels section */
|
|
|
|
|
idx_allocator_t *idx_ch; /** < index allocation for channels */
|
|
|
|
|
usrtc_t *chnl_tree; /** < search tree of all channels */
|
|
|
|
|
pthread_mutex_t idx_ch_lock; /** < mutex for allocating and deallocating channels */
|
|
|
|
|
struct __channel_t **channels; /** < channels O(1) storage */
|
|
|
|
|
/* RPC section */
|
|
|
|
|
usrtc_t *rpc_list; /** < search tree of possible RPC typed lists */
|
|
|
|
|
/* SSL related section */
|
|
|
|
|
SSL_CTX *ctx; /** < SSL context */
|
|
|
|
|
SSL *ssl; /** < SSL connection */
|
|
|
|
|
int ssl_data_index; /** < SSL index for the custom data */
|
|
|
|
|
pthread_mutex_t sslinout[2]; /** < SSL related locks for in and out */
|
|
|
|
|
/* Security section */
|
|
|
|
|
perm_ctx_t *pctx; /** < higher layer authentification context */
|
|
|
|
|
pthread_t cthread; /** < thread for listening the connection socket */
|
|
|
|
|
pthread_t rmsgthread; /** < thread for message queue (1) */
|
|
|
|
|
pthread_t msgthread; /** < thread for message queue (2) */
|
|
|
|
|
pth_queue_t *mqueue; /** < message queue (2) */
|
|
|
|
|
pth_queue_t *rqueue; /** < message queue (1) */
|
|
|
|
|
pth_dqtpoll_t *tpoll; /** < thread poll for rpc requests */
|
|
|
|
|
pthread_mutex_t oplock; /** < mutex used to sync operations on connection */
|
|
|
|
|
pthread_rwlock_t chnl_lock; /** < rwlock used to sync ops with channels */
|
|
|
|
|
int flags; /** < flags of the connection */
|
|
|
|
|
/* Messages section */
|
|
|
|
|
struct __message_t **messages; /** < messages O(1) storage */
|
|
|
|
|
idx_allocator_t *idx_msg;
|
|
|
|
|
pthread_mutex_t idx_msg_lock;
|
|
|
|
|
list_head_t write_pending; /** < list of messages waiting for write */
|
|
|
|
|
pthread_mutex_t write_pending_lock;
|
|
|
|
|
uint8_t unused_messages; /** < unused message count */
|
|
|
|
|
/* Other stuff */
|
|
|
|
|
pthread_t thrd_poll[8];
|
|
|
|
|
uint8_t flags; /** < flags of the connection */
|
|
|
|
|
usrtc_node_t csnode; /** < node to store the connection within list */
|
|
|
|
|
} conn_t;
|
|
|
|
|
|
|
|
|
@ -94,18 +120,9 @@ struct __message_t;
|
|
|
|
|
#define ESXCHAN_CLOSURE (1 << 2)
|
|
|
|
|
|
|
|
|
|
typedef struct __channel_t {
|
|
|
|
|
ulong_t cid; /** < ID of the channel */
|
|
|
|
|
char *uuid; /** < UUID of the channel, used in advanced implementation
|
|
|
|
|
* of the complex distributed systems */
|
|
|
|
|
uint16_t cid; /** < ID of the channel */
|
|
|
|
|
conn_t *connection; /** < pointer to the parent connection */
|
|
|
|
|
idx_allocator_t *idx_msg; /** < index allocation for messages */
|
|
|
|
|
usrtc_t *msgs_tree; /** < search tree of the existing messages */
|
|
|
|
|
struct __message_t *sysmsg; /** < system message used to operate with channel */
|
|
|
|
|
struct __connection_rpc_list_type *rpc_list; /** < rpc functions list */
|
|
|
|
|
pthread_mutex_t oplock; /** < operation ops lock */
|
|
|
|
|
pthread_rwlock_t msglock; /** < rwlock used to operate with messages */
|
|
|
|
|
usrtc_node_t node; /** < node for connection search tree */
|
|
|
|
|
int use_count; /** < use count */
|
|
|
|
|
int flags; /** < flags of the channel */
|
|
|
|
|
} chnl_t;
|
|
|
|
|
|
|
|
|
@ -137,15 +154,12 @@ typedef struct __sexp_payload_t {
|
|
|
|
|
*/
|
|
|
|
|
typedef struct __message_t {
|
|
|
|
|
chnl_t *pch; /** < channel of the message(if applicable) */
|
|
|
|
|
ulong_t mid; /** < unique ID within connection context */
|
|
|
|
|
char *uuid; /** < UUID of the message, used for special messages */
|
|
|
|
|
usrtc_node_t pendingq_node; /** < node for the pending queue */
|
|
|
|
|
pthread_mutex_t wait; /** < special wait mutex, used for sync */
|
|
|
|
|
pthread_mutex_t wait; /** < special wait mutex, used for pending list and sync */
|
|
|
|
|
void *payload; /** < payload */
|
|
|
|
|
sexp_t *initial_sx;
|
|
|
|
|
int opcode; /** < opcode for system and pulse messages */
|
|
|
|
|
int flags; /** < flags of the message (type, state etc ...)*/
|
|
|
|
|
int use_count; /** < use count */
|
|
|
|
|
uint16_t payload_length; /** < payload length */
|
|
|
|
|
uint8_t opcode; /** < opcode for system and pulse messages */
|
|
|
|
|
uint16_t flags; /** < flags of the message (type, state etc ...)*/
|
|
|
|
|
uint16_t idx;
|
|
|
|
|
} sxmsg_t;
|
|
|
|
|
|
|
|
|
|
typedef struct __connection_rpc_entry_type {
|
|
|
|
@ -169,11 +183,6 @@ typedef struct __connection_rpc_list_type {
|
|
|
|
|
*/
|
|
|
|
|
typedef struct __connections_subsys_type {
|
|
|
|
|
usrtc_t *connections;
|
|
|
|
|
pth_queue_t *ioq; /** < general messages queue */
|
|
|
|
|
pth_queue_t *ioqueue; /** < system messages queue */
|
|
|
|
|
/* system threads */
|
|
|
|
|
pthread_t iog_thread; /** < general io queue */
|
|
|
|
|
pthread_t ios_thread; /** < system io queue */
|
|
|
|
|
pthread_rwlock_t rwlock;
|
|
|
|
|
char *rootca, *certpem, *certkey; /* path name to the certificates */
|
|
|
|
|
cx_rpc_list_t *system_rpc;
|
|
|
|
@ -185,6 +194,7 @@ typedef struct __connections_subsys_type {
|
|
|
|
|
int (*set_typed_list_callback)(conn_t *, int, char *); /** < this function is a callback
|
|
|
|
|
* during setting up a typed channel */
|
|
|
|
|
void (*on_destroy)(conn_t *); /** < callback on connection destroy */
|
|
|
|
|
void (*on_pulse)(conn_t *, sxmsg_t *); /** < callback on pulse emit */
|
|
|
|
|
void *priv;
|
|
|
|
|
} conn_sys_t;
|
|
|
|
|
|
|
|
|
|