#include "platform.h"
#include "gnunet_rest_plugin.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet_transport_service.h"
#include "gnunet_rest_lib.h"
#include "gnunet_json_lib.h"
#include "microhttpd.h"
#include <jansson.h>
Go to the source code of this file.
Data Structures | |
struct | Plugin |
Handle for a plugin. More... | |
struct | AddressRecord |
Record we keep for each printable address. More... | |
struct | PrintContext |
Structure we use to collect printable address information. More... | |
struct | RequestHandle |
The request handle. More... | |
Macros | |
#define | GNUNET_REST_API_NS_PEERINFO "/peerinfo" |
Peerinfo Namespace. More... | |
#define | GNUNET_REST_PEERINFO_PEER "peer" |
Peerinfo parameter peer. More... | |
#define | GNUNET_REST_PEERINFO_FRIEND "friend" |
Peerinfo parameter friend. More... | |
#define | GNUNET_REST_PEERINFO_ARRAY "array" |
Peerinfo parameter array. More... | |
#define | GNUNET_REST_PEERINFO_ERROR_UNKNOWN "Unknown Error" |
Error message Unknown Error. More... | |
#define | TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
How long until we time out during address lookup? More... | |
Functions | |
static void | cleanup_handle (void *cls) |
Cleanup lookup handle. More... | |
static void | do_error (void *cls) |
Task run on errors. More... | |
static void | peerinfo_list_finished (void *cls) |
Function that assembles the response. More... | |
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. More... | |
static void | dump_pc (struct PrintContext *pc) |
Print the collected address information to the console and free pc. More... | |
static void | process_resolved_address (void *cls, const char *address, int res) |
Function to call with a human-readable format of an address. More... | |
static int | print_address (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration) |
Iterator callback to go over all addresses. More... | |
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. More... | |
void | peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Handle peerinfo GET request. More... | |
static void | options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls) |
Respond to OPTIONS request. More... | |
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. More... | |
void * | libgnunet_plugin_rest_peerinfo_init (void *cls) |
Entry point for the plugin. More... | |
void * | libgnunet_plugin_rest_peerinfo_done (void *cls) |
Exit point from the plugin. More... | |
Variables | |
const struct GNUNET_CONFIGURATION_Handle * | cfg |
The configuration handle. More... | |
static char * | allow_methods |
HTTP methods allows for this plugin. More... | |
static struct GNUNET_PEERINFO_Handle * | peerinfo_handle |
Handle to PEERINFO. More... | |
static struct PrintContext * | pc_head |
Head of list of print contexts. More... | |
static struct PrintContext * | pc_tail |
Tail of list of print contexts. More... | |
static struct RequestHandle * | requests_head |
DLL. More... | |
static struct RequestHandle * | requests_tail |
DLL. More... | |
#define GNUNET_REST_API_NS_PEERINFO "/peerinfo" |
Peerinfo Namespace.
Definition at line 39 of file plugin_rest_peerinfo.c.
#define GNUNET_REST_PEERINFO_PEER "peer" |
Peerinfo parameter peer.
Definition at line 44 of file plugin_rest_peerinfo.c.
#define GNUNET_REST_PEERINFO_FRIEND "friend" |
Peerinfo parameter friend.
Definition at line 49 of file plugin_rest_peerinfo.c.
#define GNUNET_REST_PEERINFO_ARRAY "array" |
Peerinfo parameter array.
Definition at line 54 of file plugin_rest_peerinfo.c.
#define GNUNET_REST_PEERINFO_ERROR_UNKNOWN "Unknown Error" |
Error message Unknown Error.
Definition at line 59 of file plugin_rest_peerinfo.c.
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
How long until we time out during address lookup?
Definition at line 64 of file plugin_rest_peerinfo.c.
|
static |
Cleanup lookup handle.
handle | Handle to clean up |
Definition at line 279 of file plugin_rest_peerinfo.c.
References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_nz, GNUNET_log, GNUNET_PEERINFO_disconnect(), GNUNET_PEERINFO_iterate_cancel(), GNUNET_SCHEDULER_cancel(), handle, peerinfo_handle, requests_head, and requests_tail.
Referenced by do_error(), libgnunet_plugin_rest_peerinfo_done(), options_cont(), and peerinfo_list_finished().
|
static |
Task run on errors.
Reports an error and cleans up everything.
cls | the struct RequestHandle |
Definition at line 335 of file plugin_rest_peerinfo.c.
References cleanup_handle(), GNUNET_free, GNUNET_REST_create_response(), GNUNET_REST_PEERINFO_ERROR_UNKNOWN, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, MHD_HTTP_OK, and response.
Referenced by peerinfo_list_finished(), and peerinfo_list_iteration().
|
static |
Function that assembles the response.
cls | the struct RequestHandle |
Definition at line 365 of file plugin_rest_peerinfo.c.
References cleanup_handle(), do_error(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, MHD_HTTP_NOT_FOUND, and MHD_HTTP_OK.
Referenced by dump_pc().
|
static |
Iterator callback to go over all addresses and count them.
cls | struct PrintContext * with off to increment |
address | the address |
expiration | expiration time |
Definition at line 400 of file plugin_rest_peerinfo.c.
References expiration, GNUNET_OK, GNUNET_TIME_absolute_get_remaining(), and pc.
Referenced by peerinfo_list_iteration().
|
static |
Print the collected address information to the console and free pc.
pc | printing context |
Definition at line 422 of file plugin_rest_peerinfo.c.
References address, GNUNET_asprintf(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_i2s_full(), GNUNET_REST_PEERINFO_ARRAY, GNUNET_REST_PEERINFO_PEER, GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_YES, handle, pc, pc_head, pc_tail, peerinfo_list_finished(), and RequestHandle::temp_array.
Referenced by peerinfo_list_iteration(), and process_resolved_address().
|
static |
Function to call with a human-readable format of an address.
cls | closure |
address | NULL on error, otherwise 0-terminated printable UTF-8 string |
res | result of the address to string conversion: if GNUNET_OK: address was valid (conversion to string might still have failed) if GNUNET_SYSERR: address is invalid |
Definition at line 505 of file plugin_rest_peerinfo.c.
References _, address, AddressRecord::atsc, dump_pc(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_strdup, GNUNET_SYSERR, pc, AddressRecord::pc, PrintContext::peer, res, and AddressRecord::result.
Referenced by print_address().
|
static |
Iterator callback to go over all addresses.
cls | closure |
address | the address |
expiration | expiration time |
Definition at line 542 of file plugin_rest_peerinfo.c.
References address, AddressRecord::atsc, cfg, expiration, AddressRecord::expiration, GNUNET_asprintf(), GNUNET_assert, GNUNET_NO, GNUNET_OK, GNUNET_TIME_absolute_get_remaining(), GNUNET_TRANSPORT_address_to_string(), pc, AddressRecord::pc, process_resolved_address(), AddressRecord::result, and TIMEOUT.
Referenced by peerinfo_list_iteration().
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.
cls | closure, NULL |
peer | id of the peer, NULL for last call |
hello | hello message for the peer (can be NULL) |
err_msg | message |
Definition at line 583 of file plugin_rest_peerinfo.c.
References count_address(), do_error(), dump_pc(), PrintContext::friend_only, GNUNET_CONTAINER_DLL_insert, GNUNET_free, GNUNET_HELLO_is_friend_only(), GNUNET_HELLO_iterate_addresses(), GNUNET_malloc, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_strdup, handle, MHD_HTTP_INTERNAL_SERVER_ERROR, pc, pc_head, pc_tail, peer, and print_address().
Referenced by peerinfo_get().
void peerinfo_get | ( | struct GNUNET_REST_RequestHandle * | con_handle, |
const char * | url, | ||
void * | cls | ||
) |
Handle peerinfo GET request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 652 of file plugin_rest_peerinfo.c.
References GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_hash(), GNUNET_NO, GNUNET_PEERINFO_iterate(), GNUNET_REST_PEERINFO_FRIEND, GNUNET_REST_PEERINFO_PEER, GNUNET_YES, handle, include_friend_only, key, peerinfo_handle, peerinfo_list_iteration(), and GNUNET_REST_RequestHandle::url_param_map.
|
static |
Respond to OPTIONS request.
con_handle | the connection handle |
url | the url |
cls | the RequestHandle |
Definition at line 707 of file plugin_rest_peerinfo.c.
References allow_methods, cleanup_handle(), GNUNET_REST_create_response(), GNUNET_SCHEDULER_add_now(), handle, and MHD_HTTP_OK.
|
static |
Function processing the REST call.
method | HTTP method |
url | URL of the HTTP request |
data | body of the HTTP request (optional) |
data_size | length of the body |
proc | callback function for the result |
proc_cls | closure for callback function |
Definition at line 707 of file plugin_rest_peerinfo.c.
Referenced by libgnunet_plugin_rest_peerinfo_init().
void* libgnunet_plugin_rest_peerinfo_init | ( | void * | cls | ) |
Entry point for the plugin.
cls | Config info |
Definition at line 787 of file plugin_rest_peerinfo.c.
References _, allow_methods, cfg, GNUNET_REST_Plugin::cls, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_PEERINFO_connect(), GNUNET_REST_API_NS_PEERINFO, GNUNET_REST_Plugin::name, peerinfo_handle, plugin, GNUNET_REST_Plugin::process_request, and rest_process_request().
void* libgnunet_plugin_rest_peerinfo_done | ( | void * | cls | ) |
Exit point from the plugin.
cls | the plugin context (as returned by "init") |
Definition at line 823 of file plugin_rest_peerinfo.c.
References allow_methods, Plugin::api, cleanup_handle(), GNUNET_BLOCK_PluginFunctions::cls, GNUNET_REST_Plugin::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_PEERINFO_disconnect(), peerinfo_handle, plugin, and requests_head.
const struct GNUNET_CONFIGURATION_Handle* cfg |
The configuration handle.
Handle to our configuration.
Definition at line 68 of file plugin_rest_peerinfo.c.
Referenced by libgnunet_plugin_rest_peerinfo_init(), and print_address().
|
static |
HTTP methods allows for this plugin.
Definition at line 73 of file plugin_rest_peerinfo.c.
Referenced by libgnunet_plugin_rest_peerinfo_done(), libgnunet_plugin_rest_peerinfo_init(), and options_cont().
|
static |
Handle to PEERINFO.
Definition at line 78 of file plugin_rest_peerinfo.c.
Referenced by cleanup_handle(), libgnunet_plugin_rest_peerinfo_done(), libgnunet_plugin_rest_peerinfo_init(), and peerinfo_get().
|
static |
Head of list of print contexts.
Definition at line 170 of file plugin_rest_peerinfo.c.
Referenced by dump_pc(), and peerinfo_list_iteration().
|
static |
Tail of list of print contexts.
Definition at line 175 of file plugin_rest_peerinfo.c.
Referenced by dump_pc(), and peerinfo_list_iteration().
|
static |
DLL.
Definition at line 267 of file plugin_rest_peerinfo.c.
Referenced by cleanup_handle(), and libgnunet_plugin_rest_peerinfo_done().
|
static |