34#define SCAN_FREQ GNUNET_TIME_UNIT_MINUTES
72 struct sockaddr_storage
addr;
249 const struct sockaddr *
addr,
265 if ( (NULL == dst) ||
266 (dst->ph_count >= pos->ph_count) )
270 plugin->env->disconnect_cb (dst->app_ctx);
329 (
const struct sockaddr *)
addr,
369 struct addrinfo hints = {
372 struct addrinfo *
result = NULL;
387 colon = strchr (addr,
':');
480 void *finished_cb_cls)
483 char buf[
sizeof (
plugin->my_id) + msg_size];
488 memcpy (&buf[
sizeof (
plugin->my_id)],
494 (
const struct sockaddr *) &target->
addr,
510 const struct sockaddr *
addr,
521 switch (
addr->sa_family)
525 const struct sockaddr_in *s4 = (
const struct sockaddr_in *) addr;
526 char buf[INET_ADDRSTRLEN];
535 ntohs (s4->sin_port));
540 const struct sockaddr_in6 *s6 = (
const struct sockaddr_in6 *) addr;
541 char buf[INET6_ADDRSTRLEN];
550 ntohs (s6->sin6_port));
580 const struct sockaddr *a2,
584 switch (a1->sa_family)
589 const struct sockaddr_in *s1 = (
const struct sockaddr_in *) a1;
590 const struct sockaddr_in *s2 = (
const struct sockaddr_in *) a2;
592 if (s1->sin_addr.s_addr != s2->sin_addr.s_addr)
599 const struct sockaddr_in6 *s1 = (
const struct sockaddr_in6 *) a1;
600 const struct sockaddr_in6 *s2 = (
const struct sockaddr_in6 *) a2;
626 const struct sockaddr *a2,
630 switch (a1->sa_family)
635 const struct sockaddr_in *s1 = (
const struct sockaddr_in *) a1;
636 const struct sockaddr_in *s2 = (
const struct sockaddr_in *) a2;
638 if (s1->sin_port != s2->sin_port)
640 if (s1->sin_addr.s_addr != s2->sin_addr.s_addr)
647 const struct sockaddr_in6 *s1 = (
const struct sockaddr_in6 *) a1;
648 const struct sockaddr_in6 *s2 = (
const struct sockaddr_in6 *) a2;
650 if (s1->sin6_port != s2->sin6_port)
680 const struct sockaddr *addr,
681 const struct sockaddr *broadcast_addr,
682 const struct sockaddr *netmask,
688 for (src =
plugin->src_head;
694 (
const struct sockaddr *) &src->
addr,
701 switch (
addr->sa_family)
705 struct sockaddr_in v4;
711 v4.sin_port = htons (
plugin->port16);
713 (
const struct sockaddr *) &v4,
719 struct sockaddr_in6 v6;
725 v6.sin6_port = htons (
plugin->port16);
727 (
const struct sockaddr *) &v6,
747 plugin->scan_generation++;
755 if (src->scan_generation >=
plugin->scan_generation)
760 plugin->env->address_del_cb (src->app_ctx);
788 if ( (
addrlen == src->addrlen) &&
790 (
const struct sockaddr *) &src->addr,
796 (
const struct sockaddr *)
addr,
813 struct sockaddr_storage sa;
816 .iov_len =
sizeof (buf)
821 .msg_namelen =
sizeof (sa),
825 .msg_controllen =
sizeof (ctl)
846 for (
struct cmsghdr *cmsg = CMSG_FIRSTHDR (&
mh);
848 cmsg = CMSG_NXTHDR (&
mh,
852 "Got CMSG level %u (%d/%d), type %u (%d/%d)\n",
854 (cmsg->cmsg_level == IPPROTO_IP),
855 (cmsg->cmsg_level == IPPROTO_IPV6),
857 (cmsg->cmsg_type == IP_PKTINFO),
858 (cmsg->cmsg_type == IPV6_PKTINFO));
859 if ( (cmsg->cmsg_level == IPPROTO_IP) &&
860 (cmsg->cmsg_type == IP_PKTINFO) )
862 if (CMSG_LEN (
sizeof (
struct in_pktinfo)) ==
865 struct in_pktinfo pi;
871 struct sockaddr_in sa_tmp = {
872 .sin_family = AF_INET,
873 .sin_addr = pi.ipi_addr,
874 .sin_port = htons (
plugin->port16)
889 if ( (cmsg->cmsg_level == IPPROTO_IPV6) &&
890 (cmsg->cmsg_type == IPV6_PKTINFO) )
892 if (CMSG_LEN (
sizeof (
struct in6_pktinfo)) ==
895 struct in6_pktinfo pi;
901 struct sockaddr_in6 sa_tmp = {
902 .sin6_family = AF_INET6,
903 .sin6_addr = pi.ipi6_addr,
904 .sin6_port = htons (
plugin->port16),
905 .sin6_scope_id = pi.ipi6_ifindex
959 unsigned long long nse;
986 if ( (1 != sscanf (
port,
990 (nport > UINT16_MAX) )
995 "must be number below 65536");
1003 plugin->port16 = (uint16_t) nport;
1044 struct sockaddr_in sa = {
1045 .sin_family = AF_INET,
1046 .sin_port = htons ((uint16_t) nport)
1051 (
const struct sockaddr *) &sa,
1080 struct sockaddr_in6 sa = {
1081 .sin6_family = AF_INET6,
1082 .sin6_port = htons ((uint16_t) nport)
1087 (
const struct sockaddr *) &sa,
1109 env->network_size_cb (
env->cls,
1111 log (
nse) / log (2),
1138 while (NULL != (dst =
plugin->dst_head))
1147 while (NULL != (src =
plugin->src_head))
1161 if (NULL !=
plugin->read_task)
1164 plugin->read_task = NULL;
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static int ret
Final status code.
static uint16_t port
Port number.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
static void finished_cb(void *cls, enum GNUNET_GenericReturnValue rv)
static char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static char * name
Name (label) of the records to list.
static struct GNUNET_NSE_Handle * nse
The handle to the NSE service.
static int result
Global testing status.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
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.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#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.
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
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_box_native(int fd)
Box a native socket (and check that it is a socket).
enum GNUNET_GenericReturnValue GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
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...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
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.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static int addrcmp(const struct sockaddr *a1, const struct sockaddr *a2, size_t alen)
Compare two addresses for equality.
static enum GNUNET_GenericReturnValue process_ifcs(void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
Callback function invoked for each interface found.
struct GNUNET_DHTU_PluginFunctions * DHTU_ip_init(struct GNUNET_DHTU_PluginEnvironment *env)
Entry point for the plugin.
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 int addrcmp_np(const struct sockaddr *a1, const struct sockaddr *a2, size_t alen)
Compare two addresses excluding the ports for equality.
static struct GNUNET_DHTU_Source * find_source(struct Plugin *plugin, const void *addr, size_t addrlen)
Find our source matching addr.
static void read_cb(void *cls)
UDP socket is ready to receive.
static void scan(void *cls)
Scan network interfaces for IP address changes.
#define MAX_DESTS
Maximum number of concurrently active destinations to support.
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.
#define SCAN_FREQ
How frequently should we re-scan our local interfaces for IPs?
static struct GNUNET_DHTU_Target * find_target(struct Plugin *plugin, const struct GNUNET_PeerIdentity *pid, const void *addr, size_t addrlen)
Find target matching addr.
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 struct GNUNET_DHTU_Source * create_source(struct Plugin *plugin, const struct sockaddr *addr, socklen_t addrlen)
Create a new source on which we may be receiving traffic.
void * DHTU_ip_done(struct GNUNET_DHTU_PluginFunctions *api)
Exit point from the plugin.
static void ip_drop(struct GNUNET_DHTU_PreferenceHandle *ph)
Do no long request underlay to keep the connection alive.
static struct GNUNET_DHTU_Target * create_target(struct Plugin *plugin, const struct GNUNET_PeerIdentity *pid, const struct sockaddr *addr, socklen_t addrlen)
Create a target to which we may send traffic.
void * cls
Closure for all of the callbacks.
Internal representation of the hash map.
The datastore service will pass a pointer to a struct of this type as the first and only argument to ...
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.
Opaque handle expressing a preference of the DHT to keep a particular target connected.
struct GNUNET_DHTU_PreferenceHandle * prev
Kept in a DLL.
struct GNUNET_DHTU_Target * target
Target a preference was expressed for.
struct GNUNET_DHTU_PreferenceHandle * next
Kept in a DLL.
Opaque handle that the underlay offers for our address to be used when sending messages to another pe...
struct GNUNET_DHTU_Source * prev
Kept in a DLL.
void * app_ctx
Application context for this source.
socklen_t addrlen
Number of bytes in addr.
struct GNUNET_DHTU_Source * next
Kept in a DLL.
char * address
Address in URL form ("ip+udp://$PID/$IP:$PORT")
struct sockaddr_storage addr
My actual address.
unsigned int scan_generation
Last generation this address was observed.
Opaque handle that the underlay offers for the target peer when sending messages to another peer.
struct GNUNET_DHTU_Target * prev
Kept in a DLL.
struct GNUNET_DHTU_PreferenceHandle * ph_head
Head of preferences expressed for this target.
unsigned int ph_count
Preference counter, length of the ph_head DLL.
socklen_t addrlen
Number of bytes in addr.
void * app_ctx
Application context for this target.
struct GNUNET_DHTU_PreferenceHandle * ph_tail
Tail of preferences expressed for this target.
struct GNUNET_DHTU_Target * next
Kept in a DLL.
struct sockaddr_storage addr
Target IP address.
struct GNUNET_PeerIdentity pid
Identity of this peer.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
void * cls
Closure to pass to start_testcase.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
struct GNUNET_PeerIdentity my_id
My identity.
struct GNUNET_SCHEDULER_Task * scan_task
Task that scans for IP address changes.
unsigned int scan_generation
How often have we scanned for IPs?
struct GNUNET_SCHEDULER_Task * read_task
Task that reads incoming UDP packets.
struct GNUNET_NETWORK_Handle * sock
My UDP socket.
uint16_t port16
Port as a 16-bit value.
char * port
Port we bind to.
struct GNUNET_DHTU_Source * src_tail
Tail of sources where we receive traffic.
struct GNUNET_CONTAINER_MultiHashMap * dsts
Map from hashes of sockaddrs to targets.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_DHTU_Target * dst_tail
Tail of destinations that are active.
struct GNUNET_DHTU_Target * dst_head
Head of destinations that are active.
struct GNUNET_DHTU_Source * src_head
Head of sources where we receive traffic.