GNUnet 0.21.1
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 1129 of file plugin_dhtu_ip.c.

1130{
1131 struct Plugin *plugin = api->cls;
1132 struct GNUNET_DHTU_Source *src;
1133 struct GNUNET_DHTU_Target *dst;
1134
1135 while (NULL != (dst = plugin->dst_head))
1136 {
1137 plugin->env->disconnect_cb (dst->app_ctx);
1138 GNUNET_assert (NULL == dst->ph_head);
1140 plugin->dst_tail,
1141 dst);
1142 GNUNET_free (dst);
1143 }
1144 while (NULL != (src = plugin->src_head))
1145 {
1146 plugin->env->address_del_cb (src->app_ctx);
1148 plugin->src_tail,
1149 src);
1150 GNUNET_free (src->address);
1151 GNUNET_free (src);
1152 }
1153 plugin->env->network_size_cb (plugin->env->cls,
1155 0.0,
1156 0.0);
1158 if (NULL != plugin->read_task)
1159 {
1160 GNUNET_SCHEDULER_cancel (plugin->read_task);
1161 plugin->read_task = NULL;
1162 }
1163 GNUNET_SCHEDULER_cancel (plugin->scan_task);
1166 GNUNET_free (plugin->port);
1168 GNUNET_free (api);
1169 return NULL;
1170}
struct TestcasePlugin * plugin
The process handle to the testbed service.
#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:981
#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.
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_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 af = AF_INET6;
1012 sock = socket (af,
1013 SOCK_DGRAM,
1014 IPPROTO_UDP);
1015 if (-1 == sock)
1016 {
1018 "socket");
1019 GNUNET_free (plugin->port);
1021 return NULL;
1022 }
1023 switch (af)
1024 {
1025 case AF_INET:
1026 {
1027 int on = 1;
1028
1029 if (0 !=
1030 setsockopt (sock,
1031 IPPROTO_IP,
1032 IP_PKTINFO,
1033 &on,
1034 sizeof (on)))
1035 {
1037 "setsockopt");
1038 }
1039 }
1040 {
1041 struct sockaddr_in sa = {
1042 .sin_family = AF_INET,
1043 .sin_port = htons ((uint16_t) nport)
1044 };
1045
1046 if (0 !=
1047 bind (sock,
1048 (const struct sockaddr *) &sa,
1049 sizeof (sa)))
1050 {
1052 "socket");
1053 GNUNET_break (0 ==
1054 close (sock));
1055 GNUNET_free (plugin->port);
1057 return NULL;
1058 }
1059 }
1060 break;
1061 case AF_INET6:
1062 {
1063 int on = 1;
1064
1065 if (0 !=
1066 setsockopt (sock,
1067 IPPROTO_IPV6,
1068 IPV6_RECVPKTINFO,
1069 &on,
1070 sizeof (on)))
1071 {
1073 "setsockopt");
1074 }
1075 }
1076 {
1077 struct sockaddr_in6 sa = {
1078 .sin6_family = AF_INET6,
1079 .sin6_port = htons ((uint16_t) nport)
1080 };
1081
1082 if (0 !=
1083 bind (sock,
1084 (const struct sockaddr *) &sa,
1085 sizeof (sa)))
1086 {
1088 "socket");
1089 GNUNET_break (0 ==
1090 close (sock));
1091 GNUNET_free (plugin->port);
1093 return NULL;
1094 }
1095 }
1096 break;
1097 }
1099 GNUNET_NO);
1103 plugin->sock,
1104 &read_cb,
1105 plugin);
1106 env->network_size_cb (env->cls,
1108 log (nse) / log (2),
1109 -1.0 /* stddev */);
1110 plugin->scan_task = GNUNET_SCHEDULER_add_now (&scan,
1111 plugin);
1113 api->cls = plugin;
1115 api->hold = &ip_hold;
1116 api->drop = &ip_drop;
1117 api->send = &ip_send;
1118 return api;
1119}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
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:579
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:1512
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:1305
#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_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: