diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-03-31 13:09:12 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-03-31 13:09:12 +0200 |
commit | f2bc5ddbeca144fa79208a5ac6a029da6ed5c10c (patch) | |
tree | 68f67274f3464256d051a4a5376e79a0d578838a /ecp/test/client.c | |
parent | 55474b81146327e8cfa7702fa9366cc7da6562e7 (diff) |
vconn bugfix
Diffstat (limited to 'ecp/test/client.c')
-rw-r--r-- | ecp/test/client.c | 90 |
1 files changed, 44 insertions, 46 deletions
diff --git a/ecp/test/client.c b/ecp/test/client.c index 577a888..d526f76 100644 --- a/ecp/test/client.c +++ b/ecp/test/client.c @@ -1,80 +1,78 @@ -#include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> -#include <stdlib.h> +#include <stdio.h> + +#include <core.h> -#include "core.h" -#include "util.h" +#include <util.h> ECPContext ctx; ECPSocket sock; ECPConnHandler handler; - -ECPNode node; ECPConnection conn; #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; - } - - char *msg = "PERA JE CAR!"; - unsigned char buf[1000]; - - strcpy((char *)buf, msg); - ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000); - - return s; -} +#define MTYPE_MSG 0 + +static int handle_open(ECPConnection *conn, ECP2Buffer *b) { + char *_msg = "PERA JE CAR!"; + ssize_t rv; + + printf("OPEN\n"); + rv = ecp_msg_send(conn, MTYPE_MSG, (unsigned char *)_msg, strlen(_msg)+1); -ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) { - printf("MSG C:%s size:%ld\n", p, s); - return s; + return ECP_OK; } +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 C:%s size:%ld\n", msg, msg_size); + return msg_size; +} static void usage(char *arg) { - fprintf(stderr, "Usage: %s <node.pub>\n", arg); + fprintf(stderr, "Usage: %s <address> <node.pub>\n", arg); exit(1); } int main(int argc, char *argv[]) { + ECPDHKey key_perma; + ECPNode node; + ecp_ecdh_public_t node_pub; int rv; - - if (argc != 2) usage(argv[0]); - + + /* client */ + 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_sock_init(&sock, &ctx, NULL); - printf("ecp_sock_init RV:%d\n", rv); + ecp_conn_handler_init(&handler, handle_msg, handle_open, NULL, NULL); + ecp_ctx_set_handler(&ctx, &handler, CTYPE_TEST); + + 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); - + 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); + rv = ecp_conn_create(&conn, &sock, CTYPE_TEST); + printf("ecp_conn_create RV:%d\n", rv); + + rv = ecp_util_load_pub(&node_pub, argv[2]); + 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_node_init(&node, &node_pub, argv[1]); + printf("ecp_node_init RV:%d\n", rv); rv = ecp_conn_open(&conn, &node); printf("ecp_conn_open RV:%d\n", rv); - + while (1) sleep(1); -}
\ No newline at end of file +} |