55#define LOG(kind, ...) GNUNET_log_from (kind, "core-underlay-dummy", __VA_ARGS__)
57#define SOCK_NAME_BASE "/tmp/gnunet-core-underlay-dummy-socket"
58#define SOCK_EXTENSION ".sock"
320 return "C_INITIALIZING";
323 return "C_INITIALIZING_SEND";
326 return "C_INITIALIZING_RECV";
395 if (NULL != connection->
sock)
430 for (
unsigned int i = 0; NULL !=
handlers[i].cb; i++)
503 h->notify_connect(
h->cls,
515 connection->
cls_mq = cls_mq;
548 "Going to cancle all initializing connections to %s\n",
551 for (
struct Connection *c_iter =
h->connections_head;
553 c_iter = c_iter_next)
555 c_iter_next = c_iter->
next;
560 if ((c_iter != connection) &&
561 (NULL != c_iter->peer_addr) &&
562 (0 == strcmp (c_iter->peer_addr,
peer_addr)) &&
569 " -> Cancelling connection - MQ_destroy()\n");
592 "do_read(): receiving bytes from %s :%s\n",
627 while (0 < ret_remain)
637 struct GNUNET_UNDERLAY_DUMMY_Message
648 struct GNUNET_UNDERLAY_DUMMY_Message *msg_dbg =
649 (
struct GNUNET_UNDERLAY_DUMMY_Message *) msg_iter;
661 buf_iter = buf_iter + ntohs (msg_iter->
size);
662 ret_remain = ret_remain - ntohs (msg_iter->
size);
668 buf_iter = buf + ntohs (
msg->
size);
671 while (0 < ret_remain)
683 buf_iter = buf_iter + ntohs (msg_iter->
size);
684 ret_remain = ret_remain - ntohs (msg_iter->
size);
689 if ((0 == ntohs (
msg->
type)) &&
692 char *peer_addr_sent = (
char *) &
msg[1];
696 "Init-message: %s\n",
699 (0 != strcmp (peer_addr_sent, connection->
peer_addr)))
702 "Peer sent us an Init-message with an address different from the one we already know. -> MQ_destroy()\n");
704 "sent address: %s\n",
713 switch (connection->
status)
727 "Connection to %s is now %s\n",
735 c_iter = c_iter->
next)
741 if ((NULL != c_iter->peer_addr) &&
742 (0 == strcmp (peer_addr_sent, c_iter->peer_addr)) &&
744 (connection != c_iter))
749 "Init from other peer - already connected: %s - MQ_destroy()\n",
756 connection->
peer_addr = strdup (peer_addr_sent);
758 "Init-Message - notifying caller (%s :%s)\n",
764 "Finished initializing - going to cancle all still initializing connections to this address\n");
778 else if ((0 == ntohs (
msg->
type)) &&
836 "write_cb(): sending bytes to %s :%s\n",
843 struct GNUNET_UNDERLAY_DUMMY_Message
854 struct GNUNET_UNDERLAY_DUMMY_Message *msg_dbg =
896 switch (connection->
status)
902 "Finished initializing - going to cancle all still initializing connections to this address\n");
914 "Connection to %s is now %s\n",
926 uint32_t peer_addr_len;
930 "Sending init: %s\n",
961 struct GNUNET_UNDERLAY_DUMMY_Message
970 struct GNUNET_UNDERLAY_DUMMY_Message *msg_dbg =
971 (
struct GNUNET_UNDERLAY_DUMMY_Message *)
msg;
1034 "mq_error_handler_impl: %u\n",
1051 struct sockaddr_un addr_other;
1052 socklen_t addr_other_len =
sizeof(addr_other);
1053 memset (&addr_other, 0,
sizeof (addr_other));
1066 (
struct sockaddr *) &addr_other,
1077 "Failed setting socket of incoming connection to non-blocking\n");
1081 connection->
sock = sock;
1090 h->connections_tail,
1129 struct sockaddr_un addr_other;
1130 memset (&addr_other, 0,
sizeof (addr_other));
1139 if (NULL == connection->
sock)
1153 addr_other.sun_family = AF_UNIX;
1157 (
struct sockaddr *) &addr_other,
1158 sizeof(addr_other)))
1161 "failed to connect to the socket: %u %s (closing socket)\n",
1162 errno, strerror(errno));
1184 h->connections_tail,
1208 const char *addresses[1] = {
h->sock_name};
1211 h->notify_address_change_task = NULL;
1212 h->notify_address_change (
h->cls, 1, addresses);
1221 if (0 == strcmp (
address,
h->sock_name))
1227 "Discovered another peer with address `%s'\n",
1236 for (
struct Connection *conn_iter =
h->connections_head;
1238 conn_iter = conn_iter->next)
1242 conn_iter->peer_addr,
1244 if ((NULL != conn_iter->peer_addr) &&
1245 (0 == strcmp (
address, conn_iter->peer_addr)) &&
1254 pcc_iter = pcc_iter->next)
1257 pcc_iter->sock_name))
1267 peer_connect_cls->
h =
h;
1273 h->peer_connect_cls_tail,
1338 struct sockaddr_un *addr_un;
1339 socklen_t addr_un_len;
1347 addr_un->sun_family = AF_UNIX;
1349 GNUNET_memcpy (&addr_un->sun_path, sock_name, strlen (sock_name));
1350 addr_un_len =
sizeof (
struct sockaddr_un);
1353 (
struct sockaddr *) addr_un,
1359 "Faild binding to socket: %u %s (closing socket)\n",
1360 errno, strerror(errno));
1362 h->sock_listen = NULL;
1369 " -> something went wrong (address is probably in use)\n");
1371 h->sock_listen = NULL;
1377 " -> succeeded! (binding to socket)\n");
1398 uint64_t sock_name_ctr_start)
1402 uint64_t sock_name_ctr = sock_name_ctr_start;
1410 SOCK_NAME_BASE
"%" PRIu64
"" SOCK_EXTENSION
"\0", sock_name_ctr++);
1416 h->sock_name_index_start = sock_name_ctr_start;
1417 h->sock_name_index = sock_name_ctr;
1425 h->sock_listen = NULL;
1430 if (NULL !=
h->notify_address_change)
1434 h->notify_address_change_task =
1460 if (NULL !=
h->notify_address_change_task)
1464 h->notify_address_change_task = NULL;
1466 if (NULL !=
h->peer_discovery_task)
1470 h->peer_discovery_task = NULL;
1476 pcc_next = pcc->
next;
1480 h->peer_connect_cls_tail,
1485 if (NULL !=
h->listen_task)
1489 h->listen_task = NULL;
1491 if (NULL !=
h->sock_listen)
1495 h->sock_listen = NULL;
1497 for (
struct Connection *conn_iter =
h->connections_head;
1499 conn_iter = conn_next)
1504 conn_next = conn_iter->
next;
1516 GNUNET_CORE_UNDERLAY_DUMMY_change_address (
h);
1551 h->notify_connect =
nc;
1552 h->notify_disconnect = nd;
1553 h->notify_address_change = na;
1581 if (NULL !=
handle->address_change_task)
1612GNUNET_CORE_UNDERLAY_DUMMY_receive_continue (
1621 for (
struct Connection *conn_iter =
h->connections_head;
1623 conn_iter = conn_iter->next)
1625 if (
mq == conn_iter->mq)
1627 connection = conn_iter;
1651GNUNET_CORE_UNDERLAY_DUMMY_connect_to_peer (
1653 const char *peer_address,
1667GNUNET_CORE_UNDERLAY_DUMMY_change_address (
1672 if (0 ==
h->sock_name_index_start)
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static size_t strnlen(const char *s, size_t n)
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * address
GNS address for this phone.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static int status
The program status; 0 for success.
static struct GNUNET_NotificationContext * nc
Notification context for broadcasting to monitors.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
API of the dummy core underlay that uses unix domain sockets.
API to schedule computations using continuation passing style.
struct GNUNET_MQ_MessageHandler * handlers
Array of message handlers given by the client.
const struct GNUNET_MessageHeader * message_to_send
Message about to be sent, given by the message queue, waiting for the socket to be ready.
static void do_close_listening_socket(void *cls)
struct GNUNET_NETWORK_Handle * sock
Socket for the connected peer.
void GNUNET_CORE_UNDERLAY_DUMMY_disconnect(struct GNUNET_CORE_UNDERLAY_DUMMY_Handle *handle)
Disconnect from the core underlay dummy service.
struct QueuedMessage * prev
struct QueuedMessage * queued_recv_messages_tail
GNUNET_CORE_UNDERLAY_DUMMY_NotifyAddressChange notify_address_change
Callback (from/to client) to call when our address changes.
void * cls
Closure for handlers given by the client - connection-independant (notify_connect,...
GNUNET_CORE_UNDERLAY_DUMMY_NotifyConnect notify_connect
Callback (from/to client) to call when another peer connects.
struct GNUNET_SCHEDULER_Task * listen_task
Task that waits for incoming connections.
char * sock_name
Name of the listening socket.
struct Connection * prev
Linked list previous.
struct GNUNET_SCHEDULER_Task * write_task
Task waiting until the socket becomes ready to be written to.
static void do_read(void *cls)
Callback scheduled to run when there is something to read from the socket.
struct Connection * connections_head
Head of linked list with peer connect closures.
struct PeerConnectCls * peer_connect_cls_tail
Tail of linked list with peer connect closures.
struct PeerConnectCls * next
Linked list next.
struct GNUNET_CORE_UNDERLAY_DUMMY_Handle * GNUNET_CORE_UNDERLAY_DUMMY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_CORE_UNDERLAY_DUMMY_NotifyConnect nc, GNUNET_CORE_UNDERLAY_DUMMY_NotifyDisconnect nd, GNUNET_CORE_UNDERLAY_DUMMY_NotifyAddressChange na)
Connect to the core underlay dummy service.
static void connection_destroy(struct Connection *connection)
Destroy a connection.
static void do_notify_address_change(void *cls)
Notify core about address change.
struct Connection * connections_tail
Tail of linked list with peer connect closures.
char * peer_addr
Address of the connected peer.
static void do_discover_peers(void *cls)
Discover sockets of other peers.
struct GNUNET_CORE_UNDERLAY_DUMMY_Handle * h
The handle for the service.
static void cancle_initiating_connections(struct GNUNET_CORE_UNDERLAY_DUMMY_Handle *h, struct Connection *connection)
void * cls_mq
Closure for the mq towards the client.
struct GNUNET_SCHEDULER_Task * address_change_task
struct GNUNET_SCHEDULER_Task * peer_discovery_task
Task to discover other peers.
static void write_cb(void *cls)
Callback scheduled to run once the socket is ready for writing.
struct GNUNET_SCHEDULER_Task * peer_connect_task
Task to connect to another peer.
struct QueuedMessage * queued_recv_messages_head
Queued received messages in a DLL TODO implement cleanup TODO replace with a performant queue.
struct PeerConnectCls * prev
Linked list previous.
static enum GNUNET_GenericReturnValue try_open_listening_socket(struct GNUNET_CORE_UNDERLAY_DUMMY_Handle *h, char *sock_name)
static void do_connect_to_peer(void *cls)
Connect to another peer.
struct GNUNET_SCHEDULER_Task * notify_address_change_task
Task to notify core about address changes.
static void check_for_messages(struct Connection *connection)
struct GNUNET_SCHEDULER_Task * handle_message_task
Task to pass the message to the client's handlers.
void(* GNUNET_CORE_UNDERLAY_DUMMY_NotifyAddressChange)(void *cls, uint32_t num_addresses, const char *addresses[static num_addresses])
Function called to notify core of the now available addresses.
static void mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Callback to destroy the message queue.
struct Connection * next
Linked list next.
static const char * status2string(enum ConnectionStatus status)
struct GNUNET_NETWORK_Handle * sock_listen
Socket on which we listen for incoming connections.
static void try_notify_connect(struct Connection *connection)
enum GNUNET_GenericReturnValue notify_connect_called
Whether notify_connect was called already It is used to check whether to call notify_disconnect or no...
static void do_notify_connect(void *cls)
Notify the api caller about a new connection.
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Handle * mq
Message queue towards the connected peer.
static void do_handle_message(void *cls)
static void mq_error_handler_impl(void *cls, enum GNUNET_MQ_Error error)
Handle mq errors.
static void do_open_listening_socket(void *cls, uint64_t sock_name_ctr_start)
Opens UNIX domain socket.
struct GNUNET_MQ_MessageHandler * handlers
Handlers for mq.
struct GNUNET_CORE_UNDERLAY_DUMMY_Handle * handle
Handle to the service.
enum ConnectionStatus status
Status of the connection: Initializing, Live, Destroy.
static void do_accept(void *cls)
Accept a connection on the dummy's socket.
static void mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Callback to cancel sending a message.
GNUNET_CORE_UNDERLAY_DUMMY_NotifyDisconnect notify_disconnect
Callback (from/to client) to call when a peer disconnects.
uint64_t sock_name_index_start
struct PeerConnectCls * peer_connect_cls_head
Head of linked list with peer connect closures.
struct QueuedMessage * next
static void set_handlers_closure(struct GNUNET_MQ_MessageHandler *handlers, void *handlers_cls)
Set the closures for mq handlers.
enum GNUNET_GenericReturnValue client_ready_to_receive
Indicating whether the client is ready to receive new messages.
static enum GNUNET_GenericReturnValue discovered_socket_cb(void *cls, const char *filename)
Handle the discovery of a certain socket.
void *(* GNUNET_CORE_UNDERLAY_DUMMY_NotifyConnect)(void *cls, uint32_t num_addresses, const char *addresses[static num_addresses], struct GNUNET_MQ_Handle *mq, const struct GNUNET_PeerIdentity *peer_id)
Function called to notify core underlay dummy users that another peer connected to us.
void(* GNUNET_CORE_UNDERLAY_DUMMY_NotifyDisconnect)(void *cls, void *handler_cls)
Function called to notify core underlay dummy users that another peer disconnected from us.
static void send_init(struct Connection *connection)
struct GNUNET_SCHEDULER_Task * recv_task
Task waiting for incoming messages.
struct GNUNET_SCHEDULER_Task * notify_connect_task
Task to notify the client about an open connection.
char * sock_name
The file name to connect to.
static void try_connect(struct GNUNET_CORE_UNDERLAY_DUMMY_Handle *h, const char *address)
static void mq_send_impl(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Callback called from the MQ to send a message over a socket.
static void do_change_address(void *cls)
@ CONNECTION_INITIALIZING
@ CONNECTION_INITIALIZING_RECV
@ CONNECTION_INITIALIZING_SEND
int GNUNET_DISK_glob(const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
Find all files matching a glob pattern.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
#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.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#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.
@ 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_strdup(a)
Wrapper around GNUNET_xstrdup_.
#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.
GNUNET_MQ_Error
Error codes for the queue.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
GNUNET_MQ_PriorityPreferences
Per envelope preferences and priorities.
enum GNUNET_GenericReturnValue GNUNET_MQ_handle_message(const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given h...
#define GNUNET_MQ_msg_header_extra(mh, esize, type)
Allocate a GNUNET_MQ_Envelope, where the message only consists of a header and extra space.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_set_blocking(struct GNUNET_NETWORK_Handle *fd, int doBlock)
Set if a socket should use blocking or non-blocking IO.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
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...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *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_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_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_SECONDS
One second.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Used to keep track of context of peer.
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
Opaque handle to the service.
Handle to a message queue.
Message handler for a specific message type.
Entry in list of pending tasks.
Closure used for the peer_connect_task.