GNUnet 0.22.0
plugin_dhtu_ip.h File Reference
Include dependency graph for plugin_dhtu_ip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void * DHTU_ip_done (struct GNUNET_DHTU_PluginFunctions *p)
 Exit point from the plugin. More...
 
struct GNUNET_DHTU_PluginFunctionsDHTU_ip_init (struct GNUNET_DHTU_PluginEnvironment *env)
 Entry point for the plugin. More...
 

Function Documentation

◆ DHTU_ip_done()

void * DHTU_ip_done ( struct GNUNET_DHTU_PluginFunctions api)

Exit point from the plugin.

Parameters
clsclosure (our struct Plugin)
Returns
NULL

Definition at line 1132 of file plugin_dhtu_ip.c.

1133{
1134 struct Plugin *plugin = api->cls;
1135 struct GNUNET_DHTU_Source *src;
1136 struct GNUNET_DHTU_Target *dst;
1137
1138 while (NULL != (dst = plugin->dst_head))
1139 {
1140 plugin->env->disconnect_cb (dst->app_ctx);
1141 GNUNET_assert (NULL == dst->ph_head);
1143 plugin->dst_tail,
1144 dst);
1145 GNUNET_free (dst);
1146 }
1147 while (NULL != (src = plugin->src_head))
1148 {
1149 plugin->env->address_del_cb (src->app_ctx);
1151 plugin->src_tail,
1152 src);
1153 GNUNET_free (src->address);
1154 GNUNET_free (src);
1155 }
1156 plugin->env->network_size_cb (plugin->env->cls,
1158 0.0,
1159 0.0);
1161 if (NULL != plugin->read_task)
1162 {
1163 GNUNET_SCHEDULER_cancel (plugin->read_task);
1164 plugin->read_task = NULL;
1165 }
1166 GNUNET_SCHEDULER_cancel (plugin->scan_task);
1169 GNUNET_free (plugin->port);
1171 GNUNET_free (api);
1172 return NULL;
1173}
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
@ GNUNET_OK
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
void * cls
Closure for all of the callbacks.
Opaque handle that the underlay offers for our address to be used when sending messages to another pe...
void * app_ctx
Application context for this source.
char * address
Address in URL form ("ip+udp://$PID/$IP:$PORT")
Opaque handle that the underlay offers for the target peer when sending messages to another peer.
struct GNUNET_DHTU_PreferenceHandle * ph_head
Head of preferences expressed for this target.
void * app_ctx
Application context for this target.
void * cls
Closure to pass to start_testcase.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References GNUNET_DHTU_Source::address, Plugin::api, GNUNET_DHTU_Source::app_ctx, GNUNET_DHTU_Target::app_ctx, GNUNET_BLOCK_PluginFunctions::cls, GNUNET_TESTING_PluginFunctions::cls, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_DHTU_Target::ph_head, and plugin.

Referenced by shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DHTU_ip_init()

struct GNUNET_DHTU_PluginFunctions * DHTU_ip_init ( struct GNUNET_DHTU_PluginEnvironment env)

Entry point for the plugin.

Parameters
clsclosure (the struct IP_DHTU_PluginEnvironment)
Returns
the plugin's API
Parameters
clsclosure (the struct GNUNET_DHTU_PluginEnvironment)
Returns
the plugin's API

Definition at line 951 of file plugin_dhtu_ip.c.

952{
953 struct GNUNET_DHTU_PluginFunctions *api;
954 struct Plugin *plugin;
955 char *port;
956 unsigned int nport;
957 int sock;
958 int af;
959 unsigned long long nse;
960
961 if (GNUNET_OK !=
963 "DHTU-IP",
964 "NSE",
965 &nse))
966 {
968 "DHTU-IP",
969 "NSE");
970 return NULL;
971 }
972 if (GNUNET_OK !=
974 "DHTU-IP",
975 "UDP_PORT",
976 &port))
977 {
979 "DHTU-IP",
980 "UDP_PORT");
981 return NULL;
982 }
983 {
984 char dummy;
985
986 if ( (1 != sscanf (port,
987 "%u%c",
988 &nport,
989 &dummy)) ||
990 (nport > UINT16_MAX) )
991 {
993 "DHTU-IP",
994 "UDP_PORT",
995 "must be number below 65536");
997 return NULL;
998 }
999 }
1000 plugin = GNUNET_new (struct Plugin);
1001 plugin->env = env;
1002 plugin->port = port;
1003 plugin->port16 = (uint16_t) nport;
1004 if (GNUNET_OK !=
1006 &plugin->my_id))
1007 {
1009 return NULL;
1010 }
1011 if (GNUNET_NETWORK_test_pf (PF_INET6))
1012 af = AF_INET6;
1013 else
1014 af = AF_INET;
1015 sock = socket (af,
1016 SOCK_DGRAM,
1017 IPPROTO_UDP);
1018 if (-1 == sock)
1019 {
1021 "socket");
1022 GNUNET_free (plugin->port);
1024 return NULL;
1025 }
1026 switch (af)
1027 {
1028 case AF_INET:
1029 {
1030 int on = 1;
1031
1032 if (0 !=
1033 setsockopt (sock,
1034 IPPROTO_IP,
1035 IP_PKTINFO,
1036 &on,
1037 sizeof (on)))
1038 {
1040 "setsockopt");
1041 }
1042 }
1043 {
1044 struct sockaddr_in sa = {
1045 .sin_family = AF_INET,
1046 .sin_port = htons ((uint16_t) nport)
1047 };
1048
1049 if (0 !=
1050 bind (sock,
1051 (const struct sockaddr *) &sa,
1052 sizeof (sa)))
1053 {
1055 "socket");
1056 GNUNET_break (0 ==
1057 close (sock));
1058 GNUNET_free (plugin->port);
1060 return NULL;
1061 }
1062 }
1063 break;
1064 case AF_INET6:
1065 {
1066 int on = 1;
1067
1068 if (0 !=
1069 setsockopt (sock,
1070 IPPROTO_IPV6,
1071 IPV6_RECVPKTINFO,
1072 &on,
1073 sizeof (on)))
1074 {
1076 "setsockopt");
1077 }
1078 }
1079 {
1080 struct sockaddr_in6 sa = {
1081 .sin6_family = AF_INET6,
1082 .sin6_port = htons ((uint16_t) nport)
1083 };
1084
1085 if (0 !=
1086 bind (sock,
1087 (const struct sockaddr *) &sa,
1088 sizeof (sa)))
1089 {
1091 "socket");
1092 GNUNET_break (0 ==
1093 close (sock));
1094 GNUNET_free (plugin->port);
1096 return NULL;
1097 }
1098 }
1099 break;
1100 }
1102 GNUNET_NO);
1106 plugin->sock,
1107 &read_cb,
1108 plugin);
1109 env->network_size_cb (env->cls,
1111 log (nse) / log (2),
1112 -1.0 /* stddev */);
1113 plugin->scan_task = GNUNET_SCHEDULER_add_now (&scan,
1114 plugin);
1116 api->cls = plugin;
1118 api->hold = &ip_hold;
1119 api->drop = &ip_drop;
1120 api->send = &ip_send;
1121 return api;
1122}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static uint16_t port
Port number.
Definition: gnunet-bcd.c:146
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static struct GNUNET_NSE_Handle * nse
The handle to the NSE service.
Definition: gnunet-nse.c:34
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_get_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst)
Retrieve the identity of the host's peer.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_NO
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_box_native(int fd)
Box a native socket (and check that it is a socket).
Definition: network.c:580
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:79
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1510
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:1303
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
static void ip_send(void *cls, struct GNUNET_DHTU_Target *target, const void *msg, size_t msg_size, GNUNET_SCHEDULER_TaskCallback finished_cb, void *finished_cb_cls)
Send message to some other participant over the network.
static void read_cb(void *cls)
UDP socket is ready to receive.
static void scan(void *cls)
Scan network interfaces for IP address changes.
static struct GNUNET_DHTU_PreferenceHandle * ip_hold(void *cls, struct GNUNET_DHTU_Target *target)
Request underlay to keep the connection to target alive if possible.
static void ip_try_connect(void *cls, const struct GNUNET_PeerIdentity *pid, const char *address)
Request creation of a session with a peer at the given address.
static void ip_drop(struct GNUNET_DHTU_PreferenceHandle *ph)
Do no long request underlay to keep the connection alive.
struct returned by the initialization function of the plugin
void(* try_connect)(void *cls, const struct GNUNET_PeerIdentity *pid, const char *address)
Request creation of a session with a peer at the given address.
void * cls
Closure to pass to all plugin functions.
struct GNUNET_DHTU_PreferenceHandle *(* hold)(void *cls, struct GNUNET_DHTU_Target *target)
Request underlay to keep the connection to target alive if possible.
void(* drop)(struct GNUNET_DHTU_PreferenceHandle *ph)
Do no longer request underlay to keep the connection alive.
void(* send)(void *cls, struct GNUNET_DHTU_Target *target, const void *msg, size_t msg_size, GNUNET_SCHEDULER_TaskCallback finished_cb, void *finished_cb_cls)
Send message to some other participant over the network.
struct GNUNET_NETWORK_Handle * sock
My UDP socket.

References GNUNET_DHTU_PluginFunctions::cls, GNUNET_DHTU_PluginFunctions::drop, dummy, env, GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CRYPTO_get_peer_identity(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_invalid(), GNUNET_log_config_missing(), GNUNET_log_strerror, GNUNET_NETWORK_socket_box_native(), GNUNET_NETWORK_test_pf(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_net(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_DHTU_PluginFunctions::hold, ip_drop(), ip_hold(), ip_send(), ip_try_connect(), nse, plugin, port, read_cb(), scan(), GNUNET_DHTU_PluginFunctions::send, Plugin::sock, and GNUNET_DHTU_PluginFunctions::try_connect.

Referenced by load_underlay().

Here is the call graph for this function:
Here is the caller graph for this function: