aboutsummaryrefslogtreecommitdiff
path: root/src/psycstore
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2015-09-05 23:44:08 +0000
committerGabor X Toth <*@tg-x.net>2015-09-05 23:44:08 +0000
commit878b09fe6521df37c2d39f884a6c892b370473a5 (patch)
treeaccd38e3a5fb995546508ffb081d0f9f9fc850a0 /src/psycstore
parent5e4dfeb7fb48a506f25af0c206ee65a5f7de7f58 (diff)
downloadgnunet-878b09fe6521df37c2d39f884a6c892b370473a5.tar.gz
gnunet-878b09fe6521df37c2d39f884a6c892b370473a5.zip
multicast, psyc, psycstore, client_manager fixes
Diffstat (limited to 'src/psycstore')
-rw-r--r--src/psycstore/gnunet-service-psycstore.c10
-rw-r--r--src/psycstore/plugin_psycstore_sqlite.c11
-rw-r--r--src/psycstore/psyc_util_lib.c53
3 files changed, 46 insertions, 28 deletions
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c
index 1f9de54f8..01eb5d707 100644
--- a/src/psycstore/gnunet-service-psycstore.c
+++ b/src/psycstore/gnunet-service-psycstore.c
@@ -508,8 +508,10 @@ struct StateModifyClosure
508 508
509 509
510static void 510static void
511recv_state_message_part (void *cls, uint64_t message_id, uint64_t data_offset, 511recv_state_message_part (void *cls,
512 uint32_t flags, const struct GNUNET_MessageHeader *msg) 512 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
513 uint64_t message_id, uint32_t flags, uint64_t data_offset,
514 const struct GNUNET_MessageHeader *msg)
513{ 515{
514 struct StateModifyClosure *scls = cls; 516 struct StateModifyClosure *scls = cls;
515 uint16_t psize; 517 uint16_t psize;
@@ -618,7 +620,7 @@ recv_state_fragment (void *cls, struct GNUNET_MULTICAST_MessageHeader *msg,
618 620
619 if (NULL == scls->recv) 621 if (NULL == scls->recv)
620 { 622 {
621 scls->recv = GNUNET_PSYC_receive_create (NULL, &recv_state_message_part, 623 scls->recv = GNUNET_PSYC_receive_create (NULL, recv_state_message_part,
622 scls); 624 scls);
623 } 625 }
624 626
@@ -660,7 +662,7 @@ handle_state_modify (void *cls,
660 { 662 {
661 ret = db->message_get (db->cls, &req->channel_key, 663 ret = db->message_get (db->cls, &req->channel_key,
662 message_id, message_id, 664 message_id, message_id,
663 &ret_frags, &recv_state_fragment, &scls); 665 &ret_frags, recv_state_fragment, &scls);
664 if (GNUNET_OK != ret) 666 if (GNUNET_OK != ret)
665 { 667 {
666 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 668 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/psycstore/plugin_psycstore_sqlite.c b/src/psycstore/plugin_psycstore_sqlite.c
index 1bf14644b..8f9a3ef63 100644
--- a/src/psycstore/plugin_psycstore_sqlite.c
+++ b/src/psycstore/plugin_psycstore_sqlite.c
@@ -598,7 +598,7 @@ database_setup (struct Plugin *plugin)
598 "SELECT name, value_current\n" 598 "SELECT name, value_current\n"
599 "FROM state\n" 599 "FROM state\n"
600 "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n" 600 "WHERE channel_id = (SELECT id FROM channels WHERE pub_key = ?)\n"
601 " AND (name = ? OR name LIKE ?);", 601 " AND (name = ? OR substr(name, 1, ?) = ? || '_');",
602 &plugin->select_state_prefix); 602 &plugin->select_state_prefix);
603 603
604 sql_prepare (plugin->dbh, 604 sql_prepare (plugin->dbh,
@@ -1763,16 +1763,12 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_
1763 int ret = GNUNET_SYSERR; 1763 int ret = GNUNET_SYSERR;
1764 sqlite3_stmt *stmt = plugin->select_state_prefix; 1764 sqlite3_stmt *stmt = plugin->select_state_prefix;
1765 size_t name_len = strlen (name); 1765 size_t name_len = strlen (name);
1766 char *name_prefix;
1767 1766
1768 GNUNET_asprintf (&name_prefix,
1769 "%s_%%",
1770 name);
1771 if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key, 1767 if (SQLITE_OK != sqlite3_bind_blob (stmt, 1, channel_key,
1772 sizeof (*channel_key), SQLITE_STATIC) 1768 sizeof (*channel_key), SQLITE_STATIC)
1773 || SQLITE_OK != sqlite3_bind_text (stmt, 2, name, name_len, SQLITE_STATIC) 1769 || SQLITE_OK != sqlite3_bind_text (stmt, 2, name, name_len, SQLITE_STATIC)
1774 || SQLITE_OK != sqlite3_bind_text (stmt, 3, name_prefix, name_len + 2, 1770 || SQLITE_OK != sqlite3_bind_int (stmt, 3, name_len + 1)
1775 SQLITE_STATIC)) 1771 || SQLITE_OK != sqlite3_bind_text (stmt, 4, name, name_len, SQLITE_STATIC))
1776 { 1772 {
1777 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1773 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1778 "sqlite3_bind"); 1774 "sqlite3_bind");
@@ -1808,7 +1804,6 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_
1808 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 1804 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
1809 "sqlite3_reset"); 1805 "sqlite3_reset");
1810 } 1806 }
1811 GNUNET_free (name_prefix);
1812 return ret; 1807 return ret;
1813} 1808}
1814 1809
diff --git a/src/psycstore/psyc_util_lib.c b/src/psycstore/psyc_util_lib.c
index 7b13ac57f..e45bcafb3 100644
--- a/src/psycstore/psyc_util_lib.c
+++ b/src/psycstore/psyc_util_lib.c
@@ -401,12 +401,17 @@ transmit_queue_insert (struct GNUNET_PSYC_TransmitHandle *tmit,
401static void 401static void
402transmit_data (struct GNUNET_PSYC_TransmitHandle *tmit) 402transmit_data (struct GNUNET_PSYC_TransmitHandle *tmit)
403{ 403{
404 uint16_t data_size = GNUNET_PSYC_DATA_MAX_PAYLOAD; 404 int notify_ret = GNUNET_YES;
405 uint16_t data_size = 0;
405 char data[GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD] = ""; 406 char data[GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD] = "";
406 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) data; 407 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) data;
407 msg->type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA); 408 msg->type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA);
408 409
409 int notify_ret = tmit->notify_data (tmit->notify_data_cls, &data_size, &msg[1]); 410 if (NULL != tmit->notify_data)
411 {
412 data_size = GNUNET_PSYC_DATA_MAX_PAYLOAD;
413 notify_ret = tmit->notify_data (tmit->notify_data_cls, &data_size, &msg[1]);
414 }
410 LOG (GNUNET_ERROR_TYPE_DEBUG, 415 LOG (GNUNET_ERROR_TYPE_DEBUG,
411 "transmit_data (ret: %d, size: %u): %.*s\n", 416 "transmit_data (ret: %d, size: %u): %.*s\n",
412 notify_ret, data_size, data_size, &msg[1]); 417 notify_ret, data_size, data_size, &msg[1]);
@@ -461,10 +466,11 @@ transmit_data (struct GNUNET_PSYC_TransmitHandle *tmit)
461static void 466static void
462transmit_mod (struct GNUNET_PSYC_TransmitHandle *tmit) 467transmit_mod (struct GNUNET_PSYC_TransmitHandle *tmit)
463{ 468{
464 uint16_t max_data_size, data_size; 469 uint16_t max_data_size = 0;
470 uint16_t data_size = 0;
465 char data[GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD] = ""; 471 char data[GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD] = "";
466 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) data; 472 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) data;
467 int notify_ret; 473 int notify_ret = GNUNET_YES;
468 474
469 switch (tmit->state) 475 switch (tmit->state)
470 { 476 {
@@ -472,11 +478,16 @@ transmit_mod (struct GNUNET_PSYC_TransmitHandle *tmit)
472 { 478 {
473 struct GNUNET_PSYC_MessageModifier *mod 479 struct GNUNET_PSYC_MessageModifier *mod
474 = (struct GNUNET_PSYC_MessageModifier *) msg; 480 = (struct GNUNET_PSYC_MessageModifier *) msg;
475 max_data_size = data_size = GNUNET_PSYC_MODIFIER_MAX_PAYLOAD;
476 msg->type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER); 481 msg->type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER);
477 msg->size = sizeof (struct GNUNET_PSYC_MessageModifier); 482 msg->size = sizeof (struct GNUNET_PSYC_MessageModifier);
478 notify_ret = tmit->notify_mod (tmit->notify_mod_cls, &data_size, &mod[1], 483
479 &mod->oper, &mod->value_size); 484 if (NULL != tmit->notify_mod)
485 {
486 max_data_size = GNUNET_PSYC_MODIFIER_MAX_PAYLOAD;
487 data_size = max_data_size;
488 notify_ret = tmit->notify_mod (tmit->notify_mod_cls, &data_size, &mod[1],
489 &mod->oper, &mod->value_size);
490 }
480 491
481 mod->name_size = strnlen ((char *) &mod[1], data_size) + 1; 492 mod->name_size = strnlen ((char *) &mod[1], data_size) + 1;
482 LOG (GNUNET_ERROR_TYPE_DEBUG, 493 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -498,11 +509,16 @@ transmit_mod (struct GNUNET_PSYC_TransmitHandle *tmit)
498 } 509 }
499 case GNUNET_PSYC_MESSAGE_STATE_MOD_CONT: 510 case GNUNET_PSYC_MESSAGE_STATE_MOD_CONT:
500 { 511 {
501 max_data_size = data_size = GNUNET_PSYC_MOD_CONT_MAX_PAYLOAD;
502 msg->type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT); 512 msg->type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT);
503 msg->size = sizeof (struct GNUNET_MessageHeader); 513 msg->size = sizeof (struct GNUNET_MessageHeader);
504 notify_ret = tmit->notify_mod (tmit->notify_mod_cls, 514
505 &data_size, &msg[1], NULL, NULL); 515 if (NULL != tmit->notify_mod)
516 {
517 max_data_size = GNUNET_PSYC_MOD_CONT_MAX_PAYLOAD;
518 data_size = max_data_size;
519 notify_ret = tmit->notify_mod (tmit->notify_mod_cls,
520 &data_size, &msg[1], NULL, NULL);
521 }
506 tmit->mod_value_remaining -= data_size; 522 tmit->mod_value_remaining -= data_size;
507 LOG (GNUNET_ERROR_TYPE_DEBUG, 523 LOG (GNUNET_ERROR_TYPE_DEBUG,
508 "transmit_mod (ret: %d, size: %u): %.*s\n", 524 "transmit_mod (ret: %d, size: %u): %.*s\n",
@@ -847,7 +863,8 @@ static void
847recv_error (struct GNUNET_PSYC_ReceiveHandle *recv) 863recv_error (struct GNUNET_PSYC_ReceiveHandle *recv)
848{ 864{
849 if (NULL != recv->message_part_cb) 865 if (NULL != recv->message_part_cb)
850 recv->message_part_cb (recv->cb_cls, recv->message_id, 0, recv->flags, NULL); 866 recv->message_part_cb (recv->cb_cls, NULL, recv->message_id, recv->flags,
867 0, NULL);
851 868
852 if (NULL != recv->message_cb) 869 if (NULL != recv->message_cb)
853 recv->message_cb (recv->cb_cls, recv->message_id, recv->flags, NULL); 870 recv->message_cb (recv->cb_cls, recv->message_id, recv->flags, NULL);
@@ -1066,8 +1083,10 @@ GNUNET_PSYC_receive_message (struct GNUNET_PSYC_ReceiveHandle *recv,
1066 } 1083 }
1067 1084
1068 if (NULL != recv->message_part_cb) 1085 if (NULL != recv->message_part_cb)
1069 recv->message_part_cb (recv->cb_cls, recv->message_id, 0, // FIXME: data_offset 1086 recv->message_part_cb (recv->cb_cls, &recv->slave_key,
1070 recv->flags, pmsg); 1087 recv->message_id, recv->flags,
1088 0, // FIXME: data_offset
1089 pmsg);
1071 1090
1072 switch (ptype) 1091 switch (ptype)
1073 { 1092 {
@@ -1144,8 +1163,10 @@ struct ParseMessageClosure
1144 1163
1145 1164
1146static void 1165static void
1147parse_message_part_cb (void *cls, uint64_t message_id, uint64_t data_offset, 1166parse_message_part_cb (void *cls,
1148 uint32_t flags, const struct GNUNET_MessageHeader *msg) 1167 const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
1168 uint64_t message_id, uint32_t flags, uint64_t data_offset,
1169 const struct GNUNET_MessageHeader *msg)
1149{ 1170{
1150 struct ParseMessageClosure *pmc = cls; 1171 struct ParseMessageClosure *pmc = cls;
1151 if (NULL == msg) 1172 if (NULL == msg)
@@ -1230,7 +1251,7 @@ GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_Message *msg,
1230 memcpy (&pmsg[1], &msg[1], msg_size - sizeof (*msg)); 1251 memcpy (&pmsg[1], &msg[1], msg_size - sizeof (*msg));
1231 1252
1232 struct GNUNET_PSYC_ReceiveHandle * 1253 struct GNUNET_PSYC_ReceiveHandle *
1233 recv = GNUNET_PSYC_receive_create (NULL, &parse_message_part_cb, &cls); 1254 recv = GNUNET_PSYC_receive_create (NULL, parse_message_part_cb, &cls);
1234 GNUNET_PSYC_receive_message (recv, pmsg); 1255 GNUNET_PSYC_receive_message (recv, pmsg);
1235 GNUNET_PSYC_receive_destroy (recv); 1256 GNUNET_PSYC_receive_destroy (recv);
1236 GNUNET_free (pmsg); 1257 GNUNET_free (pmsg);