summaryrefslogtreecommitdiff
path: root/ecp/test/vc_client.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-03-31 13:09:12 +0200
committerUros Majstorovic <majstor@majstor.org>2022-03-31 13:09:12 +0200
commitf2bc5ddbeca144fa79208a5ac6a029da6ed5c10c (patch)
tree68f67274f3464256d051a4a5376e79a0d578838a /ecp/test/vc_client.c
parent55474b81146327e8cfa7702fa9366cc7da6562e7 (diff)
vconn bugfix
Diffstat (limited to 'ecp/test/vc_client.c')
-rw-r--r--ecp/test/vc_client.c95
1 files changed, 47 insertions, 48 deletions
diff --git a/ecp/test/vc_client.c b/ecp/test/vc_client.c
index cd0ea44..89602ca 100644
--- a/ecp/test/vc_client.c
+++ b/ecp/test/vc_client.c
@@ -1,70 +1,63 @@
-#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <stdlib.h>
+#include <stdio.h>
+
+#include <core.h>
+#include <vconn/vconn.h>
-#include "core.h"
-#include "vconn/vconn.h"
-#include "util.h"
+#include <util.h>
ECPContext ctx;
ECPSocket sock;
ECPConnHandler handler;
-
ECPConnection conn;
-ECPNode node;
-
-ECPVConnOut vconn[20];
-ECPNode vconn_node[20];
+ECPConnection vconn[3];
#define CTYPE_TEST 0
-#define MTYPE_MSG 8
-
-ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) {
- uint32_t seq = 0;
-
- ecp_conn_handle_open(conn, sq, t, p, s, b);
- if (s < 0) {
- printf("OPEN ERR:%ld\n", s);
- return s;
- }
-
- printf("OPEN!\n");
+#define MTYPE_MSG 0
- char *msg = "PERA JE CAR!";
- unsigned char buf[1156];
+static int handle_open(ECPConnection *conn, ECP2Buffer *b) {
+ char *_msg = "PERA JE CAR!";
+ ssize_t rv;
- strcpy((char *)buf, msg);
- ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1156);
+ printf("OPEN\n");
+ rv = ecp_msg_send(conn, MTYPE_MSG, (unsigned char *)_msg, strlen(_msg)+1);
- return s;
+ return ECP_OK;
}
-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);
- return s;
+static ssize_t handle_msg(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *b) {
+ printf("MSG:%s size:%ld\n", msg, msg_size);
+
+ return msg_size;
}
static void usage(char *arg) {
- fprintf(stderr, "Usage: %s <server.pub> <vcs1.pub> ... <vcsn.pub>\n", arg);
+ fprintf(stderr, "Usage: %s <server.pub> <address> <vcs0.pub> [ ... <vcsN.pub> ]\n", arg);
exit(1);
}
int main(int argc, char *argv[]) {
+ ECPDHKey key_perma;
+ ECPNode node;
+ ecp_ecdh_public_t node_pub;
+ ecp_ecdh_public_t vconn_pub[3];
int rv, i;
- if ((argc < 3) || (argc > 22)) usage(argv[0]);
+ if ((argc < 4) || (argc > 6)) 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;
+ ecp_conn_handler_init(&handler, handle_msg, handle_open, NULL, NULL);
+ ecp_ctx_set_handler(&ctx, &handler, CTYPE_TEST);
- rv = ecp_sock_init(&sock, &ctx, NULL);
- printf("ecp_sock_init RV:%d\n", rv);
+ rv = ecp_dhkey_gen(&key_perma);
+ printf("ecp_dhkey_gen RV:%d\n", rv);
+
+ rv = ecp_sock_create(&sock, &ctx, &key_perma);
+ printf("ecp_sock_create RV:%d\n", rv);
rv = ecp_sock_open(&sock, NULL);
printf("ecp_sock_open RV:%d\n", rv);
@@ -72,19 +65,25 @@ int main(int argc, char *argv[]) {
rv = ecp_start_receiver(&sock);
printf("ecp_start_receiver RV:%d\n", rv);
- rv = ecp_util_node_load(&ctx, &node, argv[1]);
- printf("ecp_util_node_load RV:%d\n", rv);
-
- for (i=0; i<argc-2; i++) {
- rv = ecp_util_node_load(&ctx, &vconn_node[i], argv[i+2]);
- printf("ecp_util_node_load RV:%d\n", rv);
+ for (i=3; i<argc; i++) {
+ rv = ecp_util_load_pub(&vconn_pub[i-3], argv[i]);
+ printf("ecp_util_load_pub RV:%d\n", rv);
}
- rv = ecp_conn_init(&conn, &sock, CTYPE_TEST);
- printf("ecp_conn_init RV:%d\n", rv);
+ rv = ecp_conn_create(&conn, &sock, CTYPE_TEST);
+ printf("ecp_conn_create RV:%d\n", rv);
- rv = ecp_vconn_open(&conn, &node, vconn, vconn_node, argc-2);
+ rv = ecp_vconn_create(vconn, vconn_pub, argc-3, &conn);
+ printf("ecp_vconn_create RV:%d\n", rv);
+
+ rv = ecp_util_load_pub(&node_pub, argv[1]);
+ printf("ecp_util_load_pub RV:%d\n", rv);
+
+ rv = ecp_node_init(&node, &node_pub, argv[2]);
+ printf("ecp_node_init RV:%d\n", rv);
+
+ rv = ecp_vconn_open(&conn, &node);
printf("ecp_vconn_open RV:%d\n", rv);
while (1) sleep(1);
-} \ No newline at end of file
+}