diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-05 11:51:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-05 11:51:32 +0000 |
commit | 0b8a02cc156081ad9a087ea91952a5cfc4270475 (patch) | |
tree | 1d7ea9dd11882d0d5d97c6fff8dbd7cfc8947a79 /src/util/test_service.c | |
parent | 904c393e01da94dc9e842b1c3050eea7ae96b4f0 (diff) | |
download | gnunet-0b8a02cc156081ad9a087ea91952a5cfc4270475.tar.gz gnunet-0b8a02cc156081ad9a087ea91952a5cfc4270475.zip |
update tests to use new MQ API
Diffstat (limited to 'src/util/test_service.c')
-rw-r--r-- | src/util/test_service.c | 90 |
1 files changed, 42 insertions, 48 deletions
diff --git a/src/util/test_service.c b/src/util/test_service.c index f340b724d..707f8658b 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2013 GNUnet e.V. | 3 | Copyright (C) 2009, 2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -37,16 +37,16 @@ static struct GNUNET_SERVICE_Context *sctx; | |||
37 | 37 | ||
38 | static int ok = 1; | 38 | static int ok = 1; |
39 | 39 | ||
40 | static struct GNUNET_CLIENT_Connection *client; | 40 | static struct GNUNET_MQ_Handle *mq; |
41 | 41 | ||
42 | 42 | ||
43 | static void | 43 | static void |
44 | do_stop (void *cls) | 44 | do_stop (void *cls) |
45 | { | 45 | { |
46 | if (NULL != client) | 46 | if (NULL != mq) |
47 | { | 47 | { |
48 | GNUNET_CLIENT_disconnect (client); | 48 | GNUNET_MQ_destroy (mq); |
49 | client = NULL; | 49 | mq = NULL; |
50 | } | 50 | } |
51 | if (NULL != sctx) | 51 | if (NULL != sctx) |
52 | { | 52 | { |
@@ -60,49 +60,33 @@ do_stop (void *cls) | |||
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
63 | static size_t | ||
64 | build_msg (void *cls, size_t size, void *buf) | ||
65 | { | ||
66 | struct GNUNET_MessageHeader *msg = buf; | ||
67 | |||
68 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
69 | { | ||
70 | /* timeout */ | ||
71 | GNUNET_break (0); | ||
72 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | ||
73 | ok = 1; | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected, transmitting\n"); | ||
78 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | ||
79 | msg->type = htons (MY_TYPE); | ||
80 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
81 | return sizeof (struct GNUNET_MessageHeader); | ||
82 | } | ||
83 | |||
84 | |||
85 | static void | 63 | static void |
86 | ready (void *cls, | 64 | ready (void *cls, |
87 | int result) | 65 | int result) |
88 | { | 66 | { |
89 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 67 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
68 | struct GNUNET_MQ_Envelope *env; | ||
69 | struct GNUNET_MessageHeader *msg; | ||
90 | 70 | ||
91 | GNUNET_assert (GNUNET_YES == result); | 71 | GNUNET_assert (GNUNET_YES == result); |
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service confirmed running\n"); | ||
93 | client = GNUNET_CLIENT_connect ("test_service", cfg); | ||
94 | GNUNET_assert (client != NULL); | ||
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 72 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
96 | "Client connecting, waiting to transmit\n"); | 73 | "Service confirmed running\n"); |
97 | GNUNET_CLIENT_notify_transmit_ready (client, | 74 | mq = GNUNET_CLIENT_connecT (cfg, |
98 | sizeof (struct GNUNET_MessageHeader), | 75 | "test_service", |
99 | GNUNET_TIME_UNIT_SECONDS, GNUNET_NO, | 76 | NULL, |
100 | &build_msg, NULL); | 77 | NULL, |
78 | NULL); | ||
79 | GNUNET_assert (NULL != mq); | ||
80 | env = GNUNET_MQ_msg (msg, | ||
81 | MY_TYPE); | ||
82 | GNUNET_MQ_send (mq, | ||
83 | env); | ||
101 | } | 84 | } |
102 | 85 | ||
103 | 86 | ||
104 | static void | 87 | static void |
105 | recv_cb (void *cls, struct GNUNET_SERVER_Client *sc, | 88 | recv_cb (void *cls, |
89 | struct GNUNET_SERVER_Client *sc, | ||
106 | const struct GNUNET_MessageHeader *message) | 90 | const struct GNUNET_MessageHeader *message) |
107 | { | 91 | { |
108 | GNUNET_assert (NULL != message); | 92 | GNUNET_assert (NULL != message); |
@@ -120,11 +104,14 @@ static struct GNUNET_SERVER_MessageHandler myhandlers[] = { | |||
120 | 104 | ||
121 | 105 | ||
122 | static void | 106 | static void |
123 | runner (void *cls, struct GNUNET_SERVER_Handle *server, | 107 | runner (void *cls, |
108 | struct GNUNET_SERVER_Handle *server, | ||
124 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 109 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
125 | { | 110 | { |
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service initializing\n"); | 111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
127 | GNUNET_SERVER_add_handlers (server, myhandlers); | 112 | "Service initializing\n"); |
113 | GNUNET_SERVER_add_handlers (server, | ||
114 | myhandlers); | ||
128 | GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS, | 115 | GNUNET_CLIENT_service_test ("test_service", cfg, GNUNET_TIME_UNIT_SECONDS, |
129 | &ready, (void *) cfg); | 116 | &ready, (void *) cfg); |
130 | } | 117 | } |
@@ -158,21 +145,28 @@ ready6 (void *cls, | |||
158 | int result) | 145 | int result) |
159 | { | 146 | { |
160 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 147 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
148 | struct GNUNET_MQ_Envelope *env; | ||
149 | struct GNUNET_MessageHeader *msg; | ||
161 | 150 | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 ready\n"); | ||
163 | GNUNET_assert (GNUNET_YES == result); | 151 | GNUNET_assert (GNUNET_YES == result); |
164 | client = GNUNET_CLIENT_connect ("test_service6", cfg); | 152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
165 | GNUNET_assert (client != NULL); | 153 | "V6 ready\n"); |
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n"); | 154 | mq = GNUNET_CLIENT_connecT (cfg, |
167 | GNUNET_CLIENT_notify_transmit_ready (client, | 155 | "test_service6", |
168 | sizeof (struct GNUNET_MessageHeader), | 156 | NULL, |
169 | GNUNET_TIME_UNIT_SECONDS, GNUNET_NO, | 157 | NULL, |
170 | &build_msg, NULL); | 158 | NULL); |
159 | GNUNET_assert (NULL != mq); | ||
160 | env = GNUNET_MQ_msg (msg, | ||
161 | MY_TYPE); | ||
162 | GNUNET_MQ_send (mq, | ||
163 | env); | ||
171 | } | 164 | } |
172 | 165 | ||
173 | 166 | ||
174 | static void | 167 | static void |
175 | runner6 (void *cls, struct GNUNET_SERVER_Handle *server, | 168 | runner6 (void *cls, |
169 | struct GNUNET_SERVER_Handle *server, | ||
176 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 170 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
177 | { | 171 | { |
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |