summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--code/core/core.c29
-rw-r--r--code/core/core.h18
-rw-r--r--code/core/timer.c4
-rw-r--r--code/proxy/proxy.c12
-rw-r--r--code/test/basic.c8
-rw-r--r--code/test/client.c6
-rw-r--r--code/test/echo.c2
-rw-r--r--code/test/pr_client.c6
-rw-r--r--code/test/pr_server.c6
-rw-r--r--code/test/server.c2
-rw-r--r--code/test/stress.c8
-rw-r--r--code/test/voip.c4
-rw-r--r--code/util/util.c8
13 files changed, 63 insertions, 50 deletions
diff --git a/code/core/core.c b/code/core/core.c
index 02d8ce2..a4ccfc5 100644
--- a/code/core/core.c
+++ b/code/core/core.c
@@ -648,7 +648,7 @@ int ecp_conn_handle_new(ECPSocket *sock, ECPConnection **_conn, ECPConnection *p
return rv;
}
-ssize_t ecp_conn_handle_open(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
+ssize_t ecp_conn_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) {
if (size < 0) return size;
#ifdef ECP_WITH_PTHREAD
@@ -677,7 +677,7 @@ ssize_t ecp_conn_handle_open(ECPConnection *conn, unsigned char mtype, unsigned
return ECP_ERR;
}
-ssize_t ecp_conn_handle_kget(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
+ssize_t ecp_conn_handle_kget(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) {
if (conn->out) {
ECPContext *ctx = conn->sock->ctx;
#ifdef ECP_WITH_PTHREAD
@@ -690,7 +690,7 @@ ssize_t ecp_conn_handle_kget(ECPConnection *conn, unsigned char mtype, unsigned
if ((size < 0) && !conn_is_open) {
ecp_conn_handler_msg_t *handler = ctx->handler[conn->type] ? ctx->handler[conn->type]->msg[ECP_MTYPE_OPEN] : NULL;
- return handler ? handler(conn, mtype, msg, size) : size;
+ return handler ? handler(conn, seq, mtype, msg, size) : size;
}
if (size < 0) return size;
@@ -722,7 +722,7 @@ ssize_t ecp_conn_handle_kget(ECPConnection *conn, unsigned char mtype, unsigned
return ECP_ERR;
}
-ssize_t ecp_conn_handle_kput(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
+ssize_t ecp_conn_handle_kput(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) {
if (size < 0) return size;
if (conn->out) {
@@ -743,7 +743,7 @@ ssize_t ecp_conn_handle_kput(ECPConnection *conn, unsigned char mtype, unsigned
return ECP_ERR;
}
-ssize_t ecp_conn_handle_exec(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
+ssize_t ecp_conn_handle_exec(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) {
if (size < 0) return size;
return ecp_pkt_handle(conn->sock, NULL, conn, msg, size);
}
@@ -951,7 +951,8 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *proxy,
ECPConnection *conn = NULL;
ECPDHKey *key = NULL;
int rv = ECP_OK;
- uint32_t c_seq, p_seq, n_seq, seq_bitmap;
+ ecp_seq_t c_seq, p_seq, n_seq;
+ uint32_t seq_bitmap;
ssize_t pld_size, cnt_size, proc_size;
s_idx = (packet[ECP_SIZE_PROTO] & 0xF0) >> 4;
@@ -1085,7 +1086,17 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *proxy,
#endif
cnt_size = pld_size-ECP_SIZE_PLD_HDR;
- proc_size = ecp_msg_handle(conn, payload+pld_size-cnt_size, cnt_size);
+
+#ifdef WITH_RBUF
+ if (conn->rbuf.recv) {
+ proc_size = ecp_msg_handle(conn, p_seq, payload+pld_size-cnt_size, cnt_size);
+ } else {
+ proc_size = ecp_rbuf_recv_store(conn, p_seq, payload+pld_size-cnt_size, cnt_size);
+ }
+#else
+ proc_size = ecp_msg_handle(conn, p_seq, payload+pld_size-cnt_size, cnt_size);
+#endif
+
if (proc_size < 0) rv = ECP_ERR_HANDLE;
if (!rv) cnt_size -= proc_size;
@@ -1139,7 +1150,7 @@ ssize_t ecp_pkt_recv(ECPSocket *sock, ECPNetAddr *addr, unsigned char *packet, s
return rv;
}
-ssize_t ecp_msg_handle(ECPConnection *conn, unsigned char *msg, size_t msg_size) {
+ssize_t ecp_msg_handle(ECPConnection *conn, ecp_seq_t seq, unsigned char *msg, size_t msg_size) {
ecp_conn_handler_msg_t *handler = NULL;
ssize_t rv = 0;
unsigned char mtype = 0;
@@ -1156,7 +1167,7 @@ ssize_t ecp_msg_handle(ECPConnection *conn, unsigned char *msg, size_t msg_size)
if (conn->out) ecp_timer_pop(conn, mtype);
handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[mtype] : NULL;
if (handler) {
- rv = handler(conn, mtype, msg, rem_size);
+ rv = handler(conn, seq, mtype, msg, rem_size);
if (rv < 0) return rv;
if (rv == 0) rv = rem_size;
if (rv < ECP_MIN_MSG) rv = ECP_MIN_MSG;
diff --git a/code/core/core.h b/code/core/core.h
index 4c2b74c..6c680f9 100644
--- a/code/core/core.h
+++ b/code/core/core.h
@@ -95,10 +95,12 @@ struct ECPContext;
struct ECPSocket;
struct ECPConnection;
+typedef uint32_t ecp_seq_t;
+
typedef int ecp_rng_t (void *, size_t);
typedef int ecp_conn_handler_new_t (struct ECPSocket *s, struct ECPConnection **c, struct ECPConnection *p, unsigned char s_idx, unsigned char c_idx, unsigned char *pub, ecp_aead_key_t *sh, unsigned char *msg, size_t sz);
-typedef ssize_t ecp_conn_handler_msg_t (struct ECPConnection *c, unsigned char t, unsigned char *msg, ssize_t sz);
+typedef ssize_t ecp_conn_handler_msg_t (struct ECPConnection *c, ecp_seq_t s, unsigned char t, unsigned char *msg, ssize_t sz);
typedef struct ECPConnection * ecp_conn_alloc_t (unsigned char t);
typedef void ecp_conn_free_t (struct ECPConnection *c);
@@ -235,8 +237,8 @@ typedef struct ECPConnection {
unsigned char out;
unsigned char flags;
unsigned short refcount;
- uint32_t seq_out;
- uint32_t seq_in;
+ ecp_seq_t seq_out;
+ ecp_seq_t seq_in;
uint32_t seq_in_bitmap;
ECPSocket *sock;
ECPNode node;
@@ -287,10 +289,10 @@ int ecp_conn_close(ECPConnection *conn, unsigned int timeout);
int ecp_conn_handler_init(ECPConnHandler *handler);
ssize_t ecp_conn_send_open(ECPConnection *conn);
int ecp_conn_handle_new(ECPSocket *sock, ECPConnection **_conn, ECPConnection *proxy, unsigned char s_idx, unsigned char c_idx, unsigned char *c_public, ecp_aead_key_t *shsec, unsigned char *payload, size_t payload_size);
-ssize_t ecp_conn_handle_open(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size);
-ssize_t ecp_conn_handle_kget(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size);
-ssize_t ecp_conn_handle_kput(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size);
-ssize_t ecp_conn_handle_exec(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size);
+ssize_t ecp_conn_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size);
+ssize_t ecp_conn_handle_kget(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size);
+ssize_t ecp_conn_handle_kput(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size);
+ssize_t ecp_conn_handle_exec(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size);
int ecp_conn_dhkey_new(ECPConnection *conn);
int ecp_conn_dhkey_new_pub(ECPConnection *conn, unsigned char idx, unsigned char *public);
@@ -305,7 +307,7 @@ ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *proxy,
ssize_t ecp_pkt_send(ECPSocket *sock, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size);
ssize_t ecp_pkt_recv(ECPSocket *sock, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size);
-ssize_t ecp_msg_handle(ECPConnection *conn, unsigned char *msg, size_t msg_size);
+ssize_t ecp_msg_handle(ECPConnection *conn, ecp_seq_t seq, unsigned char *msg, size_t msg_size);
unsigned char *ecp_pld_get_buf(unsigned char *payload);
void ecp_pld_set_type(unsigned char *payload, unsigned char mtype);
unsigned char ecp_pld_get_type(unsigned char *payload);
diff --git a/code/core/timer.c b/code/core/timer.c
index 47a3b9d..0d06ba4 100644
--- a/code/core/timer.c
+++ b/code/core/timer.c
@@ -195,9 +195,9 @@ unsigned int ecp_timer_exe(ECPSocket *sock) {
if (_rv < 0) rv = _rv;
}
if (!rv) rv = ecp_timer_push(to_exec+i);
- if (rv && (rv != ECP_ERR_CLOSED) && handler) handler(conn, mtype, NULL, rv);
+ if (rv && (rv != ECP_ERR_CLOSED) && handler) handler(conn, 0, mtype, NULL, rv);
} else if (handler) {
- handler(conn, mtype, NULL, ECP_ERR_TIMEOUT);
+ handler(conn, 0, mtype, NULL, ECP_ERR_TIMEOUT);
}
#ifdef ECP_WITH_PTHREAD
pthread_mutex_lock(&conn->mutex);
diff --git a/code/proxy/proxy.c b/code/proxy/proxy.c
index c6bded8..6e84dc3 100644
--- a/code/proxy/proxy.c
+++ b/code/proxy/proxy.c
@@ -95,7 +95,7 @@ static ssize_t proxyf_open(ECPConnection *conn) {
return _proxyf_send_open(conn);
}
-static ssize_t proxyf_handle_open(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
+static ssize_t proxyf_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) {
if (conn->type != ECP_CTYPE_PROXYF) return ECP_ERR;
if (conn->out) {
@@ -106,7 +106,7 @@ static ssize_t proxyf_handle_open(ECPConnection *conn, unsigned char mtype, unsi
conn = conn_p->next;
}
handler = conn->sock->ctx->handler[conn->type] ? conn->sock->ctx->handler[conn->type]->msg[ECP_MTYPE_OPEN] : NULL;
- return handler ? handler(conn, mtype, msg, size) : size;
+ return handler ? handler(conn, seq, mtype, msg, size) : size;
}
return 0;
} else {
@@ -145,7 +145,7 @@ static ssize_t proxyf_handle_open(ECPConnection *conn, unsigned char mtype, unsi
return ECP_ERR;
}
-static ssize_t proxyf_handle_relay(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
+static ssize_t proxyf_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) {
ECPContext *ctx = conn->sock->ctx;
ECPConnection *conn_out = NULL;
ECPConnProxyF *conn_p = (ECPConnProxyF *)conn;
@@ -250,14 +250,14 @@ static ssize_t proxyb_open(ECPConnection *conn) {
return ecp_timer_send(conn, _proxyb_send_open, ECP_MTYPE_OPEN, 3, 500);
}
-static ssize_t proxyb_handle_open(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
+static ssize_t proxyb_handle_open(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) {
ssize_t rv;
if (size < 0) return size;
if (conn->type != ECP_CTYPE_PROXYB) return ECP_ERR;
- rv = ecp_conn_handle_open(conn, mtype, msg, size);
+ rv = ecp_conn_handle_open(conn, seq, mtype, msg, size);
if (rv < 0) return rv;
if (conn->out) {
@@ -270,7 +270,7 @@ static ssize_t proxyb_handle_open(ECPConnection *conn, unsigned char mtype, unsi
return ECP_ERR;
}
-static ssize_t proxyb_handle_relay(ECPConnection *conn, unsigned char mtype, unsigned char *msg, ssize_t size) {
+static ssize_t proxyb_handle_relay(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size) {
ECPContext *ctx = conn->sock->ctx;
unsigned char *payload = NULL;
ssize_t rv;
diff --git a/code/test/basic.c b/code/test/basic.c
index 36dfc2e..c9f6bd5 100644
--- a/code/test/basic.c
+++ b/code/test/basic.c
@@ -20,10 +20,10 @@ ECPConnection conn;
#define CTYPE_TEST 0
#define MTYPE_MSG 8
-ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_open_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
uint32_t seq = 0;
- ecp_conn_handle_open(conn, t, p, s);
+ ecp_conn_handle_open(conn, sq, t, p, s);
if (s < 0) {
printf("OPEN ERR:%ld\n", s);
return 0;
@@ -39,12 +39,12 @@ ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ss
return 0;
}
-ssize_t handle_msg_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
printf("MSG C:%s size:%ld\n", p, s);
return s;
}
-ssize_t handle_msg_s(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_s(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
printf("MSG S:%s size:%ld\n", p, s);
unsigned char payload[ECP_SIZE_PLD(1000)];
diff --git a/code/test/client.c b/code/test/client.c
index 3f33d71..6e45df4 100644
--- a/code/test/client.c
+++ b/code/test/client.c
@@ -16,10 +16,10 @@ ECPConnection conn;
#define CTYPE_TEST 0
#define MTYPE_MSG 8
-ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_open_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
uint32_t seq = 0;
- ecp_conn_handle_open(conn, t, p, s);
+ ecp_conn_handle_open(conn, sq, t, p, s);
if (s < 0) {
printf("OPEN ERR:%ld\n", s);
return 0;
@@ -35,7 +35,7 @@ ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ss
return 0;
}
-ssize_t handle_msg_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
printf("MSG C:%s size:%ld\n", p, s);
return s;
}
diff --git a/code/test/echo.c b/code/test/echo.c
index 2494868..fe17901 100644
--- a/code/test/echo.c
+++ b/code/test/echo.c
@@ -14,7 +14,7 @@ ECPConnHandler handler_s;
#define CTYPE_TEST 0
#define MTYPE_MSG 8
-ssize_t handle_msg_s(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_s(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
ssize_t rv = ecp_send(conn, p-ECP_SIZE_MSG_HDR, ECP_SIZE_MSG_HDR+s);
return s;
diff --git a/code/test/pr_client.c b/code/test/pr_client.c
index 7d0cd90..7b80d6f 100644
--- a/code/test/pr_client.c
+++ b/code/test/pr_client.c
@@ -20,10 +20,10 @@ ECPNode node_proxy[20];
#define CTYPE_TEST 0
#define MTYPE_MSG 8
-ssize_t handle_open(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
uint32_t seq = 0;
- ecp_conn_handle_open(conn, t, p, s);
+ ecp_conn_handle_open(conn, sq, t, p, s);
if (s < 0) {
printf("OPEN ERR:%ld\n", s);
return 0;
@@ -41,7 +41,7 @@ ssize_t handle_open(ECPConnection *conn, unsigned char t, unsigned char *p, ssiz
return 0;
}
-ssize_t handle_msg(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
printf("MSG S:%s size:%ld\n", p, s);
return s;
}
diff --git a/code/test/pr_server.c b/code/test/pr_server.c
index 0f898ce..2fd81a6 100644
--- a/code/test/pr_server.c
+++ b/code/test/pr_server.c
@@ -18,12 +18,12 @@ ECPConnection conn;
#define CTYPE_TEST 0
#define MTYPE_MSG 8
-ssize_t handle_open(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
printf("OPEN RECEIVED\n");
- return ecp_conn_handle_open(conn, t, p, s);
+ return ecp_conn_handle_open(conn, sq, t, p, s);
}
-ssize_t handle_msg(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
printf("MSG S:%s size:%ld\n", p, s);
unsigned char payload[ECP_SIZE_PLD(1000)];
diff --git a/code/test/server.c b/code/test/server.c
index a83c1c5..6851cdf 100644
--- a/code/test/server.c
+++ b/code/test/server.c
@@ -14,7 +14,7 @@ ECPConnHandler handler_s;
#define CTYPE_TEST 0
#define MTYPE_MSG 8
-ssize_t handle_msg_s(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_s(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
printf("MSG S:%s size:%ld\n", p, s);
unsigned char payload[ECP_SIZE_PLD(1000)];
diff --git a/code/test/stress.c b/code/test/stress.c
index c76ebe9..42663fc 100644
--- a/code/test/stress.c
+++ b/code/test/stress.c
@@ -95,11 +95,11 @@ void *sender(ECPConnection *c) {
}
}
-ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_open_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
int idx = (int)(conn->conn_data);
int rv = 0;
- ecp_conn_handle_open(conn, t, p, s);
+ ecp_conn_handle_open(conn, sq, t, p, s);
rv = pthread_create(&s_thd[idx], NULL, (void *(*)(void *))sender, (void *)conn);
if (rv) {
char msg[256];
@@ -110,7 +110,7 @@ ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ss
return 0;
}
-ssize_t handle_msg_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
int idx = (int)(conn->conn_data);
unsigned char payload[ECP_SIZE_PLD(1000)];
@@ -125,7 +125,7 @@ ssize_t handle_msg_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssi
return s;
}
-ssize_t handle_msg_s(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_s(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
unsigned char payload[ECP_SIZE_PLD(1000)];
ecp_pld_set_type(payload, MTYPE_MSG);
ssize_t _rv = ecp_send(conn, payload, sizeof(payload));
diff --git a/code/test/voip.c b/code/test/voip.c
index 673bb8a..67e1afe 100644
--- a/code/test/voip.c
+++ b/code/test/voip.c
@@ -123,7 +123,7 @@ int a_init(void) {
opus_decoder_init(opus_dec, sample_rate, nchannels);
}
-ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_open_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
uint32_t seq = 0;
ecp_conn_handle_open(conn, t, p, s);
@@ -137,7 +137,7 @@ ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ss
return s;
}
-ssize_t handle_msg_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s) {
a_write(opus_dec, p, s, handle_plb, alsa_out_buf, alsa_frames);
return s;
}
diff --git a/code/util/util.c b/code/util/util.c
index e07748b..af47079 100644
--- a/code/util/util.c
+++ b/code/util/util.c
@@ -9,7 +9,7 @@ int ecp_util_key_save(ECPContext *ctx, ECPDHKey *key, char *filename) {
int fd;
ssize_t rv;
- if((fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) < 0) return ECP_ERR;
+ if ((fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) < 0) return ECP_ERR;
rv = write(fd, ctx->cr.dh_pub_get_buf(&key->public), ECP_ECDH_SIZE_KEY);
if (rv != ECP_ECDH_SIZE_KEY) {
close(fd);
@@ -29,7 +29,7 @@ int ecp_util_key_load(ECPContext *ctx, ECPDHKey *key, char *filename) {
ssize_t rv;
unsigned char buf[ECP_ECDH_SIZE_KEY];
- if((fd = open(filename, O_RDONLY)) < 0) return ECP_ERR;
+ if ((fd = open(filename, O_RDONLY)) < 0) return ECP_ERR;
rv = read(fd, buf, ECP_ECDH_SIZE_KEY);
if (rv != ECP_ECDH_SIZE_KEY) {
close(fd);
@@ -52,7 +52,7 @@ int ecp_util_node_save(ECPContext *ctx, ECPNode *node, char *filename) {
int fd;
ssize_t rv;
- if((fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) < 0) return ECP_ERR;
+ if ((fd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) < 0) return ECP_ERR;
rv = write(fd, ctx->cr.dh_pub_get_buf(&node->public), ECP_ECDH_SIZE_KEY);
if (rv != ECP_ECDH_SIZE_KEY) {
close(fd);
@@ -72,7 +72,7 @@ int ecp_util_node_load(ECPContext *ctx, ECPNode *node, char *filename) {
ssize_t rv;
unsigned char buf[ECP_ECDH_SIZE_KEY];
- if((fd = open(filename, O_RDONLY)) < 0) return ECP_ERR;
+ if ((fd = open(filename, O_RDONLY)) < 0) return ECP_ERR;
rv = read(fd, buf, ECP_ECDH_SIZE_KEY);
if (rv != ECP_ECDH_SIZE_KEY) {
close(fd);