diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-04-28 15:05:12 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-04-28 15:05:12 +0000 |
commit | 7581e114280c0c33f375b5d3ba49508b82680755 (patch) | |
tree | d24afeeda69f94b70d1dc325db06810a4b0b1be0 /src/include | |
parent | 553909348c19833330ad94d7a1064eaf48f97e3f (diff) | |
download | gnunet-7581e114280c0c33f375b5d3ba49508b82680755.tar.gz gnunet-7581e114280c0c33f375b5d3ba49508b82680755.zip |
extending datacache API with function to return random element, implemented (only) in heap plugin right now
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_container_lib.h | 16 | ||||
-rw-r--r-- | src/include/gnunet_datacache_lib.h | 57 | ||||
-rw-r--r-- | src/include/gnunet_datacache_plugin.h | 46 |
3 files changed, 86 insertions, 33 deletions
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index 125bc81b2..1ecf4f52a 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h | |||
@@ -854,6 +854,22 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct GNUNET_CONTAINER_MultiH | |||
854 | void *it_cls); | 854 | void *it_cls); |
855 | 855 | ||
856 | 856 | ||
857 | /** | ||
858 | * @ingroup hashmap | ||
859 | * Call @a it on a random value from the map, or not at all | ||
860 | * if the map is empty. | ||
861 | * | ||
862 | * @param map the map | ||
863 | * @param it function to call on a random entry | ||
864 | * @param it_cls extra argument to @a it | ||
865 | * @return the number of key value pairs processed, zero or one. | ||
866 | */ | ||
867 | unsigned int | ||
868 | GNUNET_CONTAINER_multihashmap_get_random (const struct GNUNET_CONTAINER_MultiHashMap *map, | ||
869 | GNUNET_CONTAINER_HashMapIterator it, | ||
870 | void *it_cls); | ||
871 | |||
872 | |||
857 | /* ***************** Version of Multihashmap for peer identities ****************** */ | 873 | /* ***************** Version of Multihashmap for peer identities ****************** */ |
858 | 874 | ||
859 | /** | 875 | /** |
diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h index 5e2ad1c1d..f3761bd89 100644 --- a/src/include/gnunet_datacache_lib.h +++ b/src/include/gnunet_datacache_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2006, 2009 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2006, 2009, 2015 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 |
@@ -75,21 +75,23 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h); | |||
75 | * | 75 | * |
76 | * @param cls closure | 76 | * @param cls closure |
77 | * @param key key for the content | 77 | * @param key key for the content |
78 | * @param size number of bytes in data | 78 | * @param data_size number of bytes in @a data |
79 | * @param data content stored | 79 | * @param data content stored |
80 | * @param type type of the content | 80 | * @param type type of the content |
81 | * @param exp when will the content expire? | 81 | * @param exp when will the content expire? |
82 | * @param path_info_len number of entries in 'path_info' | 82 | * @param path_info_len number of entries in @a path_info |
83 | * @param path_info a path through the network | 83 | * @param path_info a path through the network |
84 | * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort | 84 | * @return #GNUNET_OK to continue iterating, #GNUNET_SYSERR to abort |
85 | */ | 85 | */ |
86 | typedef int (*GNUNET_DATACACHE_Iterator) (void *cls, | 86 | typedef int |
87 | const struct GNUNET_HashCode *key, | 87 | (*GNUNET_DATACACHE_Iterator) (void *cls, |
88 | size_t size, const char *data, | 88 | const struct GNUNET_HashCode *key, |
89 | enum GNUNET_BLOCK_Type type, | 89 | size_t data_size, |
90 | struct GNUNET_TIME_Absolute exp, | 90 | const char *data, |
91 | unsigned int path_info_len, | 91 | enum GNUNET_BLOCK_Type type, |
92 | const struct GNUNET_PeerIdentity *path_info); | 92 | struct GNUNET_TIME_Absolute exp, |
93 | unsigned int path_info_len, | ||
94 | const struct GNUNET_PeerIdentity *path_info); | ||
93 | 95 | ||
94 | 96 | ||
95 | /** | 97 | /** |
@@ -97,18 +99,20 @@ typedef int (*GNUNET_DATACACHE_Iterator) (void *cls, | |||
97 | * | 99 | * |
98 | * @param h handle to the datacache | 100 | * @param h handle to the datacache |
99 | * @param key key to store data under | 101 | * @param key key to store data under |
100 | * @param size number of bytes in data | 102 | * @param data_size number of bytes in @a data |
101 | * @param data data to store | 103 | * @param data data to store |
102 | * @param type type of the value | 104 | * @param type type of the value |
103 | * @param discard_time when to discard the value in any case | 105 | * @param discard_time when to discard the value in any case |
104 | * @param path_info_len number of entries in 'path_info' | 106 | * @param path_info_len number of entries in @a path_info |
105 | * @param path_info a path through the network | 107 | * @param path_info a path through the network |
106 | * @return GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if duplicate | 108 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error, #GNUNET_NO if duplicate |
107 | */ | 109 | */ |
108 | int | 110 | int |
109 | GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, | 111 | GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, |
110 | const struct GNUNET_HashCode * key, size_t size, | 112 | const struct GNUNET_HashCode *key, |
111 | const char *data, enum GNUNET_BLOCK_Type type, | 113 | size_t data_size, |
114 | const char *data, | ||
115 | enum GNUNET_BLOCK_Type type, | ||
112 | struct GNUNET_TIME_Absolute discard_time, | 116 | struct GNUNET_TIME_Absolute discard_time, |
113 | unsigned int path_info_len, | 117 | unsigned int path_info_len, |
114 | const struct GNUNET_PeerIdentity *path_info); | 118 | const struct GNUNET_PeerIdentity *path_info); |
@@ -122,15 +126,32 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, | |||
122 | * @param key what to look up | 126 | * @param key what to look up |
123 | * @param type entries of which type are relevant? | 127 | * @param type entries of which type are relevant? |
124 | * @param iter maybe NULL (to just count) | 128 | * @param iter maybe NULL (to just count) |
125 | * @param iter_cls closure for iter | 129 | * @param iter_cls closure for @a iter |
126 | * @return the number of results found | 130 | * @return the number of results found |
127 | */ | 131 | */ |
128 | unsigned int | 132 | unsigned int |
129 | GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, | 133 | GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, |
130 | const struct GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type, | 134 | const struct GNUNET_HashCode *key, |
135 | enum GNUNET_BLOCK_Type type, | ||
131 | GNUNET_DATACACHE_Iterator iter, void *iter_cls); | 136 | GNUNET_DATACACHE_Iterator iter, void *iter_cls); |
132 | 137 | ||
133 | 138 | ||
139 | /** | ||
140 | * Obtain a random element from the datacache. | ||
141 | * | ||
142 | * @param h handle to the datacache | ||
143 | * @param iter maybe NULL (to just count) | ||
144 | * @param iter_cls closure for @a iter | ||
145 | * @return the number of results found (zero or 1) | ||
146 | */ | ||
147 | unsigned int | ||
148 | GNUNET_DATACACHE_get_random (struct GNUNET_DATACACHE_Handle *h, | ||
149 | GNUNET_DATACACHE_Iterator iter, | ||
150 | void *iter_cls); | ||
151 | |||
152 | |||
153 | |||
154 | |||
134 | #if 0 /* keep Emacsens' auto-indent happy */ | 155 | #if 0 /* keep Emacsens' auto-indent happy */ |
135 | { | 156 | { |
136 | #endif | 157 | #endif |
diff --git a/src/include/gnunet_datacache_plugin.h b/src/include/gnunet_datacache_plugin.h index 347ed9a59..34cf8fecc 100644 --- a/src/include/gnunet_datacache_plugin.h +++ b/src/include/gnunet_datacache_plugin.h | |||
@@ -45,9 +45,10 @@ extern "C" | |||
45 | * @param key key of the content that was deleted | 45 | * @param key key of the content that was deleted |
46 | * @param size number of bytes that were made available | 46 | * @param size number of bytes that were made available |
47 | */ | 47 | */ |
48 | typedef void (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls, | 48 | typedef void |
49 | const struct GNUNET_HashCode * | 49 | (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls, |
50 | key, size_t size); | 50 | const struct GNUNET_HashCode *key, |
51 | size_t size); | ||
51 | 52 | ||
52 | 53 | ||
53 | /** | 54 | /** |
@@ -58,7 +59,6 @@ typedef void (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls, | |||
58 | struct GNUNET_DATACACHE_PluginEnvironment | 59 | struct GNUNET_DATACACHE_PluginEnvironment |
59 | { | 60 | { |
60 | 61 | ||
61 | |||
62 | /** | 62 | /** |
63 | * Configuration to use. | 63 | * Configuration to use. |
64 | */ | 64 | */ |
@@ -103,46 +103,62 @@ struct GNUNET_DATACACHE_PluginFunctions | |||
103 | * Store an item in the datastore. | 103 | * Store an item in the datastore. |
104 | * | 104 | * |
105 | * @param cls closure (internal context for the plugin) | 105 | * @param cls closure (internal context for the plugin) |
106 | * @param size number of bytes in data | 106 | * @param key key to store the value under |
107 | * @param size number of bytes in @a data | ||
107 | * @param data data to store | 108 | * @param data data to store |
108 | * @param type type of the value | 109 | * @param type type of the value |
109 | * @param discard_time when to discard the value in any case | 110 | * @param discard_time when to discard the value in any case |
110 | * @param path_info_len number of entries in 'path_info' | 111 | * @param path_info_len number of entries in @a path_info |
111 | * @param path_info a path through the network | 112 | * @param path_info a path through the network |
112 | * @return 0 if duplicate, -1 on error, number of bytes used otherwise | 113 | * @return 0 if duplicate, -1 on error, number of bytes used otherwise |
113 | */ | 114 | */ |
114 | ssize_t (*put) (void *cls, const struct GNUNET_HashCode * key, size_t size, | 115 | ssize_t (*put) (void *cls, |
115 | const char *data, enum GNUNET_BLOCK_Type type, | 116 | const struct GNUNET_HashCode *key, |
117 | size_t size, | ||
118 | const char *data, | ||
119 | enum GNUNET_BLOCK_Type type, | ||
116 | struct GNUNET_TIME_Absolute discard_time, | 120 | struct GNUNET_TIME_Absolute discard_time, |
117 | unsigned int path_info_len, | 121 | unsigned int path_info_len, |
118 | const struct GNUNET_PeerIdentity *path_info); | 122 | const struct GNUNET_PeerIdentity *path_info); |
119 | 123 | ||
120 | |||
121 | /** | 124 | /** |
122 | * Iterate over the results for a particular key | 125 | * Iterate over the results for a particular key |
123 | * in the datastore. | 126 | * in the datastore. |
124 | * | 127 | * |
125 | * @param cls closure (internal context for the plugin) | 128 | * @param cls closure (internal context for the plugin) |
126 | * @param key | 129 | * @param key key to look for |
127 | * @param type entries of which type are relevant? | 130 | * @param type entries of which type are relevant? |
128 | * @param iter maybe NULL (to just count) | 131 | * @param iter maybe NULL (to just count) |
129 | * @param iter_cls closure for iter | 132 | * @param iter_cls closure for @a iter |
130 | * @return the number of results found | 133 | * @return the number of results found |
131 | */ | 134 | */ |
132 | unsigned int (*get) (void *cls, const struct GNUNET_HashCode * key, | 135 | unsigned int (*get) (void *cls, |
136 | const struct GNUNET_HashCode * key, | ||
133 | enum GNUNET_BLOCK_Type type, | 137 | enum GNUNET_BLOCK_Type type, |
134 | GNUNET_DATACACHE_Iterator iter, void *iter_cls); | 138 | GNUNET_DATACACHE_Iterator iter, |
135 | 139 | void *iter_cls); | |
136 | 140 | ||
137 | /** | 141 | /** |
138 | * Delete the entry with the lowest expiration value | 142 | * Delete the entry with the lowest expiration value |
139 | * from the datacache right now. | 143 | * from the datacache right now. |
140 | * | 144 | * |
141 | * @param cls closure (internal context for the plugin) | 145 | * @param cls closure (internal context for the plugin) |
142 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 146 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
143 | */ | 147 | */ |
144 | int (*del) (void *cls); | 148 | int (*del) (void *cls); |
145 | 149 | ||
150 | /** | ||
151 | * Return a random value from the datastore. | ||
152 | * | ||
153 | * @param cls closure (internal context for the plugin) | ||
154 | * @param iter maybe NULL (to just count) | ||
155 | * @param iter_cls closure for @a iter | ||
156 | * @return the number of results found (zero or one) | ||
157 | */ | ||
158 | unsigned int (*get_random) (void *cls, | ||
159 | GNUNET_DATACACHE_Iterator iter, | ||
160 | void *iter_cls); | ||
161 | |||
146 | 162 | ||
147 | }; | 163 | }; |
148 | 164 | ||