summaryrefslogtreecommitdiff
path: root/src/psyc/test_psyc.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-10-10 18:08:53 +0000
committerGabor X Toth <*@tg-x.net>2013-10-10 18:08:53 +0000
commit1b5d4aba9d8bbcb62c93f96782e3567f6f79d0cb (patch)
tree3cd28bfee831af0417c2dcbb543c03481517ad00 /src/psyc/test_psyc.c
parent67a8e21eedb6d35fec76841d4a1a6b4b41b37879 (diff)
downloadgnunet-1b5d4aba9d8bbcb62c93f96782e3567f6f79d0cb.tar.gz
gnunet-1b5d4aba9d8bbcb62c93f96782e3567f6f79d0cb.zip
PSYC: master msg transmission
Diffstat (limited to 'src/psyc/test_psyc.c')
-rw-r--r--src/psyc/test_psyc.c90
1 files changed, 83 insertions, 7 deletions
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c
index b5bc6d135..1d7035a87 100644
--- a/src/psyc/test_psyc.c
+++ b/src/psyc/test_psyc.c
@@ -19,8 +19,8 @@
19 */ 19 */
20 20
21/** 21/**
22 * @file psycstore/test_psycstore.c 22 * @file psyc/test_psyc.c
23 * @brief Test for the PSYCstore service. 23 * @brief Test for the PSYC service.
24 * @author Gabor X Toth 24 * @author Gabor X Toth
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 */ 26 */
@@ -30,6 +30,7 @@
30#include "gnunet_common.h" 30#include "gnunet_common.h"
31#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
32#include "gnunet_testing_lib.h" 32#include "gnunet_testing_lib.h"
33#include "gnunet_env_lib.h"
33#include "gnunet_psyc_service.h" 34#include "gnunet_psyc_service.h"
34 35
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
@@ -59,6 +60,8 @@ static struct GNUNET_CRYPTO_EccPrivateKey *slave_key;
59static struct GNUNET_CRYPTO_EccPublicSignKey channel_pub_key; 60static struct GNUNET_CRYPTO_EccPublicSignKey channel_pub_key;
60static struct GNUNET_CRYPTO_EccPublicSignKey slave_pub_key; 61static struct GNUNET_CRYPTO_EccPublicSignKey slave_pub_key;
61 62
63struct GNUNET_PSYC_MasterTransmitHandle *mth;
64
62/** 65/**
63 * Clean up all resources used. 66 * Clean up all resources used.
64 */ 67 */
@@ -120,11 +123,14 @@ end ()
120 123
121static int 124static int
122method (void *cls, const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key, 125method (void *cls, const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key,
123 uint64_t message_id, const char *method_name, 126 uint64_t message_id, const char *name,
124 size_t modifier_count, const struct GNUNET_ENV_Modifier *modifiers, 127 size_t modifier_count, const struct GNUNET_ENV_Modifier *modifiers,
125 uint64_t data_offset, const void *data, size_t data_size, 128 uint64_t data_offset, const void *data, size_t data_size,
126 enum GNUNET_PSYC_MessageFlags flags) 129 enum GNUNET_PSYC_MessageFlags flags)
127{ 130{
131 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
132 "Method: %s, modifiers: %lu, flags: %u\n%.*s\n",
133 name, modifier_count, flags, data_size, data);
128 return GNUNET_OK; 134 return GNUNET_OK;
129} 135}
130 136
@@ -138,11 +144,72 @@ join (void *cls, const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key,
138 return GNUNET_OK; 144 return GNUNET_OK;
139} 145}
140 146
147struct TransmitClosure
148{
149 struct GNUNET_PSYC_MasterTransmitHandle *handle;
150 uint8_t n;
151 uint8_t fragment_count;
152 char *fragments[16];
153 uint16_t fragment_sizes[16];
154};
155
156
157static void
158transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
159{
160 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transmit resume\n");
161 struct TransmitClosure *tmit = cls;
162 GNUNET_PSYC_master_transmit_resume (tmit->handle);
163}
164
165
166static int
167transmit_notify (void *cls, size_t *data_size, void *data)
168{
169 struct TransmitClosure *tmit = cls;
170 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
171 "Transmit notify: %lu bytes\n", *data_size);
172
173 if (tmit->fragment_count <= tmit->n)
174 return GNUNET_YES;
175
176 GNUNET_assert (tmit->fragment_sizes[tmit->n] <= *data_size);
177
178 *data_size = tmit->fragment_sizes[tmit->n];
179 memcpy (data, tmit->fragments[tmit->n], *data_size);
180 tmit->n++;
181
182 if (tmit->n == tmit->fragment_count - 1)
183 {
184 /* Send last fragment later. */
185 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &transmit_resume,
186 tmit);
187 *data_size = 0;
188 return GNUNET_NO;
189 }
190 return tmit->n <= tmit->fragment_count ? GNUNET_NO : GNUNET_YES;
191}
141 192
142void 193void
143master_started (void *cls, uint64_t max_message_id) 194master_started (void *cls, uint64_t max_message_id)
144{ 195{
145 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Master started: %lu\n", max_message_id); 196 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Master started: %lu\n", max_message_id);
197
198 struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
199 GNUNET_ENV_environment_add_mod (env, GNUNET_ENV_OP_ASSIGN,
200 "_foo", "bar baz", 7);
201 GNUNET_ENV_environment_add_mod (env, GNUNET_ENV_OP_ASSIGN,
202 "_foo_bar", "foo bar baz", 11);
203
204 struct TransmitClosure *tmit = GNUNET_new (struct TransmitClosure);
205 tmit->fragment_count = 2;
206 tmit->fragments[0] = "foo bar";
207 tmit->fragment_sizes[0] = 7;
208 tmit->fragments[1] = "baz!";
209 tmit->fragment_sizes[1] = 4;
210 tmit->handle
211 = GNUNET_PSYC_master_transmit (mst, "_test", env, transmit_notify, tmit,
212 GNUNET_PSYC_MASTER_TRANSMIT_INC_GROUP_GEN);
146} 213}
147 214
148 215
@@ -157,7 +224,7 @@ slave_joined (void *cls, uint64_t max_message_id)
157 * Main function of the test, run from scheduler. 224 * Main function of the test, run from scheduler.
158 * 225 *
159 * @param cls NULL 226 * @param cls NULL
160 * @param cfg configuration we use (also to connect to PSYCstore service) 227 * @param cfg configuration we use (also to connect to PSYC service)
161 * @param peer handle to access more of the peer (not used) 228 * @param peer handle to access more of the peer (not used)
162 */ 229 */
163static void 230static void
@@ -182,9 +249,18 @@ run (void *cls,
182 mst = GNUNET_PSYC_master_start (cfg, channel_key, 249 mst = GNUNET_PSYC_master_start (cfg, channel_key,
183 GNUNET_PSYC_CHANNEL_PRIVATE, 250 GNUNET_PSYC_CHANNEL_PRIVATE,
184 &method, &join, &master_started, NULL); 251 &method, &join, &master_started, NULL);
185 252 return;
186 slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key, 253 struct GNUNET_PeerIdentity origin;
187 &method, &join, &slave_joined, NULL); 254 struct GNUNET_PeerIdentity relays[16];
255 struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
256 GNUNET_ENV_environment_add_mod (env, GNUNET_ENV_OP_ASSIGN,
257 "_foo", "bar baz", 7);
258 GNUNET_ENV_environment_add_mod (env, GNUNET_ENV_OP_ASSIGN,
259 "_foo_bar", "foo bar baz", 11);
260 slv = GNUNET_PSYC_slave_join (cfg, &channel_pub_key, slave_key, &origin,
261 16, relays, &method, &join, &slave_joined,
262 NULL, "_request_join", env, "some data", 9);
263 GNUNET_ENV_environment_destroy (env);
188} 264}
189 265
190 266