GNUnet  0.11.x
plugin_rest_peerinfo.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012-2015 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
27 #include "platform.h"
28 #include "gnunet_rest_plugin.h"
31 #include "gnunet_rest_lib.h"
32 #include "gnunet_json_lib.h"
33 #include "microhttpd.h"
34 #include <jansson.h>
35 
39 #define GNUNET_REST_API_NS_PEERINFO "/peerinfo"
40 
44 #define GNUNET_REST_PEERINFO_PEER "peer"
45 
49 #define GNUNET_REST_PEERINFO_FRIEND "friend"
50 
54 #define GNUNET_REST_PEERINFO_ARRAY "array"
55 
59 #define GNUNET_REST_PEERINFO_ERROR_UNKNOWN "Unknown Error"
60 
64 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
65 
69 
73 static char *allow_methods;
74 
79 
83 struct Plugin
84 {
85  const struct GNUNET_CONFIGURATION_Handle *cfg;
86 };
87 
88 
92 struct AddressRecord
93 {
98 
102  struct GNUNET_TIME_Absolute expiration;
103 
107  char *result;
108 
112  struct PrintContext *pc;
113 };
114 
115 
119 struct PrintContext
120 {
124  struct PrintContext *next;
125 
129  struct PrintContext *prev;
130 
134  struct GNUNET_PeerIdentity peer;
135 
139  struct AddressRecord *address_list;
140 
144  unsigned int num_addresses;
145 
149  unsigned int address_list_size;
150 
154  unsigned int off;
155 
159  int friend_only;
160 
165 };
166 
170 static struct PrintContext *pc_head;
171 
175 static struct PrintContext *pc_tail;
176 
180 struct RequestHandle
181 {
185  struct RequestHandle *next;
186 
190  struct RequestHandle *prev;
191 
195  json_t *temp_array;
196 
201 
205  const char *address;
206 
210  char *pubkey;
211 
215  json_t *response;
216 
221 
222 
226  struct GNUNET_REST_RequestHandle *rest_handle;
227 
232 
237 
242 
246  void *proc_cls;
247 
251  char *url;
252 
256  char *emsg;
257 
261  int response_code;
262 };
263 
268 
273 
278 static void
279 cleanup_handle (void *cls)
280 {
281  struct RequestHandle *handle = cls;
282 
284  "Cleaning up\n");
285  if (NULL != handle->timeout_task)
286  {
288  handle->timeout_task = NULL;
289  }
290  if (NULL != handle->url)
291  GNUNET_free (handle->url);
292  if (NULL != handle->emsg)
293  GNUNET_free (handle->emsg);
294  if (NULL != handle->address)
295  GNUNET_free_nz ((char *) handle->address);
296  if (NULL != handle->expiration_str)
297  GNUNET_free (handle->expiration_str);
298  if (NULL != handle->pubkey)
299  GNUNET_free (handle->pubkey);
300 
301  if (NULL != handle->temp_array)
302  {
303  json_decref (handle->temp_array);
304  handle->temp_array = NULL;
305  }
306  if (NULL != handle->response)
307  {
308  json_decref (handle->response);
309  handle->response = NULL;
310  }
311 
312  if (NULL != handle->list_it)
313  {
315  handle->list_it = NULL;
316  }
317  if (NULL != peerinfo_handle)
318  {
319  GNUNET_PEERINFO_disconnect (peerinfo_handle);
320  peerinfo_handle = NULL;
321  }
322  GNUNET_CONTAINER_DLL_remove (requests_head,
323  requests_tail,
324  handle);
325  GNUNET_free (handle);
326 }
327 
328 
334 static void
335 do_error (void *cls)
336 {
337  struct RequestHandle *handle = cls;
338  struct MHD_Response *resp;
339  json_t *json_error = json_object ();
340  char *response;
341 
342  if (NULL == handle->emsg)
344 
345  json_object_set_new (json_error, "error", json_string (handle->emsg));
346 
347  if (0 == handle->response_code)
348  handle->response_code = MHD_HTTP_OK;
349  response = json_dumps (json_error, 0);
350  resp = GNUNET_REST_create_response (response);
351  MHD_add_response_header (resp, "Content-Type", "application/json");
352  handle->proc (handle->proc_cls, resp, handle->response_code);
353  json_decref (json_error);
354  GNUNET_free (response);
356 }
357 
358 
364 static void
366 {
367  struct RequestHandle *handle = cls;
368  char *result_str;
369  struct MHD_Response *resp;
370 
371  if (NULL == handle->response)
372  {
373  handle->response_code = MHD_HTTP_NOT_FOUND;
374  handle->emsg = GNUNET_strdup ("No peers found");
376  return;
377  }
378 
379  result_str = json_dumps (handle->response, 0);
380  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
381  resp = GNUNET_REST_create_response (result_str);
382  GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
383  "Content-Type",
384  "application/json"));
385  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
386  GNUNET_free (result_str);
388 }
389 
390 
399 static int
400 count_address (void *cls,
401  const struct GNUNET_HELLO_Address *address,
403 {
404  struct PrintContext *pc = cls;
405 
406  if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
407  {
408  return GNUNET_OK; /* ignore expired address */
409  }
410 
411  pc->off++;
412  return GNUNET_OK;
413 }
414 
415 
421 static void
423 {
424  struct RequestHandle *handle;
425  unsigned int i;
426  json_t *response_entry;
427  json_t *temp_array;
428  json_t *object;
429  json_t *address;
430  json_t *expires;
431  json_t *friend_and_peer_json;
432  char *friend_and_peer;
433 
434  temp_array = json_array ();
435  response_entry = json_object ();
436 
437  for (i = 0; i < pc->num_addresses; i++)
438  {
439  if (NULL != pc->address_list[i].result)
440  {
441  object = json_object ();
442  address = json_string (pc->address_list[i].result);
443  expires = json_string (
445  pc->address_list[i].expiration));
446  json_object_set (object, "address", address);
447  json_object_set (object, "expires", expires);
448 
449  json_decref (address);
450  json_decref (expires);
451 
452  json_array_append (temp_array, object);
453  json_decref (object);
455  }
456  }
457 
458  if (0 < json_array_size (temp_array))
459  {
460  GNUNET_asprintf (&friend_and_peer,
461  "%s%s",
462  (GNUNET_YES == pc->friend_only) ? "F2F:" : "",
463  GNUNET_i2s_full (&pc->peer));
464  friend_and_peer_json = json_string (friend_and_peer);
465  json_object_set (response_entry,
467  friend_and_peer_json);
468  json_object_set (response_entry,
470  temp_array);
471  json_array_append (pc->handle->response, response_entry);
472  json_decref (friend_and_peer_json);
473  GNUNET_free (friend_and_peer);
474  }
475 
476  json_decref (temp_array);
477  json_decref (response_entry);
478 
481  pc_tail,
482  pc);
483  handle = pc->handle;
484  GNUNET_free (pc);
485 
486  if ((NULL == pc_head) &&
487  (NULL == handle->list_it))
488  {
490  }
491 }
492 
493 
504 static void
506  const char *address,
507  int res)
508 {
509  struct AddressRecord *ar = cls;
510  struct PrintContext *pc = ar->pc;
511 
512  if (NULL != address)
513  {
514  if (0 != strlen (address))
515  {
516  if (NULL != ar->result)
517  GNUNET_free (ar->result);
518  ar->result = GNUNET_strdup (address);
519  }
520  return;
521  }
522  ar->atsc = NULL;
523  if (GNUNET_SYSERR == res)
525  _ ("Failure: Cannot convert address to string for peer `%s'\n"),
526  GNUNET_i2s (&ar->pc->peer));
527  pc->num_addresses++;
528  if (pc->num_addresses == pc->address_list_size)
529  dump_pc (ar->pc);
530 }
531 
532 
541 static int
542 print_address (void *cls,
543  const struct GNUNET_HELLO_Address *address,
545 {
546  struct PrintContext *pc = cls;
547  struct AddressRecord *ar;
548 
549  if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
550  {
551  return GNUNET_OK; /* ignore expired address */
552  }
553 
554  GNUNET_assert (0 < pc->off);
555  ar = &pc->address_list[--pc->off];
556  ar->pc = pc;
557  ar->expiration = expiration;
558  GNUNET_asprintf (&ar->result,
559  "%s:%lu:%u",
560  address->transport_name,
561  (unsigned long) address->address_length,
562  address->local_info);
564  address,
565  GNUNET_NO,
566  TIMEOUT,
568  ar);
569  return GNUNET_OK;
570 }
571 
572 
582 void
584  const struct GNUNET_PeerIdentity *peer,
585  const struct GNUNET_HELLO_Message *hello,
586  const char *err_msg)
587 {
588  struct RequestHandle *handle = cls;
589  struct PrintContext *pc;
590  int friend_only;
591 
592  if (NULL == handle->response)
593  {
594  handle->response = json_array ();
595  }
596 
597  if (NULL == peer)
598  {
599  handle->list_it = NULL;
600  handle->emsg = GNUNET_strdup ("Error in communication with peerinfo");
601  if (NULL != err_msg)
602  {
603  GNUNET_free (handle->emsg);
604  handle->emsg = GNUNET_strdup (err_msg);
605  handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
606  }
607  if (NULL == pc_head)
609  return;
610  }
611  if (NULL == hello)
612  return;
613 
614  friend_only = GNUNET_NO;
615  if (NULL != hello)
616  friend_only = GNUNET_HELLO_is_friend_only (hello);
617 
618  pc = GNUNET_new (struct PrintContext);
620  pc_tail,
621  pc);
622  pc->peer = *peer;
623  pc->friend_only = friend_only;
624  pc->handle = handle;
626  GNUNET_NO,
627  &count_address,
628  pc);
629  if (0 == pc->off)
630  {
631  dump_pc (pc);
632  return;
633  }
634  pc->address_list_size = pc->off;
636  sizeof(struct AddressRecord) * pc->off);
638  GNUNET_NO,
639  &print_address,
640  pc);
641 }
642 
643 
651 void
653  const char*url,
654  void *cls)
655 {
656  struct RequestHandle *handle = cls;
657  struct GNUNET_HashCode key;
658  const struct GNUNET_PeerIdentity *specific_peer;
659  // GNUNET_PEER_Id peer_id;
661  char*include_friend_only_str;
662 
663  include_friend_only = GNUNET_NO;
666  &key);
667  if (GNUNET_YES
669  &key))
670  {
671  include_friend_only_str = GNUNET_CONTAINER_multihashmap_get (
672  con_handle->url_param_map, &key);
673  if (0 == strcmp (include_friend_only_str, "yes"))
674  {
675  include_friend_only = GNUNET_YES;
676  }
677  }
678 
679  specific_peer = NULL;
681  strlen (GNUNET_REST_PEERINFO_PEER),
682  &key);
683  if (GNUNET_YES
685  &key))
686  {
687  // peer_id = *(unsigned int*)GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map, &key);
688  // specific_peer = GNUNET_PEER_resolve2(peer_id);
689  }
690 
691  handle->list_it = GNUNET_PEERINFO_iterate (peerinfo_handle,
692  include_friend_only,
693  specific_peer,
695  handle);
696 }
697 
698 
706 static void
708  const char*url,
709  void *cls)
710 {
711  struct MHD_Response *resp;
712  struct RequestHandle *handle = cls;
713 
714  // independent of path return all options
715  resp = GNUNET_REST_create_response (NULL);
716  MHD_add_response_header (resp,
717  "Access-Control-Allow-Methods",
718  allow_methods);
719  handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
721  return;
722 }
723 
724 
736 static enum GNUNET_GenericReturnValue
739  void *proc_cls)
740 {
741  struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
743  static const struct GNUNET_REST_RequestHandler handlers[] = {
744  { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_PEERINFO, &peerinfo_get },
745  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_PEERINFO, &options_cont },
747  };
748 
749  handle->response_code = 0;
751  60);
752  handle->proc_cls = proc_cls;
753  handle->proc = proc;
754  handle->rest_handle = rest_handle;
755 
756  handle->url = GNUNET_strdup (rest_handle->url);
757  if (handle->url[strlen (handle->url) - 1] == '/')
758  handle->url[strlen (handle->url) - 1] = '\0';
759  handle->timeout_task =
761  &do_error,
762  handle);
763  GNUNET_CONTAINER_DLL_insert (requests_head,
764  requests_tail,
765  handle);
766  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
768  handlers,
769  &err,
770  handle))
771  {
772  cleanup_handle (handle);
773  return GNUNET_NO;
774  }
775  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
776  return GNUNET_YES;
777 }
778 
779 
786 void *
788 {
789  static struct Plugin plugin;
790  struct GNUNET_REST_Plugin *api;
791 
792  cfg = cls;
793  if (NULL != plugin.cfg)
794  return NULL; /* can only initialize once! */
795  memset (&plugin, 0, sizeof(struct Plugin));
796  plugin.cfg = cfg;
797  api = GNUNET_new (struct GNUNET_REST_Plugin);
798  api->cls = &plugin;
802  "%s, %s, %s, %s, %s",
803  MHD_HTTP_METHOD_GET,
804  MHD_HTTP_METHOD_POST,
805  MHD_HTTP_METHOD_PUT,
806  MHD_HTTP_METHOD_DELETE,
807  MHD_HTTP_METHOD_OPTIONS);
808  peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
809 
811  _ ("Peerinfo REST API initialized\n"));
812  return api;
813 }
814 
815 
822 void *
824 {
825  struct GNUNET_REST_Plugin *api = cls;
826  struct Plugin *plugin = api->cls;
827 
828  plugin->cfg = NULL;
829  while (NULL != requests_head)
830  cleanup_handle (requests_head);
831  if (NULL != peerinfo_handle)
832  GNUNET_PEERINFO_disconnect (peerinfo_handle);
833 
835  GNUNET_free (api);
837  "Peerinfo REST plugin is finished\n");
838  return NULL;
839 }
840 
841 
842 /* end of plugin_rest_peerinfo.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
size_t address_length
Number of bytes in address.
enum GNUNET_HELLO_AddressInfo local_info
Extended information about address.
void(* GNUNET_REST_ResultProcessor)(void *cls, struct MHD_Response *resp, int status)
Iterator called on obtained result for a REST result.
void peerinfo_list_iteration(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
Callback that processes each of the known HELLOs for the iteration response construction.
struct GNUNET_PeerIdentity peer
Identity of the peer.
Handle to the peerinfo service.
Definition: peerinfo_api.c:84
A HELLO message is used to exchange information about transports with other peers.
struct GNUNET_PEERINFO_IteratorContext * list_it
Handle to PEERINFO it.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static char * allow_methods
HTTP methods allows for this plugin.
functions to parse JSON objects into GNUnet objects
struct GNUNET_PEERINFO_Handle * GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the peerinfo service.
Definition: peerinfo_api.c:130
void * cls
The closure of the plugin.
struct PrintContext * pc
Print context this address record belongs to.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
Structure we use to collect printable address information.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_SECONDS
One second.
void peerinfo_get(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle peerinfo GET request.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct returned by the initialization function of the plugin
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:83
static int include_friend_only
Option &#39;-f&#39;.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void * libgnunet_plugin_rest_peerinfo_init(void *cls)
Entry point for the plugin.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
static struct GNUNET_PEERINFO_Handle * peerinfo_handle
Handle to PEERINFO.
struct PrintContext * next
Kept in DLL.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
void * proc_cls
The closure of the result processor.
Context for an iteration request.
Definition: peerinfo_api.c:37
#define GNUNET_REST_HANDLER_END
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
The request handle.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
struct GNUNET_PEERINFO_IteratorContext * GNUNET_PEERINFO_iterate(struct GNUNET_PEERINFO_Handle *h, int include_friend_only, const struct GNUNET_PeerIdentity *peer, GNUNET_PEERINFO_Processor callback, void *callback_cls)
Call a method for each known matching host.
Definition: peerinfo_api.c:487
#define GNUNET_REST_API_NS_PEERINFO
Peerinfo Namespace.
unsigned int num_addresses
Number of completed addresses in address_list.
struct GNUNET_NAMESTORE_ZoneIterator * list_it
Handle to NAMESTORE it.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
void GNUNET_PEERINFO_iterate_cancel(struct GNUNET_PEERINFO_IteratorContext *ic)
Cancel an iteration over peer information.
Definition: peerinfo_api.c:520
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
Record we keep for each printable address.
static int print_address(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Iterator callback to go over all addresses.
char * emsg
Error response message.
#define GNUNET_REST_PEERINFO_ERROR_UNKNOWN
Error message Unknown Error.
struct GNUNET_CONTAINER_MultiHashMap * url_param_map
Map of url parameters.
static void peerinfo_list_finished(void *cls)
Function that assembles the response.
struct GNUNET_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
Definition: hello.c:254
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
const char * url
The url as string.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
char * name
Plugin name.
struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
const char * transport_name
Name of the transport plugin enabling the communication using this address.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static int result
Global testing status.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:311
static struct RequestHandle * requests_head
DLL.
int GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn, const struct GNUNET_REST_RequestHandler *handlers, struct GNUNET_REST_RequestHandlerError *err, void *cls)
Definition: rest.c:77
struct GNUNET_REST_RequestHandle * rest_handle
Rest connection.
A 512-bit hashcode.
int response_code
Response code.
static char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
struct PrintContext * prev
Kept in DLL.
static int res
static char * plugin
Solver plugin name as string.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
struct RequestHandle * next
DLL.
struct GNUNET_TIME_Absolute expiration
Address expiration time.
#define GNUNET_REST_PEERINFO_ARRAY
Peerinfo parameter array.
#define GNUNET_free_nz(ptr)
Wrapper around free.
static void process_resolved_address(void *cls, const char *address, int res)
Function to call with a human-readable format of an address.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
json_t * response
JSON response.
struct GNUNET_TRANSPORT_AddressToStringContext * GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HELLO_Address *address, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressToStringCallback aluc, void *aluc_cls)
Convert a binary address into a human readable address.
int GNUNET_HELLO_is_friend_only(const struct GNUNET_HELLO_Message *h)
Return HELLO type.
Definition: hello.c:89
struct RequestHandle * prev
DLL.
static struct GNUNET_SCHEDULER_Task * timeout_task
Task to be run on timeout.
Definition: gnunet-arm.c:124
static enum GNUNET_GenericReturnValue rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
struct GNUNET_TRANSPORT_AddressToStringContext * atsc
Current address-to-string context (if active, otherwise NULL).
static void cleanup_handle(void *cls)
Cleanup lookup handle.
#define GNUNET_REST_PEERINFO_PEER
Peerinfo parameter peer.
char * result
Printable address.
static struct RequestHandle * requests_tail
DLL.
The identity of the host (wraps the signing key of the peer).
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
static struct PrintContext * pc_head
Head of list of print contexts.
void * libgnunet_plugin_rest_peerinfo_done(void *cls)
Exit point from the plugin.
unsigned int off
Current offset in address_list (counted down).
configuration data
Definition: configuration.c:84
Handle for a plugin.
Definition: block.c:37
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:57
char * expiration_str
Expiration time string.
An address for communicating with a peer.
json_t * temp_array
JSON temporary array.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
#define TIMEOUT
How long until we time out during address lookup?
void GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h)
Disconnect from the peerinfo service.
Definition: peerinfo_api.c:156
static struct MHD_Response * response
Our canonical response.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:232
Time for absolute times used by GNUnet, in microseconds.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
int friend_only
Hello was friend only, GNUNET_YES or GNUNET_NO.
struct AddressRecord * address_list
List of printable addresses.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:758
static int count_address(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Iterator callback to go over all addresses and count them.
static void dump_pc(struct PrintContext *pc)
Print the collected address information to the console and free pc.
unsigned int address_list_size
Number of addresses allocated in address_list.
const char * address
Address string.
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration handle.
static char * address
GNS address for this phone.
struct RequestHandle * handle
RequestHandle.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_REST_PEERINFO_FRIEND
Peerinfo parameter friend.
char * pubkey
Iteration peer public key.
static struct PrintContext * pc_tail
Tail of list of print contexts.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
static void do_error(void *cls)
Task run on errors.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
char * url
The url.