58
55
static int parseOptions(int argc,
63
60
int option_index = 0;
64
61
static struct GNoption long_options[] = {
65
62
LONG_DEFAULT_OPTIONS,
66
63
{ "memory", 1, 0, 'm' },
67
{ "table", 1, 0, 't' },
64
{ "table", 1, 0, 't' },
68
65
{ "verbose", 0, 0, 'V' },
71
68
c = GNgetopt_long(argc,
73
70
"vhH:c:L:dt:m:T:V",
77
74
break; /* No more flags to process */
78
75
if (YES == parseDefaultOptions(c, GNoptarg))
86
83
if (1 != sscanf(GNoptarg, "%ud", &max)) {
88
_("You must pass a number to the '%s' option.\n"),
85
_("You must pass a number to the `%s' option.\n"),
148
#define LOGRET(ret) dump(_("Call to '%s' returns %d.\n"), __FUNCTION__, ret)
149
#define LOGKEY(key) do { EncName kn; hash2enc(key, &kn); dump(_("Call to '%s' with key '%s'.\n"), __FUNCTION__, &kn); } while (0)
150
#define LOGVAL(val) dump(_("Call to '%s' with value '%.*s' (%d bytes).\n"), __FUNCTION__, (val == NULL) ? 0 : val->dataLength, (val == NULL) ? NULL : val->data, (val == NULL) ? 0 : val->dataLength)
131
#define LOGRET(ret) dump(_("Call to `%s' returns %d.\n"), __FUNCTION__, ret)
132
#define LOGKEY(key) do { EncName kn; hash2enc(key, &kn); dump(_("Call to `%s' with key `%s'.\n"), __FUNCTION__, &kn); } while (0)
133
#define LOGVAL(val) dump(_("Call to `%s' with value '%.*s' (%d bytes).\n"), __FUNCTION__, (val == NULL) ? 0 : &val[1], (val == NULL) ? NULL : &val[1], (val == NULL) ? 0 : (ntohl(val->size) - sizeof(DataContainer)))
152
135
static int lookup(void * closure,
153
const HashCode160 * key,
154
unsigned int maxResults,
155
DHT_DataContainer * results,
138
unsigned int keyCount,
139
const HashCode512 * keys,
140
DataProcessor processor,
158
DHT_Datastore * cls = (DHT_Datastore*) closure;
160
ret = cls->lookup(cls->closure,
143
Blockstore * cls = (Blockstore*) closure;
145
ret = cls->get(cls->closure,
171
156
static int store(void * closure,
172
const HashCode160 * key,
173
const DHT_DataContainer * value,
157
const HashCode512 * key,
158
const DataContainer * value,
176
DHT_Datastore * cls = (DHT_Datastore*) closure;
161
Blockstore * cls = (Blockstore*) closure;
179
ret = cls->store(cls->closure,
164
ret = cls->put(cls->closure,
187
172
static int removeDS(void * closure,
188
const HashCode160 * key,
189
const DHT_DataContainer * value,
173
const HashCode512 * key,
174
const DataContainer * value) {
192
DHT_Datastore * cls = (DHT_Datastore*) closure;
176
Blockstore * cls = (Blockstore*) closure;
195
ret = cls->remove(cls->closure,
179
ret = cls->del(cls->closure,
203
static int iterate(void * closure,
205
DHT_DataProcessor processor,
186
static int iterate(void * closure,
187
DataProcessor processor,
208
DHT_Datastore * cls = (DHT_Datastore*) closure;
190
Blockstore * cls = (Blockstore*) closure;
209
191
ret = cls->iterate(cls->closure,
219
200
char * tableName;
221
201
unsigned int mem;
223
DHT_Datastore myStore;
225
if (SYSERR == initUtil(argc, argv, &parseOptions))
205
if (SYSERR == initUtil(argc, argv, &parseOptions))
228
tableName = getConfigurationString("DHT-JOIN",
208
tableName = getConfigurationString("DHT-JOIN",
230
210
if (tableName == NULL) {
231
printf(_("No table name specified, using '%s'.\n"),
211
printf(_("No table name specified, using `%s'.\n"),
233
213
tableName = STRDUP("test");
242
222
mem = getConfigurationInt("DHT-JOIN",
244
224
if (mem == 0) mem = 65536; /* default: use 64k */
245
myStore.closure = create_datastore_memory(mem);
246
myStore.lookup = &lookup;
247
myStore.store = &store;
248
myStore.remove = &removeDS;
225
myStore.closure = create_blockstore_memory(mem);
226
myStore.get = &lookup;
227
myStore.put = &store;
228
myStore.del = &removeDS;
249
229
myStore.iterate = &iterate;
251
flags = 1; /* one replica */
254
232
initializeShutdownHandlers();
255
233
if (OK != DHT_LIB_join(&myStore,
260
236
_("Error joining DHT.\n"));
261
destroy_datastore_memory((DHT_Datastore*)myStore.closure);
237
destroy_blockstore_memory((Blockstore*)myStore.closure);
262
238
doneShutdownHandlers();
267
243
printf(_("Joined DHT. Press CTRL-C to leave.\n"));
268
244
/* wait for CTRL-C */
269
245
wait_for_shutdown();
272
if (OK != DHT_LIB_leave(&table,
273
getConfigurationInt("DHT-JOIN",
274
"TIMEOUT") * cronSECONDS,
248
if (OK != DHT_LIB_leave(&table)) {
277
250
_("Error leaving DHT.\n"));
278
destroy_datastore_memory((DHT_Datastore*)myStore.closure);
251
destroy_blockstore_memory((Blockstore*)myStore.closure);
279
252
doneShutdownHandlers();
283
destroy_datastore_memory((DHT_Datastore*)myStore.closure);
256
destroy_blockstore_memory((Blockstore*)myStore.closure);
284
257
doneShutdownHandlers();