diff options
author | Uros Majstorovic <majstor@majstor.org> | 2021-08-31 22:20:15 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2021-08-31 22:20:15 +0200 |
commit | 2a33ef2344145e12f1eea96214cdb317857321c1 (patch) | |
tree | 1db9ce4e9c227c54595132edbce8adc65dd086ce /ecp/test | |
parent | 2a46bdf517eb5fcb8ba59c398a32859c6496475d (diff) |
directory service added
Diffstat (limited to 'ecp/test')
-rw-r--r-- | ecp/test/Makefile | 5 | ||||
-rw-r--r-- | ecp/test/dir.c | 100 |
2 files changed, 104 insertions, 1 deletions
diff --git a/ecp/test/Makefile b/ecp/test/Makefile index 863a3ef..84fdbe1 100644 --- a/ecp/test/Makefile +++ b/ecp/test/Makefile @@ -6,11 +6,14 @@ dep=../src/build-posix/*.a ../util/libecputil.a %.o: %.c $(CC) $(CFLAGS) -c $< -all: basic client server echo frag stress vcs vc_server vc_client vc_client_t +all: basic dir server echo frag stress vcs vc_server vc_client vc_client_t basic: basic.o init.o $(dep) $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) +dir: dir.o init.o $(dep) + $(CC) -DWITH_DIR_SERVER -o $@ $< init.o $(dep) $(LDFLAGS) + client: client.o init.o $(dep) $(CC) -o $@ $< init.o $(dep) $(LDFLAGS) diff --git a/ecp/test/dir.c b/ecp/test/dir.c new file mode 100644 index 0000000..a4e94a3 --- /dev/null +++ b/ecp/test/dir.c @@ -0,0 +1,100 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#include "core.h" +#include "cr.h" +#include "dir.h" + +ECPContext ctx_s; +ECPSocket sock_s; +ECPDHKey key_perma_s; + +ECPContext ctx_c; +ECPSocket sock_c; +ECPDHKey key_perma_c; +ECPConnHandler handler_c; + +ECPNode node; +ECPConnection conn; + +static ECPDirList dir_online; +static ECPDirList dir_shadow; + +#define CTYPE_TEST 0 + +ssize_t handle_dir(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size, ECP2Buffer *b) { + ECPDirItem item; + size_t _size; + + _size = size; + if (mtype == ECP_MTYPE_DIR_REP) { + int rv; + + while (_size >= ECP_SIZE_DIR_ITEM) { + ecp_dir_parse_item(msg, &item); + + printf("DIR: %s\n", (char *)ecp_cr_dh_pub_get_buf(&item.node.public)); + + msg += ECP_SIZE_DIR_ITEM; + _size -= ECP_SIZE_DIR_ITEM; + }; + } + + return size - _size; +} + +int main(int argc, char *argv[]) { + int rv; + + dir_online.count = 1; + strcpy((char *)ecp_cr_dh_pub_get_buf(&dir_online.item[0].node.public), "PERA"); + + rv = ecp_init(&ctx_s); + printf("ecp_init RV:%d\n", rv); + + rv = ecp_dir_init(&ctx_s, &dir_online, &dir_shadow); + printf("ecp_dir_init RV:%d\n", rv); + + 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_open(&sock_s, "0.0.0.0:3000"); + printf("ecp_sock_open RV:%d\n", rv); + + rv = ecp_start_receiver(&sock_s); + printf("ecp_start_receiver RV:%d\n", rv); + + rv = ecp_init(&ctx_c); + printf("ecp_init RV:%d\n", rv); + + rv = ecp_conn_handler_init(&handler_c); + handler_c.msg[ECP_MTYPE_DIR] = handle_dir; + ctx_c.handler[CTYPE_TEST] = &handler_c; + + 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_open(&sock_c, NULL); + printf("ecp_sock_open RV:%d\n", rv); + + rv = ecp_start_receiver(&sock_c); + printf("ecp_start_receiver RV:%d\n", rv); + + 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_get_dirlist(&conn, &node); + printf("ecp_conn_get_dirlist RV:%d\n", rv); + + while (1) sleep(1); +}
\ No newline at end of file |