code for access to services More...
#include "platform.h"
#include "gnunet_protocols.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
#include "gnunet_socks.h"
Go to the source code of this file.
Data Structures | |
struct | AddressProbe |
During connect, we try multiple possible IP addresses to find out which one might work. More... | |
struct | ClientState |
State we keep per client. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "util-client", __VA_ARGS__) |
#define | CONNECT_RETRY_TIMEOUT |
Timeout we use on TCP connect before trying another result from the DNS resolver. More... | |
Functions | |
static void | start_connect (void *cls) |
Try to connect to the service. More... | |
static void | connect_fail_continuation (struct ClientState *cstate) |
We've failed for good to establish a connection (timeout or no more addresses to try). More... | |
static void | transmit_ready (void *cls) |
We are ready to send a message to the service. More... | |
static enum GNUNET_GenericReturnValue | recv_message (void *cls, const struct GNUNET_MessageHeader *msg) |
We have received a full message, pass to the MQ dispatcher. More... | |
static void | cancel_aps (struct ClientState *cstate) |
Cancel all remaining connect attempts. More... | |
static void | connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
Implement the destruction of a message queue. More... | |
static void | receive_ready (void *cls) |
This function is called once we have data ready to read. More... | |
static void | connect_success_continuation (struct ClientState *cstate) |
We've succeeded in establishing a connection. More... | |
static struct GNUNET_NETWORK_Handle * | try_unixpath (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg) |
Try connecting to the server using UNIX domain sockets. More... | |
static void | connect_probe_continuation (void *cls) |
Scheduler let us know that we're either ready to write on the socket OR connect timed out. More... | |
static void | try_connect_using_address (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
Try to establish a connection given the specified address. More... | |
static int | test_service_configuration (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg) |
Test whether the configuration has proper values for connection (UNIXPATH || (PORT && HOSTNAME)). More... | |
static void | connection_client_send_impl (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state) |
Implements the transmission functionality of a message queue. More... | |
static void | connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
Cancel the currently sent message. More... | |
enum GNUNET_GenericReturnValue | GNUNET_CLIENT_test (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name) |
Test if the port or UNIXPATH of the given service_name is in use and thus (most likely) the respective service is up. More... | |
struct GNUNET_MQ_Handle * | GNUNET_CLIENT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls) |
Create a message queue to connect to a GNUnet service. More... | |
code for access to services
Generic TCP code for reliable, record-oriented TCP connections between clients and service providers.
Definition in file client.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "util-client", __VA_ARGS__) |
#define CONNECT_RETRY_TIMEOUT |
Timeout we use on TCP connect before trying another result from the DNS resolver.
Actual value used is this value divided by the number of address families. Default is 5s.
|
static |
Try to connect to the service.
cls | the struct ClientState to try to connect to the service |
Definition at line 787 of file client.c.
References ClientState::attempts, ClientState::cfg, connect_fail_continuation(), CONNECT_RETRY_TIMEOUT, connect_success_continuation(), ClientState::dns_active, GNUNET_RESOLVER_ip_get(), GNUNET_SOCKS_check_service(), GNUNET_YES, ClientState::hostname, ClientState::port, ClientState::retry_task, ClientState::service_name, ClientState::sock, try_connect_using_address(), and try_unixpath().
Referenced by connect_fail_continuation(), and GNUNET_CLIENT_connect().
|
static |
We've failed for good to establish a connection (timeout or no more addresses to try).
cstate | the connection we tried to establish |
Definition at line 221 of file client.c.
References ClientState::ap_head, ClientState::ap_tail, ClientState::back_off, ClientState::dns_active, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, LOG, ClientState::recv_task, ClientState::retry_task, ClientState::send_task, ClientState::service_name, ClientState::sock, and start_connect().
Referenced by connect_probe_continuation(), start_connect(), and try_connect_using_address().
|
static |
We are ready to send a message to the service.
cls | the struct ClientState with the msg to transmit |
Definition at line 250 of file client.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_MQ_ERROR_WRITE, GNUNET_MQ_impl_send_continue(), GNUNET_MQ_impl_send_in_flight(), GNUNET_MQ_inject_error(), GNUNET_NETWORK_socket_send(), GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, ClientState::in_destroy, LOG, ClientState::mq, ClientState::msg, ClientState::msg_off, ret, ClientState::send_task, GNUNET_MessageHeader::size, ClientState::sock, transmit_ready(), and GNUNET_MessageHeader::type.
Referenced by connect_success_continuation(), connection_client_send_impl(), and transmit_ready().
|
static |
We have received a full message, pass to the MQ dispatcher.
Called by the tokenizer via receive_ready().
cls | the struct ClientState |
msg | message we received. |
Definition at line 335 of file client.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_inject_message(), GNUNET_NO, GNUNET_OK, GNUNET_YES, ClientState::in_destroy, LOG, ClientState::mq, msg, ClientState::service_name, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.
Referenced by GNUNET_CLIENT_connect(), and reconnect().
|
static |
Cancel all remaining connect attempts.
cstate | handle of the client state to process |
Definition at line 361 of file client.c.
References ClientState::ap_head, ClientState::ap_tail, AddressProbe::cstate, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), AddressProbe::sock, and AddressProbe::task.
Referenced by connect_probe_continuation(), and connection_client_destroy_impl().
|
static |
Implement the destruction of a message queue.
Implementations must not free mq, but should take care of impl_state.
mq | the message queue to destroy |
impl_state | our struct ClientState |
Definition at line 386 of file client.c.
References cancel_aps(), ClientState::dns_active, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MST_destroy(), GNUNET_NETWORK_socket_close(), GNUNET_RESOLVER_request_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_YES, ClientState::hostname, ClientState::in_destroy, LOG, mq, ClientState::mq, ClientState::mst, ClientState::recv_task, ClientState::retry_task, ClientState::send_task, ClientState::service_name, and ClientState::sock.
Referenced by GNUNET_CLIENT_connect(), and receive_ready().
|
static |
This function is called once we have data ready to read.
cls | struct ClientState with connection to read from |
Definition at line 440 of file client.c.
References connection_client_destroy_impl(), GNUNET_assert, GNUNET_MQ_ERROR_READ, GNUNET_MQ_inject_error(), GNUNET_MST_read(), GNUNET_NO, GNUNET_SCHEDULER_add_read_net(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, ClientState::in_destroy, ClientState::mq, ClientState::mst, receive_ready(), ClientState::recv_task, ret, and ClientState::sock.
Referenced by connect_success_continuation(), and receive_ready().
|
static |
We've succeeded in establishing a connection.
cstate | the connection we tried to establish |
Definition at line 483 of file client.c.
References GNUNET_assert, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_UNIT_FOREVER_REL, ClientState::msg, receive_ready(), ClientState::recv_task, ClientState::send_task, ClientState::sock, and transmit_ready().
Referenced by connect_probe_continuation(), and start_connect().
|
static |
Try connecting to the server using UNIX domain sockets.
service_name | name of service to connect to |
cfg | configuration to use |
Definition at line 511 of file client.c.
References _, cfg, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_NETWORK_shorten_unixpath(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_OK, GNUNET_strlcpy(), LOG, and service_name.
Referenced by start_connect().
|
static |
Scheduler let us know that we're either ready to write on the socket OR connect timed out.
Do the right thing.
cls | the struct AddressProbe * with the address that we are probing |
Definition at line 583 of file client.c.
References ClientState::ap_head, ClientState::ap_tail, cancel_aps(), connect_fail_continuation(), connect_success_continuation(), AddressProbe::cstate, ClientState::dns_active, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_getsockopt(), GNUNET_OK, GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_WRITE_READY, LOG, GNUNET_SCHEDULER_TaskContext::reason, ClientState::service_name, AddressProbe::sock, ClientState::sock, AddressProbe::task, and tc.
Referenced by try_connect_using_address().
|
static |
Try to establish a connection given the specified address.
This function is called by the resolver once we have a DNS reply.
cls | our struct ClientState * |
addr | address to try, NULL for "last call" |
addrlen | length of addr |
Definition at line 638 of file client.c.
References AddressProbe::addr, AddressProbe::addrlen, ClientState::ap_head, ClientState::ap_tail, connect_fail_continuation(), connect_probe_continuation(), CONNECT_RETRY_TIMEOUT, AddressProbe::cstate, ClientState::dns_active, GNUNET_a2s(), GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log_strerror, GNUNET_malloc, GNUNET_memcpy, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_OK, GNUNET_SCHEDULER_add_write_net(), LOG, ClientState::port, AddressProbe::sock, ClientState::sock, and AddressProbe::task.
Referenced by start_connect().
|
static |
Test whether the configuration has proper values for connection (UNIXPATH || (PORT && HOSTNAME)).
service_name | name of service to connect to |
cfg | configuration to use |
Definition at line 726 of file client.c.
References _, cfg, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_invalid(), GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, port, ret, and service_name.
Referenced by GNUNET_CLIENT_connect().
|
static |
Implements the transmission functionality of a message queue.
mq | the message queue |
msg | the message to send |
impl_state | our struct ClientState |
Definition at line 841 of file client.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_now(), LOG, mq, msg, ClientState::msg, ClientState::msg_off, ClientState::send_task, ClientState::sock, transmit_ready(), and GNUNET_MessageHeader::type.
Referenced by GNUNET_CLIENT_connect().
|
static |
Cancel the currently sent message.
mq | message queue |
impl_state | our struct ClientState |
Definition at line 873 of file client.c.
References GNUNET_assert, GNUNET_SCHEDULER_cancel(), mq, ClientState::msg, ClientState::msg_off, and ClientState::send_task.
Referenced by GNUNET_CLIENT_connect().