diff options
author | Gabor X Toth <*@tg-x.net> | 2013-09-25 17:46:03 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2013-09-25 17:46:03 +0000 |
commit | 303d6a97bc552a337c992944c3151ea53c1f74dc (patch) | |
tree | 295d478fd8e82879830588da0c47778512ffad9b /src/psycstore | |
parent | ffc11bb1c2c09cda9e7bed84e56cedb8ed49d46c (diff) | |
download | gnunet-303d6a97bc552a337c992944c3151ea53c1f74dc.tar.gz gnunet-303d6a97bc552a337c992944c3151ea53c1f74dc.zip |
psycstore: single counters function for master & slave
Diffstat (limited to 'src/psycstore')
-rw-r--r-- | src/psycstore/gnunet-service-psycstore.c | 72 | ||||
-rw-r--r-- | src/psycstore/plugin_psycstore_sqlite.c | 50 | ||||
-rw-r--r-- | src/psycstore/psycstore.h | 138 | ||||
-rw-r--r-- | src/psycstore/psycstore_api.c | 162 | ||||
-rw-r--r-- | src/psycstore/test_plugin_psycstore.c | 16 | ||||
-rw-r--r-- | src/psycstore/test_psycstore.c | 71 |
6 files changed, 201 insertions, 308 deletions
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c index 14945641f..128bfd46c 100644 --- a/src/psycstore/gnunet-service-psycstore.c +++ b/src/psycstore/gnunet-service-psycstore.c | |||
@@ -170,7 +170,7 @@ send_state_var (void *cls, const char *name, | |||
170 | res->op_id = sc->op_id; | 170 | res->op_id = sc->op_id; |
171 | res->name_size = htons (name_size); | 171 | res->name_size = htons (name_size); |
172 | memcpy (&res[1], name, name_size); | 172 | memcpy (&res[1], name, name_size); |
173 | memcpy ((void *) &res[1] + name_size, value, value_size); | 173 | memcpy ((char *) &res[1] + name_size, value, value_size); |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
175 | "Sending state variable %s to client\n", name); | 175 | "Sending state variable %s to client\n", name); |
176 | GNUNET_SERVER_notification_context_add (nc, sc->client); | 176 | GNUNET_SERVER_notification_context_add (nc, sc->client); |
@@ -334,19 +334,21 @@ handle_message_get_fragment (void *cls, | |||
334 | 334 | ||
335 | 335 | ||
336 | static void | 336 | static void |
337 | handle_counters_get_master (void *cls, | 337 | handle_counters_get (void *cls, |
338 | struct GNUNET_SERVER_Client *client, | 338 | struct GNUNET_SERVER_Client *client, |
339 | const struct GNUNET_MessageHeader *msg) | 339 | const struct GNUNET_MessageHeader *msg) |
340 | { | 340 | { |
341 | const struct OperationRequest *req = (const struct OperationRequest *) msg; | 341 | const struct OperationRequest *req = (const struct OperationRequest *) msg; |
342 | struct MasterCountersResult res = { {0} }; | 342 | struct CountersResult res = { {0} }; |
343 | 343 | ||
344 | int ret = db->counters_get_master (db->cls, &req->channel_key, | 344 | int ret = db->counters_message_get (db->cls, &req->channel_key, |
345 | &res.fragment_id, &res.message_id, | 345 | &res.max_fragment_id, &res.max_message_id, |
346 | &res.group_generation); | 346 | &res.max_group_generation); |
347 | switch (ret) | 347 | switch (ret) |
348 | { | 348 | { |
349 | case GNUNET_YES: | 349 | case GNUNET_YES: |
350 | ret = db->counters_state_get (db->cls, &req->channel_key, | ||
351 | &res.max_state_message_id); | ||
350 | case GNUNET_NO: | 352 | case GNUNET_NO: |
351 | break; | 353 | break; |
352 | default: | 354 | default: |
@@ -354,50 +356,14 @@ handle_counters_get_master (void *cls, | |||
354 | _("Failed to get master counters!\n")); | 356 | _("Failed to get master counters!\n")); |
355 | } | 357 | } |
356 | 358 | ||
357 | res.header.type | 359 | res.header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS); |
358 | = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_MASTER); | ||
359 | res.header.size = htons (sizeof (res)); | ||
360 | res.result_code = htonl (ret); | ||
361 | res.op_id = req->op_id; | ||
362 | res.fragment_id = GNUNET_htonll (res.fragment_id); | ||
363 | res.message_id = GNUNET_htonll (res.message_id); | ||
364 | res.group_generation = GNUNET_htonll (res.group_generation); | ||
365 | |||
366 | GNUNET_SERVER_notification_context_add (nc, client); | ||
367 | GNUNET_SERVER_notification_context_unicast (nc, client, &res.header, | ||
368 | GNUNET_NO); | ||
369 | |||
370 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
371 | } | ||
372 | |||
373 | |||
374 | static void | ||
375 | handle_counters_get_slave (void *cls, | ||
376 | struct GNUNET_SERVER_Client *client, | ||
377 | const struct GNUNET_MessageHeader *msg) | ||
378 | { | ||
379 | const struct OperationRequest *req = (const struct OperationRequest *) msg; | ||
380 | struct SlaveCountersResult res = { {0} }; | ||
381 | |||
382 | int ret = db->counters_get_slave (db->cls, &req->channel_key, | ||
383 | &res.max_known_msg_id); | ||
384 | |||
385 | switch (ret) | ||
386 | { | ||
387 | case GNUNET_YES: | ||
388 | case GNUNET_NO: | ||
389 | break; | ||
390 | default: | ||
391 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
392 | _("Failed to get slave counters!\n")); | ||
393 | } | ||
394 | |||
395 | res.header.type | ||
396 | = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_SLAVE); | ||
397 | res.header.size = htons (sizeof (res)); | 360 | res.header.size = htons (sizeof (res)); |
398 | res.result_code = htonl (ret); | 361 | res.result_code = htonl (ret); |
399 | res.op_id = req->op_id; | 362 | res.op_id = req->op_id; |
400 | res.max_known_msg_id = GNUNET_htonll (res.max_known_msg_id); | 363 | res.max_fragment_id = GNUNET_htonll (res.max_fragment_id); |
364 | res.max_message_id = GNUNET_htonll (res.max_message_id); | ||
365 | res.max_group_generation = GNUNET_htonll (res.max_group_generation); | ||
366 | res.max_state_message_id = GNUNET_htonll (res.max_state_message_id); | ||
401 | 367 | ||
402 | GNUNET_SERVER_notification_context_add (nc, client); | 368 | GNUNET_SERVER_notification_context_add (nc, client); |
403 | GNUNET_SERVER_notification_context_unicast (nc, client, &res.header, | 369 | GNUNET_SERVER_notification_context_unicast (nc, client, &res.header, |
@@ -697,12 +663,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
697 | GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT, | 663 | GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT, |
698 | sizeof (struct MessageGetFragmentRequest) }, | 664 | sizeof (struct MessageGetFragmentRequest) }, |
699 | 665 | ||
700 | { &handle_counters_get_master, NULL, | 666 | { &handle_counters_get, NULL, |
701 | GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_MASTER, | 667 | GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET, |
702 | sizeof (struct OperationRequest) }, | ||
703 | |||
704 | { &handle_counters_get_slave, NULL, | ||
705 | GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_SLAVE, | ||
706 | sizeof (struct OperationRequest) }, | 668 | sizeof (struct OperationRequest) }, |
707 | 669 | ||
708 | { &handle_state_modify, NULL, | 670 | { &handle_state_modify, NULL, |
diff --git a/src/psycstore/plugin_psycstore_sqlite.c b/src/psycstore/plugin_psycstore_sqlite.c index e9cc76e70..592eaf384 100644 --- a/src/psycstore/plugin_psycstore_sqlite.c +++ b/src/psycstore/plugin_psycstore_sqlite.c | |||
@@ -143,14 +143,14 @@ struct Plugin | |||
143 | sqlite3_stmt *select_message_fragment; | 143 | sqlite3_stmt *select_message_fragment; |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * Precompiled SQL for counters_get_master() | 146 | * Precompiled SQL for counters_get_message() |
147 | */ | 147 | */ |
148 | sqlite3_stmt *select_counters_master; | 148 | sqlite3_stmt *select_counters_message; |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Precompiled SQL for counters_get_slave() | 151 | * Precompiled SQL for counters_get_state() |
152 | */ | 152 | */ |
153 | sqlite3_stmt *select_max_state_message_id; | 153 | sqlite3_stmt *select_counters_state; |
154 | 154 | ||
155 | /** | 155 | /** |
156 | * Precompiled SQL for state_modify_end() | 156 | * Precompiled SQL for state_modify_end() |
@@ -482,13 +482,13 @@ database_setup (struct Plugin *plugin) | |||
482 | "FROM messages\n" | 482 | "FROM messages\n" |
483 | "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" | 483 | "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" |
484 | "ORDER BY fragment_id DESC LIMIT 1;", | 484 | "ORDER BY fragment_id DESC LIMIT 1;", |
485 | &plugin->select_counters_master); | 485 | &plugin->select_counters_message); |
486 | 486 | ||
487 | sql_prepare (plugin->dbh, | 487 | sql_prepare (plugin->dbh, |
488 | "SELECT max_state_message_id\n" | 488 | "SELECT max_state_message_id\n" |
489 | "FROM channels\n" | 489 | "FROM channels\n" |
490 | "WHERE pub_key = ? AND max_state_message_id IS NOT NULL;", | 490 | "WHERE pub_key = ? AND max_state_message_id IS NOT NULL;", |
491 | &plugin->select_max_state_message_id); | 491 | &plugin->select_counters_state); |
492 | 492 | ||
493 | sql_prepare (plugin->dbh, | 493 | sql_prepare (plugin->dbh, |
494 | "UPDATE channels\n" | 494 | "UPDATE channels\n" |
@@ -1205,21 +1205,21 @@ message_get_fragment (void *cls, | |||
1205 | } | 1205 | } |
1206 | 1206 | ||
1207 | /** | 1207 | /** |
1208 | * Retrieve latest values of counters for a channel master. | 1208 | * Retrieve the max. values of message counters for a channel. |
1209 | * | 1209 | * |
1210 | * @see GNUNET_PSYCSTORE_counters_get_master() | 1210 | * @see GNUNET_PSYCSTORE_counters_get() |
1211 | * | 1211 | * |
1212 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 1212 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
1213 | */ | 1213 | */ |
1214 | static int | 1214 | static int |
1215 | counters_get_master (void *cls, | 1215 | counters_message_get (void *cls, |
1216 | const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key, | 1216 | const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key, |
1217 | uint64_t *fragment_id, | 1217 | uint64_t *max_fragment_id, |
1218 | uint64_t *message_id, | 1218 | uint64_t *max_message_id, |
1219 | uint64_t *group_generation) | 1219 | uint64_t *max_group_generation) |
1220 | { | 1220 | { |
1221 | struct Plugin *plugin = cls; | 1221 | struct Plugin *plugin = cls; |
1222 | sqlite3_stmt *stmt = plugin->select_counters_master; | 1222 | sqlite3_stmt *stmt = plugin->select_counters_message; |
1223 | int ret = GNUNET_SYSERR; | 1223 | int ret = GNUNET_SYSERR; |
1224 | 1224 | ||
1225 | if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key, | 1225 | if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key, |
@@ -1237,9 +1237,9 @@ counters_get_master (void *cls, | |||
1237 | ret = GNUNET_NO; | 1237 | ret = GNUNET_NO; |
1238 | break; | 1238 | break; |
1239 | case SQLITE_ROW: | 1239 | case SQLITE_ROW: |
1240 | *fragment_id = sqlite3_column_int64 (stmt, 0); | 1240 | *max_fragment_id = sqlite3_column_int64 (stmt, 0); |
1241 | *message_id = sqlite3_column_int64 (stmt, 1); | 1241 | *max_message_id = sqlite3_column_int64 (stmt, 1); |
1242 | *group_generation = sqlite3_column_int64 (stmt, 2); | 1242 | *max_group_generation = sqlite3_column_int64 (stmt, 2); |
1243 | ret = GNUNET_OK; | 1243 | ret = GNUNET_OK; |
1244 | break; | 1244 | break; |
1245 | default: | 1245 | default: |
@@ -1258,19 +1258,19 @@ counters_get_master (void *cls, | |||
1258 | } | 1258 | } |
1259 | 1259 | ||
1260 | /** | 1260 | /** |
1261 | * Retrieve latest values of counters for a channel slave. | 1261 | * Retrieve the max. values of state counters for a channel. |
1262 | * | 1262 | * |
1263 | * @see GNUNET_PSYCSTORE_counters_get_slave() | 1263 | * @see GNUNET_PSYCSTORE_counters_get() |
1264 | * | 1264 | * |
1265 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 1265 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
1266 | */ | 1266 | */ |
1267 | static int | 1267 | static int |
1268 | counters_get_slave (void *cls, | 1268 | counters_state_get (void *cls, |
1269 | const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key, | 1269 | const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key, |
1270 | uint64_t *max_state_msg_id) | 1270 | uint64_t *max_state_message_id) |
1271 | { | 1271 | { |
1272 | struct Plugin *plugin = cls; | 1272 | struct Plugin *plugin = cls; |
1273 | sqlite3_stmt *stmt = plugin->select_max_state_message_id; | 1273 | sqlite3_stmt *stmt = plugin->select_counters_state; |
1274 | int ret = GNUNET_SYSERR; | 1274 | int ret = GNUNET_SYSERR; |
1275 | 1275 | ||
1276 | if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key, | 1276 | if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key, |
@@ -1288,7 +1288,7 @@ counters_get_slave (void *cls, | |||
1288 | ret = GNUNET_NO; | 1288 | ret = GNUNET_NO; |
1289 | break; | 1289 | break; |
1290 | case SQLITE_ROW: | 1290 | case SQLITE_ROW: |
1291 | *max_state_msg_id = sqlite3_column_int64 (stmt, 0); | 1291 | *max_state_message_id = sqlite3_column_int64 (stmt, 0); |
1292 | ret = GNUNET_OK; | 1292 | ret = GNUNET_OK; |
1293 | break; | 1293 | break; |
1294 | default: | 1294 | default: |
@@ -1779,8 +1779,8 @@ libgnunet_plugin_psycstore_sqlite_init (void *cls) | |||
1779 | api->fragment_get = &fragment_get; | 1779 | api->fragment_get = &fragment_get; |
1780 | api->message_get = &message_get; | 1780 | api->message_get = &message_get; |
1781 | api->message_get_fragment = &message_get_fragment; | 1781 | api->message_get_fragment = &message_get_fragment; |
1782 | api->counters_get_master = &counters_get_master; | 1782 | api->counters_message_get = &counters_message_get; |
1783 | api->counters_get_slave = &counters_get_slave; | 1783 | api->counters_state_get = &counters_state_get; |
1784 | api->state_modify_begin = &state_modify_begin; | 1784 | api->state_modify_begin = &state_modify_begin; |
1785 | api->state_modify_set = &state_modify_set; | 1785 | api->state_modify_set = &state_modify_set; |
1786 | api->state_modify_end = &state_modify_end; | 1786 | api->state_modify_end = &state_modify_end; |
diff --git a/src/psycstore/psycstore.h b/src/psycstore/psycstore.h index cc382a456..61d4adc06 100644 --- a/src/psycstore/psycstore.h +++ b/src/psycstore/psycstore.h | |||
@@ -43,12 +43,15 @@ struct OperationResult | |||
43 | struct GNUNET_MessageHeader header; | 43 | struct GNUNET_MessageHeader header; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Operation ID. | ||
47 | */ | ||
48 | uint32_t op_id GNUNET_PACKED; | ||
49 | |||
50 | /** | ||
46 | * Status code for the operation. | 51 | * Status code for the operation. |
47 | */ | 52 | */ |
48 | int64_t result_code GNUNET_PACKED; | 53 | int64_t result_code GNUNET_PACKED; |
49 | 54 | ||
50 | uint32_t op_id GNUNET_PACKED; | ||
51 | |||
52 | /* followed by 0-terminated error message (on error) */ | 55 | /* followed by 0-terminated error message (on error) */ |
53 | 56 | ||
54 | }; | 57 | }; |
@@ -57,52 +60,32 @@ struct OperationResult | |||
57 | /** | 60 | /** |
58 | * Answer from service to client about master counters. | 61 | * Answer from service to client about master counters. |
59 | * | 62 | * |
60 | * @see GNUNET_PSYCSTORE_counters_get_master() | 63 | * @see GNUNET_PSYCSTORE_counters_get() |
61 | */ | 64 | */ |
62 | struct MasterCountersResult | 65 | struct CountersResult |
63 | { | 66 | { |
64 | /** | 67 | /** |
65 | * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_MASTER | 68 | * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS |
66 | */ | 69 | */ |
67 | struct GNUNET_MessageHeader header; | 70 | struct GNUNET_MessageHeader header; |
68 | 71 | ||
69 | uint64_t fragment_id GNUNET_PACKED; | ||
70 | |||
71 | uint64_t message_id GNUNET_PACKED; | ||
72 | |||
73 | uint64_t group_generation GNUNET_PACKED; | ||
74 | |||
75 | /** | 72 | /** |
76 | * Status code for the operation. | 73 | * Operation ID. |
77 | */ | 74 | */ |
78 | int64_t result_code GNUNET_PACKED; | ||
79 | |||
80 | uint32_t op_id GNUNET_PACKED; | 75 | uint32_t op_id GNUNET_PACKED; |
81 | 76 | ||
82 | }; | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Answer from service to client about slave counters. | ||
87 | * | ||
88 | * @see GNUNET_PSYCSTORE_counters_get_slave() | ||
89 | */ | ||
90 | struct SlaveCountersResult | ||
91 | { | ||
92 | /** | ||
93 | * Type: GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_SLAVE | ||
94 | */ | ||
95 | struct GNUNET_MessageHeader header; | ||
96 | |||
97 | uint64_t max_known_msg_id GNUNET_PACKED; | ||
98 | |||
99 | /** | 77 | /** |
100 | * Status code for the operation. | 78 | * Status code for the operation. |
101 | */ | 79 | */ |
102 | int64_t result_code GNUNET_PACKED; | 80 | int64_t result_code GNUNET_PACKED; |
103 | 81 | ||
104 | uint32_t op_id GNUNET_PACKED; | 82 | uint64_t max_fragment_id GNUNET_PACKED; |
105 | 83 | ||
84 | uint64_t max_message_id GNUNET_PACKED; | ||
85 | |||
86 | uint64_t max_group_generation GNUNET_PACKED; | ||
87 | |||
88 | uint64_t max_state_message_id GNUNET_PACKED; | ||
106 | }; | 89 | }; |
107 | 90 | ||
108 | 91 | ||
@@ -116,6 +99,9 @@ struct FragmentResult | |||
116 | */ | 99 | */ |
117 | struct GNUNET_MessageHeader header; | 100 | struct GNUNET_MessageHeader header; |
118 | 101 | ||
102 | /** | ||
103 | * Operation ID. | ||
104 | */ | ||
119 | uint32_t op_id GNUNET_PACKED; | 105 | uint32_t op_id GNUNET_PACKED; |
120 | 106 | ||
121 | uint32_t psycstore_flags GNUNET_PACKED; | 107 | uint32_t psycstore_flags GNUNET_PACKED; |
@@ -135,6 +121,9 @@ struct StateResult | |||
135 | */ | 121 | */ |
136 | struct GNUNET_MessageHeader header; | 122 | struct GNUNET_MessageHeader header; |
137 | 123 | ||
124 | /** | ||
125 | * Operation ID. | ||
126 | */ | ||
138 | uint32_t op_id GNUNET_PACKED; | 127 | uint32_t op_id GNUNET_PACKED; |
139 | 128 | ||
140 | uint16_t name_size GNUNET_PACKED; | 129 | uint16_t name_size GNUNET_PACKED; |
@@ -150,9 +139,13 @@ struct OperationRequest | |||
150 | { | 139 | { |
151 | struct GNUNET_MessageHeader header; | 140 | struct GNUNET_MessageHeader header; |
152 | 141 | ||
142 | /** | ||
143 | * Operation ID. | ||
144 | */ | ||
145 | uint32_t op_id GNUNET_PACKED; | ||
146 | |||
153 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 147 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
154 | 148 | ||
155 | uint32_t op_id GNUNET_PACKED; | ||
156 | }; | 149 | }; |
157 | 150 | ||
158 | 151 | ||
@@ -167,6 +160,11 @@ struct MembershipStoreRequest | |||
167 | struct GNUNET_MessageHeader header; | 160 | struct GNUNET_MessageHeader header; |
168 | 161 | ||
169 | /** | 162 | /** |
163 | * Operation ID. | ||
164 | */ | ||
165 | uint32_t op_id GNUNET_PACKED; | ||
166 | |||
167 | /** | ||
170 | * Channel's public key. | 168 | * Channel's public key. |
171 | */ | 169 | */ |
172 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 170 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
@@ -176,12 +174,10 @@ struct MembershipStoreRequest | |||
176 | */ | 174 | */ |
177 | struct GNUNET_CRYPTO_EccPublicSignKey slave_key; | 175 | struct GNUNET_CRYPTO_EccPublicSignKey slave_key; |
178 | 176 | ||
179 | int did_join; | 177 | uint64_t announced_at GNUNET_PACKED; |
180 | uint64_t announced_at; | 178 | uint64_t effective_since GNUNET_PACKED; |
181 | uint64_t effective_since; | 179 | uint64_t group_generation GNUNET_PACKED; |
182 | uint64_t group_generation; | 180 | int did_join GNUNET_PACKED; |
183 | |||
184 | uint32_t op_id GNUNET_PACKED; | ||
185 | }; | 181 | }; |
186 | 182 | ||
187 | 183 | ||
@@ -196,6 +192,11 @@ struct MembershipTestRequest | |||
196 | struct GNUNET_MessageHeader header; | 192 | struct GNUNET_MessageHeader header; |
197 | 193 | ||
198 | /** | 194 | /** |
195 | * Operation ID. | ||
196 | */ | ||
197 | uint32_t op_id GNUNET_PACKED; | ||
198 | |||
199 | /** | ||
199 | * Channel's public key. | 200 | * Channel's public key. |
200 | */ | 201 | */ |
201 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 202 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
@@ -208,8 +209,6 @@ struct MembershipTestRequest | |||
208 | uint64_t message_id GNUNET_PACKED; | 209 | uint64_t message_id GNUNET_PACKED; |
209 | 210 | ||
210 | uint64_t group_generation GNUNET_PACKED; | 211 | uint64_t group_generation GNUNET_PACKED; |
211 | |||
212 | uint32_t op_id GNUNET_PACKED; | ||
213 | }; | 212 | }; |
214 | 213 | ||
215 | 214 | ||
@@ -224,13 +223,16 @@ struct FragmentStoreRequest | |||
224 | struct GNUNET_MessageHeader header; | 223 | struct GNUNET_MessageHeader header; |
225 | 224 | ||
226 | /** | 225 | /** |
226 | * Operation ID. | ||
227 | */ | ||
228 | uint32_t op_id GNUNET_PACKED; | ||
229 | |||
230 | /** | ||
227 | * Channel's public key. | 231 | * Channel's public key. |
228 | */ | 232 | */ |
229 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 233 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
230 | 234 | ||
231 | uint32_t psycstore_flags GNUNET_PACKED; | 235 | uint32_t psycstore_flags GNUNET_PACKED; |
232 | |||
233 | uint32_t op_id GNUNET_PACKED; | ||
234 | }; | 236 | }; |
235 | 237 | ||
236 | 238 | ||
@@ -245,13 +247,16 @@ struct FragmentGetRequest | |||
245 | struct GNUNET_MessageHeader header; | 247 | struct GNUNET_MessageHeader header; |
246 | 248 | ||
247 | /** | 249 | /** |
250 | * Operation ID. | ||
251 | */ | ||
252 | uint32_t op_id GNUNET_PACKED; | ||
253 | |||
254 | /** | ||
248 | * Channel's public key. | 255 | * Channel's public key. |
249 | */ | 256 | */ |
250 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 257 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
251 | 258 | ||
252 | uint64_t fragment_id; | 259 | uint64_t fragment_id GNUNET_PACKED; |
253 | |||
254 | uint32_t op_id GNUNET_PACKED; | ||
255 | }; | 260 | }; |
256 | 261 | ||
257 | 262 | ||
@@ -266,13 +271,16 @@ struct MessageGetRequest | |||
266 | struct GNUNET_MessageHeader header; | 271 | struct GNUNET_MessageHeader header; |
267 | 272 | ||
268 | /** | 273 | /** |
274 | * Operation ID. | ||
275 | */ | ||
276 | uint32_t op_id GNUNET_PACKED; | ||
277 | |||
278 | /** | ||
269 | * Channel's public key. | 279 | * Channel's public key. |
270 | */ | 280 | */ |
271 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 281 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
272 | 282 | ||
273 | uint64_t message_id; | 283 | uint64_t message_id GNUNET_PACKED; |
274 | |||
275 | uint32_t op_id GNUNET_PACKED; | ||
276 | }; | 284 | }; |
277 | 285 | ||
278 | 286 | ||
@@ -287,15 +295,18 @@ struct MessageGetFragmentRequest | |||
287 | struct GNUNET_MessageHeader header; | 295 | struct GNUNET_MessageHeader header; |
288 | 296 | ||
289 | /** | 297 | /** |
298 | * Operation ID. | ||
299 | */ | ||
300 | uint32_t op_id GNUNET_PACKED; | ||
301 | |||
302 | /** | ||
290 | * Channel's public key. | 303 | * Channel's public key. |
291 | */ | 304 | */ |
292 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 305 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
293 | 306 | ||
294 | uint64_t message_id; | 307 | uint64_t message_id GNUNET_PACKED; |
295 | |||
296 | uint64_t fragment_offset; | ||
297 | 308 | ||
298 | uint32_t op_id GNUNET_PACKED; | 309 | uint64_t fragment_offset GNUNET_PACKED; |
299 | }; | 310 | }; |
300 | 311 | ||
301 | 312 | ||
@@ -310,13 +321,16 @@ struct StateHashUpdateRequest | |||
310 | struct GNUNET_MessageHeader header; | 321 | struct GNUNET_MessageHeader header; |
311 | 322 | ||
312 | /** | 323 | /** |
324 | * Operation ID. | ||
325 | */ | ||
326 | uint32_t op_id GNUNET_PACKED; | ||
327 | |||
328 | /** | ||
313 | * Channel's public key. | 329 | * Channel's public key. |
314 | */ | 330 | */ |
315 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 331 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
316 | 332 | ||
317 | struct GNUNET_HashCode hash; | 333 | struct GNUNET_HashCode hash; |
318 | |||
319 | uint32_t op_id GNUNET_PACKED; | ||
320 | }; | 334 | }; |
321 | 335 | ||
322 | enum StateOpFlags | 336 | enum StateOpFlags |
@@ -336,6 +350,11 @@ struct StateModifyRequest | |||
336 | struct GNUNET_MessageHeader header; | 350 | struct GNUNET_MessageHeader header; |
337 | 351 | ||
338 | /** | 352 | /** |
353 | * Operation ID. | ||
354 | */ | ||
355 | uint32_t op_id GNUNET_PACKED; | ||
356 | |||
357 | /** | ||
339 | * Channel's public key. | 358 | * Channel's public key. |
340 | */ | 359 | */ |
341 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 360 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
@@ -344,8 +363,6 @@ struct StateModifyRequest | |||
344 | 363 | ||
345 | uint64_t state_delta GNUNET_PACKED; | 364 | uint64_t state_delta GNUNET_PACKED; |
346 | 365 | ||
347 | uint32_t op_id GNUNET_PACKED; | ||
348 | |||
349 | /** | 366 | /** |
350 | * Size of name, including NUL terminator. | 367 | * Size of name, including NUL terminator. |
351 | */ | 368 | */ |
@@ -376,14 +393,17 @@ struct StateSyncRequest | |||
376 | struct GNUNET_MessageHeader header; | 393 | struct GNUNET_MessageHeader header; |
377 | 394 | ||
378 | /** | 395 | /** |
396 | * Operation ID. | ||
397 | */ | ||
398 | uint32_t op_id GNUNET_PACKED; | ||
399 | |||
400 | /** | ||
379 | * Channel's public key. | 401 | * Channel's public key. |
380 | */ | 402 | */ |
381 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; | 403 | struct GNUNET_CRYPTO_EccPublicSignKey channel_key; |
382 | 404 | ||
383 | uint64_t message_id GNUNET_PACKED; | 405 | uint64_t message_id GNUNET_PACKED; |
384 | 406 | ||
385 | uint32_t op_id GNUNET_PACKED; | ||
386 | |||
387 | /** | 407 | /** |
388 | * Size of name, including NUL terminator. | 408 | * Size of name, including NUL terminator. |
389 | */ | 409 | */ |
diff --git a/src/psycstore/psycstore_api.c b/src/psycstore/psycstore_api.c index 5b9bb7e89..2b8c9305e 100644 --- a/src/psycstore/psycstore_api.c +++ b/src/psycstore/psycstore_api.c | |||
@@ -188,8 +188,7 @@ find_op_by_id (struct GNUNET_PSYCSTORE_Handle *h, uint32_t op_id) | |||
188 | * @param tc scheduler context | 188 | * @param tc scheduler context |
189 | */ | 189 | */ |
190 | static void | 190 | static void |
191 | reconnect (void *cls, | 191 | reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
192 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
193 | 192 | ||
194 | 193 | ||
195 | /** | 194 | /** |
@@ -239,18 +238,15 @@ transmit_next (struct GNUNET_PSYCSTORE_Handle *h); | |||
239 | * @param msg message received, NULL on timeout or fatal error | 238 | * @param msg message received, NULL on timeout or fatal error |
240 | */ | 239 | */ |
241 | static void | 240 | static void |
242 | message_handler (void *cls, | 241 | message_handler (void *cls, const struct GNUNET_MessageHeader *msg) |
243 | const struct GNUNET_MessageHeader *msg) | ||
244 | { | 242 | { |
245 | struct GNUNET_PSYCSTORE_Handle *h = cls; | 243 | struct GNUNET_PSYCSTORE_Handle *h = cls; |
246 | struct GNUNET_PSYCSTORE_OperationHandle *op; | 244 | struct GNUNET_PSYCSTORE_OperationHandle *op; |
247 | const struct OperationResult *opres; | 245 | const struct OperationResult *opres; |
248 | const struct MasterCountersResult *mcres; | 246 | const struct CountersResult *cres; |
249 | const struct SlaveCountersResult *scres; | ||
250 | const struct FragmentResult *fres; | 247 | const struct FragmentResult *fres; |
251 | const struct StateResult *sres; | 248 | const struct StateResult *sres; |
252 | const char *str; | 249 | const char *str; |
253 | uint16_t size; | ||
254 | 250 | ||
255 | if (NULL == msg) | 251 | if (NULL == msg) |
256 | { | 252 | { |
@@ -260,8 +256,9 @@ message_handler (void *cls, | |||
260 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 256 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
261 | "Received message of type %d from PSYCstore service\n", | 257 | "Received message of type %d from PSYCstore service\n", |
262 | ntohs (msg->type)); | 258 | ntohs (msg->type)); |
263 | size = ntohs (msg->size); | 259 | uint16_t size = ntohs (msg->size); |
264 | switch (ntohs (msg->type)) | 260 | uint16_t type = ntohs (msg->type); |
261 | switch (type) | ||
265 | { | 262 | { |
266 | case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE: | 263 | case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_CODE: |
267 | if (size < sizeof (struct OperationResult)) | 264 | if (size < sizeof (struct OperationResult)) |
@@ -269,7 +266,7 @@ message_handler (void *cls, | |||
269 | LOG (GNUNET_ERROR_TYPE_ERROR, | 266 | LOG (GNUNET_ERROR_TYPE_ERROR, |
270 | "Received message of type %d with length %lu bytes. " | 267 | "Received message of type %d with length %lu bytes. " |
271 | "Expected >= %lu\n", | 268 | "Expected >= %lu\n", |
272 | ntohs (msg->type), size, sizeof (struct OperationResult)); | 269 | type, size, sizeof (struct OperationResult)); |
273 | GNUNET_break (0); | 270 | GNUNET_break (0); |
274 | reschedule_connect (h); | 271 | reschedule_connect (h); |
275 | return; | 272 | return; |
@@ -291,8 +288,9 @@ message_handler (void *cls, | |||
291 | if (NULL == op) | 288 | if (NULL == op) |
292 | { | 289 | { |
293 | LOG (GNUNET_ERROR_TYPE_ERROR, | 290 | LOG (GNUNET_ERROR_TYPE_ERROR, |
294 | "Received result of an unkown operation ID: %ld\n", | 291 | "Received result message (type %d) " |
295 | ntohl (opres->op_id)); | 292 | "with an unknown operation ID: %ld\n", |
293 | type, ntohl (opres->op_id)); | ||
296 | } | 294 | } |
297 | else | 295 | else |
298 | { | 296 | { |
@@ -323,67 +321,38 @@ message_handler (void *cls, | |||
323 | } | 321 | } |
324 | break; | 322 | break; |
325 | 323 | ||
326 | case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_MASTER: | 324 | case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS: |
327 | if (size != sizeof (struct MasterCountersResult)) | 325 | if (size != sizeof (struct CountersResult)) |
328 | { | 326 | { |
329 | LOG (GNUNET_ERROR_TYPE_ERROR, | 327 | LOG (GNUNET_ERROR_TYPE_ERROR, |
330 | "Received message of type %d with length %lu bytes. " | 328 | "Received message of type %d with length %lu bytes. " |
331 | "Expected %lu\n", | 329 | "Expected %lu\n", |
332 | ntohs (msg->type), size, sizeof (struct MasterCountersResult)); | 330 | type, size, sizeof (struct CountersResult)); |
333 | GNUNET_break (0); | 331 | GNUNET_break (0); |
334 | reschedule_connect (h); | 332 | reschedule_connect (h); |
335 | return; | 333 | return; |
336 | } | 334 | } |
337 | 335 | ||
338 | mcres = (const struct MasterCountersResult *) msg; | 336 | cres = (const struct CountersResult *) msg; |
339 | 337 | ||
340 | op = find_op_by_id (h, ntohl (mcres->op_id)); | 338 | op = find_op_by_id (h, ntohl (cres->op_id)); |
341 | if (NULL == op) | 339 | if (NULL == op) |
342 | { | 340 | { |
343 | LOG (GNUNET_ERROR_TYPE_ERROR, | 341 | LOG (GNUNET_ERROR_TYPE_ERROR, |
344 | "Received result of an unkown operation ID: %ld\n", | 342 | "Received counters result message (type %d) " |
345 | ntohl (mcres->op_id)); | 343 | "with an unknown operation ID: %ld\n", |
344 | ntohl (cres->op_id)); | ||
346 | } | 345 | } |
347 | else | 346 | else |
348 | { | 347 | { |
349 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 348 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); |
350 | if (NULL != op->data_cb) | 349 | if (NULL != op->data_cb) |
351 | ((GNUNET_PSYCSTORE_MasterCountersCallback) | 350 | ((GNUNET_PSYCSTORE_CountersCallback) |
352 | op->data_cb) (op->cls, | 351 | op->data_cb) (op->cls, |
353 | GNUNET_ntohll (mcres->fragment_id), | 352 | GNUNET_ntohll (cres->max_fragment_id), |
354 | GNUNET_ntohll (mcres->message_id), | 353 | GNUNET_ntohll (cres->max_message_id), |
355 | GNUNET_ntohll (mcres->group_generation)); | 354 | GNUNET_ntohll (cres->max_group_generation), |
356 | GNUNET_free (op); | 355 | GNUNET_ntohll (cres->max_state_message_id)); |
357 | } | ||
358 | break; | ||
359 | |||
360 | case GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_SLAVE: | ||
361 | if (size != sizeof (struct SlaveCountersResult)) | ||
362 | { | ||
363 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
364 | "Received message of type %d with length %lu bytes. " | ||
365 | "Expected %lu\n", | ||
366 | ntohs (msg->type), size, sizeof (struct SlaveCountersResult)); | ||
367 | GNUNET_break (0); | ||
368 | reschedule_connect (h); | ||
369 | return; | ||
370 | } | ||
371 | |||
372 | scres = (const struct SlaveCountersResult *) msg; | ||
373 | |||
374 | op = find_op_by_id (h, ntohl (scres->op_id)); | ||
375 | if (NULL == op) | ||
376 | { | ||
377 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
378 | "Received result of an unkown operation ID: %ld\n", | ||
379 | ntohl (scres->op_id)); | ||
380 | } | ||
381 | else | ||
382 | { | ||
383 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | ||
384 | if (NULL != op->data_cb) | ||
385 | ((GNUNET_PSYCSTORE_SlaveCountersCallback) | ||
386 | op->data_cb) (op->cls, GNUNET_ntohll (scres->max_known_msg_id)); | ||
387 | GNUNET_free (op); | 356 | GNUNET_free (op); |
388 | } | 357 | } |
389 | break; | 358 | break; |
@@ -394,7 +363,7 @@ message_handler (void *cls, | |||
394 | LOG (GNUNET_ERROR_TYPE_ERROR, | 363 | LOG (GNUNET_ERROR_TYPE_ERROR, |
395 | "Received message of type %d with length %lu bytes. " | 364 | "Received message of type %d with length %lu bytes. " |
396 | "Expected >= %lu\n", | 365 | "Expected >= %lu\n", |
397 | ntohs (msg->type), size, sizeof (struct FragmentResult)); | 366 | type, size, sizeof (struct FragmentResult)); |
398 | GNUNET_break (0); | 367 | GNUNET_break (0); |
399 | reschedule_connect (h); | 368 | reschedule_connect (h); |
400 | return; | 369 | return; |
@@ -408,7 +377,7 @@ message_handler (void *cls, | |||
408 | LOG (GNUNET_ERROR_TYPE_ERROR, | 377 | LOG (GNUNET_ERROR_TYPE_ERROR, |
409 | "Received message of type %d with length %lu bytes. " | 378 | "Received message of type %d with length %lu bytes. " |
410 | "Expected = %lu\n", | 379 | "Expected = %lu\n", |
411 | ntohs (msg->type), size, | 380 | type, size, |
412 | sizeof (struct FragmentResult) + ntohs (mmsg->header.size)); | 381 | sizeof (struct FragmentResult) + ntohs (mmsg->header.size)); |
413 | GNUNET_break (0); | 382 | GNUNET_break (0); |
414 | reschedule_connect (h); | 383 | reschedule_connect (h); |
@@ -419,8 +388,9 @@ message_handler (void *cls, | |||
419 | if (NULL == op) | 388 | if (NULL == op) |
420 | { | 389 | { |
421 | LOG (GNUNET_ERROR_TYPE_ERROR, | 390 | LOG (GNUNET_ERROR_TYPE_ERROR, |
422 | "Received result of an unkown operation ID: %ld\n", | 391 | "Received fragment result message (type %d) " |
423 | ntohl (fres->op_id)); | 392 | "with an unknown operation ID: %ld\n", |
393 | type, ntohl (fres->op_id)); | ||
424 | } | 394 | } |
425 | else | 395 | else |
426 | { | 396 | { |
@@ -436,7 +406,7 @@ message_handler (void *cls, | |||
436 | LOG (GNUNET_ERROR_TYPE_ERROR, | 406 | LOG (GNUNET_ERROR_TYPE_ERROR, |
437 | "Received message of type %d with length %lu bytes. " | 407 | "Received message of type %d with length %lu bytes. " |
438 | "Expected >= %lu\n", | 408 | "Expected >= %lu\n", |
439 | ntohs (msg->type), size, sizeof (struct StateResult)); | 409 | type, size, sizeof (struct StateResult)); |
440 | GNUNET_break (0); | 410 | GNUNET_break (0); |
441 | reschedule_connect (h); | 411 | reschedule_connect (h); |
442 | return; | 412 | return; |
@@ -450,7 +420,7 @@ message_handler (void *cls, | |||
450 | { | 420 | { |
451 | LOG (GNUNET_ERROR_TYPE_ERROR, | 421 | LOG (GNUNET_ERROR_TYPE_ERROR, |
452 | "Received state result message (type %d) with invalid name.\n", | 422 | "Received state result message (type %d) with invalid name.\n", |
453 | ntohs (msg->type), name_size, name); | 423 | type); |
454 | GNUNET_break (0); | 424 | GNUNET_break (0); |
455 | reschedule_connect (h); | 425 | reschedule_connect (h); |
456 | return; | 426 | return; |
@@ -460,14 +430,15 @@ message_handler (void *cls, | |||
460 | if (NULL == op) | 430 | if (NULL == op) |
461 | { | 431 | { |
462 | LOG (GNUNET_ERROR_TYPE_ERROR, | 432 | LOG (GNUNET_ERROR_TYPE_ERROR, |
463 | "Received result of an unkown operation ID: %ld\n", | 433 | "Received state result message (type %d) " |
464 | ntohl (sres->op_id)); | 434 | "with an unknown operation ID: %ld\n", |
435 | type, ntohl (sres->op_id)); | ||
465 | } | 436 | } |
466 | else | 437 | else |
467 | { | 438 | { |
468 | if (NULL != op->data_cb) | 439 | if (NULL != op->data_cb) |
469 | ((GNUNET_PSYCSTORE_StateCallback) | 440 | ((GNUNET_PSYCSTORE_StateCallback) |
470 | op->data_cb) (op->cls, name, (void *) &sres[1] + name_size, | 441 | op->data_cb) (op->cls, name, (char *) &sres[1] + name_size, |
471 | ntohs (sres->header.size) - sizeof (*sres) - name_size); | 442 | ntohs (sres->header.size) - sizeof (*sres) - name_size); |
472 | } | 443 | } |
473 | break; | 444 | break; |
@@ -590,9 +561,8 @@ reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
590 | struct GNUNET_PSYCSTORE_Handle * | 561 | struct GNUNET_PSYCSTORE_Handle * |
591 | GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 562 | GNUNET_PSYCSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
592 | { | 563 | { |
593 | struct GNUNET_PSYCSTORE_Handle *h; | 564 | struct GNUNET_PSYCSTORE_Handle *h |
594 | 565 | = GNUNET_new (struct GNUNET_PSYCSTORE_Handle); | |
595 | h = GNUNET_new (struct GNUNET_PSYCSTORE_Handle); | ||
596 | h->cfg = cfg; | 566 | h->cfg = cfg; |
597 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 567 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
598 | h->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, h); | 568 | h->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, h); |
@@ -609,7 +579,6 @@ void | |||
609 | GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h) | 579 | GNUNET_PSYCSTORE_disconnect (struct GNUNET_PSYCSTORE_Handle *h) |
610 | { | 580 | { |
611 | GNUNET_assert (NULL != h); | 581 | GNUNET_assert (NULL != h); |
612 | GNUNET_assert (h->op_head == h->op_tail); | ||
613 | if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK) | 582 | if (h->reconnect_task != GNUNET_SCHEDULER_NO_TASK) |
614 | { | 583 | { |
615 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 584 | GNUNET_SCHEDULER_cancel (h->reconnect_task); |
@@ -985,64 +954,21 @@ GNUNET_PSYCSTORE_message_get_fragment (struct GNUNET_PSYCSTORE_Handle *h, | |||
985 | * @return Handle that can be used to cancel the operation. | 954 | * @return Handle that can be used to cancel the operation. |
986 | */ | 955 | */ |
987 | struct GNUNET_PSYCSTORE_OperationHandle * | 956 | struct GNUNET_PSYCSTORE_OperationHandle * |
988 | GNUNET_PSYCSTORE_counters_get_master (struct GNUNET_PSYCSTORE_Handle *h, | 957 | GNUNET_PSYCSTORE_counters_get (struct GNUNET_PSYCSTORE_Handle *h, |
989 | struct GNUNET_CRYPTO_EccPublicSignKey *channel_key, | 958 | struct GNUNET_CRYPTO_EccPublicSignKey *channel_key, |
990 | GNUNET_PSYCSTORE_MasterCountersCallback mccb, | 959 | GNUNET_PSYCSTORE_CountersCallback ccb, |
991 | void *mccb_cls) | 960 | void *mccb_cls) |
992 | { | 961 | { |
993 | struct OperationRequest *req; | 962 | struct OperationRequest *req; |
994 | struct GNUNET_PSYCSTORE_OperationHandle *op | 963 | struct GNUNET_PSYCSTORE_OperationHandle *op |
995 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | 964 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); |
996 | op->h = h; | 965 | op->h = h; |
997 | op->data_cb = mccb; | 966 | op->data_cb = ccb; |
998 | op->cls = mccb_cls; | 967 | op->cls = mccb_cls; |
999 | 968 | ||
1000 | req = (struct OperationRequest *) &op[1]; | 969 | req = (struct OperationRequest *) &op[1]; |
1001 | op->msg = (struct GNUNET_MessageHeader *) req; | 970 | op->msg = (struct GNUNET_MessageHeader *) req; |
1002 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_MASTER); | 971 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET); |
1003 | req->header.size = htons (sizeof (*req)); | ||
1004 | req->channel_key = *channel_key; | ||
1005 | |||
1006 | op->op_id = get_next_op_id (h); | ||
1007 | req->op_id = htonl (op->op_id); | ||
1008 | |||
1009 | GNUNET_CONTAINER_DLL_insert_tail (h->transmit_head, h->transmit_tail, op); | ||
1010 | transmit_next (h); | ||
1011 | |||
1012 | return op; | ||
1013 | } | ||
1014 | |||
1015 | |||
1016 | |||
1017 | /** | ||
1018 | * Retrieve latest values of counters for a channel slave. | ||
1019 | * | ||
1020 | * The current value of counters are needed when a channel slave rejoins | ||
1021 | * and starts the state synchronization process. | ||
1022 | * | ||
1023 | * @param h Handle for the PSYCstore. | ||
1024 | * @param channel_key Public key that identifies the channel. | ||
1025 | * @param sccb Callback to call with the result. | ||
1026 | * @param sccb_cls Closure for the callback. | ||
1027 | * | ||
1028 | * @return Handle that can be used to cancel the operation. | ||
1029 | */ | ||
1030 | struct GNUNET_PSYCSTORE_OperationHandle * | ||
1031 | GNUNET_PSYCSTORE_counters_get_slave (struct GNUNET_PSYCSTORE_Handle *h, | ||
1032 | struct GNUNET_CRYPTO_EccPublicSignKey *channel_key, | ||
1033 | GNUNET_PSYCSTORE_SlaveCountersCallback sccb, | ||
1034 | void *sccb_cls) | ||
1035 | { | ||
1036 | struct OperationRequest *req; | ||
1037 | struct GNUNET_PSYCSTORE_OperationHandle *op | ||
1038 | = GNUNET_malloc (sizeof (*op) + sizeof (*req)); | ||
1039 | op->h = h; | ||
1040 | op->data_cb = sccb; | ||
1041 | op->cls = sccb_cls; | ||
1042 | |||
1043 | req = (struct OperationRequest *) &op[1]; | ||
1044 | op->msg = (struct GNUNET_MessageHeader *) req; | ||
1045 | req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_SLAVE); | ||
1046 | req->header.size = htons (sizeof (*req)); | 972 | req->header.size = htons (sizeof (*req)); |
1047 | req->channel_key = *channel_key; | 973 | req->channel_key = *channel_key; |
1048 | 974 | ||
@@ -1114,7 +1040,7 @@ GNUNET_PSYCSTORE_state_modify (struct GNUNET_PSYCSTORE_Handle *h, | |||
1114 | : 0; | 1040 | : 0; |
1115 | 1041 | ||
1116 | memcpy (&req[1], modifiers[i].name, name_size); | 1042 | memcpy (&req[1], modifiers[i].name, name_size); |
1117 | memcpy ((void *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size); | 1043 | memcpy ((char *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size); |
1118 | 1044 | ||
1119 | op->op_id = get_next_op_id (h); | 1045 | op->op_id = get_next_op_id (h); |
1120 | req->op_id = htonl (op->op_id); | 1046 | req->op_id = htonl (op->op_id); |
@@ -1180,7 +1106,7 @@ GNUNET_PSYCSTORE_state_sync (struct GNUNET_PSYCSTORE_Handle *h, | |||
1180 | : 0; | 1106 | : 0; |
1181 | 1107 | ||
1182 | memcpy (&req[1], modifiers[i].name, name_size); | 1108 | memcpy (&req[1], modifiers[i].name, name_size); |
1183 | memcpy ((void *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size); | 1109 | memcpy ((char *) &req[1] + name_size, modifiers[i].value, modifiers[i].value_size); |
1184 | 1110 | ||
1185 | op->op_id = get_next_op_id (h); | 1111 | op->op_id = get_next_op_id (h); |
1186 | req->op_id = htonl (op->op_id); | 1112 | req->op_id = htonl (op->op_id); |
diff --git a/src/psycstore/test_plugin_psycstore.c b/src/psycstore/test_plugin_psycstore.c index 77a4186bf..0a8d4c2bc 100644 --- a/src/psycstore/test_plugin_psycstore.c +++ b/src/psycstore/test_plugin_psycstore.c | |||
@@ -276,13 +276,13 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
276 | &retfrags, fragment_cb, &fcls)); | 276 | &retfrags, fragment_cb, &fcls)); |
277 | GNUNET_assert (fcls.n == 2 && retfrags == 2); | 277 | GNUNET_assert (fcls.n == 2 && retfrags == 2); |
278 | 278 | ||
279 | /* Master counters */ | 279 | /* Message counters */ |
280 | 280 | ||
281 | uint64_t fragment_id = 0, message_id = 0, group_generation = 0; | 281 | uint64_t fragment_id = 0, message_id = 0, group_generation = 0; |
282 | GNUNET_assert ( | 282 | GNUNET_assert ( |
283 | GNUNET_OK == db->counters_get_master (db->cls, &channel_pub_key, | 283 | GNUNET_OK == db->counters_message_get (db->cls, &channel_pub_key, |
284 | &fragment_id, &message_id, | 284 | &fragment_id, &message_id, |
285 | &group_generation) | 285 | &group_generation) |
286 | && fragment_id == GNUNET_ntohll (msg1->fragment_id) | 286 | && fragment_id == GNUNET_ntohll (msg1->fragment_id) |
287 | && message_id == GNUNET_ntohll (msg1->message_id) | 287 | && message_id == GNUNET_ntohll (msg1->message_id) |
288 | && group_generation == GNUNET_ntohll (msg1->group_generation)); | 288 | && group_generation == GNUNET_ntohll (msg1->group_generation)); |
@@ -334,12 +334,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
334 | state_cb, &scls)); | 334 | state_cb, &scls)); |
335 | GNUNET_assert (scls.n == 2); | 335 | GNUNET_assert (scls.n == 2); |
336 | 336 | ||
337 | /* Slave counters */ | 337 | /* State counters */ |
338 | 338 | ||
339 | uint64_t max_state_msg_id = 0; | 339 | uint64_t max_state_msg_id = 0; |
340 | GNUNET_assert (GNUNET_OK == db->counters_get_slave (db->cls, &channel_pub_key, | 340 | GNUNET_assert (GNUNET_OK == db->counters_state_get (db->cls, &channel_pub_key, |
341 | &max_state_msg_id) | 341 | &max_state_msg_id) |
342 | && max_state_msg_id == message_id); | 342 | && max_state_msg_id == message_id); |
343 | 343 | ||
344 | /* State sync */ | 344 | /* State sync */ |
345 | 345 | ||
diff --git a/src/psycstore/test_psycstore.c b/src/psycstore/test_psycstore.c index cfda6819e..bb6f88665 100644 --- a/src/psycstore/test_psycstore.c +++ b/src/psycstore/test_psycstore.c | |||
@@ -28,8 +28,8 @@ | |||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_common.h" | 29 | #include "gnunet_common.h" |
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_psycstore_service.h" | ||
32 | #include "gnunet_testing_lib.h" | 31 | #include "gnunet_testing_lib.h" |
32 | #include "gnunet_psycstore_service.h" | ||
33 | 33 | ||
34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
35 | 35 | ||
@@ -231,16 +231,20 @@ state_get_result (void *cls, int64_t result, const char *err_msg) | |||
231 | 231 | ||
232 | 232 | ||
233 | void | 233 | void |
234 | counters_slave_result (void *cls, uint64_t max_state_msg_id) | 234 | counters_result (void *cls, uint64_t max_fragment_id, uint64_t max_message_id, |
235 | uint64_t max_group_generation, uint64_t max_state_message_id) | ||
235 | { | 236 | { |
236 | struct FragmentClosure *fcls = cls; | 237 | struct FragmentClosure *fcls = cls; |
237 | int result = 0; | 238 | int result = 0; |
238 | op = NULL; | 239 | op = NULL; |
239 | 240 | ||
240 | if (max_state_msg_id == GNUNET_ntohll (fcls->msg[0]->message_id)) | 241 | if (max_fragment_id == GNUNET_ntohll (fcls->msg[2]->fragment_id) |
242 | && max_message_id == GNUNET_ntohll (fcls->msg[2]->message_id) | ||
243 | && max_group_generation == GNUNET_ntohll (fcls->msg[2]->group_generation) | ||
244 | && max_state_message_id == GNUNET_ntohll (fcls->msg[0]->message_id)) | ||
241 | result = 1; | 245 | result = 1; |
242 | 246 | ||
243 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get_slave:\t%d\n", result); | 247 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get:\t%d\n", result); |
244 | GNUNET_assert (result == 1); | 248 | GNUNET_assert (result == 1); |
245 | 249 | ||
246 | scls.n = 0; | 250 | scls.n = 0; |
@@ -260,8 +264,8 @@ state_modify_result (void *cls, int64_t result, const char *err_msg) | |||
260 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_modify_result:\t%d\n", result); | 264 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "state_modify_result:\t%d\n", result); |
261 | GNUNET_assert (GNUNET_OK == result); | 265 | GNUNET_assert (GNUNET_OK == result); |
262 | 266 | ||
263 | op = GNUNET_PSYCSTORE_counters_get_slave (h, &channel_pub_key, | 267 | op = GNUNET_PSYCSTORE_counters_get (h, &channel_pub_key, |
264 | &counters_slave_result, cls); | 268 | &counters_result, cls); |
265 | } | 269 | } |
266 | 270 | ||
267 | 271 | ||
@@ -292,41 +296,6 @@ state_sync_result (void *cls, int64_t result, const char *err_msg) | |||
292 | } | 296 | } |
293 | 297 | ||
294 | 298 | ||
295 | void | ||
296 | counters_master_result (void *cls, uint64_t fragment_id, uint64_t message_id, | ||
297 | uint64_t group_generation) | ||
298 | { | ||
299 | struct FragmentClosure *fcls = cls; | ||
300 | int result = 0; | ||
301 | op = NULL; | ||
302 | |||
303 | if (fragment_id == GNUNET_ntohll (fcls->msg[2]->fragment_id) && | ||
304 | message_id == GNUNET_ntohll (fcls->msg[2]->message_id) && | ||
305 | group_generation == GNUNET_ntohll (fcls->msg[2]->group_generation)) | ||
306 | result = 1; | ||
307 | |||
308 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "counters_get_master:\t%d\n", result); | ||
309 | GNUNET_assert (result == 1); | ||
310 | |||
311 | modifiers[0] = (struct GNUNET_ENV_Modifier) { | ||
312 | .oper = '=', | ||
313 | .name = "_sync_foo", | ||
314 | .value = "three two one", | ||
315 | .value_size = sizeof ("three two one") - 1 | ||
316 | }; | ||
317 | modifiers[1] = (struct GNUNET_ENV_Modifier) { | ||
318 | .oper = '=', | ||
319 | .name = "_sync_bar", | ||
320 | .value = "ten eleven twelve", | ||
321 | .value_size = sizeof ("ten eleven twelve") - 1 | ||
322 | }; | ||
323 | |||
324 | op = GNUNET_PSYCSTORE_state_sync (h, &channel_pub_key, | ||
325 | GNUNET_ntohll (fcls->msg[0]->message_id) + 1, | ||
326 | 2, modifiers, state_sync_result, fcls); | ||
327 | } | ||
328 | |||
329 | |||
330 | int | 299 | int |
331 | fragment_result (void *cls, | 300 | fragment_result (void *cls, |
332 | struct GNUNET_MULTICAST_MessageHeader *msg, | 301 | struct GNUNET_MULTICAST_MessageHeader *msg, |
@@ -361,8 +330,24 @@ message_get_result (void *cls, int64_t result, const char *err_msg) | |||
361 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "message_get:\t%d\n", result); | 330 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "message_get:\t%d\n", result); |
362 | GNUNET_assert (result > 0 && fcls->n && fcls->n_expected); | 331 | GNUNET_assert (result > 0 && fcls->n && fcls->n_expected); |
363 | 332 | ||
364 | op = GNUNET_PSYCSTORE_counters_get_master (h, &channel_pub_key, | 333 | |
365 | &counters_master_result, fcls); | 334 | |
335 | modifiers[0] = (struct GNUNET_ENV_Modifier) { | ||
336 | .oper = '=', | ||
337 | .name = "_sync_foo", | ||
338 | .value = "three two one", | ||
339 | .value_size = sizeof ("three two one") - 1 | ||
340 | }; | ||
341 | modifiers[1] = (struct GNUNET_ENV_Modifier) { | ||
342 | .oper = '=', | ||
343 | .name = "_sync_bar", | ||
344 | .value = "ten eleven twelve", | ||
345 | .value_size = sizeof ("ten eleven twelve") - 1 | ||
346 | }; | ||
347 | |||
348 | op = GNUNET_PSYCSTORE_state_sync (h, &channel_pub_key, | ||
349 | GNUNET_ntohll (fcls->msg[0]->message_id) + 1, | ||
350 | 2, modifiers, state_sync_result, fcls); | ||
366 | } | 351 | } |
367 | 352 | ||
368 | 353 | ||