aboutsummaryrefslogtreecommitdiff
path: root/src/psyc/test_psyc.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2014-01-06 00:09:37 +0000
committerGabor X Toth <*@tg-x.net>2014-01-06 00:09:37 +0000
commitc04d45b9738e1764d2e2c21efdbeb129f298d5d1 (patch)
tree9eec32efdd3fe3f9f459630af16058cc47436bce /src/psyc/test_psyc.c
parent83a0e31631dbc199c37c42f11004e1be544f04a8 (diff)
downloadgnunet-c04d45b9738e1764d2e2c21efdbeb129f298d5d1.tar.gz
gnunet-c04d45b9738e1764d2e2c21efdbeb129f298d5d1.zip
psyc: ipc messages
Diffstat (limited to 'src/psyc/test_psyc.c')
-rw-r--r--src/psyc/test_psyc.c74
1 files changed, 54 insertions, 20 deletions
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c
index 2986fdf6a..704819c50 100644
--- a/src/psyc/test_psyc.c
+++ b/src/psyc/test_psyc.c
@@ -148,11 +148,16 @@ join (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
148struct TransmitClosure 148struct TransmitClosure
149{ 149{
150 struct GNUNET_PSYC_MasterTransmitHandle *handle; 150 struct GNUNET_PSYC_MasterTransmitHandle *handle;
151 uint8_t n; 151
152 char *mod_names[16];
153 char *mod_values[16];
154 char *data[16];
155
156 uint8_t mod_count;
157 uint8_t data_count;
158
152 uint8_t paused; 159 uint8_t paused;
153 uint8_t fragment_count; 160 uint8_t n;
154 char *fragments[16];
155 uint16_t fragment_sizes[16];
156}; 161};
157 162
158 163
@@ -167,16 +172,47 @@ transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
167 172
168 173
169static int 174static int
170transmit_notify (void *cls, size_t *data_size, void *data) 175tmit_notify_mod (void *cls, size_t *data_size, void *data)
171{ 176{
172 struct TransmitClosure *tmit = cls; 177 struct TransmitClosure *tmit = cls;
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
174 "Transmit notify: %lu bytes available, " 179 "Transmit notify modifier: %lu bytes available, "
180 "processing modifier %u/%u.\n",
181 *data_size, tmit->n + 1, tmit->fragment_count);
182 /* FIXME: continuation */
183 uint16_t name_size = strlen (tmit->mod_names[tmit->n]);
184 uint16_t value_size = strlen (tmit->mod_values[tmit->n]);
185 if (name_size + 1 + value_size <= *data_size)
186 return GNUNET_NO;
187
188 *data_size = name_size + 1 + value_size;
189 memcpy (data, tmit->fragments[tmit->n], *data_size);
190
191 if (++tmit->n < tmit->mod_count)
192 {
193 return GNUNET_NO;
194 }
195 else
196 {
197 tmit->n = 0;
198 return GNUNET_YES;
199 }
200}
201
202
203static int
204tmit_notify_data (void *cls, size_t *data_size, void *data)
205{
206 struct TransmitClosure *tmit = cls;
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
208 "Transmit notify data: %lu bytes available, "
175 "processing fragment %u/%u.\n", 209 "processing fragment %u/%u.\n",
176 *data_size, tmit->n + 1, tmit->fragment_count); 210 *data_size, tmit->n + 1, tmit->fragment_count);
177 GNUNET_assert (tmit->fragment_sizes[tmit->n] <= *data_size); 211 uint16_t size = strlen (tmit->data[tmit->n]);
212 if (size <= *data_size)
213 return GNUNET_NO;
178 214
179 if (GNUNET_YES == tmit->paused && tmit->n == tmit->fragment_count - 1) 215 if (GNUNET_YES == tmit->paused && tmit->n == tmit->data_count - 1)
180 { 216 {
181 /* Send last fragment later. */ 217 /* Send last fragment later. */
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n"); 218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
@@ -188,13 +224,13 @@ transmit_notify (void *cls, size_t *data_size, void *data)
188 return GNUNET_NO; 224 return GNUNET_NO;
189 } 225 }
190 226
191 GNUNET_assert (tmit->fragment_sizes[tmit->n] <= *data_size); 227 *data_size = size;
192 *data_size = tmit->fragment_sizes[tmit->n]; 228 memcpy (data, tmit->data[tmit->n], size);
193 memcpy (data, tmit->fragments[tmit->n], *data_size);
194 229
195 return ++tmit->n < tmit->fragment_count ? GNUNET_NO : GNUNET_YES; 230 return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
196} 231}
197 232
233
198void 234void
199master_started (void *cls, uint64_t max_message_id) 235master_started (void *cls, uint64_t max_message_id)
200{ 236{
@@ -208,15 +244,13 @@ master_started (void *cls, uint64_t max_message_id)
208 "_foo_bar", "foo bar baz", 11); 244 "_foo_bar", "foo bar baz", 11);
209 245
210 struct TransmitClosure *tmit = GNUNET_new (struct TransmitClosure); 246 struct TransmitClosure *tmit = GNUNET_new (struct TransmitClosure);
211 tmit->fragment_count = 3; 247 tmit->data[0] = "foo";
212 tmit->fragments[0] = "foo"; 248 tmit->data[1] = "foo bar";
213 tmit->fragment_sizes[0] = 4; 249 tmit->data[2] = "foo bar baz";
214 tmit->fragments[1] = "foo bar"; 250 tmit->data_count = 3;
215 tmit->fragment_sizes[1] = 7;
216 tmit->fragments[2] = "foo bar baz";
217 tmit->fragment_sizes[2] = 11;
218 tmit->handle 251 tmit->handle
219 = GNUNET_PSYC_master_transmit (mst, "_test", env, transmit_notify, tmit, 252 = GNUNET_PSYC_master_transmit (mst, "_test", tmit_notify_mod,
253 tmit_notify_data, tmit,
220 GNUNET_PSYC_MASTER_TRANSMIT_INC_GROUP_GEN); 254 GNUNET_PSYC_MASTER_TRANSMIT_INC_GROUP_GEN);
221} 255}
222 256