fixed comments, renaming;

v0.5.xx
Alexander Vdolainen 9 years ago
parent ba5c37630e
commit e749301178

@ -1,6 +1,6 @@
/*
* Secure Network Transport Layer Library v2 implementation.
* (sntllv2) it superseed all versions before due to the:
* Secure X Message Passing Library v2 implementation.
* (sxmplv2) it superseed all versions before due to the:
* - memory consumption
* - new features such as pulse emitting
* - performance optimization

@ -1,6 +1,6 @@
/*
* Secure Network Transport Layer Library v2 implementation.
* (sntllv2) it superseed all versions before due to the:
* Secure X Message Passing Library v2 implementation.
* (sxmplv2) it superseed all versions before due to the:
* - memory consumption
* - new features such as pulse emitting
* - performance optimization

@ -1,6 +1,6 @@
/*
* Secure Network Transport Layer Library v2 implementation.
* (sntllv2) it superseed all versions before due to the:
* Secure X Message Passing Library v2 implementation.
* (sxmplv2) it superseed all versions before due to the:
* - memory consumption
* - new features such as pulse emitting
* - performance optimization

@ -1,5 +1,5 @@
/*
* Secure Network Transport Layer Library implementation.
* Secure X Message Passing Library v2 implementation.
* This is a proprietary software. See COPYING for further details.
*
* (c) Askele Group 2013-2015 <http://askele.com>

@ -1,6 +1,6 @@
/*
* Secure Network Transport Layer Library v2 implementation.
* (sntllv2) it superseed all versions before due to the:
* Secure X Message Passing Library v2 implementation.
* (sxmplv2) it superseed all versions before due to the:
* - memory consumption
* - new features such as pulse emitting
* - performance optimization
@ -41,22 +41,22 @@
#include <tdata/list.h>
#include <sexpr/sexp.h>
#include <sntl/limits.h>
#include <sntl/sntllv2.h>
#include <sxmp/limits.h>
#include <sxmp/sxmplv2.h>
#include "internal.h"
typedef struct __sntll_bundle_type {
typedef struct __sxmpl_bundle_type {
void *buf;
conn_t *conn;
} sntllv2_bundle_t;
} sxmplv2_bundle_t;
/* networking helpers */
#ifndef WIN32
int __resolvehost(const char *hostname, char *buf, int buf_len,
struct hostent **rhp)
struct hostent **rhp)
{
struct hostent *hostbuf ;//= malloc(sizeof(struct hostent));
struct hostent *hostbuf ;
struct hostent *hp = *rhp = NULL;
int herr = 0, hres = 0;
@ -84,7 +84,7 @@ static int __conn_read(conn_t *co, void *buf, size_t buf_len)
ofcmode = fcntl(rfd, F_GETFL,0);
ofcmode |= O_NDELAY;
if(fcntl(rfd, F_SETFL, ofcmode))
fprintf(stderr, "[sntllv2] (RD)Couldn't make socket nonblocking");
fprintf(stderr, "[sxmplv2] (RD)Couldn't make socket nonblocking");
#endif
__retry:
@ -109,26 +109,26 @@ static int __conn_read(conn_t *co, void *buf, size_t buf_len)
case SSL_ERROR_SYSCALL:
if(errno == EAGAIN || errno == EINTR) goto __try_again;
else {
fprintf(stderr, "[sntllv2] (RD)SSL syscall error.\n");
fprintf(stderr, "[sxmplv2] (RD)SSL syscall error.\n");
goto __close_conn;
}
break;
case SSL_ERROR_WANT_CONNECT:
case SSL_ERROR_WANT_ACCEPT:
fprintf(stderr, "[sntllv2] (RD)SSL negotiation required. Trying again.\n");
fprintf(stderr, "[sxmplv2] (RD)SSL negotiation required. Trying again.\n");
goto __try_again;
break;
case SSL_ERROR_SSL:
fprintf(stderr, "[sntllv2] (RD)SSL error occured. Connection will be closed.\n");
fprintf(stderr, "[sxmplv2] (RD)SSL error occured. Connection will be closed.\n");
goto __close_conn;
break;
case SSL_ERROR_ZERO_RETURN:
fprintf(stderr, "[sntllv2] (RD)SSL connection is cleary closed.\n");
fprintf(stderr, "[sxmplv2] (RD)SSL connection is cleary closed.\n");
default:
__close_conn:
ERR_free_strings();
co->flags |= SNSX_CLOSED;
fprintf(stderr, "[sntllv2] (RD)Unknown error on %s (errno = %d)\n", co->uuid, errno);
fprintf(stderr, "[sxmplv2] (RD)Unknown error on %s (errno = %d)\n", co->uuid, errno);
ERR_remove_state(0);
return -1;
}
@ -143,12 +143,12 @@ static int __conn_read(conn_t *co, void *buf, size_t buf_len)
r = select(rfd + 1, &readset, NULL, NULL, NULL);
if(r < 0) {
if(errno == EINTR || errno == EAGAIN) goto __select_retry;
fprintf(stderr, "[sntllv2] (RD)Select (%d) on %s\n", errno, co->uuid);
fprintf(stderr, "[sxmplv2] (RD)Select (%d) on %s\n", errno, co->uuid);
ERR_remove_state(0);
return -1;
}
if(!r) {
fprintf(stderr, "[sntllv2] (RD)Nothing to wait for\n");
fprintf(stderr, "[sxmplv2] (RD)Nothing to wait for\n");
ERR_remove_state(0);
return 0;
}
@ -198,7 +198,7 @@ static int __conn_write(conn_t *co, void *buf, size_t buf_len)
/* set closed flag */
ERR_free_strings();
co->flags |= SNSX_CLOSED;
fprintf(stderr, "[sntllv2] (WR)Unknown error on %s (%d)\n", co->uuid, r);
fprintf(stderr, "[sxmplv2] (WR)Unknown error on %s (%d)\n", co->uuid, r);
ERR_remove_state(0);
return -1;
} else return r;
@ -207,9 +207,9 @@ static int __conn_write(conn_t *co, void *buf, size_t buf_len)
return r;
}
int _sntll_writemsg(conn_t *co, sxmsg_t *msg)
int _sxmpl_writemsg(conn_t *co, sxmsg_t *msg)
{
sntllv2_head_t *head;
sxmplv2_head_t *head;
size_t rd;
int r;
char *buf = NULL;
@ -221,16 +221,16 @@ int _sntll_writemsg(conn_t *co, sxmsg_t *msg)
if(head->payload_length && !msg->payload) return SNE_FAILED;
if(head->payload_length) {
buf = malloc(sizeof(sntllv2_head_t) + head->payload_length);
memcpy(buf, head, sizeof(sntllv2_head_t));
memcpy(buf + sizeof(sntllv2_head_t), msg->payload, head->payload_length);
buf = malloc(sizeof(sxmplv2_head_t) + head->payload_length);
memcpy(buf, head, sizeof(sxmplv2_head_t));
memcpy(buf + sizeof(sxmplv2_head_t), msg->payload, head->payload_length);
}
/* write the head and payload if applicable */
pthread_mutex_lock(&co->sslinout[1]);
if(!buf)
rd = __conn_write(co, head, sizeof(sntllv2_head_t));
else rd = __conn_write(co, buf, sizeof(sntllv2_head_t) + head->payload_length);
rd = __conn_write(co, head, sizeof(sxmplv2_head_t));
else rd = __conn_write(co, buf, sizeof(sxmplv2_head_t) + head->payload_length);
if(rd < 0) {
co->flags |= SNSX_CLOSED;
r = SNE_ESSL;
@ -242,12 +242,12 @@ int _sntll_writemsg(conn_t *co, sxmsg_t *msg)
return r;
}
static sntllv2_bundle_t *__sntll_bundle_create(conn_t *co)
static sxmplv2_bundle_t *__sxmpl_bundle_create(conn_t *co)
{
sntllv2_bundle_t *n = malloc(sizeof(sntllv2_bundle_t));
sxmplv2_bundle_t *n = malloc(sizeof(sxmplv2_bundle_t));
if(!n) return NULL;
else memset(n, 0, sizeof(sntllv2_bundle_t));
else memset(n, 0, sizeof(sxmplv2_bundle_t));
n->buf = mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(n->buf == MAP_FAILED) {
@ -260,7 +260,7 @@ static sntllv2_bundle_t *__sntll_bundle_create(conn_t *co)
return n;
}
static void __sntll_bundle_destroy(sntllv2_bundle_t *n)
static void __sxmpl_bundle_destroy(sxmplv2_bundle_t *n)
{
munmap(n->buf, 65536);
free(n);
@ -352,7 +352,7 @@ static void pthreads_thread_id(CRYPTO_THREADID *tid)
#endif
}
int sntl_init(void)
int sxmp_init(void)
{
int i;
@ -378,7 +378,7 @@ int sntl_init(void)
return 0;
}
void sntl_finalize(void)
void sxmp_finalize(void)
{
int i;
@ -548,7 +548,7 @@ static void __connection_destroy(conn_t *co)
ppmsg_t *ppm;
list_node_t *iter, *siter;
chnl_t *chan;
sntllv2_head_t *head;
sxmplv2_head_t *head;
conn_sys_t *ssys = co->ssys;
/* first we will unpin all messages and mark it as errors on */
@ -634,13 +634,13 @@ static void __connection_destroy(conn_t *co)
return;
}
static void *__sntll_thread(void *b)
static void *__sxmpl_thread(void *b)
{
sntllv2_bundle_t *bun = (sntllv2_bundle_t *)b;
sxmplv2_bundle_t *bun = (sxmplv2_bundle_t *)b;
conn_t *co = bun->conn;
void *buf = bun->buf;
char *bbuf = (char*)buf;
sntllv2_head_t *mhead = (sntllv2_head_t *)buf;
sxmplv2_head_t *mhead = (sxmplv2_head_t *)buf;
sxmsg_t *msg, *omsg;
sexp_t *sx;
chnl_t *channel;
@ -655,7 +655,7 @@ static void *__sntll_thread(void *b)
struct timeval beg, end;
#endif
/* byte buffer is following head */
bbuf += sizeof(sntllv2_head_t);
bbuf += sizeof(sxmplv2_head_t);
__wait_alive:
/* flag test - FIXME: make it atomic (it will works atomically on x86, btw on others not) */
@ -687,7 +687,7 @@ static void *__sntll_thread(void *b)
list_for_each_safe(&co->write_pending, iter, siter) {
ppm = container_of(iter, ppmsg_t, node);
omsg = ppm->msg;
if(_sntll_writemsg(co, omsg) != SNE_SUCCESS) {
if(_sxmpl_writemsg(co, omsg) != SNE_SUCCESS) {
pthread_mutex_unlock(&co->write_pending_lock);
goto __finish; /* write failed - finishing ... */
}
@ -718,7 +718,7 @@ static void *__sntll_thread(void *b)
#ifdef _PERFPROFILE
gettimeofday(&beg, NULL);
#endif
rd = __conn_read(co, mhead, sizeof(sntllv2_head_t));
rd = __conn_read(co, mhead, sizeof(sxmplv2_head_t));
#ifdef _PERFPROFILE
gettimeofday(&end, NULL);
@ -782,7 +782,7 @@ static void *__sntll_thread(void *b)
mhead->attr |= SXMSG_CLOSED;
mhead->payload_length = 0;
pthread_mutex_lock(&(co->sslinout[1]));
wr = __conn_write(co, mhead, sizeof(sntllv2_head_t));
wr = __conn_write(co, mhead, sizeof(sxmplv2_head_t));
pthread_mutex_unlock(&(co->sslinout[1]));
if(wr == -1) goto __finish;
else goto __again;
@ -800,14 +800,14 @@ static void *__sntll_thread(void *b)
mhead->payload_length = 0;
mhead->attr &= ~SXMSG_REPLYREQ;
pthread_mutex_lock(&(co->sslinout[1]));
wr = __conn_write(co, mhead, sizeof(sntllv2_head_t));
wr = __conn_write(co, mhead, sizeof(sxmplv2_head_t));
pthread_mutex_unlock(&(co->sslinout[1]));
if(wr < 0) goto __finish;
} else { /* it's came back */
/* reply came ... */
if(mhead->msgid >= 1024) {
__inval_idx_nor:
fprintf(stderr, "[sntllv2] Invalid index of the message.\n");
fprintf(stderr, "[sxmplv2] Invalid index of the message.\n");
goto __again;
}
mid = mhead->msgid;
@ -817,7 +817,7 @@ static void *__sntll_thread(void *b)
if(!msg) goto __inval_idx_nor;
/* ok now we'are copy data and unlock wait mutex */
memcpy(&msg->mhead, mhead, sizeof(sntllv2_head_t));
memcpy(&msg->mhead, mhead, sizeof(sxmplv2_head_t));
pthread_mutex_unlock(&msg->wait);
}
} else if(mhead->attr & SXMSG_LINK) { /* link layer messages */
@ -841,7 +841,7 @@ static void *__sntll_thread(void *b)
mhead->attr &= ~SXMSG_OPEN;
mhead->attr |= SXMSG_CLOSED;
pthread_mutex_lock(&(co->sslinout[1]));
wr = __conn_write(co, mhead, sizeof(sntllv2_head_t));
wr = __conn_write(co, mhead, sizeof(sxmplv2_head_t));
pthread_mutex_unlock(&(co->sslinout[1]));
if(wr < 0) goto __finish;
else goto __again;
@ -860,7 +860,7 @@ static void *__sntll_thread(void *b)
pthread_mutex_lock(&msg->wait);
msg->pch = channel;
/* copy header only */
memcpy(&msg->mhead, mhead, sizeof(sntllv2_head_t));
memcpy(&msg->mhead, mhead, sizeof(sxmplv2_head_t));
if(mhead->payload_length) msg->payload = bbuf;
}
@ -892,7 +892,7 @@ static void *__sntll_thread(void *b)
pthread_mutex_destroy(&msg->wait);
free(msg);
} else {
memcpy(&msg->mhead, mhead, sizeof(sntllv2_head_t));
memcpy(&msg->mhead, mhead, sizeof(sxmplv2_head_t));
if(mhead->payload_length) {
msg->payload = malloc(mhead->payload_length);
if(msg->payload) memcpy(msg->payload, bbuf, mhead->payload_length);
@ -923,7 +923,7 @@ static void *__sntll_thread(void *b)
mhead->opcode = SNE_ETIMEDOUT;
goto __ret_regerr;
} else {
memcpy(&msg->mhead, mhead, sizeof(sntllv2_head_t));
memcpy(&msg->mhead, mhead, sizeof(sxmplv2_head_t));
if(mhead->payload_length) {
msg->payload = malloc(mhead->payload_length);
if(msg->payload) memcpy(msg->payload, bbuf, mhead->payload_length);
@ -936,7 +936,7 @@ static void *__sntll_thread(void *b)
mhead->attr &= ~SXMSG_OPEN;
mhead->attr |= SXMSG_CLOSED;
pthread_mutex_lock(&(co->sslinout[1]));
wr = __conn_write(co, mhead, sizeof(sntllv2_head_t));
wr = __conn_write(co, mhead, sizeof(sxmplv2_head_t));
pthread_mutex_unlock(&(co->sslinout[1]));
if(wr < 0) goto __finish;
}
@ -952,7 +952,7 @@ static void *__sntll_thread(void *b)
co->flags |= SNSX_CLOSED;
__connection_destroy(co);
__sntll_bundle_destroy(b); /* destroy bundle */
__sxmpl_bundle_destroy(b); /* destroy bundle */
return NULL;
}
@ -962,8 +962,8 @@ conn_t *connection_master_link(conn_sys_t *ssys, int sck, struct in_addr *addr)
char *bbuf;
conn_t *co = __connection_minimal_alloc(addr);
sxmsg_t *msg = NULL;
sntllv2_head_t *head;
sntllv2_bundle_t *bundle;
sxmplv2_head_t *head;
sxmplv2_bundle_t *bundle;
size_t rd;
int r = SNE_FAILED;
@ -1038,13 +1038,13 @@ conn_t *connection_master_link(conn_sys_t *ssys, int sck, struct in_addr *addr)
co->messages[0] = msg;
}
bbuf = (char *)buf;
bbuf += sizeof(sntllv2_head_t);
bbuf += sizeof(sxmplv2_head_t);
sexp_t *sx;
while(co->flags & SNSX_BATCHMODE) {
rd = __conn_read(co, buf, sizeof(sntllv2_head_t));
if(rd == sizeof(sntllv2_head_t)) {
head = (sntllv2_head_t *)buf;
rd = __conn_read(co, buf, sizeof(sxmplv2_head_t));
if(rd == sizeof(sxmplv2_head_t)) {
head = (sxmplv2_head_t *)buf;
/* check for returns */
if(head->opcode != SNE_SUCCESS) { r = head->opcode; goto __fail3; }
@ -1070,17 +1070,17 @@ conn_t *connection_master_link(conn_sys_t *ssys, int sck, struct in_addr *addr)
msg->mhead.payload_length = 0;
/* deal with it */
r = __eval_syssexp(co, sx);
memcpy(head, &msg->mhead, sizeof(sntllv2_head_t));
memcpy(head, &msg->mhead, sizeof(sxmplv2_head_t));
head->opcode = r;
if(r != SNE_SUCCESS) { /* we finish */
head->payload_length = 0;
__conn_write(co, head, sizeof(sntllv2_head_t));
__conn_write(co, head, sizeof(sxmplv2_head_t));
destroy_sexp(sx);
goto __fail3;
}
rd = __conn_write(co, buf, sizeof(sntllv2_head_t) + msg->mhead.payload_length);
rd = __conn_write(co, buf, sizeof(sxmplv2_head_t) + msg->mhead.payload_length);
if(rd == -1) { r = SNE_LINKERROR; goto __fail3; }
if(rd != sizeof(sntllv2_head_t) + msg->mhead.payload_length) {
if(rd != sizeof(sxmplv2_head_t) + msg->mhead.payload_length) {
destroy_sexp(sx);
goto __fail3;
}
@ -1098,16 +1098,16 @@ conn_t *connection_master_link(conn_sys_t *ssys, int sck, struct in_addr *addr)
free(msg);
/* and now we're need to create a thread poll */
if(!(bundle = malloc(sizeof(sntllv2_bundle_t)))) { r = SNE_ENOMEM; goto __fail4; }
if(!(bundle = malloc(sizeof(sxmplv2_bundle_t)))) { r = SNE_ENOMEM; goto __fail4; }
else {
bundle->buf = buf;
bundle->conn = co;
}
int i;
for(i = 0; i < MAX_SNTLLTHREADS; i++) {
if(bundle == (void *)0xdead) bundle = __sntll_bundle_create(co);
if(bundle == (void *)0xdead) bundle = __sxmpl_bundle_create(co);
if(!bundle) goto __fail5;
r = pthread_create(&co->thrd_poll[i], NULL, __sntll_thread, bundle); /* and here, alloc tls */
r = pthread_create(&co->thrd_poll[i], NULL, __sxmpl_thread, bundle); /* and here, alloc tls */
if(r) goto __fail5;
else {
bundle = (void *)0xdead;
@ -1168,8 +1168,8 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
char hostbuf[2048];
void *buf = NULL;
char *bbuf;
sntllv2_head_t *head;
sntllv2_bundle_t *bundle;
sxmplv2_head_t *head;
sxmplv2_bundle_t *bundle;
sxmsg_t *msg;
size_t rd, wr;
int i;
@ -1290,22 +1290,22 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
co->messages[0] = msg;
}
bbuf = (char *)buf;
bbuf += sizeof(sntllv2_head_t);
head = (sntllv2_head_t *)buf;
bbuf += sizeof(sxmplv2_head_t);
head = (sxmplv2_head_t *)buf;
sexp_t *sx;
size_t ln;
while(co->flags & SNSX_BATCHMODE) {
/* form a message -- credentials */
ln = snprintf(bbuf, 65535 - sizeof(sntllv2_head_t), "(auth-set-credentials \"%s\" \"%s\")",
ln = snprintf(bbuf, 65535 - sizeof(sxmplv2_head_t), "(auth-set-credentials \"%s\" \"%s\")",
login ? login : "nil", passwd ? passwd : "nil");
head->opcode = SNE_SUCCESS;
head->payload_length = ln;
wr = __conn_write(co, buf, ln + sizeof(sntllv2_head_t));
wr = __conn_write(co, buf, ln + sizeof(sxmplv2_head_t));
if(wr < 0) goto __fail2;
rd = __conn_read(co, head, sizeof(sntllv2_head_t));
rd = __conn_read(co, head, sizeof(sxmplv2_head_t));
if(rd < 0) goto __fail2;
if(head->opcode != SNE_SUCCESS) {
r = head->opcode;
@ -1314,12 +1314,12 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
/* ok, get available channels */
head->opcode = SNE_SUCCESS;
ln = snprintf(bbuf, 65535 - sizeof(sntllv2_head_t), "(get-channels-list)");
ln = snprintf(bbuf, 65535 - sizeof(sxmplv2_head_t), "(get-channels-list)");
head->payload_length = ln;
wr = __conn_write(co, buf, ln + sizeof(sntllv2_head_t));
wr = __conn_write(co, buf, ln + sizeof(sxmplv2_head_t));
if(wr < 0) goto __fail2;
rd = __conn_read(co, head, sizeof(sntllv2_head_t));
rd = __conn_read(co, head, sizeof(sxmplv2_head_t));
if(rd < 0) goto __fail2;
if(head->opcode != SNE_SUCCESS) goto __fail2;
if(!head->payload_length) goto __fail2;
@ -1337,7 +1337,7 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
/* write back */
head->opcode = r;
head->payload_length = 0;
wr = __conn_write(co, head, sizeof(sntllv2_head_t));
wr = __conn_write(co, head, sizeof(sxmplv2_head_t));
if(wr < 0) {
r = SNE_LINKERROR; goto __fail2;}
if(r != SNE_SUCCESS) { r = SNE_LINKERROR; goto __fail2;}
@ -1352,15 +1352,15 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
free(msg);
/* and now we're need to create a thread poll */
if(!(bundle = malloc(sizeof(sntllv2_bundle_t)))) { r = SNE_ENOMEM; goto __fail4; }
if(!(bundle = malloc(sizeof(sxmplv2_bundle_t)))) { r = SNE_ENOMEM; goto __fail4; }
else {
bundle->buf = buf;
bundle->conn = co;
}
for(i = 0; i < MAX_SNTLLTHREADS; i++) {
if(bundle == (void *)0xdead) bundle = __sntll_bundle_create(co);
if(bundle == (void *)0xdead) bundle = __sxmpl_bundle_create(co);
if(!bundle) goto __fail5;
r = pthread_create(&co->thrd_poll[i], NULL, __sntll_thread, bundle);
r = pthread_create(&co->thrd_poll[i], NULL, __sxmpl_thread, bundle);
if(r) goto __fail5;
else {
pthread_detach(co->thrd_poll[i]);
@ -1398,14 +1398,14 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
int connection_close(conn_t *co)
{
sntllv2_head_t mhead;
sxmplv2_head_t mhead;
memset(&mhead, 0, sizeof(sntllv2_head_t));
memset(&mhead, 0, sizeof(sxmplv2_head_t));
/* setup header */
mhead.attr = SXMSG_LINK | SXMSG_CLOSED;
pthread_mutex_lock(&(co->sslinout[1]));
__conn_write(co, &mhead, sizeof(sntllv2_head_t));
__conn_write(co, &mhead, sizeof(sxmplv2_head_t));
pthread_mutex_unlock(&(co->sslinout[1]));
/* we will not wait anything */

@ -1,5 +1,5 @@
/*
* Secure Network Transport Layer Library implementation.
* Secure X Message Passing Library v2 implementation.
* This is a proprietary software. See COPYING for further details.
*
* (c) Askele Group 2013-2015 <http://askele.com>

Loading…
Cancel
Save