41 #define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
48 #include <sys/ioctl.h>
49 #include <sys/select.h>
53 #define PM_SET_DELAY_AND_TIMEOUT _IOW (PM_MAGIC, 1, struct pm_times)
57 unsigned long delay_msecs;
58 unsigned long timeout_msecs;
104 struct pm_times cryogenic_times;
151 "Received beacon with %u bytes from peer `%s' via address `%s'\n",
169 _ (
"# Multicast HELLO beacons received via UDP"),
202 mc.ats_address_network_type = network_type;
231 msg->header.
size = htons (msg_size);
252 struct sockaddr_in *addr = (
struct sockaddr_in *) baddr->
addr;
256 (
const struct sockaddr *) addr,
260 if ((ENETUNREACH == errno) || (ENETDOWN == errno))
267 "Network connectivity is down, cannot send beacon!\n");
275 "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent,
284 if (NULL != baddr->cryogenic_fd)
286 baddr->cryogenic_times.delay_msecs =
288 baddr->cryogenic_times.timeout_msecs =
291 if (ioctl (baddr->cryogenic_fd->fd,
292 PM_SET_DELAY_AND_TIMEOUT,
293 &baddr->cryogenic_times) < 0)
322 const struct sockaddr_in6 *s6 = (
const struct sockaddr_in6 *) baddr->
addr;
336 (
const struct sockaddr *)
338 sizeof(
struct sockaddr_in6));
342 if ((ENETUNREACH == errno) || (ENETDOWN == errno))
349 "Network connectivity is down, cannot send beacon!\n");
357 "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n",
360 sizeof(
struct sockaddr_in6)));
366 if (NULL != baddr->cryogenic_fd)
368 baddr->cryogenic_times.delay_msecs =
370 baddr->cryogenic_times.timeout_msecs =
373 if (ioctl (baddr->cryogenic_fd->fd,
374 PM_SET_DELAY_AND_TIMEOUT,
375 &baddr->cryogenic_times) < 0)
412 const struct sockaddr *addr,
413 const struct sockaddr *broadcast_addr,
414 const struct sockaddr *netmask, socklen_t addrlen)
423 "address %s for interface %s %p\n ",
425 if (NULL == broadcast_addr)
428 "broadcast address %s for interface %s %p\n ",
449 (
addrlen ==
sizeof(
struct sockaddr_in)))
460 if (0 == access (
name, R_OK))
474 (
addrlen ==
sizeof(
struct sockaddr_in6)))
477 struct ipv6_mreq multicastRequest;
478 const struct sockaddr_in6 *s6 = (
const struct
479 sockaddr_in6 *) broadcast_addr;
481 multicastRequest.ipv6mr_multiaddr =
493 multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
499 &multicastRequest,
sizeof(multicastRequest)))
502 "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n");
515 if (0 == access (
name, R_OK))
543 struct sockaddr_in6 *server_addrv6,
544 struct sockaddr_in *server_addrv4)
553 "Disabling HELLO broadcasting due to friend-to-friend only configuration!\n"));
571 "Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
572 ntohs (server_addrv4->sin_port));
580 inet_pton (AF_INET6,
"FF05::13B",
604 if (
p->broadcast_task != NULL)
607 p->broadcast_task = NULL;
611 (
p->addrlen ==
sizeof(
struct sockaddr_in6)))
614 struct ipv6_mreq multicastRequest;
615 const struct sockaddr_in6 *s6 = (
const struct sockaddr_in6 *)
p->addr;
617 multicastRequest.ipv6mr_multiaddr =
619 multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
625 &multicastRequest,
sizeof(multicastRequest)))
struct GNUNET_MessageHeader * msg
struct Plugin * plugin
The process handle to the testbed service.
static char * address
GNS address for this phone.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
static struct GNUNET_OS_Process * p
Helper process we started.
#define GNUNET_log(kind,...)
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
#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.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
#define GNUNET_HELLO_address_free(addr)
Free an address.
@ GNUNET_HELLO_ADDRESS_INFO_NONE
No additional information.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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...
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
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).
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
@ GNUNET_NT_LOOPBACK
Loopback (same host).
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON
Message send by a peer to notify the other to keep the session alive.
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.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *wfd, 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_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static unsigned int size
Size of the "table".
const char * udp_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
Implementation of the UDP transport protocol.
#define UDP_MTU
MTU for fragmentation subsystem.
static unsigned int prepare_beacon(struct Plugin *plugin, struct UDP_Beacon_Message *msg)
void stop_broadcast(struct Plugin *plugin)
Stop broadcasting subsystem.
static void udp_ipv6_broadcast_send(void *cls)
void setup_broadcast(struct Plugin *plugin, struct sockaddr_in6 *server_addrv6, struct sockaddr_in *server_addrv4)
Setup broadcasting subsystem.
static int broadcast_mst_cb(void *cls, const struct GNUNET_MessageHeader *message)
Parse broadcast message received.
static void udp_ipv4_broadcast_send(void *cls)
void udp_broadcast_receive(struct Plugin *plugin, const char *buf, ssize_t size, const union UdpAddress *udp_addr, size_t udp_addr_len, enum GNUNET_NetworkType network_type)
We received a broadcast message.
static int iface_proc(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 BroadcastAddress * prev
struct BroadcastAddress * next
struct GNUNET_SCHEDULER_Task * broadcast_task
ID of select broadcast task.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
void * cls
Closure to use for callbacks.
Handle used to access files (and pipes).
An address for communicating with a peer.
A HELLO message is used to exchange information about transports with other peers.
Handle to a message stream tokenizer.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
uint64_t rel_value_us
The actual value.
Client-specific context for broadcast_mst_cb().
enum GNUNET_NetworkType ats_address_network_type
ATS network type.
const union UdpAddress * udp_addr
struct GNUNET_TIME_Relative broadcast_interval
Broadcast interval.
struct BroadcastAddress * broadcast_head
Tail of DLL of broadcast addresses.
int enable_ipv6
Is IPv6 enabled: GNUNET_YES or GNUNET_NO.
int enable_ipv4
Is IPv4 enabled: GNUNET_YES or GNUNET_NO.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_NETWORK_Handle * sockv4
The read socket for IPv4.
int enable_broadcasting
Is broadcasting enabled: GNUNET_YES or GNUNET_NO.
char * port
Port we bind to.
struct sockaddr_in6 ipv6_multicast_address
IPv6 multicast address.
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.
struct BroadcastAddress * broadcast_tail
Head of DLL of broadcast addresses.
struct GNUNET_MessageHeader header
Message header.
struct GNUNET_PeerIdentity sender
What is the identity of the sender.
common internal definitions for transport service
Either an IPv4 or IPv6 UDP address.