diff options
| author | Anton <anton@picapica> | 2017-11-12 01:13:02 +0400 |
|---|---|---|
| committer | Anton <anton@picapica> | 2017-11-12 01:13:02 +0400 |
| commit | fdb06bfda394614a18fa714f3209eba2b844925c (patch) | |
| tree | 6bd154cf9592d114093ecca08d8c392a2ac9eb67 | |
| parent | 1ec1d72b5dc98b93c86b4a09950a3e975efe8487 (diff) | |
| download | pica-pica-fdb06bfda394614a18fa714f3209eba2b844925c.tar.gz pica-pica-fdb06bfda394614a18fa714f3209eba2b844925c.zip | |
test_client: implemented sending & receiving files
| -rw-r--r-- | tests/test_client.c | 36 |
1 files changed, 33 insertions, 3 deletions
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; + } + } |
