diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-11-13 20:05:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-11-13 20:05:40 +0000 |
commit | 4e1d85bac66209e6655f3fb4d3ddef7929f0f3fc (patch) | |
tree | df5c5a0d972f35d741b51c3a3fc8d2298ac8b4fd /src/dht/gnunet-service-dht_datacache.c | |
parent | 855362e698928b0a5a8f72fc6427c2ea42af4e79 (diff) | |
download | gnunet-4e1d85bac66209e6655f3fb4d3ddef7929f0f3fc.tar.gz gnunet-4e1d85bac66209e6655f3fb4d3ddef7929f0f3fc.zip |
changing datacache API to separate put-paths from data (so that plugins can test for duplicates), removing support for MySQL
Diffstat (limited to 'src/dht/gnunet-service-dht_datacache.c')
-rw-r--r-- | src/dht/gnunet-service-dht_datacache.c | 80 |
1 files changed, 16 insertions, 64 deletions
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index b2cb93d12..4768c14fd 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c | |||
@@ -39,28 +39,6 @@ static struct GNUNET_DATACACHE_Handle *datacache; | |||
39 | 39 | ||
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Entry for inserting data into datacache from the DHT. | ||
43 | */ | ||
44 | struct DHTPutEntry | ||
45 | { | ||
46 | /** | ||
47 | * Size of data. | ||
48 | */ | ||
49 | uint16_t data_size; | ||
50 | |||
51 | /** | ||
52 | * Length of recorded path. | ||
53 | */ | ||
54 | uint16_t path_length; | ||
55 | |||
56 | /* PATH ENTRIES */ | ||
57 | |||
58 | /* PUT DATA */ | ||
59 | |||
60 | }; | ||
61 | |||
62 | |||
63 | /** | ||
64 | * Handle a datum we've received from another peer. Cache if | 42 | * Handle a datum we've received from another peer. Cache if |
65 | * possible. | 43 | * possible. |
66 | * | 44 | * |
@@ -80,14 +58,7 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | |||
80 | enum GNUNET_BLOCK_Type type, size_t data_size, | 58 | enum GNUNET_BLOCK_Type type, size_t data_size, |
81 | const void *data) | 59 | const void *data) |
82 | { | 60 | { |
83 | size_t plen = | 61 | if (NULL == datacache) |
84 | data_size + put_path_length * sizeof (struct GNUNET_PeerIdentity) + | ||
85 | sizeof (struct DHTPutEntry); | ||
86 | char buf[plen]; | ||
87 | struct DHTPutEntry *pe; | ||
88 | struct GNUNET_PeerIdentity *pp; | ||
89 | |||
90 | if (datacache == NULL) | ||
91 | { | 62 | { |
92 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 63 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
93 | _("%s request received, but have no datacache!\n"), "PUT"); | 64 | _("%s request received, but have no datacache!\n"), "PUT"); |
@@ -102,14 +73,9 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | |||
102 | GNUNET_STATISTICS_update (GDS_stats, | 73 | GNUNET_STATISTICS_update (GDS_stats, |
103 | gettext_noop ("# ITEMS stored in datacache"), 1, | 74 | gettext_noop ("# ITEMS stored in datacache"), 1, |
104 | GNUNET_NO); | 75 | GNUNET_NO); |
105 | pe = (struct DHTPutEntry *) buf; | 76 | (void) GNUNET_DATACACHE_put (datacache, key, |
106 | pe->data_size = htons (data_size); | 77 | data_size, data, type, |
107 | pe->path_length = htons ((uint16_t) put_path_length); | 78 | expiration, put_path_length, put_path); |
108 | pp = (struct GNUNET_PeerIdentity *) &pe[1]; | ||
109 | memcpy (pp, put_path, put_path_length * sizeof (struct GNUNET_PeerIdentity)); | ||
110 | memcpy (&pp[put_path_length], data, data_size); | ||
111 | (void) GNUNET_DATACACHE_put (datacache, key, plen, (const char *) pe, type, | ||
112 | expiration); | ||
113 | } | 79 | } |
114 | 80 | ||
115 | 81 | ||
@@ -159,40 +125,26 @@ struct GetRequestContext | |||
159 | * @param size the size of the data identified by key | 125 | * @param size the size of the data identified by key |
160 | * @param data the actual data | 126 | * @param data the actual data |
161 | * @param type the type of the data | 127 | * @param type the type of the data |
162 | * | 128 | * @param put_path_length number of peers in 'put_path' |
129 | * @param put_path path the reply took on put | ||
163 | * @return GNUNET_OK to continue iteration, anything else | 130 | * @return GNUNET_OK to continue iteration, anything else |
164 | * to stop iteration. | 131 | * to stop iteration. |
165 | */ | 132 | */ |
166 | static int | 133 | static int |
167 | datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | 134 | datacache_get_iterator (void *cls, |
168 | const struct GNUNET_HashCode * key, size_t size, | 135 | const struct GNUNET_HashCode * key, size_t size, |
169 | const char *data, enum GNUNET_BLOCK_Type type) | 136 | const char *data, enum GNUNET_BLOCK_Type type, |
137 | struct GNUNET_TIME_Absolute exp, | ||
138 | unsigned int put_path_length, | ||
139 | const struct GNUNET_PeerIdentity *put_path) | ||
170 | { | 140 | { |
171 | struct GetRequestContext *ctx = cls; | 141 | struct GetRequestContext *ctx = cls; |
172 | const struct DHTPutEntry *pe; | ||
173 | const struct GNUNET_PeerIdentity *pp; | ||
174 | const char *rdata; | ||
175 | size_t rdata_size; | ||
176 | uint16_t put_path_length; | ||
177 | enum GNUNET_BLOCK_EvaluationResult eval; | 142 | enum GNUNET_BLOCK_EvaluationResult eval; |
178 | 143 | ||
179 | pe = (const struct DHTPutEntry *) data; | ||
180 | put_path_length = ntohs (pe->path_length); | ||
181 | rdata_size = ntohs (pe->data_size); | ||
182 | |||
183 | if (size != | ||
184 | sizeof (struct DHTPutEntry) + rdata_size + | ||
185 | (put_path_length * sizeof (struct GNUNET_PeerIdentity))) | ||
186 | { | ||
187 | GNUNET_break (0); | ||
188 | return GNUNET_OK; | ||
189 | } | ||
190 | pp = (const struct GNUNET_PeerIdentity *) &pe[1]; | ||
191 | rdata = (const char *) &pp[put_path_length]; | ||
192 | eval = | 144 | eval = |
193 | GNUNET_BLOCK_evaluate (GDS_block_context, type, key, ctx->reply_bf, | 145 | GNUNET_BLOCK_evaluate (GDS_block_context, type, key, ctx->reply_bf, |
194 | ctx->reply_bf_mutator, ctx->xquery, | 146 | ctx->reply_bf_mutator, ctx->xquery, |
195 | ctx->xquery_size, rdata, rdata_size); | 147 | ctx->xquery_size, data, size); |
196 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
197 | "Found reply for query %s in datacache, evaluation result is %d\n", | 149 | "Found reply for query %s in datacache, evaluation result is %d\n", |
198 | GNUNET_h2s (key), (int) eval); | 150 | GNUNET_h2s (key), (int) eval); |
@@ -206,11 +158,11 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | |||
206 | gettext_noop | 158 | gettext_noop |
207 | ("# Good RESULTS found in datacache"), 1, | 159 | ("# Good RESULTS found in datacache"), 1, |
208 | GNUNET_NO); | 160 | GNUNET_NO); |
209 | GDS_CLIENTS_handle_reply (exp, key, 0, NULL, put_path_length, pp, type, | 161 | GDS_CLIENTS_handle_reply (exp, key, 0, NULL, put_path_length, put_path, type, |
210 | rdata_size, rdata); | 162 | size, data); |
211 | /* forward to other peers */ | 163 | /* forward to other peers */ |
212 | GDS_ROUTING_process (type, exp, key, put_path_length, pp, 0, NULL, rdata, | 164 | GDS_ROUTING_process (type, exp, key, put_path_length, put_path, 0, NULL, data, |
213 | rdata_size); | 165 | size); |
214 | break; | 166 | break; |
215 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: | 167 | case GNUNET_BLOCK_EVALUATION_OK_DUPLICATE: |
216 | GNUNET_STATISTICS_update (GDS_stats, | 168 | GNUNET_STATISTICS_update (GDS_stats, |