|
Electroneum
|
#include "dnscrypt/dnscrypt.h"

Go to the source code of this file.
Classes | |
| struct | comm_base |
| struct | comm_reply |
| struct | comm_point |
| struct | comm_timer |
| struct | comm_signal |
Macros | |
| #define | NETEVENT_NOERROR 0 |
| #define | NETEVENT_CLOSED -1 |
| #define | NETEVENT_TIMEOUT -2 |
| #define | NETEVENT_CAPSFAIL -3 |
| #define | NETEVENT_DONE -4 |
| #define | NETEVENT_SLOW_ACCEPT_TIME 2000 |
Typedefs | |
| typedef int | comm_point_callback_type(struct comm_point *, void *, int, struct comm_reply *) |
Functions | |
| struct comm_base * | comm_base_create (int sigs) |
| struct comm_base * | comm_base_create_event (struct ub_event_base *base) |
| void | comm_base_delete_no_base (struct comm_base *b) |
| void | comm_base_delete (struct comm_base *b) |
| void | comm_base_timept (struct comm_base *b, time_t **tt, struct timeval **tv) |
| void | comm_base_dispatch (struct comm_base *b) |
| void | comm_base_exit (struct comm_base *b) |
| void | comm_base_set_slow_accept_handlers (struct comm_base *b, void(*stop_accept)(void *), void(*start_accept)(void *), void *arg) |
| struct ub_event_base * | comm_base_internal (struct comm_base *b) |
| struct comm_point * | comm_point_create_udp (struct comm_base *base, int fd, struct sldns_buffer *buffer, comm_point_callback_type *callback, void *callback_arg) |
| struct comm_point * | comm_point_create_udp_ancil (struct comm_base *base, int fd, struct sldns_buffer *buffer, comm_point_callback_type *callback, void *callback_arg) |
| struct comm_point * | comm_point_create_tcp (struct comm_base *base, int fd, int num, size_t bufsize, comm_point_callback_type *callback, void *callback_arg) |
| struct comm_point * | comm_point_create_tcp_out (struct comm_base *base, size_t bufsize, comm_point_callback_type *callback, void *callback_arg) |
| struct comm_point * | comm_point_create_http_out (struct comm_base *base, size_t bufsize, comm_point_callback_type *callback, void *callback_arg, struct sldns_buffer *temp) |
| struct comm_point * | comm_point_create_local (struct comm_base *base, int fd, size_t bufsize, comm_point_callback_type *callback, void *callback_arg) |
| struct comm_point * | comm_point_create_raw (struct comm_base *base, int fd, int writing, comm_point_callback_type *callback, void *callback_arg) |
| void | comm_point_close (struct comm_point *c) |
| void | comm_point_delete (struct comm_point *c) |
| void | comm_point_send_reply (struct comm_reply *repinfo) |
| void | comm_point_drop_reply (struct comm_reply *repinfo) |
| int | comm_point_send_udp_msg (struct comm_point *c, struct sldns_buffer *packet, struct sockaddr *addr, socklen_t addrlen) |
| void | comm_point_stop_listening (struct comm_point *c) |
| void | comm_point_start_listening (struct comm_point *c, int newfd, int msec) |
| void | comm_point_listen_for_rw (struct comm_point *c, int rd, int wr) |
| size_t | comm_point_get_mem (struct comm_point *c) |
| struct comm_timer * | comm_timer_create (struct comm_base *base, void(*cb)(void *), void *cb_arg) |
| void | comm_timer_disable (struct comm_timer *timer) |
| void | comm_timer_set (struct comm_timer *timer, struct timeval *tv) |
| void | comm_timer_delete (struct comm_timer *timer) |
| int | comm_timer_is_set (struct comm_timer *timer) |
| size_t | comm_timer_get_mem (struct comm_timer *timer) |
| struct comm_signal * | comm_signal_create (struct comm_base *base, void(*callback)(int, void *), void *cb_arg) |
| int | comm_signal_bind (struct comm_signal *comsig, int sig) |
| void | comm_signal_delete (struct comm_signal *comsig) |
| int | comm_point_perform_accept (struct comm_point *c, struct sockaddr_storage *addr, socklen_t *addrlen) |
| void | comm_point_udp_callback (int fd, short event, void *arg) |
| void | comm_point_udp_ancil_callback (int fd, short event, void *arg) |
| void | comm_point_tcp_accept_callback (int fd, short event, void *arg) |
| void | comm_point_tcp_handle_callback (int fd, short event, void *arg) |
| void | comm_point_http_handle_callback (int fd, short event, void *arg) |
| void | comm_timer_callback (int fd, short event, void *arg) |
| void | comm_signal_callback (int fd, short event, void *arg) |
| void | comm_point_local_handle_callback (int fd, short event, void *arg) |
| void | comm_point_raw_handle_callback (int fd, short event, void *arg) |
| void | comm_base_handle_slow_accept (int fd, short event, void *arg) |
| int | tcp_connect_errno_needs_log (struct sockaddr *addr, socklen_t addrlen) |
This file contains event notification functions.
There are three types of communication points o UDP socket - perthread buffer. o TCP-accept socket - array of TCP-sockets, socketcount. o TCP socket - own buffer, parent-TCPaccept, read/write state, number of bytes read/written, timeout.
There are sockets aimed towards our clients and towards the internet. o frontside - aimed towards our clients, queries come in, answers back. o behind - aimed towards internet, to the authoritative DNS servers.
Several event types are available: o comm_base - for thread safety of the comm points, one per thread. o comm_point - udp and tcp networking, with callbacks. o comm_timer - a timeout with callback. o comm_signal - callbacks when signal is caught. o comm_reply - holds reply info during networking callback.
Definition in file netevent.h.
| #define NETEVENT_CAPSFAIL -3 |
to pass fallback from capsforID to callback function; 0x20 failed
Definition at line 86 of file netevent.h.
| #define NETEVENT_CLOSED -1 |
to pass closed connection to callback function
Definition at line 82 of file netevent.h.
| #define NETEVENT_DONE -4 |
to pass done transfer to callback function; http file is complete
Definition at line 88 of file netevent.h.
| #define NETEVENT_NOERROR 0 |
to pass no_error to callback function
Definition at line 80 of file netevent.h.
| #define NETEVENT_SLOW_ACCEPT_TIME 2000 |
timeout to slow accept calls when not possible, in msec.
Definition at line 91 of file netevent.h.
| #define NETEVENT_TIMEOUT -2 |
to pass timeout happened to callback function
Definition at line 84 of file netevent.h.
| typedef int comm_point_callback_type(struct comm_point *, void *, int, struct comm_reply *) |
callback from communication point function type
Definition at line 76 of file netevent.h.
| struct comm_base* comm_base_create | ( | int | sigs | ) |
Create a new comm base.
| sigs | if true it attempts to create a default loop for signal handling. |
| struct comm_base* comm_base_create_event | ( | struct ub_event_base * | base | ) |
Create comm base that uses the given ub_event_base (underlying pluggable event mechanism pointer).
| base | underlying pluggable event base. |
| void comm_base_delete | ( | struct comm_base * | b | ) |
Destroy a comm base. All comm points must have been deleted.
| b | the base to delete. |
| void comm_base_delete_no_base | ( | struct comm_base * | b | ) |
Delete comm base structure but not the underlying lib event base. All comm points must have been deleted.
| b | the base to delete. |
| void comm_base_dispatch | ( | struct comm_base * | b | ) |
Dispatch the comm base events.
| b | the communication to perform. |
| void comm_base_exit | ( | struct comm_base * | b | ) |
Exit from dispatch loop.
| b | the communication base that is in dispatch(). |
| void comm_base_handle_slow_accept | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. libevent callback for timeout on slow accept.
| fd | file descriptor. |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the comm_point structure. |
| struct ub_event_base* comm_base_internal | ( | struct comm_base * | b | ) |
Access internal data structure (for util/tube.c on windows)
| b | comm base |
| void comm_base_set_slow_accept_handlers | ( | struct comm_base * | b, |
| void(*)(void *) | stop_accept, | ||
| void(*)(void *) | start_accept, | ||
| void * | arg | ||
| ) |
Set the slow_accept mode handlers. You can not provide these if you do not perform accept() calls.
| b | comm base |
| stop_accept | function that stops listening to accept fds. |
| start_accept | function that resumes listening to accept fds. |
| arg | callback arg to pass to the functions. |
| void comm_base_timept | ( | struct comm_base * | b, |
| time_t ** | tt, | ||
| struct timeval ** | tv | ||
| ) |
Obtain two pointers. The pointers never change (until base_delete()). The pointers point to time values that are updated regularly.
| b | the communication base that will update the time values. |
| tt | pointer to time in seconds is returned. |
| tv | pointer to time in microseconds is returned. |
| void comm_point_close | ( | struct comm_point * | c | ) |
Close a comm point fd.
| c | comm point to close. |
| struct comm_point* comm_point_create_http_out | ( | struct comm_base * | base, |
| size_t | bufsize, | ||
| comm_point_callback_type * | callback, | ||
| void * | callback_arg, | ||
| struct sldns_buffer * | temp | ||
| ) |
Create an outgoing HTTP commpoint. No file descriptor is opened, left at -1.
| base | in which base to alloc the commpoint. |
| bufsize | size of buffer to create for handlers. |
| callback | callback function pointer for the handler. |
| callback_arg | will be passed to your callback function. |
| temp | sldns buffer, shared between other http_out commpoints, for temporary data when performing callbacks. |
| struct comm_point* comm_point_create_local | ( | struct comm_base * | base, |
| int | fd, | ||
| size_t | bufsize, | ||
| comm_point_callback_type * | callback, | ||
| void * | callback_arg | ||
| ) |
Create commpoint to listen to a local domain file descriptor.
| base | in which base to alloc the commpoint. |
| fd | file descriptor of open AF_UNIX socket set to listen nonblocking. |
| bufsize | size of buffer to create for handlers. |
| callback | callback function pointer for the handler. |
| callback_arg | will be passed to your callback function. |
| struct comm_point* comm_point_create_raw | ( | struct comm_base * | base, |
| int | fd, | ||
| int | writing, | ||
| comm_point_callback_type * | callback, | ||
| void * | callback_arg | ||
| ) |
Create commpoint to listen to a local domain pipe descriptor.
| base | in which base to alloc the commpoint. |
| fd | file descriptor. |
| writing | true if you want to listen to writes, false for reads. |
| callback | callback function pointer for the handler. |
| callback_arg | will be passed to your callback function. |
| struct comm_point* comm_point_create_tcp | ( | struct comm_base * | base, |
| int | fd, | ||
| int | num, | ||
| size_t | bufsize, | ||
| comm_point_callback_type * | callback, | ||
| void * | callback_arg | ||
| ) |
Create a TCP listener comm point. Calls malloc. Setups the structure with the parameters you provide. Also Creates TCP Handlers, pre allocated for you. Uses the parameters you provide.
| base | in which base to alloc the commpoint. |
| fd | file descriptor of open TCP socket set to listen nonblocking. |
| num | becomes max_tcp_count, the routine allocates that many tcp handler commpoints. |
| bufsize | size of buffer to create for handlers. |
| callback | callback function pointer for TCP handlers. |
| callback_arg | will be passed to your callback function. |
| struct comm_point* comm_point_create_tcp_out | ( | struct comm_base * | base, |
| size_t | bufsize, | ||
| comm_point_callback_type * | callback, | ||
| void * | callback_arg | ||
| ) |
Create an outgoing TCP commpoint. No file descriptor is opened, left at -1.
| base | in which base to alloc the commpoint. |
| bufsize | size of buffer to create for handlers. |
| callback | callback function pointer for the handler. |
| callback_arg | will be passed to your callback function. |
| struct comm_point* comm_point_create_udp | ( | struct comm_base * | base, |
| int | fd, | ||
| struct sldns_buffer * | buffer, | ||
| comm_point_callback_type * | callback, | ||
| void * | callback_arg | ||
| ) |
Create an UDP comm point. Calls malloc. setups the structure with the parameters you provide.
| base | in which base to alloc the commpoint. |
| fd | : file descriptor of open UDP socket. |
| buffer | shared buffer by UDP sockets from this thread. |
| callback | callback function pointer. |
| callback_arg | will be passed to your callback function. |
| struct comm_point* comm_point_create_udp_ancil | ( | struct comm_base * | base, |
| int | fd, | ||
| struct sldns_buffer * | buffer, | ||
| comm_point_callback_type * | callback, | ||
| void * | callback_arg | ||
| ) |
Create an UDP with ancillary data comm point. Calls malloc. Uses recvmsg instead of recv to get udp message. setups the structure with the parameters you provide.
| base | in which base to alloc the commpoint. |
| fd | : file descriptor of open UDP socket. |
| buffer | shared buffer by UDP sockets from this thread. |
| callback | callback function pointer. |
| callback_arg | will be passed to your callback function. |
| void comm_point_delete | ( | struct comm_point * | c | ) |
Close and deallocate (free) the comm point. If the comm point is a tcp-accept point, also its tcp-handler points are deleted.
| c | comm point to delete. |
| void comm_point_drop_reply | ( | struct comm_reply * | repinfo | ) |
Drop reply. Cleans up.
| repinfo | The reply info copied from a commpoint callback call. |
| size_t comm_point_get_mem | ( | struct comm_point * | c | ) |
Get size of memory used by comm point. For TCP handlers this includes subhandlers. For UDP handlers, this does not include the (shared) UDP buffer.
| c | commpoint. |
| void comm_point_http_handle_callback | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. handle libevent callback for tcp data comm point
| fd | file descriptor. |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the comm_point structure. |
| void comm_point_listen_for_rw | ( | struct comm_point * | c, |
| int | rd, | ||
| int | wr | ||
| ) |
Stop listening and start listening again for reading or writing.
| c | commpoint |
| rd | if true, listens for reading. |
| wr | if true, listens for writing. |
| void comm_point_local_handle_callback | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. libevent callback for AF_UNIX fds
| fd | file descriptor. |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the comm_point structure. |
| int comm_point_perform_accept | ( | struct comm_point * | c, |
| struct sockaddr_storage * | addr, | ||
| socklen_t * | addrlen | ||
| ) |
perform accept(2) with error checking.
| c | commpoint with accept fd. |
| addr | remote end returned here. |
| addrlen | length of remote end returned here. |
| void comm_point_raw_handle_callback | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. libevent callback for raw fd access.
| fd | file descriptor. |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the comm_point structure. |
| void comm_point_send_reply | ( | struct comm_reply * | repinfo | ) |
Send reply. Put message into commpoint buffer.
| repinfo | The reply info copied from a commpoint callback call. |
| int comm_point_send_udp_msg | ( | struct comm_point * | c, |
| struct sldns_buffer * | packet, | ||
| struct sockaddr * | addr, | ||
| socklen_t | addrlen | ||
| ) |
Send an udp message over a commpoint.
| c | commpoint to send it from. |
| packet | what to send. |
| addr | where to send it to. |
| addrlen | length of addr. |
| void comm_point_start_listening | ( | struct comm_point * | c, |
| int | newfd, | ||
| int | msec | ||
| ) |
Start listening again for input on the comm point.
| c | commpoint to enable again. |
| newfd | new fd, or -1 to leave fd be. |
| msec | timeout in milliseconds, or -1 for no (change to the) timeout. So seconds*1000. |
| void comm_point_stop_listening | ( | struct comm_point * | c | ) |
Stop listening for input on the commpoint. No callbacks will happen.
| c | commpoint to disable. The fd is not closed. |
| void comm_point_tcp_accept_callback | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. handle libevent callback for tcp accept comm point
| fd | file descriptor. |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the comm_point structure. |
| void comm_point_tcp_handle_callback | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. handle libevent callback for tcp data comm point
| fd | file descriptor. |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the comm_point structure. |
| void comm_point_udp_ancil_callback | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. handle libevent callback for udp ancillary data comm point.
| fd | file descriptor. |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the comm_point structure. |
| void comm_point_udp_callback | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. handle libevent callback for udp comm point.
| fd | file descriptor. |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the comm_point structure. |
| int comm_signal_bind | ( | struct comm_signal * | comsig, |
| int | sig | ||
| ) |
Bind signal struct to catch a signal. A signle comm_signal can be bound to multiple signals, calling comm_signal_bind multiple times.
| comsig | the communication point, with callback information. |
| sig | signal number. |
| void comm_signal_callback | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. handle libevent callback for signal comm.
| fd | file descriptor (used for the signal number). |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the internal commsignal structure. |
| struct comm_signal* comm_signal_create | ( | struct comm_base * | base, |
| void(*)(int, void *) | callback, | ||
| void * | cb_arg | ||
| ) |
Create a signal handler. Call signal_bind() later to bind to a signal.
| base | communication base to use. |
| callback | called when signal is caught. |
| cb_arg | user argument to callback |
| void comm_signal_delete | ( | struct comm_signal * | comsig | ) |
Delete the signal communication point.
| comsig | to delete. |
| void comm_timer_callback | ( | int | fd, |
| short | event, | ||
| void * | arg | ||
| ) |
This routine is published for checks and tests, and is only used internally. handle libevent callback for timer comm.
| fd | file descriptor (always -1). |
| event | event bits from libevent: EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. |
| arg | the comm_timer structure. |
| struct comm_timer* comm_timer_create | ( | struct comm_base * | base, |
| void(*)(void *) | cb, | ||
| void * | cb_arg | ||
| ) |
create timer. Not active upon creation.
| base | event handling base. |
| cb | callback function: void myfunc(void* myarg); |
| cb_arg | user callback argument. |
| void comm_timer_delete | ( | struct comm_timer * | timer | ) |
delete timer.
| timer | to delete. |
| void comm_timer_disable | ( | struct comm_timer * | timer | ) |
disable timer. Stops callbacks from happening.
| timer | to disable. |
| size_t comm_timer_get_mem | ( | struct comm_timer * | timer | ) |
Get size of memory used by comm timer.
| timer | the timer to examine. |
| int comm_timer_is_set | ( | struct comm_timer * | timer | ) |
see if timeout has been set to a value.
| timer | the timer to examine. |
| void comm_timer_set | ( | struct comm_timer * | timer, |
| struct timeval * | tv | ||
| ) |
reset timevalue for timer.
| timer | timer to (re)set. |
| tv | when the timer should activate. if NULL timer is disabled. |
| int tcp_connect_errno_needs_log | ( | struct sockaddr * | addr, |
| socklen_t | addrlen | ||
| ) |
see if errno for tcp connect has to be logged or not. This uses errno