summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAnton <anton@picapica>2017-07-12 13:16:08 +0400
committerAnton <anton@picapica>2017-07-12 13:16:08 +0400
commit0b7e4355d56973ec801ef86371d837dd50b1012e (patch)
treee6707143c348a242e7bef3e1a5d9e910c1863b71 /tests
parent9b2132d83ab2ea8fa60cdb7ebfebf10f7c62c470 (diff)
downloadpica-pica-0b7e4355d56973ec801ef86371d837dd50b1012e.tar.gz
pica-pica-0b7e4355d56973ec801ef86371d837dd50b1012e.zip
implemented echo mode in test client
Diffstat (limited to 'tests')
-rw-r--r--tests/test_client.c23
1 files changed, 21 insertions, 2 deletions
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);