summaryrefslogtreecommitdiff
path: root/ecp/test
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-01-19 02:49:47 +0100
committerUros Majstorovic <majstor@majstor.org>2022-01-19 02:49:47 +0100
commita4f22127be441c4c158c10fe65916872d99253d2 (patch)
tree0d476ce70c63b93ee2c4a2b3fafd0fa3df66b998 /ecp/test
parente356da0b15f8fef6559c7761a1b04b8f6e2dc649 (diff)
code cleanup
Diffstat (limited to 'ecp/test')
-rw-r--r--ecp/test/basic.c12
-rw-r--r--ecp/test/client.c8
-rw-r--r--ecp/test/dir.c13
-rw-r--r--ecp/test/echo.c4
-rw-r--r--ecp/test/frag.c12
-rw-r--r--ecp/test/init.c15
-rw-r--r--ecp/test/init_vconn.c21
-rw-r--r--ecp/test/server.c4
-rw-r--r--ecp/test/stress.c6
-rw-r--r--ecp/test/vc_client.c10
-rw-r--r--ecp/test/vc_client_t.c20
-rw-r--r--ecp/test/vc_server.c22
-rw-r--r--ecp/test/vcs.c8
-rw-r--r--ecp/test/voip.c8
14 files changed, 95 insertions, 68 deletions
diff --git a/ecp/test/basic.c b/ecp/test/basic.c
index eb14b0e..0f4e322 100644
--- a/ecp/test/basic.c
+++ b/ecp/test/basic.c
@@ -68,8 +68,8 @@ int main(int argc, char *argv[]) {
rv = ecp_dhkey_gen(&ctx_s, &key_perma_s);
printf("ecp_dhkey_gen RV:%d\n", rv);
- rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock_s, &ctx_s, &key_perma_s);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock_s, "0.0.0.0:3000");
printf("ecp_sock_open RV:%d\n", rv);
@@ -88,8 +88,8 @@ int main(int argc, char *argv[]) {
rv = ecp_dhkey_gen(&ctx_c, &key_perma_c);
printf("ecp_dhkey_gen RV:%d\n", rv);
- rv = ecp_sock_create(&sock_c, &ctx_c, &key_perma_c);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock_c, &ctx_c, &key_perma_c);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock_c, NULL);
printf("ecp_sock_open RV:%d\n", rv);
@@ -100,8 +100,8 @@ int main(int argc, char *argv[]) {
rv = ecp_node_init(&node, &key_perma_s.public, "127.0.0.1:3000");
printf("ecp_node_init RV:%d\n", rv);
- rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST);
- printf("ecp_conn_create RV:%d\n", rv);
+ rv = ecp_conn_init(&conn, &sock_c, CTYPE_TEST);
+ printf("ecp_conn_init RV:%d\n", rv);
rv = ecp_conn_open(&conn, &node);
printf("ecp_conn_open RV:%d\n", rv);
diff --git a/ecp/test/client.c b/ecp/test/client.c
index e6c8208..577a888 100644
--- a/ecp/test/client.c
+++ b/ecp/test/client.c
@@ -58,8 +58,8 @@ int main(int argc, char *argv[]) {
handler.msg[MTYPE_MSG] = handle_msg;
ctx.handler[CTYPE_TEST] = &handler;
- rv = ecp_sock_create(&sock, &ctx, NULL);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock, &ctx, NULL);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock, NULL);
printf("ecp_sock_open RV:%d\n", rv);
@@ -70,8 +70,8 @@ int main(int argc, char *argv[]) {
rv = ecp_util_node_load(&ctx, &node, argv[1]);
printf("ecp_util_node_load RV:%d\n", rv);
- rv = ecp_conn_create(&conn, &sock, CTYPE_TEST);
- printf("ecp_conn_create RV:%d\n", rv);
+ rv = ecp_conn_init(&conn, &sock, CTYPE_TEST);
+ printf("ecp_conn_init RV:%d\n", rv);
rv = ecp_conn_open(&conn, &node);
printf("ecp_conn_open RV:%d\n", rv);
diff --git a/ecp/test/dir.c b/ecp/test/dir.c
index 413cd03..0c2ac72 100644
--- a/ecp/test/dir.c
+++ b/ecp/test/dir.c
@@ -5,6 +5,7 @@
#include "core.h"
#include "cr.h"
#include "dir.h"
+#include "dir_srv.h"
ECPContext ctx_s;
ECPSocket sock_s;
@@ -51,8 +52,8 @@ int main(int argc, char *argv[]) {
rv = ecp_dhkey_gen(&ctx_s, &key_perma_s);
printf("ecp_dhkey_gen RV:%d\n", rv);
- rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock_s, &ctx_s, &key_perma_s);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock_s, "0.0.0.0:3000");
printf("ecp_sock_open RV:%d\n", rv);
@@ -70,8 +71,8 @@ int main(int argc, char *argv[]) {
rv = ecp_dhkey_gen(&ctx_c, &key_perma_c);
printf("ecp_dhkey_gen RV:%d\n", rv);
- rv = ecp_sock_create(&sock_c, &ctx_c, &key_perma_c);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock_c, &ctx_c, &key_perma_c);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock_c, NULL);
printf("ecp_sock_open RV:%d\n", rv);
@@ -82,8 +83,8 @@ int main(int argc, char *argv[]) {
rv = ecp_node_init(&node, &key_perma_s.public, "127.0.0.1:3000");
printf("ecp_node_init RV:%d\n", rv);
- rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST);
- printf("ecp_conn_create RV:%d\n", rv);
+ rv = ecp_conn_init(&conn, &sock_c, CTYPE_TEST);
+ printf("ecp_conn_init RV:%d\n", rv);
rv = ecp_conn_get_dirlist(&conn, &node);
printf("ecp_conn_get_dirlist RV:%d\n", rv);
diff --git a/ecp/test/echo.c b/ecp/test/echo.c
index ff9c01c..f3057df 100644
--- a/ecp/test/echo.c
+++ b/ecp/test/echo.c
@@ -43,8 +43,8 @@ int main(int argc, char *argv[]) {
rv = ecp_util_key_load(&ctx_s, &key_perma_s, argv[2]);
printf("ecp_util_key_load RV:%d\n", rv);
- rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock_s, &ctx_s, &key_perma_s);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock_s, argv[1]);
printf("ecp_sock_open RV:%d\n", rv);
diff --git a/ecp/test/frag.c b/ecp/test/frag.c
index bf7c1a2..73e45cb 100644
--- a/ecp/test/frag.c
+++ b/ecp/test/frag.c
@@ -74,8 +74,8 @@ int main(int argc, char *argv[]) {
rv = ecp_dhkey_gen(&ctx_s, &key_perma_s);
printf("ecp_dhkey_gen RV:%d\n", rv);
- rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock_s, &ctx_s, &key_perma_s);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock_s, "0.0.0.0:3000");
printf("ecp_sock_open RV:%d\n", rv);
@@ -94,8 +94,8 @@ int main(int argc, char *argv[]) {
rv = ecp_dhkey_gen(&ctx_c, &key_perma_c);
printf("ecp_dhkey_gen RV:%d\n", rv);
- rv = ecp_sock_create(&sock_c, &ctx_c, &key_perma_c);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock_c, &ctx_c, &key_perma_c);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock_c, NULL);
printf("ecp_sock_open RV:%d\n", rv);
@@ -106,8 +106,8 @@ int main(int argc, char *argv[]) {
rv = ecp_node_init(&node, &key_perma_s.public, "127.0.0.1:3000");
printf("ecp_node_init RV:%d\n", rv);
- rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST);
- printf("ecp_conn_create RV:%d\n", rv);
+ rv = ecp_conn_init(&conn, &sock_c, CTYPE_TEST);
+ printf("ecp_conn_init RV:%d\n", rv);
rv = ecp_rbuf_create(&conn, NULL, NULL, 0, &rbuf_recv, rbuf_r_msg, 128);
printf("ecp_rbuf_create RV:%d\n", rv);
diff --git a/ecp/test/init.c b/ecp/test/init.c
index 4dff693..7b59578 100644
--- a/ecp/test/init.c
+++ b/ecp/test/init.c
@@ -14,8 +14,19 @@ static int v_rng(void *buf, size_t bufsize) {
return 0;
}
-static ECPConnection *conn_alloc(unsigned char type) {
- return malloc(sizeof(ECPConnection));
+static ECPConnection *conn_alloc(ECPSocket *sock, unsigned char type) {
+ ECPConnection *conn;
+ int rv;
+
+ conn = malloc(sizeof(ECPConnection));
+ if (conn == NULL) return NULL;
+
+ rv = ecp_conn_init(conn, sock, type);
+ if (rv) {
+ free(conn);
+ return NULL;
+ }
+ return conn;
}
static void conn_free(ECPConnection *conn) {
diff --git a/ecp/test/init_vconn.c b/ecp/test/init_vconn.c
index b79aa3d..59e9517 100644
--- a/ecp/test/init_vconn.c
+++ b/ecp/test/init_vconn.c
@@ -15,16 +15,31 @@ static int v_rng(void *buf, size_t bufsize) {
return 0;
}
-static ECPConnection *conn_alloc(unsigned char type) {
+static ECPConnection *conn_alloc(ECPSocket *sock, unsigned char type) {
+ ECPConnection *conn;
+ int rv;
+
switch (type) {
case ECP_CTYPE_VCONN:
- return malloc(sizeof(ECPVConnIn));
+ conn = malloc(sizeof(ECPVConnIn));
+ break;
default:
- return malloc(sizeof(ECPConnection));
+ conn = malloc(sizeof(ECPConnection));
+ break;
+ }
+ if (conn == NULL) return NULL;
+
+ rv = ecp_conn_init(conn, sock, type);
+ if (rv) {
+ printf("free1\n");
+ free(conn);
+ return NULL;
}
+ return conn;
}
static void conn_free(ECPConnection *conn) {
+ printf("free2\n");
free(conn);
}
diff --git a/ecp/test/server.c b/ecp/test/server.c
index f70cc79..fabaf4e 100644
--- a/ecp/test/server.c
+++ b/ecp/test/server.c
@@ -46,8 +46,8 @@ int main(int argc, char *argv[]) {
rv = ecp_util_key_load(&ctx, &key_perma, argv[2]);
printf("ecp_util_key_load RV:%d\n", rv);
- rv = ecp_sock_create(&sock, &ctx, &key_perma);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock, &ctx, &key_perma);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock, argv[1]);
printf("ecp_sock_open RV:%d\n", rv);
diff --git a/ecp/test/stress.c b/ecp/test/stress.c
index 4dae990..6eed851 100644
--- a/ecp/test/stress.c
+++ b/ecp/test/stress.c
@@ -202,7 +202,7 @@ int main(int argc, char *argv[]) {
if (!rv) rv = ecp_dhkey_gen(&ctx_s, &key_perma_s);
for (i=0; i<num_s; i++) {
- if (!rv) rv = ecp_sock_create(&sock_s[i], &ctx_s, &key_perma_s);
+ if (!rv) rv = ecp_sock_init(&sock_s[i], &ctx_s, &key_perma_s);
strcpy(addr, "0.0.0.0:");
sprintf(addr+strlen(addr), "%d", 3000+i);
@@ -230,7 +230,7 @@ int main(int argc, char *argv[]) {
ctx_c[i].handler[CTYPE_TEST] = &handler_c;
if (!rv) rv = ecp_dhkey_gen(&ctx_c[i], &key_perma_c[i]);
- if (!rv) rv = ecp_sock_create(&sock_c[i], &ctx_c[i], &key_perma_c[i]);
+ if (!rv) rv = ecp_sock_init(&sock_c[i], &ctx_c[i], &key_perma_c[i]);
if (!rv) rv = ecp_sock_open(&sock_c[i], NULL);
if (!rv) rv = pthread_create(&r_thd[i], NULL, (void *(*)(void *))ecp_receiver, (void *)&sock_c[i]);
@@ -239,7 +239,7 @@ int main(int argc, char *argv[]) {
sprintf(addr+strlen(addr), "%d", 3000 + (i % num_s));
if (!rv) rv = ecp_node_init(&node[i], &key_perma_s.public, addr);
- if (!rv) rv = ecp_conn_create(&conn[i], &sock_c[i], CTYPE_TEST);
+ if (!rv) rv = ecp_conn_init(&conn[i], &sock_c[i], CTYPE_TEST);
conn[i].conn_data = (void *)i;
if (!rv) rv = ecp_conn_open(&conn[i], &node[i]);
diff --git a/ecp/test/vc_client.c b/ecp/test/vc_client.c
index d669697..cd0ea44 100644
--- a/ecp/test/vc_client.c
+++ b/ecp/test/vc_client.c
@@ -14,7 +14,7 @@ ECPConnHandler handler;
ECPConnection conn;
ECPNode node;
-ECPVConnection vconn[20];
+ECPVConnOut vconn[20];
ECPNode vconn_node[20];
#define CTYPE_TEST 0
@@ -63,8 +63,8 @@ int main(int argc, char *argv[]) {
handler.msg[MTYPE_MSG] = handle_msg;
ctx.handler[CTYPE_TEST] = &handler;
- rv = ecp_sock_create(&sock, &ctx, NULL);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock, &ctx, NULL);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock, NULL);
printf("ecp_sock_open RV:%d\n", rv);
@@ -80,8 +80,8 @@ int main(int argc, char *argv[]) {
printf("ecp_util_node_load RV:%d\n", rv);
}
- rv = ecp_conn_create(&conn, &sock, CTYPE_TEST);
- printf("ecp_conn_create RV:%d\n", rv);
+ rv = ecp_conn_init(&conn, &sock, CTYPE_TEST);
+ printf("ecp_conn_init RV:%d\n", rv);
rv = ecp_vconn_open(&conn, &node, vconn, vconn_node, argc-2);
printf("ecp_vconn_open RV:%d\n", rv);
diff --git a/ecp/test/vc_client_t.c b/ecp/test/vc_client_t.c
index b021c2d..968d643 100644
--- a/ecp/test/vc_client_t.c
+++ b/ecp/test/vc_client_t.c
@@ -15,7 +15,7 @@ ECPConnHandler handler;
ECPNode node;
ECPConnection conn;
-ECPVConnection vconn[20];
+ECPVConnOut vconn[20];
ECPNode vconn_node[20];
#define CTYPE_TEST 0
@@ -80,23 +80,23 @@ static void usage(char *arg) {
int main(int argc, char *argv[]) {
int rv, i;
-
+
if ((argc < 3) || (argc > 22)) usage(argv[0]);
-
+
rv = ecp_init(&ctx);
printf("ecp_init RV:%d\n", rv);
-
+
rv = ecp_conn_handler_init(&handler);
handler.msg[ECP_MTYPE_OPEN] = handle_open;
handler.msg[MTYPE_MSG] = handle_msg;
ctx.handler[CTYPE_TEST] = &handler;
-
- rv = ecp_sock_create(&sock, &ctx, NULL);
- printf("ecp_sock_create RV:%d\n", rv);
+
+ rv = ecp_sock_init(&sock, &ctx, NULL);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock, NULL);
printf("ecp_sock_open RV:%d\n", rv);
-
+
rv = ecp_start_receiver(&sock);
printf("ecp_start_receiver RV:%d\n", rv);
@@ -108,8 +108,8 @@ int main(int argc, char *argv[]) {
printf("ecp_util_node_load RV:%d\n", rv);
}
- rv = ecp_conn_create(&conn, &sock, CTYPE_TEST);
- printf("ecp_conn_create RV:%d\n", rv);
+ rv = ecp_conn_init(&conn, &sock, CTYPE_TEST);
+ printf("ecp_conn_init RV:%d\n", rv);
rv = ecp_vconn_open(&conn, &node, vconn, vconn_node, argc-2);
printf("ecp_vconn_open RV:%d\n", rv);
diff --git a/ecp/test/vc_server.c b/ecp/test/vc_server.c
index 55f15d1..b86d7b0 100644
--- a/ecp/test/vc_server.c
+++ b/ecp/test/vc_server.c
@@ -24,7 +24,7 @@ ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned
}
ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) {
- // printf("MSG S:%s size:%ld\n", p, s);
+ printf("MSG S:%s size:%ld\n", p, s);
char *msg = "VAISTINU JE CAR!";
unsigned char buf[1000];
@@ -42,34 +42,34 @@ static void usage(char *arg) {
int main(int argc, char *argv[]) {
int rv;
-
+
if (argc != 3) usage(argv[0]);
-
+
rv = ecp_init(&ctx);
printf("ecp_init RV:%d\n", rv);
-
+
rv = ecp_conn_handler_init(&handler);
handler.msg[ECP_MTYPE_OPEN] = handle_open;
handler.msg[MTYPE_MSG] = handle_msg;
ctx.handler[CTYPE_TEST] = &handler;
-
+
rv = ecp_util_key_load(&ctx, &key_perma, argv[1]);
printf("ecp_util_key_load RV:%d\n", rv);
-
- rv = ecp_sock_create(&sock, &ctx, &key_perma);
- printf("ecp_sock_create RV:%d\n", rv);
+
+ rv = ecp_sock_init(&sock, &ctx, &key_perma);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock, NULL);
printf("ecp_sock_open RV:%d\n", rv);
-
+
rv = ecp_start_receiver(&sock);
printf("ecp_start_receiver RV:%d\n", rv);
rv = ecp_util_node_load(&ctx, &node, argv[2]);
printf("ecp_util_node_load RV:%d\n", rv);
- rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_VLINK);
- printf("ecp_conn_create RV:%d\n", rv);
+ rv = ecp_conn_init(&conn, &sock, ECP_CTYPE_VLINK);
+ printf("ecp_conn_init RV:%d\n", rv);
rv = ecp_conn_open(&conn, &node);
printf("ecp_conn_open RV:%d\n", rv);
diff --git a/ecp/test/vcs.c b/ecp/test/vcs.c
index 23e2557..f3a0156 100644
--- a/ecp/test/vcs.c
+++ b/ecp/test/vcs.c
@@ -30,8 +30,8 @@ int main(int argc, char *argv[]) {
rv = ecp_util_key_load(&ctx, &key_perma, argv[2]);
printf("ecp_util_key_load RV:%d\n", rv);
- rv = ecp_sock_create(&sock, &ctx, &key_perma);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock, &ctx, &key_perma);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock, argv[1]);
printf("ecp_sock_open RV:%d\n", rv);
@@ -43,8 +43,8 @@ int main(int argc, char *argv[]) {
rv = ecp_util_node_load(&ctx, &node, argv[3]);
printf("ecp_util_node_load RV:%d\n", rv);
- rv = ecp_conn_create(&conn, &sock, ECP_CTYPE_VLINK);
- printf("ecp_conn_create RV:%d\n", rv);
+ rv = ecp_conn_init(&conn, &sock, ECP_CTYPE_VLINK);
+ printf("ecp_conn_init RV:%d\n", rv);
rv = ecp_conn_open(&conn, &node);
printf("ecp_conn_open RV:%d\n", rv);
diff --git a/ecp/test/voip.c b/ecp/test/voip.c
index ad5032b..b0a9207 100644
--- a/ecp/test/voip.c
+++ b/ecp/test/voip.c
@@ -163,8 +163,8 @@ int main(int argc, char *argv[]) {
handler_c.msg[MTYPE_MSG] = handle_msg_c;
ctx_c.handler[CTYPE_TEST] = &handler_c;
- rv = ecp_sock_create(&sock_c, &ctx_c, NULL);
- printf("ecp_sock_create RV:%d\n", rv);
+ rv = ecp_sock_init(&sock_c, &ctx_c, NULL);
+ printf("ecp_sock_init RV:%d\n", rv);
rv = ecp_sock_open(&sock_c, NULL);
printf("ecp_sock_open RV:%d\n", rv);
@@ -175,8 +175,8 @@ int main(int argc, char *argv[]) {
rv = ecp_util_node_load(&ctx_c, &node, argv[1]);
printf("ecp_util_node_load RV:%d\n", rv);
- rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST);
- printf("ecp_conn_create RV:%d\n", rv);
+ rv = ecp_conn_init(&conn, &sock_c, CTYPE_TEST);
+ printf("ecp_conn_init RV:%d\n", rv);
rv = ecp_conn_open(&conn, &node);
printf("ecp_conn_open RV:%d\n", rv);