aboutsummaryrefslogtreecommitdiff
path: root/src/services/gnunet-service-dht-dbus.c
blob: 4b47be7084167fa5fdd3bd00c1c0ab47862440b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
#include "config.h"

#include <gnunet/platform.h>
#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_configuration_lib.h>
#include <gnunet/gnunet_getopt_lib.h>
#include <gnunet/gnunet_strings_lib.h>
#include <gnunet/gnunet_program_lib.h>
#include <gnunet/gnunet_dht_service.h>

#include "gnunet_dbus_lib.h"
#include "gnunet_dht_dbus_lib.h"
#include "gnunet_block_dbus_lib.h"
#include "gnunet_time_dbus_lib.h"

#define LOG(kind, ...) GNUNET_log_from (kind, "dht-dbus", __VA_ARGS__)

struct GetRequest
{
  struct GNUNET_DBUS_Client *client;
  struct GNUNET_DHT_GetHandle *handle;
  bool pretty;
};

struct ClientData
{
  struct GNUNET_DBUS_ObjectIterator *gets_front;
  struct GNUNET_DBUS_ObjectIterator *gets_back;
  struct GNUNET_DHT_Handle *dht_handle;
};

static struct GNUNET_DBUS_Service   *gbl_dht_service;
static struct GNUNET_DBUS_Interface *gbl_dht_interface;
static struct GNUNET_DBUS_Method    *gbl_dht_put_method;
static struct GNUNET_DBUS_Method    *gbl_dht_get_start_method;
static struct GNUNET_DBUS_Object    *gbl_dht_get_object;
static struct GNUNET_DBUS_Interface *gbl_dht_get_request_interface;
static struct GNUNET_DBUS_Method    
    *gbl_dht_get_request_filter_known_results_method;
static struct GNUNET_DBUS_Method    *gbl_dht_get_request_stop_method;
static struct GNUNET_DBUS_Signal    *gbl_dht_get_request_result_signal;

static void
put_return (
    void *cls,
    int success)
{
  struct GNUNET_DBUS_MethodContext *mc = 
      (struct GNUNET_DBUS_MethodContext *)cls;
  unsigned msg_serial = dbus_message_get_serial (mc->message);
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Received reply from DHT. Method call id %u\n",
         msg_serial);
  DBusMessage *reply;
  switch (success)
  {
  case GNUNET_OK:
    reply = GNUNET_DBUS_method_context_create_reply (mc);
    break;
  case GNUNET_NO:
    reply = dbus_message_new_error (
        mc->message, 
        DBUS_ERROR_FAILED, 
        "DHT service timed out.");
    break;
  case GNUNET_SYSERR:
    reply = dbus_message_new_error (
        mc->message, 
        DBUS_ERROR_FAILED, 
        "DHT DBus proxy was disconnected from DHT service.");
    break;
  default:
    reply = dbus_message_new_error_printf (
        mc->message, 
        DBUS_ERROR_FAILED, 
        "Unabled to interpret response from DHT service."
        "Service returned code %d.",
          success);
  };

  GNUNET_DBUS_method_context_send_reply (mc, reply);
  GNUNET_DBUS_method_context_unref (mc);
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Received reply from DHT. Method call id %u\n",
         msg_serial);
};

static void
put (
    struct GNUNET_DBUS_MethodContext *mc)
{
  struct GNUNET_HashCode key;
  uint32_t desired_replication_level;
  enum GNUNET_DHT_RouteOption options;
  enum GNUNET_BLOCK_Type type;
  int size;
  const void *data;
  struct GNUNET_TIME_Absolute expiry;

  unsigned msg_serial = dbus_message_get_serial (mc->message);
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Recieved put from dbus. Method call id %u\n",
       msg_serial);

  DBusMessage *message = mc->message;
  DBusMessageIter iter;
  dbus_message_iter_init (message, &iter);

  DBusMessage *reply = NULL;
  reply = reply ? reply : GNUNET_DBUS_pop_hashcode (
                              message, &iter, 
                              "key",
                              &key);
  reply = reply ? reply : GNUNET_DBUS_pop_uint32 (
                              message, &iter,
                              "desired_replication_level",
                              &desired_replication_level);
  reply = reply ? reply : GNUNET_DHT_DBUS_pop_route_option (
                              message, &iter,
                              "options",
                              &options);
  reply = reply ? reply : GNUNET_BLOCK_DBUS_pop_type (
                              message, &iter,
                              "type",
                              &type);
  reply = reply ? reply : GNUNET_DBUS_pop_byte_array (
                              message, &iter,
                              "data",
                              (const unsigned char **)&data, &size);
  reply = reply ? reply : GNUNET_TIME_DBUS_pop_absolute (
                              message, &iter,
                              "expiry",
                              &expiry);
  if (reply)
  {
    GNUNET_DBUS_method_context_send_reply (mc, reply);
    return;
  };

  GNUNET_DBUS_method_context_ref (mc);
  struct ClientData *cd = GNUNET_DBUS_client_get_data (mc->client);
  struct GNUNET_DHT_Handle *handle = cd->dht_handle;

  GNUNET_DHT_put (
      handle,
      &key, 
      desired_replication_level,
      options, 
      type, 
      size, 
      data, 
      expiry,
      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100),
      put_return,
      mc);

  LOG (
      GNUNET_ERROR_TYPE_DEBUG,
      "Forwarded put to dht. Method call id %u\n",
        msg_serial);
};

static void
get_filter_known_results (
    struct GNUNET_DBUS_MethodContext *mc)
{
  struct GNUNET_HashCode *results;
  size_t results_len;

  DBusMessage *message = mc->message;
  DBusMessageIter iter;
  DBusMessageIter iter_sub;
  dbus_message_iter_init (message, &iter);

  DBusMessage *reply = NULL;
  reply = GNUNET_DBUS_pop_enter_array (message, &iter, &iter_sub, 
                                       "results",
                                       &results_len);
  if (reply)
  {
    GNUNET_DBUS_method_context_send_reply (mc, reply);
    return ;
  };

  results = GNUNET_malloc (sizeof (struct GNUNET_HashCode) * results_len);
  size_t i;
  for (i = 0; i < results_len && ! results ; i++)
    reply = GNUNET_DBUS_pop_hashcode (message, &iter_sub,
                                      "result",
                                      results + i);
  if(reply)
  {
    GNUNET_free (results);
    GNUNET_DBUS_method_context_send_reply (mc, reply);
    return;
  };

  struct GetRequest *get_request = GNUNET_DBUS_object_get_data (mc->object);
  struct GNUNET_DHT_GetHandle *handle = get_request->handle;

  GNUNET_DHT_get_filter_known_results (handle, (unsigned)results_len, results);
  GNUNET_free (results);

  reply = GNUNET_DBUS_method_context_create_reply (mc);
  GNUNET_DBUS_method_context_send_reply (mc, reply);
}

static void
get_stop (
    struct GNUNET_DBUS_MethodContext *mc)
{
  struct GNUNET_DBUS_Object *object = mc->object;
  struct GetRequest *get_request = GNUNET_DBUS_object_get_data (object);
  struct GNUNET_DHT_GetHandle *handle = get_request->handle;

  GNUNET_DHT_get_stop (handle);

  struct GNUNET_DBUS_ObjectIterator *obj_it =
      GNUNET_DBUS_object_iterate_subobjects (gbl_dht_get_object);
  while (obj_it)
  {
    if (obj_it->object == object)
    {
      GNUNET_DBUS_object_remove_subobject (gbl_dht_get_object, obj_it);
      break;
    }
    obj_it = obj_it->next;
  };
  if (obj_it)
  {
    GNUNET_DBUS_client_unref (get_request->client);
    GNUNET_free (get_request);
  }
  else
  {
    LOG (GNUNET_ERROR_TYPE_WARNING,
         "Tried to stop request that does not exist\n");
    LOG (GNUNET_ERROR_TYPE_WARNING,
         "  name == %s\n",
           GNUNET_DBUS_object_get_name (object));
  }

  DBusMessage *reply = GNUNET_DBUS_method_context_create_reply (mc);
  GNUNET_DBUS_method_context_send_reply (mc, reply);
}

static void
get_iter_return (
    void *cls,
    struct GNUNET_TIME_Absolute expiry,
    const struct GNUNET_HashCode *key,
    const struct GNUNET_PeerIdentity *get_path,
    unsigned get_path_len,
    const struct GNUNET_PeerIdentity *put_path,
    unsigned put_path_len,
    enum GNUNET_BLOCK_Type type,
    size_t size,
    const void *data)
{
  unsigned i;
  struct GNUNET_DBUS_Object *request_object = (struct GNUNET_DBUS_Object *)cls;
  struct GetRequest *get_request = 
      (struct GetRequest *)GNUNET_DBUS_object_get_data (request_object);
  struct GNUNET_DBUS_Client *client = get_request->client;
  struct GNUNET_DBUS_ObjectPath *path = GNUNET_DBUS_object_path_create (
                                            gbl_dht_service,
                                            gbl_dht_get_object,
                                            request_object,
                                            NULL);

  DBusMessage *message = GNUNET_DBUS_signal_spawn_unicast (
      gbl_dht_get_request_result_signal,
      path,
      gbl_dht_get_request_interface,
      client,
      get_request->pretty);

  GNUNET_DBUS_object_path_unref (path);

  DBusMessageIter message_iter;
  DBusMessageIter message_iter_sub;
  dbus_message_iter_init_append (message, &message_iter);
  
  GNUNET_TIME_DBUS_push_absolute (message, &message_iter, &expiry);
  GNUNET_DBUS_push_hashcode (message, &message_iter, key);
  GNUNET_DBUS_push_open_array (message, &message_iter, &message_iter_sub, 
                               GNUNET_DBUS_SIGNATURE_PEER_IDENTITY);
  for (i = 0; i < get_path_len; i++)
  {
    GNUNET_DBUS_push_peer_identity (message, &message_iter_sub, get_path + i);
  }
  GNUNET_DBUS_push_close_array (message, &message_iter, &message_iter_sub);
  GNUNET_DBUS_push_open_array (message, &message_iter, &message_iter_sub,
                               GNUNET_DBUS_SIGNATURE_PEER_IDENTITY);
  for (i = 0; i < put_path_len; i++)
  {
    GNUNET_DBUS_push_peer_identity (message, &message_iter_sub, put_path + i);
  }
  GNUNET_DBUS_push_close_array (message, &message_iter, &message_iter_sub);
  GNUNET_BLOCK_DBUS_push_type (message, &message_iter, &type);
  GNUNET_DBUS_push_byte_array (message, &message_iter, data, size);
  
  GNUNET_DBUS_service_send (gbl_dht_service, message);
}

static void
get_start (
    struct GNUNET_DBUS_MethodContext *mc)
{
  enum GNUNET_BLOCK_Type type;
  struct GNUNET_HashCode key;
  uint32_t desired_replication_level;
  enum GNUNET_DHT_RouteOption options;

  unsigned msg_serial = dbus_message_get_serial (mc->message);
  LOG (GNUNET_ERROR_TYPE_DEBUG, "Recieved get_start from dbus. Method call id %u\n", msg_serial);

  DBusMessage *message = mc->message;
  DBusMessageIter iter;
  dbus_message_iter_init (message, &iter);

  DBusMessage *reply = NULL;
  reply = reply ? reply : GNUNET_BLOCK_DBUS_pop_type (
                              message, &iter,
                              "type",
                              &type);
  reply = reply ? reply : GNUNET_DBUS_pop_hashcode (
                              message, &iter,
                              "key",
                              &key);
  reply = reply ? reply : GNUNET_DBUS_pop_uint32 (
                              message, &iter,
                              "desired_replication_level",
                              &desired_replication_level);
  reply = reply ? reply : GNUNET_DHT_DBUS_pop_route_option (
                              message, &iter,
                              "options",
                              &options);
  if (reply)
  {
    GNUNET_DBUS_method_context_send_reply (mc, reply);
    return;
  };
  //if (GNUNET_DBUS_message_get_pretty_encoded (message))
    //GNUNET_DBUS_client_set_prefers_pretty_encodings (mc->client, true);

  GNUNET_DBUS_method_context_ref (mc);
  struct ClientData *cd = GNUNET_DBUS_client_get_data (mc->client);
  struct GNUNET_DHT_Handle *handle = cd->dht_handle;

  struct GetRequest *get_request = GNUNET_new (struct GetRequest);
  get_request->client = mc->client;
  GNUNET_DBUS_client_ref (mc->client);
  get_request->pretty = GNUNET_DBUS_message_get_pretty (message);

  struct GNUNET_DBUS_Object *request_object = 
      GNUNET_DBUS_object_create_uniquely_named_subobject (gbl_dht_get_object,
                                                          get_request);
  GNUNET_DBUS_object_add_interface (request_object,
                                    GNUNET_DBUS_interface_introspectable ());
  GNUNET_DBUS_object_add_interface (request_object,
                                    gbl_dht_get_request_interface);

  struct GNUNET_DBUS_ObjectPath *path = 
      GNUNET_DBUS_object_path_create (gbl_dht_service,
                                      gbl_dht_get_object,
                                      request_object,
                                      NULL);

  reply = GNUNET_DBUS_method_context_create_reply (mc);
  DBusMessageIter reply_iter;
  dbus_message_iter_init_append (reply, &reply_iter);
  GNUNET_DBUS_push_object_path (reply, &reply_iter, path);
  GNUNET_DBUS_method_context_send_reply (mc, reply);

  struct GNUNET_DBUS_ObjectIterator *obj_it = 
      GNUNET_new (struct GNUNET_DBUS_ObjectIterator);
  obj_it->object = request_object;
  GNUNET_CONTAINER_DLL_insert (cd->gets_front,
                               cd->gets_back,
                               obj_it);

  get_request->handle = GNUNET_DHT_get_start (
      handle,
      type,
      &key,
      desired_replication_level,
      options,
      NULL,
      0,
      get_iter_return,
      request_object);
};

static void
client_connects (
    struct GNUNET_DBUS_Service *service,
    struct GNUNET_DBUS_Client *client)
{
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Creating dht client for %s\n",
         GNUNET_DBUS_client_get_unique_name (client));
  const struct GNUNET_CONFIGURATION_Handle *cfg =
      GNUNET_DBUS_service_get_config (service);
  struct ClientData *cd = GNUNET_new (struct ClientData);
  cd->dht_handle = GNUNET_DHT_connect (cfg, 32);
  cd->gets_front = NULL;
  cd->gets_back = NULL;
  GNUNET_DBUS_client_set_data (client, cd);
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Finished creating DHT client for %s\n",
         GNUNET_DBUS_client_get_unique_name (client));
};

static void
client_disconnects (
    struct GNUNET_DBUS_Service *service,
    struct GNUNET_DBUS_Client *client)
{
  struct ClientData *cd = GNUNET_DBUS_client_get_data (client);
  struct GNUNET_DBUS_ObjectIterator *obj_it = cd->gets_front;
  while (obj_it)
  {
    struct GNUNET_DBUS_ObjectIterator *next = obj_it->next;
    struct GNUNET_DBUS_Object *object = obj_it->object;
    struct GetRequest *request = GNUNET_DBUS_object_get_data (object);

    GNUNET_DHT_get_stop (request->handle);
    GNUNET_free (request);
    GNUNET_DBUS_object_remove_subobject (gbl_dht_get_object, obj_it);
    GNUNET_free (obj_it);
    obj_it = next;
  };
  GNUNET_DHT_disconnect (cd->dht_handle);
  GNUNET_free (cd);
};

static void
shutdown_task (
    void *cls,
    const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  (void)cls;
  (void)tc;

  GNUNET_DBUS_service_unref (gbl_dht_service);

  LOG (GNUNET_ERROR_TYPE_INFO, "Exiting.\n");
};

static void
run (
    void *cls,
    char *const *args,
    const char *configfile,
    const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  LOG (GNUNET_ERROR_TYPE_DEBUG, "Running.\n");

  gbl_dht_service = GNUNET_DBUS_service_create (cfg, "dht");
  if (! gbl_dht_service)
  {
    LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to create dht service.\n");
    GNUNET_abort_ ();
  };
  GNUNET_DBUS_service_set_client_handlers (gbl_dht_service, 
                                           client_connects,
                                           client_disconnects);

  struct GNUNET_DBUS_Object *root_object = 
      GNUNET_DBUS_service_get_root_object (gbl_dht_service);

  gbl_dht_interface = GNUNET_DBUS_interface_create ("gnu.gnunet.dht");
  GNUNET_DBUS_object_add_interface (root_object,
                                    GNUNET_DBUS_interface_introspectable ());
  GNUNET_DBUS_object_add_interface (root_object,
                                    gbl_dht_interface);

  gbl_dht_put_method = GNUNET_DBUS_method_create ("put", put);
  GNUNET_DBUS_interface_add_method (gbl_dht_interface, gbl_dht_put_method);
  GNUNET_DBUS_method_add_arg (gbl_dht_put_method,
                              "key",
                              GNUNET_DBUS_SIGNATURE_HASHCODE);
  GNUNET_DBUS_method_add_arg (gbl_dht_put_method,
                              "desired_replication_level",
                              GNUNET_DBUS_SIGNATURE_UINT32);
  GNUNET_DBUS_method_add_arg (gbl_dht_put_method,
                              "options",
                              GNUNET_DHT_DBUS_SIGNATURE_ROUTE_OPTION);
  GNUNET_DBUS_method_add_arg (gbl_dht_put_method,
                              "type",
                              GNUNET_BLOCK_DBUS_SIGNATURE_TYPE);
  GNUNET_DBUS_method_add_arg (gbl_dht_put_method,
                              "data",
                              GNUNET_DBUS_SIGNATURE_ARRAY (
                                  GNUNET_DBUS_SIGNATURE_BYTE));
  GNUNET_DBUS_method_add_arg (gbl_dht_put_method,
                              "expiry",
                              GNUNET_TIME_DBUS_SIGNATURE_ABSOLUTE);

  gbl_dht_get_start_method = GNUNET_DBUS_method_create ("get_start",
                                                        get_start);
  GNUNET_DBUS_interface_add_method (gbl_dht_interface,
                                    gbl_dht_get_start_method);
  GNUNET_DBUS_method_add_arg (gbl_dht_get_start_method,
                              "type",
                              GNUNET_BLOCK_DBUS_SIGNATURE_TYPE);
  GNUNET_DBUS_method_add_arg (gbl_dht_get_start_method,
                              "key",
                              GNUNET_DBUS_SIGNATURE_HASHCODE);
  GNUNET_DBUS_method_add_arg (gbl_dht_get_start_method,
                              "desired_replication_level",
                              GNUNET_DBUS_SIGNATURE_UINT32);
  GNUNET_DBUS_method_add_arg (gbl_dht_get_start_method,
                              "options",
                              GNUNET_DHT_DBUS_SIGNATURE_ROUTE_OPTION);
  GNUNET_DBUS_method_add_return_arg (gbl_dht_get_start_method,
                                     "request_object",
                                     GNUNET_DBUS_SIGNATURE_OBJECT_PATH);

  gbl_dht_get_object = GNUNET_DBUS_object_create ("get", NULL);
  GNUNET_DBUS_object_add_subobject (root_object, gbl_dht_get_object);
  GNUNET_DBUS_object_add_interface (gbl_dht_get_object,
                                    GNUNET_DBUS_interface_introspectable ());

  gbl_dht_get_request_interface =
      GNUNET_DBUS_interface_create ("gnu.gnunet.dht.get");

  gbl_dht_get_request_filter_known_results_method =
      GNUNET_DBUS_method_create ("filter_known_results",
                                 get_filter_known_results);
  GNUNET_DBUS_interface_add_method (
      gbl_dht_get_request_interface,
      gbl_dht_get_request_filter_known_results_method);
  GNUNET_DBUS_method_add_arg (gbl_dht_get_request_filter_known_results_method,
                              "results",
                              GNUNET_DBUS_SIGNATURE_ARRAY (
                                  GNUNET_DBUS_SIGNATURE_HASHCODE));

  gbl_dht_get_request_stop_method = GNUNET_DBUS_method_create ("stop",
                                                               get_stop);
  GNUNET_DBUS_interface_add_method (gbl_dht_get_request_interface,
                                    gbl_dht_get_request_stop_method);

  gbl_dht_get_request_result_signal = GNUNET_DBUS_signal_create ("result");
  GNUNET_DBUS_interface_add_signal (gbl_dht_get_request_interface, 
                                    gbl_dht_get_request_result_signal);
  GNUNET_DBUS_signal_add_arg (gbl_dht_get_request_result_signal,
                              "expiry",
                              GNUNET_TIME_DBUS_SIGNATURE_ABSOLUTE);
  GNUNET_DBUS_signal_add_arg (gbl_dht_get_request_result_signal,
                              "key",
                              GNUNET_DBUS_SIGNATURE_HASHCODE);
  GNUNET_DBUS_signal_add_arg (gbl_dht_get_request_result_signal,
                              "get_path",
                              GNUNET_DBUS_SIGNATURE_ARRAY (
                                  GNUNET_DBUS_SIGNATURE_PEER_IDENTITY));
  GNUNET_DBUS_signal_add_arg (gbl_dht_get_request_result_signal,
                              "put_path",
                              GNUNET_DBUS_SIGNATURE_ARRAY (
                                  GNUNET_DBUS_SIGNATURE_PEER_IDENTITY));
  GNUNET_DBUS_signal_add_arg (gbl_dht_get_request_result_signal,
                              "type",
                              GNUNET_BLOCK_DBUS_SIGNATURE_TYPE);
  GNUNET_DBUS_signal_add_arg (gbl_dht_get_request_result_signal,
                              "data",
                              GNUNET_DBUS_SIGNATURE_ARRAY (
                                  GNUNET_DBUS_SIGNATURE_BYTE));

  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                shutdown_task, NULL);
};

int
main (
    int argc,
    char *const *argv)
{
  int ret;

  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
    GNUNET_GETOPT_OPTION_END
  };
  static const char bin_name[] = "gnunet-service-dht-dbus [OPTIONS]";
  static const char bin_help[] = gettext_noop ("DBus proxy for gnunet-service-dht");

  ret = GNUNET_log_setup ("gnunet-service-dht-dbus", "DEBUG", NULL);
  if (GNUNET_OK != ret)
  {
    fprintf (stderr, "ERROR: Failed to setup logging. GNUNET_log_setup returned %d\n", ret);
    return 1;
  }

  ret = GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv);
  if (GNUNET_OK != ret)
  {
    LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to parse command line options. GNUNET_STRINGS_get_utf8_args returned %d\n", ret);
    return 1;
  };

  ret = GNUNET_PROGRAM_run (argc, argv, bin_name, bin_help, options, run, NULL);
  if (GNUNET_OK != ret)
  {
    LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to run program. GNUNET_PROGRAM_run returned %d\n", ret);
    return 1;
  };

  GNUNET_free ((void *)argv);
  return 0;
};