From c6f557b7259ee8c8b5d71706abd3ac9b6db0bff8 Mon Sep 17 00:00:00 2001 From: me_desk Date: Fri, 30 Jan 2015 20:10:57 +0000 Subject: renamed structs PICA_conninfo to PICA_c2n (client-to-node) and PICA_chaninfo to PICA_c2c (client-to-client) git-svn-id: svn://localhost/project_picapica/trunk@340 fb96df88-216d-11de-830c-f3023f12d8ac --- tests/test_client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index f8ef157..9ea2de2 100755 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -6,8 +6,8 @@ struct sockaddr_in a; -struct PICA_conninfo *c; -struct PICA_chaninfo *chn; +struct PICA_c2n *c; +struct PICA_c2c *chn; int _outgoing_chnl=0; @@ -124,7 +124,7 @@ PICA_client_init(&cbs); printf("making connection...\n"); -//PICA_new_connection(const char *nodeaddr, unsigned int port, const char *CA_file, const char *cert_file, const char *pkey_file, const char* password, struct PICA_conninfo **ci) +//PICA_new_connection(const char *nodeaddr, unsigned int port, const char *CA_file, const char *cert_file, const char *pkey_file, const char* password, struct PICA_c2n **ci) ret=PICA_new_connection(argv[1], atoi(argv[2]), /*"trusted_CA.pem"*/ argv[3], argv[3],argv[3],NULL,&c); ERR_print_errors_fp(stdout); -- cgit v1.2.1 From a32462dd698ebf58615a5fed3af5b50c28df9fce Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 16 Mar 2015 23:56:02 +0400 Subject: updated test client --- tests/test_client | Bin 35075 -> 0 bytes tests/test_client.c | 13 +++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) delete mode 100755 tests/test_client (limited to 'tests') diff --git a/tests/test_client b/tests/test_client deleted file mode 100755 index a384dee..0000000 Binary files a/tests/test_client and /dev/null differ diff --git a/tests/test_client.c b/tests/test_client.c index 9ea2de2..a94951c 100755 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -6,6 +6,7 @@ struct sockaddr_in a; +struct PICA_acc *acc; struct PICA_c2n *c; struct PICA_c2c *chn; @@ -121,11 +122,19 @@ PICA_client_init(&cbs); // a.sin_addr.s_addr = inet_addr (argv[1]);//("127.0.0.1"); // a.sin_port = htons(51914); +printf("opening account..."); +ret = PICA_open_acc(argv[3], argv[3],argv[3], NULL, &acc); + +if (ret != PICA_OK) +{ + printf("failed to open account, ret = %i\n", ret); + return 1; +} printf("making connection...\n"); //PICA_new_connection(const char *nodeaddr, unsigned int port, const char *CA_file, const char *cert_file, const char *pkey_file, const char* password, struct PICA_c2n **ci) -ret=PICA_new_connection(argv[1], atoi(argv[2]), /*"trusted_CA.pem"*/ argv[3], argv[3],argv[3],NULL,&c); +ret=PICA_new_connection(acc, argv[1], atoi(argv[2]), /*"trusted_CA.pem"*/ &c); ERR_print_errors_fp(stdout); @@ -147,7 +156,7 @@ if (argc==5) printf("Creating channel to %s...\n",PICA_id_to_base64(peer_id, NULL)); - ret=PICA_create_channel(c,peer_id,&chn); + ret=PICA_create_channel(c,peer_id,NULL,&chn); //sleep(17);//timeout test if (ret!=PICA_OK) { -- cgit v1.2.1 From ec751f3f1260b72ade3a9fcb2dae5b55a6854fa9 Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 11 Apr 2015 23:34:46 +0400 Subject: more consistent naming, renamed conn -> c2n, channel -> c2c in function names and enumerations --- tests/test_client.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index a94951c..491154d 100755 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -34,14 +34,14 @@ void msgok_cb(const unsigned char *peer_id) puts("[V]"); } //создание канала с собеседником -void channel_established_cb(const unsigned char *peer_id) +void c2c_established_cb(const unsigned char *peer_id) { -puts("channel_established_cb"); +puts("c2c_established_cb"); } -void channel_failed_cb(const unsigned char *peer_id) +void c2c_failed_cb(const unsigned char *peer_id) { -printf("Failed to create channel to %s\n",PICA_id_to_base64(peer_id, NULL)); +printf("Failed to create c2c to %s\n",PICA_id_to_base64(peer_id, NULL)); chn=0; } @@ -53,9 +53,9 @@ void notfound_cb(const unsigned char *callee_id) puts("notfound_cb"); } -void channel_closed_cb(const unsigned char *peer_id, int reason) +void c2c_closed_cb(const unsigned char *peer_id, int reason) { -printf("channel_closed_cb( peer_id = %s, reason = %i)\n", PICA_id_to_base64(peer_id, NULL), reason); +printf("c2c_closed_cb( peer_id = %s, reason = %i)\n", PICA_id_to_base64(peer_id, NULL), reason); } void nodelist_cb(int type, void *addr_bin, const char *addr_str, unsigned int port) @@ -89,11 +89,11 @@ int peer_cert_verify_cb(const unsigned char *peer_id, const char *cert_pem, unsi struct PICA_client_callbacks cbs = { newmsg_cb, msgok_cb, - channel_established_cb, - channel_failed_cb, + c2c_established_cb, + c2c_failed_cb, accept_cb, notfound_cb, - channel_closed_cb, + c2c_closed_cb, nodelist_cb, peer_cert_verify_cb }; @@ -133,8 +133,8 @@ if (ret != PICA_OK) printf("making connection...\n"); -//PICA_new_connection(const char *nodeaddr, unsigned int port, const char *CA_file, const char *cert_file, const char *pkey_file, const char* password, struct PICA_c2n **ci) -ret=PICA_new_connection(acc, argv[1], atoi(argv[2]), /*"trusted_CA.pem"*/ &c); +//PICA_new_c2n(const char *nodeaddr, unsigned int port, const char *CA_file, const char *cert_file, const char *pkey_file, const char* password, struct PICA_c2n **ci) +ret=PICA_new_c2n(acc, argv[1], atoi(argv[2]), /*"trusted_CA.pem"*/ &c); ERR_print_errors_fp(stdout); @@ -142,7 +142,7 @@ if (ret==PICA_OK) printf("PICA_OK Connected to server...\n"); else { -printf("PICA_new_connection: ret=%i\n",ret); +printf("PICA_new_c2n: ret=%i\n",ret); return 1; } @@ -154,9 +154,9 @@ if (argc==5) return 1; } - printf("Creating channel to %s...\n",PICA_id_to_base64(peer_id, NULL)); + printf("Creating c2c to %s...\n",PICA_id_to_base64(peer_id, NULL)); - ret=PICA_create_channel(c,peer_id,NULL,&chn); + ret=PICA_new_c2c(c,peer_id,NULL,&chn); //sleep(17);//timeout test if (ret!=PICA_OK) { @@ -214,14 +214,14 @@ if (buf[0]=='.') else { peer_id=atoi(buf); - printf("Creating channel to %u...\n",peer_id); + printf("Creating c2c to %u...\n",peer_id); - ret=PICA_create_channel(c,peer_id,&chn,1); + ret=PICA_new_c2c(c,peer_id,&chn,1); if (ret==PICA_OK) { unsigned int msglen; - puts("Channel established..."); + puts("c2c established..."); gets(buf); msglen=strlen(buf); @@ -239,7 +239,7 @@ sleep(10); if (chn) { puts("--------"); - PICA_close_channel(chn); + PICA_close_c2c(chn); } PICA_close_connection(c); -- cgit v1.2.1 From 55b17bd87fc0d695500574b188534014922cb2a4 Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 11 Apr 2015 23:54:35 +0400 Subject: renamed remaining PICA_close_connection() -> PICA_close_c2n() --- tests/test_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 491154d..996639b 100755 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -242,7 +242,7 @@ if (chn) PICA_close_c2c(chn); } -PICA_close_connection(c); +PICA_close_c2n(c); return 0; } -- cgit v1.2.1 From 5f1eaf6ebf6ab1e12ebe27aa5432e1d305a7520e Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 11 May 2015 02:50:41 +0400 Subject: updated test client --- tests/test_client.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 996639b..5480eee 100755 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -21,7 +21,7 @@ return 1; } //получение сообщения. -void newmsg_cb(const unsigned char *peer_id,char* msgbuf,unsigned int nb,int type) +void newmsg_cb(const unsigned char *peer_id, const char* msgbuf,unsigned int nb,int type) { memcpy(buf,msgbuf,nb); buf[nb]=0; @@ -86,6 +86,57 @@ int peer_cert_verify_cb(const unsigned char *peer_id, const char *cert_pem, unsi return 1; } +int accept_file_cb(const unsigned char *peer_id, uint64_t file_size, const char *filename, unsigned int filename_size) +{ + printf("accept_file_cb: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); + return 0; +} + +void accepted_file_cb(const unsigned char *peer_id) +{ + printf("accepted_file_cb: peer_id %s \n", PICA_id_to_base64(peer_id, NULL)); +} + +void denied_file_cb(const unsigned char *peer_id) +{ + printf("denied_file_cb: peer_id %s \n", PICA_id_to_base64(peer_id, NULL)); +} + +void file_progress(const unsigned char *peer_id, uint64_t sent, uint64_t received) +{ + printf("file_progress: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); +} + +void file_control(const unsigned char *peer_id, unsigned int sender_cmd, unsigned int receiver_cmd) +{ + printf("file_control: peer_id %s sender_cmd %u receiver_cmd %u \n", PICA_id_to_base64(peer_id, NULL), sender_cmd, receiver_cmd); +} + +void file_finished(const unsigned char *peer_id, int sending) +{ + printf("file_finished: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); +} + +void c2n_established_cb(struct PICA_c2n *c2n) +{ + printf("c2n_established_cb: %p\n peer_id %s\n", c2n, PICA_id_to_base64(c2n->acc->id, NULL)); +} + +void c2n_failed_cb(struct PICA_c2n *c2n) +{ + printf("c2n_failed_cb: %p\n", c2n); +} + +void c2n_closed_cb(struct PICA_c2n *c2n) +{ + printf("c2n_closed_cb: %p\n", c2n); +} + +void listener_error(struct PICA_listener *lst, int errorcode) +{ + printf("listener_error: %p error code %i\n", lst, errorcode); +} + struct PICA_client_callbacks cbs = { newmsg_cb, msgok_cb, @@ -95,13 +146,24 @@ struct PICA_client_callbacks cbs = { notfound_cb, c2c_closed_cb, nodelist_cb, - peer_cert_verify_cb + peer_cert_verify_cb, + accept_file_cb, + accepted_file_cb, + denied_file_cb, + file_progress, + file_control, + file_finished, + c2n_established_cb, + c2n_failed_cb, + c2n_closed_cb, + listener_error }; int main(int argc,char** argv) { int ret; unsigned char peer_id[PICA_ID_SIZE]; +struct PICA_c2n* c2ns[] = {NULL, NULL}; if (argc<4) { @@ -139,13 +201,15 @@ ret=PICA_new_c2n(acc, argv[1], atoi(argv[2]), /*"trusted_CA.pem"*/ &c); ERR_print_errors_fp(stdout); if (ret==PICA_OK) -printf("PICA_OK Connected to server...\n"); +printf("PICA_OK started c2n connection to node...\n"); else { printf("PICA_new_c2n: ret=%i\n",ret); return 1; } +c2ns[0] = c; + if (argc==5) { if (PICA_id_from_base64(argv[4], peer_id) == NULL) @@ -166,6 +230,8 @@ if (argc==5) } + while(PICA_event_loop(c2ns, NULL, 1500) == PICA_OK); +/* do { if (chn && chn->state==PICA_CHANSTATE_ACTIVE) @@ -180,7 +246,7 @@ do printf("PICA_send_msg ret=%i\n",ret); } } -while(PICA_read(c,100000) == PICA_OK && PICA_write(c) == PICA_OK); +while(PICA_read(c,100000) == PICA_OK && PICA_write(c) == PICA_OK);*/ /* puts("Enter peer_id to talk with or . for waiting incoming sessions:"); -- cgit v1.2.1 From d6ac2d840a6f0a18ee41065db9926b585445c19c Mon Sep 17 00:00:00 2001 From: Anton Date: Sun, 19 Jun 2016 19:59:12 +0400 Subject: updated test client, now it supports two-way communication --- tests/test_client.c | 336 +++++++++++++++++++++++++--------------------------- 1 file changed, 160 insertions(+), 176 deletions(-) mode change 100755 => 100644 tests/test_client.c (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c old mode 100755 new mode 100644 index 5480eee..5cbd24d --- a/tests/test_client.c +++ b/tests/test_client.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "../PICA_client.h" @@ -10,39 +12,47 @@ struct PICA_acc *acc; struct PICA_c2n *c; struct PICA_c2c *chn; -int _outgoing_chnl=0; +int _outgoing_chnl = 0; -unsigned char buf[64*1024]; +int connected_to_node = 0; +int c2c_active = 0; +int c2c_in_progress = 0; + +unsigned char buf[64 * 1024]; int accept_cb(const unsigned char *id) { -printf("accept_cb: %s\n",PICA_id_to_base64(id, NULL)); -return 1; + printf("accept_cb: %s\n", PICA_id_to_base64(id, NULL)); + return 1; } //получение сообщения. -void newmsg_cb(const unsigned char *peer_id, const char* msgbuf,unsigned int nb,int type) +void newmsg_cb(const unsigned char *peer_id, const char* msgbuf, unsigned int nb, int type) { -memcpy(buf,msgbuf,nb); -buf[nb]=0; -printf(" %s: ",PICA_id_to_base64(peer_id, NULL)); -puts(buf); + memcpy(buf, msgbuf, nb); + buf[nb] = 0; + printf(" %s: ", PICA_id_to_base64(peer_id, NULL)); + puts(buf); } //получение подтверждения о доставке сообщения void msgok_cb(const unsigned char *peer_id) { -puts("[V]"); + puts("[V]"); } //создание канала с собеседником void c2c_established_cb(const unsigned char *peer_id) { -puts("c2c_established_cb"); + c2c_active = 1; + c2c_in_progress = 0; + puts("c2c_established_cb"); + chn = c->chan_list_head;//hack, its better to pass new c2c pointer as callback arg } void c2c_failed_cb(const unsigned char *peer_id) { -printf("Failed to create c2c to %s\n",PICA_id_to_base64(peer_id, NULL)); -chn=0; + c2c_in_progress = 0; + printf("Failed to create c2c to %s\n", PICA_id_to_base64(peer_id, NULL)); + chn = 0; } //входящий запрос на создание канала от пользователя с номером caller_id @@ -50,265 +60,239 @@ chn=0; //запрошенный пользователь не найден, в оффлайне или отказался от общения void notfound_cb(const unsigned char *callee_id) { -puts("notfound_cb"); + puts("notfound_cb"); } void c2c_closed_cb(const unsigned char *peer_id, int reason) { -printf("c2c_closed_cb( peer_id = %s, reason = %i)\n", PICA_id_to_base64(peer_id, NULL), reason); + c2c_active = 0; + c2c_in_progress = 0; + printf("c2c_closed_cb( peer_id = %s, reason = %i)\n", PICA_id_to_base64(peer_id, NULL), reason); } void nodelist_cb(int type, void *addr_bin, const char *addr_str, unsigned int port) { -switch(type) - { - case 0xA0: + switch(type) + { + case 0xA0: printf("node (IP %s port %u)\n", addr_str, port); break; - - case 0xA1: + + case 0xA1: printf("node (IPv6 %s port %u)", addr_str, port); break; - - case 0xA2: + + case 0xA2: printf("node (hostname %s port %u)\n", addr_str, port); break; - - default: + + default: puts("unknown node address type"); return; - } + } } int peer_cert_verify_cb(const unsigned char *peer_id, const char *cert_pem, unsigned int nb) { - printf("peer's certificate (%s): \n%.*s\n", PICA_id_to_base64(peer_id, NULL), nb,cert_pem); - return 1; + printf("peer's certificate (%s): \n%.*s\n", PICA_id_to_base64(peer_id, NULL), nb, cert_pem); + return 1; } int accept_file_cb(const unsigned char *peer_id, uint64_t file_size, const char *filename, unsigned int filename_size) { - printf("accept_file_cb: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); - return 0; + printf("accept_file_cb: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); + return 0; } void accepted_file_cb(const unsigned char *peer_id) { - printf("accepted_file_cb: peer_id %s \n", PICA_id_to_base64(peer_id, NULL)); + printf("accepted_file_cb: peer_id %s \n", PICA_id_to_base64(peer_id, NULL)); } void denied_file_cb(const unsigned char *peer_id) { - printf("denied_file_cb: peer_id %s \n", PICA_id_to_base64(peer_id, NULL)); + printf("denied_file_cb: peer_id %s \n", PICA_id_to_base64(peer_id, NULL)); } void file_progress(const unsigned char *peer_id, uint64_t sent, uint64_t received) { - printf("file_progress: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); + printf("file_progress: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); } void file_control(const unsigned char *peer_id, unsigned int sender_cmd, unsigned int receiver_cmd) { - printf("file_control: peer_id %s sender_cmd %u receiver_cmd %u \n", PICA_id_to_base64(peer_id, NULL), sender_cmd, receiver_cmd); + printf("file_control: peer_id %s sender_cmd %u receiver_cmd %u \n", PICA_id_to_base64(peer_id, NULL), sender_cmd, receiver_cmd); } void file_finished(const unsigned char *peer_id, int sending) { - printf("file_finished: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); + printf("file_finished: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); } void c2n_established_cb(struct PICA_c2n *c2n) { - printf("c2n_established_cb: %p\n peer_id %s\n", c2n, PICA_id_to_base64(c2n->acc->id, NULL)); + connected_to_node = 1; + printf("c2n_established_cb: %p\n my_id %s\n", c2n, PICA_id_to_base64(c2n->acc->id, NULL)); } void c2n_failed_cb(struct PICA_c2n *c2n) { - printf("c2n_failed_cb: %p\n", c2n); + printf("c2n_failed_cb: %p\n", c2n); } void c2n_closed_cb(struct PICA_c2n *c2n) { - printf("c2n_closed_cb: %p\n", c2n); + printf("c2n_closed_cb: %p\n", c2n); } void listener_error(struct PICA_listener *lst, int errorcode) { - printf("listener_error: %p error code %i\n", lst, errorcode); + printf("listener_error: %p error code %i\n", lst, errorcode); } -struct PICA_client_callbacks cbs = { - newmsg_cb, - msgok_cb, - c2c_established_cb, - c2c_failed_cb, - accept_cb, - notfound_cb, - c2c_closed_cb, - nodelist_cb, - peer_cert_verify_cb, - accept_file_cb, - accepted_file_cb, - denied_file_cb, - file_progress, - file_control, - file_finished, - c2n_established_cb, - c2n_failed_cb, - c2n_closed_cb, - listener_error +struct PICA_client_callbacks cbs = +{ + newmsg_cb, + msgok_cb, + c2c_established_cb, + c2c_failed_cb, + accept_cb, + notfound_cb, + c2c_closed_cb, + nodelist_cb, + peer_cert_verify_cb, + accept_file_cb, + accepted_file_cb, + denied_file_cb, + file_progress, + file_control, + file_finished, + c2n_established_cb, + c2n_failed_cb, + c2n_closed_cb, + listener_error }; -int main(int argc,char** argv) +int main(int argc, char** argv) { -int ret; -unsigned char peer_id[PICA_ID_SIZE]; -struct PICA_c2n* c2ns[] = {NULL, NULL}; + int ret; + unsigned char peer_id[PICA_ID_SIZE]; + struct PICA_c2n* c2ns[] = {NULL, NULL}; -if (argc<4) + fd_set stdinfds; + struct timeval tv; + + if (argc < 4) { - puts("usage: test_client address port cert_filename [peer id]"); - return 0; + puts("usage: test_client address port cert_filename [peer id]\ncert_filename should point to file that contains client certificate, private key and Diffie-Hellman parameters in PEM format"); + return 0; } -puts(SSLeay_version(SSLEAY_VERSION)); -printf("Calling PICA_init...\n"); + puts(SSLeay_version(SSLEAY_VERSION)); + printf("Calling PICA_init...\n"); -PICA_client_init(&cbs); + PICA_client_init(&cbs); -// printf("setting address...\n"); -// -// memset(&a,0,sizeof(a)); -// -// a.sin_family = AF_INET; -// a.sin_addr.s_addr = inet_addr (argv[1]);//("127.0.0.1"); -// a.sin_port = htons(51914); + printf("opening account..."); + ret = PICA_open_acc(argv[3], argv[3], argv[3], NULL, &acc); -printf("opening account..."); -ret = PICA_open_acc(argv[3], argv[3],argv[3], NULL, &acc); - -if (ret != PICA_OK) -{ - printf("failed to open account, ret = %i\n", ret); - return 1; -} + if (ret != PICA_OK) + { + printf("failed to open account, ret = %i\n", ret); + return 1; + } -printf("making connection...\n"); + printf("making connection...\n"); //PICA_new_c2n(const char *nodeaddr, unsigned int port, const char *CA_file, const char *cert_file, const char *pkey_file, const char* password, struct PICA_c2n **ci) -ret=PICA_new_c2n(acc, argv[1], atoi(argv[2]), /*"trusted_CA.pem"*/ &c); - -ERR_print_errors_fp(stdout); - -if (ret==PICA_OK) -printf("PICA_OK started c2n connection to node...\n"); -else -{ -printf("PICA_new_c2n: ret=%i\n",ret); -return 1; -} + ret = PICA_new_c2n(acc, argv[1], atoi(argv[2]), /*"trusted_CA.pem"*/ &c); -c2ns[0] = c; + ERR_print_errors_fp(stdout); -if (argc==5) - { - if (PICA_id_from_base64(argv[4], peer_id) == NULL) + if (ret == PICA_OK) + printf("PICA_OK started c2n connection to node...\n"); + else { - puts("invalid peer_id"); - return 1; - } - - printf("Creating c2c to %s...\n",PICA_id_to_base64(peer_id, NULL)); - - ret=PICA_new_c2c(c,peer_id,NULL,&chn); - //sleep(17);//timeout test - if (ret!=PICA_OK) - { - printf("error: ret=%i\n",ret); + printf("PICA_new_c2n: ret=%i\n", ret); return 1; - } - } - while(PICA_event_loop(c2ns, NULL, 1500) == PICA_OK); -/* -do + c2ns[0] = c; + + + while(PICA_event_loop(c2ns, NULL, 500) == PICA_OK) { - if (chn && chn->state==PICA_CHANSTATE_ACTIVE) + //puts("event loop..."); + if (argc == 5 && connected_to_node == 1 && c2c_active == 0 && c2c_in_progress == 0) { - unsigned int msglen; - gets(buf); - msglen=strlen(buf); - - ret=PICA_send_msg(chn,buf,msglen); - - if (ret!=PICA_OK) - printf("PICA_send_msg ret=%i\n",ret); - } - } -while(PICA_read(c,100000) == PICA_OK && PICA_write(c) == PICA_OK);*/ + if (PICA_id_from_base64(argv[4], peer_id) == NULL) + { + puts("invalid peer_id"); + return 1; + } -/* -puts("Enter peer_id to talk with or . for waiting incoming sessions:"); -gets(buf); -if (buf[0]=='.') - { - unsigned int br; - ret=PICA_read_conn(c,accept_cb,&chn); + printf("Creating c2c to %s...\n", PICA_id_to_base64(peer_id, NULL)); - if (ret==PICA_NEWCHAN) + ret = PICA_new_c2c(c, peer_id, NULL, &chn); + //sleep(17);//timeout test + if (ret != PICA_OK) { - puts("PICA_NEWCHAN!"); + printf("error: ret=%i\n", ret); + return 1; } - else - printf("read_conn error: ret=%i\n",ret); - - ret=PICA_read_msg(chn,buf,&br); - switch(ret) + + printf("chn = %p\n", chn); + c2c_in_progress = 1; + + } + + if (connected_to_node == 1 && c2c_active == 1) + { + FD_ZERO(&stdinfds); + FD_SET(STDIN_FILENO, &stdinfds); + + tv.tv_sec = 0; + tv.tv_usec = 500000; + + ret = select(STDIN_FILENO + 1, &stdinfds, NULL, NULL, &tv); + + if (ret == -1) { - case PICA_MSGUTF8: - printf("%u (%u bytes): ",c->id,br); - puts(buf); - break; - case PICA_MSGOK: - puts("[v]"); - break; - default: - printf("PICA_read_msg ret=%i\n",ret); + perror("select() on stdin failed"); + return 1; } - } -else - { - peer_id=atoi(buf); - printf("Creating c2c to %u...\n",peer_id); - - ret=PICA_new_c2c(c,peer_id,&chn,1); - if (ret==PICA_OK) - { - unsigned int msglen; - puts("c2c established..."); - gets(buf); - msglen=strlen(buf); - - ret=PICA_send_msg(chn,buf,msglen); - if (ret!=PICA_OK) - printf("PICA_send_msg ret=%i\n",ret); + if (ret > 0 && FD_ISSET(STDIN_FILENO, &stdinfds)) + { + ret = read(STDIN_FILENO, buf, 256); + + if (ret <= 0) + { + perror("read from stdin"); + return 1; + } + + ret = PICA_send_msg(chn, buf, ret); + + if (ret != PICA_OK) + printf("failed to send message, error = %i\n", ret); + } } - else - printf("error: ret=%i\n",ret); + + } -*/ -sleep(10); -if (chn) + + sleep(10); + + if (chn) { - puts("--------"); - PICA_close_c2c(chn); + puts("--------"); + PICA_close_c2c(chn); } -PICA_close_c2n(c); + PICA_close_c2n(c); -return 0; + return 0; } -- cgit v1.2.1 From c78395ea13aead21e7041f42699fcbf3753f1832 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 11 Aug 2016 22:28:55 +0400 Subject: added error code argument to c2n callbacks --- tests/test_client.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 5cbd24d..7a16732 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -135,14 +135,14 @@ void c2n_established_cb(struct PICA_c2n *c2n) printf("c2n_established_cb: %p\n my_id %s\n", c2n, PICA_id_to_base64(c2n->acc->id, NULL)); } -void c2n_failed_cb(struct PICA_c2n *c2n) +void c2n_failed_cb(struct PICA_c2n *c2n, int error) { - printf("c2n_failed_cb: %p\n", c2n); + printf("c2n_failed_cb: %p error_code %i\n", c2n, error); } -void c2n_closed_cb(struct PICA_c2n *c2n) +void c2n_closed_cb(struct PICA_c2n *c2n, int error) { - printf("c2n_closed_cb: %p\n", c2n); + printf("c2n_closed_cb: %p error_code %i\n", c2n, error); } void listener_error(struct PICA_listener *lst, int errorcode) -- cgit v1.2.1 From 242abc09a94cf0cb8b33d7d5b9affb70a4b8e86e Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 17 Jun 2017 20:48:13 +0400 Subject: updated test client --- tests/test_client.c | 80 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 7a16732..0b4db7c 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -11,6 +11,9 @@ struct sockaddr_in a; struct PICA_acc *acc; struct PICA_c2n *c; struct PICA_c2c *chn; +enum PICA_directc2c_config directc2c_cfg = PICA_DIRECTC2C_CFG_DISABLED; +struct PICA_listener *l = NULL; + int _outgoing_chnl = 0; @@ -138,11 +141,13 @@ void c2n_established_cb(struct PICA_c2n *c2n) void c2n_failed_cb(struct PICA_c2n *c2n, int error) { printf("c2n_failed_cb: %p error_code %i\n", c2n, error); + c = NULL; } void c2n_closed_cb(struct PICA_c2n *c2n, int error) { printf("c2n_closed_cb: %p error_code %i\n", c2n, error); + c = NULL; } void listener_error(struct PICA_listener *lst, int errorcode) @@ -175,37 +180,85 @@ struct PICA_client_callbacks cbs = int main(int argc, char** argv) { - int ret; + int ret, opt; unsigned char peer_id[PICA_ID_SIZE]; struct PICA_c2n* c2ns[] = {NULL, NULL}; fd_set stdinfds; struct timeval tv; - if (argc < 4) + const char *nodeaddr = NULL, *nodeport = NULL, + *certfile = NULL, *peerid = NULL, + *localdirectaddr = NULL, *extport = NULL, + *locport = NULL; + + while ((opt = getopt(argc, argv, "a:p:c:i:d:e:l:")) != -1) + { + switch(opt) + { + case 'a': + nodeaddr = optarg; + break; + + case 'p': + nodeport = optarg; + break; + + case 'c': + certfile = optarg; + break; + + case 'i': + peerid = optarg; + break; + + case 'd': + localdirectaddr = optarg; + break; + + case 'e': + extport = optarg; + break; + + case 'l': + locport = optarg; + break; + + default: + fprintf(stderr, "invalid arg %s\n", optarg); + return -1; + } + } + + if (argc < 4 || !nodeaddr || !nodeport || !certfile) { - puts("usage: test_client address port cert_filename [peer id]\ncert_filename should point to file that contains client certificate, private key and Diffie-Hellman parameters in PEM format"); + puts("usage: test_client -a node address -p node port -c cert_filename [-i peer id]\n\ + -d local address for direct incoming c2c connections\n\ + -e external port for incoming direct connections\n\ + -l internal port to listen for incoming direct connections\n\ +cert_filename should point to file that contains client certificate, private key and Diffie-Hellman parameters in PEM format"); return 0; } + puts(SSLeay_version(SSLEAY_VERSION)); printf("Calling PICA_init...\n"); PICA_client_init(&cbs); printf("opening account..."); - ret = PICA_open_acc(argv[3], argv[3], argv[3], NULL, &acc); + ret = PICA_open_acc(certfile, certfile, certfile, NULL, &acc); if (ret != PICA_OK) { - printf("failed to open account, ret = %i\n", ret); + fprintf(stderr, "failed to open account, ret = %i\n", ret); return 1; } printf("making connection...\n"); //PICA_new_c2n(const char *nodeaddr, unsigned int port, const char *CA_file, const char *cert_file, const char *pkey_file, const char* password, struct PICA_c2n **ci) - ret = PICA_new_c2n(acc, argv[1], atoi(argv[2]), /*"trusted_CA.pem"*/ &c); + ret = PICA_new_c2n(acc, nodeaddr, atoi(nodeport), directc2c_cfg, l, &c); ERR_print_errors_fp(stdout); @@ -220,12 +273,12 @@ int main(int argc, char** argv) c2ns[0] = c; - while(PICA_event_loop(c2ns, NULL, 500) == PICA_OK) + while(PICA_event_loop(c2ns, 500) == PICA_OK) { //puts("event loop..."); - if (argc == 5 && connected_to_node == 1 && c2c_active == 0 && c2c_in_progress == 0) + if (peerid && connected_to_node == 1 && c2c_active == 0 && c2c_in_progress == 0) { - if (PICA_id_from_base64(argv[4], peer_id) == NULL) + if (PICA_id_from_base64(peerid, peer_id) == NULL) { puts("invalid peer_id"); return 1; @@ -233,7 +286,7 @@ int main(int argc, char** argv) printf("Creating c2c to %s...\n", PICA_id_to_base64(peer_id, NULL)); - ret = PICA_new_c2c(c, peer_id, NULL, &chn); + ret = PICA_new_c2c(c, peer_id, l, &chn); //sleep(17);//timeout test if (ret != PICA_OK) { @@ -284,15 +337,12 @@ int main(int argc, char** argv) - sleep(10); if (chn) - { - puts("--------"); PICA_close_c2c(chn); - } - PICA_close_c2n(c); + if (c) + PICA_close_c2n(c); return 0; } -- cgit v1.2.1 From ecf7ff07d284b06a43d7f14f8320b13434627463 Mon Sep 17 00:00:00 2001 From: Anton Date: Sun, 18 Jun 2017 21:51:09 +0400 Subject: directc2c support in test_client --- tests/test_client.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 0b4db7c..7103914 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -153,6 +153,7 @@ void c2n_closed_cb(struct PICA_c2n *c2n, int error) void listener_error(struct PICA_listener *lst, int errorcode) { printf("listener_error: %p error code %i\n", lst, errorcode); + l = NULL; } struct PICA_client_callbacks cbs = @@ -192,7 +193,7 @@ int main(int argc, char** argv) *localdirectaddr = NULL, *extport = NULL, *locport = NULL; - while ((opt = getopt(argc, argv, "a:p:c:i:d:e:l:")) != -1) + while ((opt = getopt(argc, argv, "a:p:c:i:d:e:l:t")) != -1) { switch(opt) { @@ -224,6 +225,10 @@ int main(int argc, char** argv) locport = optarg; break; + case 't': + directc2c_cfg = PICA_DIRECTC2C_CFG_CONNECTONLY; + break; + default: fprintf(stderr, "invalid arg %s\n", optarg); return -1; @@ -236,11 +241,13 @@ int main(int argc, char** argv) -d local address for direct incoming c2c connections\n\ -e external port for incoming direct connections\n\ -l internal port to listen for incoming direct connections\n\ + -t enable connect-only mode for direct c2c connections\n\ cert_filename should point to file that contains client certificate, private key and Diffie-Hellman parameters in PEM format"); return 0; } + puts(SSLeay_version(SSLEAY_VERSION)); printf("Calling PICA_init...\n"); @@ -255,6 +262,29 @@ cert_filename should point to file that contains client certificate, private key return 1; } + if (localdirectaddr) + { + int intp = 2300, extp = 2300; + + directc2c_cfg = PICA_DIRECTC2C_CFG_ALLOWINCOMING; + + if (extport) + extp = atoi(extport); + if (locport) + intp = atoi(locport); + + printf("new listener on %s port %i external announced port %i\n", localdirectaddr, intp, extp); + + ret = PICA_new_listener(acc, localdirectaddr, extp, intp, &l); + + if (ret != PICA_OK) + { + fprintf(stderr, "failed to create listener, error code: %i\n", ret); + l = NULL; + } + + } + printf("making connection...\n"); //PICA_new_c2n(const char *nodeaddr, unsigned int port, const char *CA_file, const char *cert_file, const char *pkey_file, const char* password, struct PICA_c2n **ci) @@ -344,5 +374,8 @@ cert_filename should point to file that contains client certificate, private key if (c) PICA_close_c2n(c); + if(l) + PICA_close_listener(l); + return 0; } -- cgit v1.2.1 From bd355c598bcfef7897e7af3418ef1fa438beedc3 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 26 Jun 2017 19:11:21 +0400 Subject: fixed segfault in test_client --- tests/test_client.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 7103914..8434611 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -303,7 +303,7 @@ cert_filename should point to file that contains client certificate, private key c2ns[0] = c; - while(PICA_event_loop(c2ns, 500) == PICA_OK) + while(PICA_event_loop(c2ns, 500) == PICA_OK && c != NULL) { //puts("event loop..."); if (peerid && connected_to_node == 1 && c2c_active == 0 && c2c_in_progress == 0) @@ -367,10 +367,6 @@ cert_filename should point to file that contains client certificate, private key - - if (chn) - PICA_close_c2c(chn); - if (c) PICA_close_c2n(c); -- cgit v1.2.1 From 0b7e4355d56973ec801ef86371d837dd50b1012e Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 12 Jul 2017 13:16:08 +0400 Subject: implemented echo mode in test client --- tests/test_client.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 8434611..0995d51 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -21,6 +21,8 @@ int connected_to_node = 0; int c2c_active = 0; int c2c_in_progress = 0; +int echo_mode = 0; + unsigned char buf[64 * 1024]; int accept_cb(const unsigned char *id) @@ -32,6 +34,19 @@ int accept_cb(const unsigned char *id) //получение сообщения. void newmsg_cb(const unsigned char *peer_id, const char* msgbuf, unsigned int nb, int type) { + + if (echo_mode) + { + int ret; + + ret = PICA_send_msg(chn, msgbuf, nb); + + if (ret != PICA_OK) + printf("failed to send message, error = %i\n", ret); + + return; + } + memcpy(buf, msgbuf, nb); buf[nb] = 0; printf(" %s: ", PICA_id_to_base64(peer_id, NULL)); @@ -193,7 +208,7 @@ int main(int argc, char** argv) *localdirectaddr = NULL, *extport = NULL, *locport = NULL; - while ((opt = getopt(argc, argv, "a:p:c:i:d:e:l:t")) != -1) + while ((opt = getopt(argc, argv, "a:p:c:i:d:e:l:tm")) != -1) { switch(opt) { @@ -229,6 +244,10 @@ int main(int argc, char** argv) directc2c_cfg = PICA_DIRECTC2C_CFG_CONNECTONLY; break; + case 'm': + echo_mode = 1; + break; + default: fprintf(stderr, "invalid arg %s\n", optarg); return -1; @@ -329,7 +348,7 @@ cert_filename should point to file that contains client certificate, private key } - if (connected_to_node == 1 && c2c_active == 1) + if (connected_to_node == 1 && c2c_active == 1 && !echo_mode) { FD_ZERO(&stdinfds); FD_SET(STDIN_FILENO, &stdinfds); -- cgit v1.2.1 From f15e2db611dbb96e3294a5a778ac77022ece7e81 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 20 Jul 2017 01:21:50 +0400 Subject: implemented random message mode in test_client --- tests/test_client.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 0995d51..5f5e44b 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -5,7 +5,7 @@ #include #include "../PICA_client.h" - +#include "../PICA_proto.h" struct sockaddr_in a; struct PICA_acc *acc; @@ -22,6 +22,8 @@ int c2c_active = 0; int c2c_in_progress = 0; int echo_mode = 0; +int random_message_mode = 0; +int delivery_acks_count = 0; unsigned char buf[64 * 1024]; @@ -55,6 +57,7 @@ void newmsg_cb(const unsigned char *peer_id, const char* msgbuf, unsigned int nb //получение подтверждения о доставке сообщения void msgok_cb(const unsigned char *peer_id) { + delivery_acks_count++; puts("[V]"); } //создание канала с собеседником @@ -208,7 +211,7 @@ int main(int argc, char** argv) *localdirectaddr = NULL, *extport = NULL, *locport = NULL; - while ((opt = getopt(argc, argv, "a:p:c:i:d:e:l:tm")) != -1) + while ((opt = getopt(argc, argv, "a:p:c:i:d:e:l:tmr")) != -1) { switch(opt) { @@ -248,12 +251,22 @@ int main(int argc, char** argv) echo_mode = 1; break; + case 'r': + random_message_mode = 1; + break; + default: fprintf(stderr, "invalid arg %s\n", optarg); return -1; } } + if (echo_mode && random_message_mode) + { + puts("echo mode and random test messages mode are mutually exclusive, please select only one of them"); + return -1; + } + if (argc < 4 || !nodeaddr || !nodeport || !certfile) { puts("usage: test_client -a node address -p node port -c cert_filename [-i peer id]\n\ @@ -261,6 +274,8 @@ int main(int argc, char** argv) -e external port for incoming direct connections\n\ -l internal port to listen for incoming direct connections\n\ -t enable connect-only mode for direct c2c connections\n\ + -m start in echo mode, received messages are sent back, input from stdin is not accepted\n\ + -r send random test messages and exit, expects other side to be run in echo mode\n\ cert_filename should point to file that contains client certificate, private key and Diffie-Hellman parameters in PEM format"); return 0; } @@ -348,7 +363,51 @@ cert_filename should point to file that contains client certificate, private key } - if (connected_to_node == 1 && c2c_active == 1 && !echo_mode) + if (random_message_mode && connected_to_node == 1 && c2c_active == 1) + { + static int test_stage = 0; + + switch(test_stage) + { + //send zero-length message + case 0: + ret = PICA_send_msg(chn, NULL, 0); + test_stage++; + break; + + //send max length message + case 1: + memset(buf, 'X', PICA_PROTO_C2CMSG_MAXDATASIZE); + ret = PICA_send_msg(chn, buf, PICA_PROTO_C2CMSG_MAXDATASIZE); + test_stage++; + break; + + //send random length message + case 2: + RAND_pseudo_bytes((unsigned char*)&ret, sizeof ret); + if (ret < 0) + ret = 0 - ret; + ret %= PICA_PROTO_C2CMSG_MAXDATASIZE; + memset(buf, 'x', ret); + ret = PICA_send_msg(chn, buf, ret); + test_stage++; + break; + + default: + puts("waiting for test messages to be delivered"); + } + + if (ret != PICA_OK) + { + printf("failed to send message, error = %i\n", ret); + return 1; + } + + if (delivery_acks_count == 3) + break;//exit main loop on success + } + + if (connected_to_node == 1 && c2c_active == 1 && !echo_mode && !random_message_mode) { FD_ZERO(&stdinfds); FD_SET(STDIN_FILENO, &stdinfds); -- cgit v1.2.1 From c0713b9a9ffca4516b44127cc335332a9405eb27 Mon Sep 17 00:00:00 2001 From: Anton Date: Thu, 27 Jul 2017 02:17:14 +0400 Subject: test_client: compare sent & received messages in random message mode --- tests/test_client.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 5f5e44b..691dd6d 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -49,6 +49,17 @@ void newmsg_cb(const unsigned char *peer_id, const char* msgbuf, unsigned int nb return; } + if (random_message_mode) + { + //compare received & sent messages, fail if they do not match exactly + if (memcmp(msgbuf, buf, nb) != 0) + { + printf("sent and returned messages are not equal!\n"); + return 1; + } + + } + memcpy(buf, msgbuf, nb); buf[nb] = 0; printf(" %s: ", PICA_id_to_base64(peer_id, NULL)); -- cgit v1.2.1 From 1ec1d72b5dc98b93c86b4a09950a3e975efe8487 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 4 Sep 2017 22:31:11 +0400 Subject: test_client: wait for reply before sending next message in random message mode --- tests/test_client.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index 691dd6d..d78441e 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -24,6 +24,7 @@ int c2c_in_progress = 0; int echo_mode = 0; int random_message_mode = 0; int delivery_acks_count = 0; +int rmm_wait_for_reply = 0; unsigned char buf[64 * 1024]; @@ -55,9 +56,10 @@ void newmsg_cb(const unsigned char *peer_id, const char* msgbuf, unsigned int nb if (memcmp(msgbuf, buf, nb) != 0) { printf("sent and returned messages are not equal!\n"); - return 1; + exit(1); } + rmm_wait_for_reply = 0; } memcpy(buf, msgbuf, nb); @@ -374,7 +376,7 @@ cert_filename should point to file that contains client certificate, private key } - if (random_message_mode && connected_to_node == 1 && c2c_active == 1) + if (random_message_mode && connected_to_node == 1 && c2c_active == 1 && rmm_wait_for_reply == 0) { static int test_stage = 0; @@ -384,6 +386,7 @@ cert_filename should point to file that contains client certificate, private key case 0: ret = PICA_send_msg(chn, NULL, 0); test_stage++; + rmm_wait_for_reply = 1; break; //send max length message @@ -391,6 +394,7 @@ cert_filename should point to file that contains client certificate, private key memset(buf, 'X', PICA_PROTO_C2CMSG_MAXDATASIZE); ret = PICA_send_msg(chn, buf, PICA_PROTO_C2CMSG_MAXDATASIZE); test_stage++; + rmm_wait_for_reply = 1; break; //send random length message @@ -402,6 +406,7 @@ cert_filename should point to file that contains client certificate, private key memset(buf, 'x', ret); ret = PICA_send_msg(chn, buf, ret); test_stage++; + rmm_wait_for_reply = 1; break; default: -- cgit v1.2.1 From fdb06bfda394614a18fa714f3209eba2b844925c Mon Sep 17 00:00:00 2001 From: Anton Date: Sun, 12 Nov 2017 01:13:02 +0400 Subject: test_client: implemented sending & receiving files --- tests/test_client.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_client.c b/tests/test_client.c index d78441e..c469c74 100644 --- a/tests/test_client.c +++ b/tests/test_client.c @@ -134,8 +134,22 @@ int peer_cert_verify_cb(const unsigned char *peer_id, const char *cert_pem, unsi int accept_file_cb(const unsigned char *peer_id, uint64_t file_size, const char *filename, unsigned int filename_size) { - printf("accept_file_cb: peer_id %s\n", PICA_id_to_base64(peer_id, NULL)); - return 0; + int ret; + char namebuf[256]; + + printf("accept_file_cb: peer_id %s filename: %.*s\n", PICA_id_to_base64(peer_id, NULL), filename_size, filename); + + sprintf(namebuf, "/tmp/received_%.*s", filename_size, filename); + + ret = PICA_accept_file(chn, namebuf, strlen(namebuf)); + + if (ret != PICA_OK) + { + printf("faild to accept file, errror %i\n", ret); + return 0; + } + + return 2; } void accepted_file_cb(const unsigned char *peer_id) @@ -222,9 +236,10 @@ int main(int argc, char** argv) const char *nodeaddr = NULL, *nodeport = NULL, *certfile = NULL, *peerid = NULL, *localdirectaddr = NULL, *extport = NULL, + *filetosend = NULL, *locport = NULL; - while ((opt = getopt(argc, argv, "a:p:c:i:d:e:l:tmr")) != -1) + while ((opt = getopt(argc, argv, "a:p:c:i:d:e:l:f:tmr")) != -1) { switch(opt) { @@ -252,6 +267,10 @@ int main(int argc, char** argv) extport = optarg; break; + case 'f': + filetosend = optarg; + break; + case 'l': locport = optarg; break; @@ -456,6 +475,17 @@ cert_filename should point to file that contains client certificate, private key } } + if (connected_to_node == 1 && c2c_active == 1 && filetosend) + { + printf("sending file %s to peer...\n", filetosend); + ret = PICA_send_file(chn, filetosend); + + if (ret != PICA_OK) + printf("failed to send file %s, error = %i\n", filetosend, ret); + + filetosend = NULL; + } + } -- cgit v1.2.1