aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-04-03 15:10:41 +0000
committerChristian Grothoff <christian@grothoff.org>2011-04-03 15:10:41 +0000
commitd2f2c8800aa6ea07a024c5511a1b1d23ad356090 (patch)
tree244c947db2921817c15d04b6a88a3f843e33d2a3 /src
parent745d6c5753f2e5f163220a376d58083b2d7ff76d (diff)
downloadgnunet-d2f2c8800aa6ea07a024c5511a1b1d23ad356090.tar.gz
gnunet-d2f2c8800aa6ea07a024c5511a1b1d23ad356090.zip
new plugin API
Diffstat (limited to 'src')
-rw-r--r--src/datastore/gnunet-service-datastore.c1
-rw-r--r--src/datastore/perf_plugin_datastore.c5
-rw-r--r--src/datastore/plugin_datastore_mysql.c23
-rw-r--r--src/datastore/plugin_datastore_postgres.c23
-rw-r--r--src/datastore/plugin_datastore_sqlite.c23
-rw-r--r--src/datastore/plugin_datastore_template.c22
-rw-r--r--src/include/gnunet_datastore_plugin.h30
7 files changed, 122 insertions, 5 deletions
diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c
index 82a1f3ded..2538d5ef6 100644
--- a/src/datastore/gnunet-service-datastore.c
+++ b/src/datastore/gnunet-service-datastore.c
@@ -953,6 +953,7 @@ execute_put (struct GNUNET_SERVER_Client *client,
953 ntohl(dm->type), 953 ntohl(dm->type),
954 ntohl(dm->priority), 954 ntohl(dm->priority),
955 ntohl(dm->anonymity), 955 ntohl(dm->anonymity),
956 0 /* FIXME: replication */,
956 GNUNET_TIME_absolute_ntoh(dm->expiration), 957 GNUNET_TIME_absolute_ntoh(dm->expiration),
957 &msg); 958 &msg);
958 if (GNUNET_OK == ret) 959 if (GNUNET_OK == ret)
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index facf7be67..cb25da46b 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -125,9 +125,10 @@ putValue (struct GNUNET_DATASTORE_PluginFunctions * api, int i, int k)
125 &key, 125 &key,
126 size, 126 size,
127 value, 127 value,
128 i, 128 i /* type */,
129 prio, 129 prio,
130 i, 130 i /* anonymity */,
131 0 /* replication */,
131 GNUNET_TIME_relative_to_absolute 132 GNUNET_TIME_relative_to_absolute
132 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 133 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
133 60 * 60 * 60 * 1000 + 134 60 * 60 * 60 * 1000 +
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index ac81c9011..fb1b13978 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -1348,6 +1348,7 @@ mysql_plugin_get_size (void *cls)
1348 * @param type type of the content 1348 * @param type type of the content
1349 * @param priority priority of the content 1349 * @param priority priority of the content
1350 * @param anonymity anonymity-level for the content 1350 * @param anonymity anonymity-level for the content
1351 * @param replication replication-level for the content
1351 * @param expiration expiration time for the content 1352 * @param expiration expiration time for the content
1352 * @param msg set to error message 1353 * @param msg set to error message
1353 * @return GNUNET_OK on success 1354 * @return GNUNET_OK on success
@@ -1360,6 +1361,7 @@ mysql_plugin_put (void *cls,
1360 enum GNUNET_BLOCK_Type type, 1361 enum GNUNET_BLOCK_Type type,
1361 uint32_t priority, 1362 uint32_t priority,
1362 uint32_t anonymity, 1363 uint32_t anonymity,
1364 uint32_t replication,
1363 struct GNUNET_TIME_Absolute expiration, 1365 struct GNUNET_TIME_Absolute expiration,
1364 char **msg) 1366 char **msg)
1365{ 1367{
@@ -1688,6 +1690,26 @@ mysql_plugin_get (void *cls,
1688 1690
1689 1691
1690/** 1692/**
1693 * Get a random item for replication. Returns a single, not expired, random item
1694 * from those with the highest replication counters. The item's
1695 * replication counter is decremented by one IF it was positive before.
1696 * Call 'iter' with all values ZERO or NULL if the datastore is empty.
1697 *
1698 * @param cls closure
1699 * @param iter function to call the value (once only).
1700 * @param iter_cls closure for iter
1701 */
1702static void
1703mysql_plugin_replication_get (void *cls,
1704 PluginIterator iter, void *iter_cls)
1705{
1706 /* FIXME: not implemented! */
1707 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0,
1708 GNUNET_TIME_UNIT_ZERO_ABS, 0);
1709}
1710
1711
1712/**
1691 * Update the priority for a particular key in the datastore. If 1713 * Update the priority for a particular key in the datastore. If
1692 * the expiration time in value is different than the time found in 1714 * the expiration time in value is different than the time found in
1693 * the datastore, the higher value should be kept. For the 1715 * the datastore, the higher value should be kept. For the
@@ -1940,6 +1962,7 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
1940 api->put = &mysql_plugin_put; 1962 api->put = &mysql_plugin_put;
1941 api->next_request = &mysql_plugin_next_request; 1963 api->next_request = &mysql_plugin_next_request;
1942 api->get = &mysql_plugin_get; 1964 api->get = &mysql_plugin_get;
1965 api->replication_get = &mysql_plugin_replication_get;
1943 api->update = &mysql_plugin_update; 1966 api->update = &mysql_plugin_update;
1944 api->iter_low_priority = &mysql_plugin_iter_low_priority; 1967 api->iter_low_priority = &mysql_plugin_iter_low_priority;
1945 api->iter_zero_anonymity = &mysql_plugin_iter_zero_anonymity; 1968 api->iter_zero_anonymity = &mysql_plugin_iter_zero_anonymity;
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index 18ad77885..c004cd59f 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -587,6 +587,7 @@ postgres_plugin_get_size (void *cls)
587 * @param type type of the content 587 * @param type type of the content
588 * @param priority priority of the content 588 * @param priority priority of the content
589 * @param anonymity anonymity-level for the content 589 * @param anonymity anonymity-level for the content
590 * @param replication replication-level for the content
590 * @param expiration expiration time for the content 591 * @param expiration expiration time for the content
591 * @param msg set to error message 592 * @param msg set to error message
592 * @return GNUNET_OK on success 593 * @return GNUNET_OK on success
@@ -599,6 +600,7 @@ postgres_plugin_put (void *cls,
599 enum GNUNET_BLOCK_Type type, 600 enum GNUNET_BLOCK_Type type,
600 uint32_t priority, 601 uint32_t priority,
601 uint32_t anonymity, 602 uint32_t anonymity,
603 uint32_t replication,
602 struct GNUNET_TIME_Absolute expiration, 604 struct GNUNET_TIME_Absolute expiration,
603 char **msg) 605 char **msg)
604{ 606{
@@ -1198,6 +1200,26 @@ postgres_plugin_get (void *cls,
1198 1200
1199 1201
1200/** 1202/**
1203 * Get a random item for replication. Returns a single, not expired, random item
1204 * from those with the highest replication counters. The item's
1205 * replication counter is decremented by one IF it was positive before.
1206 * Call 'iter' with all values ZERO or NULL if the datastore is empty.
1207 *
1208 * @param cls closure
1209 * @param iter function to call the value (once only).
1210 * @param iter_cls closure for iter
1211 */
1212static void
1213postgres_plugin_replication_get (void *cls,
1214 PluginIterator iter, void *iter_cls)
1215{
1216 /* FIXME: not implemented! */
1217 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0,
1218 GNUNET_TIME_UNIT_ZERO_ABS, 0);
1219}
1220
1221
1222/**
1201 * Select a subset of the items in the datastore and call 1223 * Select a subset of the items in the datastore and call
1202 * the given iterator for each of them. 1224 * the given iterator for each of them.
1203 * 1225 *
@@ -1333,6 +1355,7 @@ libgnunet_plugin_datastore_postgres_init (void *cls)
1333 api->put = &postgres_plugin_put; 1355 api->put = &postgres_plugin_put;
1334 api->next_request = &postgres_plugin_next_request; 1356 api->next_request = &postgres_plugin_next_request;
1335 api->get = &postgres_plugin_get; 1357 api->get = &postgres_plugin_get;
1358 api->replication_get = &postgres_plugin_replication_get;
1336 api->update = &postgres_plugin_update; 1359 api->update = &postgres_plugin_update;
1337 api->iter_low_priority = &postgres_plugin_iter_low_priority; 1360 api->iter_low_priority = &postgres_plugin_iter_low_priority;
1338 api->iter_zero_anonymity = &postgres_plugin_iter_zero_anonymity; 1361 api->iter_zero_anonymity = &postgres_plugin_iter_zero_anonymity;
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c
index 0eba474f6..260bd54cc 100644
--- a/src/datastore/plugin_datastore_sqlite.c
+++ b/src/datastore/plugin_datastore_sqlite.c
@@ -689,6 +689,7 @@ sqlite_next_request (void *next_cls,
689 * @param type type of the content 689 * @param type type of the content
690 * @param priority priority of the content 690 * @param priority priority of the content
691 * @param anonymity anonymity-level for the content 691 * @param anonymity anonymity-level for the content
692 * @param replication replication-level for the content
692 * @param expiration expiration time for the content 693 * @param expiration expiration time for the content
693 * @param msg set to an error message 694 * @param msg set to an error message
694 * @return GNUNET_OK on success 695 * @return GNUNET_OK on success
@@ -701,6 +702,7 @@ sqlite_plugin_put (void *cls,
701 enum GNUNET_BLOCK_Type type, 702 enum GNUNET_BLOCK_Type type,
702 uint32_t priority, 703 uint32_t priority,
703 uint32_t anonymity, 704 uint32_t anonymity,
705 uint32_t replication,
704 struct GNUNET_TIME_Absolute expiration, 706 struct GNUNET_TIME_Absolute expiration,
705 char ** msg) 707 char ** msg)
706{ 708{
@@ -1532,6 +1534,26 @@ sqlite_plugin_get (void *cls,
1532 1534
1533 1535
1534/** 1536/**
1537 * Get a random item for replication. Returns a single, not expired, random item
1538 * from those with the highest replication counters. The item's
1539 * replication counter is decremented by one IF it was positive before.
1540 * Call 'iter' with all values ZERO or NULL if the datastore is empty.
1541 *
1542 * @param cls closure
1543 * @param iter function to call the value (once only).
1544 * @param iter_cls closure for iter
1545 */
1546static void
1547sqlite_plugin_replication_get (void *cls,
1548 PluginIterator iter, void *iter_cls)
1549{
1550 /* FIXME: not implemented! */
1551 iter (iter_cls, NULL, NULL, 0, NULL, 0, 0, 0,
1552 GNUNET_TIME_UNIT_ZERO_ABS, 0);
1553}
1554
1555
1556/**
1535 * Drop database. 1557 * Drop database.
1536 * 1558 *
1537 * @param cls our plugin context 1559 * @param cls our plugin context
@@ -1623,6 +1645,7 @@ libgnunet_plugin_datastore_sqlite_init (void *cls)
1623 api->put = &sqlite_plugin_put; 1645 api->put = &sqlite_plugin_put;
1624 api->next_request = &sqlite_next_request; 1646 api->next_request = &sqlite_next_request;
1625 api->get = &sqlite_plugin_get; 1647 api->get = &sqlite_plugin_get;
1648 api->replication_get = &sqlite_plugin_replication_get;
1626 api->update = &sqlite_plugin_update; 1649 api->update = &sqlite_plugin_update;
1627 api->iter_low_priority = &sqlite_plugin_iter_low_priority; 1650 api->iter_low_priority = &sqlite_plugin_iter_low_priority;
1628 api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity; 1651 api->iter_zero_anonymity = &sqlite_plugin_iter_zero_anonymity;
diff --git a/src/datastore/plugin_datastore_template.c b/src/datastore/plugin_datastore_template.c
index 09dfe85d9..fc67f600e 100644
--- a/src/datastore/plugin_datastore_template.c
+++ b/src/datastore/plugin_datastore_template.c
@@ -64,6 +64,7 @@ static unsigned long long template_plugin_get_size (void *cls)
64 * @param type type of the content 64 * @param type type of the content
65 * @param priority priority of the content 65 * @param priority priority of the content
66 * @param anonymity anonymity-level for the content 66 * @param anonymity anonymity-level for the content
67 * @param replication replication-level for the content
67 * @param expiration expiration time for the content 68 * @param expiration expiration time for the content
68 * @param msg set to error message 69 * @param msg set to error message
69 * @return GNUNET_OK on success 70 * @return GNUNET_OK on success
@@ -76,6 +77,7 @@ template_plugin_put (void *cls,
76 enum GNUNET_BLOCK_Type type, 77 enum GNUNET_BLOCK_Type type,
77 uint32_t priority, 78 uint32_t priority,
78 uint32_t anonymity, 79 uint32_t anonymity,
80 uint32_t replication,
79 struct GNUNET_TIME_Absolute expiration, 81 struct GNUNET_TIME_Absolute expiration,
80 char **msg) 82 char **msg)
81{ 83{
@@ -133,6 +135,25 @@ template_plugin_get (void *cls,
133} 135}
134 136
135 137
138
139/**
140 * Get a random item for replication. Returns a single, not expired, random item
141 * from those with the highest replication counters. The item's
142 * replication counter is decremented by one IF it was positive before.
143 * Call 'iter' with all values ZERO or NULL if the datastore is empty.
144 *
145 * @param cls closure
146 * @param iter function to call the value (once only).
147 * @param iter_cls closure for iter
148 */
149static void
150template_plugin_replication_get (void *cls,
151 PluginIterator iter, void *iter_cls)
152{
153 GNUNET_break (0);
154}
155
156
136/** 157/**
137 * Update the priority for a particular key in the datastore. If 158 * Update the priority for a particular key in the datastore. If
138 * the expiration time in value is different than the time found in 159 * the expiration time in value is different than the time found in
@@ -308,6 +329,7 @@ libgnunet_plugin_datastore_template_init (void *cls)
308 api->put = &template_plugin_put; 329 api->put = &template_plugin_put;
309 api->next_request = &template_plugin_next_request; 330 api->next_request = &template_plugin_next_request;
310 api->get = &template_plugin_get; 331 api->get = &template_plugin_get;
332 api->replication_get = &template_plugin_replication_get;
311 api->update = &template_plugin_update; 333 api->update = &template_plugin_update;
312 api->iter_low_priority = &template_plugin_iter_low_priority; 334 api->iter_low_priority = &template_plugin_iter_low_priority;
313 api->iter_zero_anonymity = &template_plugin_iter_zero_anonymity; 335 api->iter_zero_anonymity = &template_plugin_iter_zero_anonymity;
diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h
index 8666dac10..c981ceb1d 100644
--- a/src/include/gnunet_datastore_plugin.h
+++ b/src/include/gnunet_datastore_plugin.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2009 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2011 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -136,8 +136,8 @@ typedef unsigned long long (*PluginGetSize) (void *cls);
136 136
137/** 137/**
138 * Store an item in the datastore. If the item is already present, 138 * Store an item in the datastore. If the item is already present,
139 * the priorities are summed up and the higher expiration time and 139 * the priorities and replication levels are summed up and the higher
140 * lower anonymity level is used. 140 * expiration time and lower anonymity level is used.
141 * 141 *
142 * @param cls closure 142 * @param cls closure
143 * @param key key for the item 143 * @param key key for the item
@@ -146,6 +146,7 @@ typedef unsigned long long (*PluginGetSize) (void *cls);
146 * @param type type of the content 146 * @param type type of the content
147 * @param priority priority of the content 147 * @param priority priority of the content
148 * @param anonymity anonymity-level for the content 148 * @param anonymity anonymity-level for the content
149 * @param replication replication-level for the content
149 * @param expiration expiration time for the content 150 * @param expiration expiration time for the content
150 * @param msg set to an error message (on failure) 151 * @param msg set to an error message (on failure)
151 * @return GNUNET_OK on success, GNUNET_NO if the content 152 * @return GNUNET_OK on success, GNUNET_NO if the content
@@ -159,6 +160,7 @@ typedef int (*PluginPut) (void *cls,
159 enum GNUNET_BLOCK_Type type, 160 enum GNUNET_BLOCK_Type type,
160 uint32_t priority, 161 uint32_t priority,
161 uint32_t anonymity, 162 uint32_t anonymity,
163 uint32_t replication,
162 struct GNUNET_TIME_Absolute expiration, 164 struct GNUNET_TIME_Absolute expiration,
163 char **msg); 165 char **msg);
164 166
@@ -191,6 +193,22 @@ typedef void (*PluginGet) (void *cls,
191 PluginIterator iter, void *iter_cls); 193 PluginIterator iter, void *iter_cls);
192 194
193 195
196
197/**
198 * Get a random item for replication. Returns a single,
199 * not expired, random item
200 * from those with the highest replication counters. The item's
201 * replication counter is decremented by one IF it was positive before.
202 * Call 'iter' with all values ZERO or NULL if the datastore is empty.
203 *
204 * @param cls closure
205 * @param iter function to call the value (once only).
206 * @param iter_cls closure for iter
207 */
208typedef void (*PluginReplicationGet) (void *cls,
209 PluginIterator iter, void *iter_cls);
210
211
194/** 212/**
195 * Update the priority for a particular key in the datastore. If 213 * Update the priority for a particular key in the datastore. If
196 * the expiration time in value is different than the time found in 214 * the expiration time in value is different than the time found in
@@ -288,6 +306,12 @@ struct GNUNET_DATASTORE_PluginFunctions
288 PluginGet get; 306 PluginGet get;
289 307
290 /** 308 /**
309 * Function to get a random item with high replication score from
310 * the database, lowering the item's replication score.
311 */
312 PluginReplicationGet replication_get;
313
314 /**
291 * Update the priority for a particular key in the datastore. If 315 * Update the priority for a particular key in the datastore. If
292 * the expiration time in value is different than the time found in 316 * the expiration time in value is different than the time found in
293 * the datastore, the higher value should be kept. For the 317 * the datastore, the higher value should be kept. For the