diff options
author | Gabor X Toth <*@tg-x.net> | 2015-08-28 13:33:43 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2015-08-28 13:33:43 +0000 |
commit | 38963d1e81332032e0ac774f4f2c6b804c38802a (patch) | |
tree | ce33b979e47fe332c7c744744d60077a7e1fefee /src/psycstore/plugin_psycstore_sqlite.c | |
parent | b4fa14499c64140273850569247abda687803053 (diff) | |
download | gnunet-38963d1e81332032e0ac774f4f2c6b804c38802a.tar.gz gnunet-38963d1e81332032e0ac774f4f2c6b804c38802a.zip |
psyc/social: get state from psycstore
Diffstat (limited to 'src/psycstore/plugin_psycstore_sqlite.c')
-rw-r--r-- | src/psycstore/plugin_psycstore_sqlite.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/psycstore/plugin_psycstore_sqlite.c b/src/psycstore/plugin_psycstore_sqlite.c index 1abc479d2..1bf14644b 100644 --- a/src/psycstore/plugin_psycstore_sqlite.c +++ b/src/psycstore/plugin_psycstore_sqlite.c | |||
@@ -64,7 +64,8 @@ | |||
64 | 64 | ||
65 | enum Transactions { | 65 | enum Transactions { |
66 | TRANSACTION_NONE = 0, | 66 | TRANSACTION_NONE = 0, |
67 | TRANSACTION_STATE_MODIFY | 67 | TRANSACTION_STATE_MODIFY, |
68 | TRANSACTION_STATE_SYNC, | ||
68 | }; | 69 | }; |
69 | 70 | ||
70 | /** | 71 | /** |
@@ -1522,18 +1523,27 @@ state_modify_begin (void *cls, | |||
1522 | 1523 | ||
1523 | uint64_t max_state_message_id = 0; | 1524 | uint64_t max_state_message_id = 0; |
1524 | int ret = counters_state_get (plugin, channel_key, &max_state_message_id); | 1525 | int ret = counters_state_get (plugin, channel_key, &max_state_message_id); |
1525 | if (GNUNET_OK != ret) | 1526 | switch (ret) |
1527 | { | ||
1528 | case GNUNET_OK: | ||
1529 | case GNUNET_NO: // no state yet | ||
1530 | ret = GNUNET_OK; | ||
1531 | break; | ||
1532 | default: | ||
1526 | return ret; | 1533 | return ret; |
1534 | } | ||
1527 | 1535 | ||
1528 | if (message_id - state_delta != max_state_message_id) | 1536 | if (max_state_message_id < message_id - state_delta) |
1529 | return GNUNET_NO; | 1537 | return GNUNET_NO; /* some stateful messages not yet applied */ |
1538 | else if (message_id - state_delta < max_state_message_id) | ||
1539 | return GNUNET_NO; /* changes already applied */ | ||
1530 | } | 1540 | } |
1531 | 1541 | ||
1532 | // Make sure no other transaction is going on. | ||
1533 | if (TRANSACTION_NONE != plugin->transaction) | 1542 | if (TRANSACTION_NONE != plugin->transaction) |
1534 | if (GNUNET_OK != transaction_rollback (plugin)) | 1543 | { |
1535 | return GNUNET_SYSERR; | 1544 | /** @todo FIXME: wait for other transaction to finish */ |
1536 | 1545 | return GNUNET_SYSERR; | |
1546 | } | ||
1537 | return transaction_begin (plugin, TRANSACTION_STATE_MODIFY); | 1547 | return transaction_begin (plugin, TRANSACTION_STATE_MODIFY); |
1538 | } | 1548 | } |
1539 | 1549 | ||
@@ -1560,8 +1570,8 @@ state_modify_op (void *cls, | |||
1560 | return state_assign (plugin, plugin->insert_state_current, channel_key, | 1570 | return state_assign (plugin, plugin->insert_state_current, channel_key, |
1561 | name, value, value_size); | 1571 | name, value, value_size); |
1562 | 1572 | ||
1563 | /// @todo implement more state operations | 1573 | default: /** @todo implement more state operations */ |
1564 | default: | 1574 | GNUNET_break (0); |
1565 | return GNUNET_SYSERR; | 1575 | return GNUNET_SYSERR; |
1566 | } | 1576 | } |
1567 | } | 1577 | } |
@@ -1630,7 +1640,13 @@ state_sync_end (void *cls, | |||
1630 | struct Plugin *plugin = cls; | 1640 | struct Plugin *plugin = cls; |
1631 | int ret = GNUNET_SYSERR; | 1641 | int ret = GNUNET_SYSERR; |
1632 | 1642 | ||
1633 | GNUNET_OK == transaction_begin (plugin, TRANSACTION_NONE) | 1643 | if (TRANSACTION_NONE != plugin->transaction) |
1644 | { | ||
1645 | /** @todo FIXME: wait for other transaction to finish */ | ||
1646 | return GNUNET_SYSERR; | ||
1647 | } | ||
1648 | |||
1649 | GNUNET_OK == transaction_begin (plugin, TRANSACTION_STATE_SYNC) | ||
1634 | && GNUNET_OK == exec_channel (plugin, plugin->delete_state, channel_key) | 1650 | && GNUNET_OK == exec_channel (plugin, plugin->delete_state, channel_key) |
1635 | && GNUNET_OK == exec_channel (plugin, plugin->insert_state_from_sync, | 1651 | && GNUNET_OK == exec_channel (plugin, plugin->insert_state_from_sync, |
1636 | channel_key) | 1652 | channel_key) |