#include "common.h"
#include "adns.h"
#include "atoms.h"
#include "inputevt.h"
#include "misc.h"
#include "glib-missing.h"
#include "tm.h"
#include "walloc.h"
#include "socket.h"
#include "override.h"
Data Structures | |
| struct | adns_common |
| struct | adns_reverse_query |
| struct | adns_query |
| struct | adns_reply |
| struct | adns_reverse_reply |
| struct | adns_request |
| struct | adns_response |
| struct | adns_async_write |
| struct | adns_cache_entry |
| struct | adns_cache_struct |
Defines | |
| #define | ADNS_CACHE_TIMEOUT (60) |
| Cache entries will expire after ADNS_CACHE_TIMEOUT seconds. | |
| #define | ADNS_CACHE_MAX_SIZE (1024) |
| Cache max. | |
| #define | CLOSE_IF_VALID(fd) |
| Private macros. | |
Typedefs | |
| typedef adns_async_write | adns_async_write_t |
| typedef adns_cache_entry | adns_cache_entry_t |
| typedef adns_cache_struct | adns_cache_t |
Functions | |
| size_t | adns_cache_entry_size (size_t n) |
| size_t | count_addrs (const host_addr_t *addrs, size_t m) |
| adns_cache_t * | adns_cache_init (void) |
| Private functions. | |
| adns_cache_entry_t * | adns_cache_get_entry (adns_cache_t *cache, guint i) |
| void | adns_cache_free_entry (adns_cache_t *cache, guint i) |
| void | adns_cache_free (adns_cache_t *cache) |
| Frees all memory allocated by the cache and returns NULL. | |
| void | adns_cache_add (adns_cache_t *cache, time_t now, const gchar *hostname, const host_addr_t *addrs, size_t n) |
| Adds ``hostname'' and ``addr'' to the cache. | |
| size_t | adns_cache_lookup (adns_cache_t *cache, time_t now, const gchar *hostname, host_addr_t *addrs, size_t n) |
| Looks for ``hostname'' in ``cache'' wrt to cache->timeout. | |
| gboolean | adns_do_transfer (gint fd, gpointer buf, size_t len, gboolean do_write) |
| Transfers the data in `buf' of size `len' through `fd'. | |
| gboolean | adns_do_read (gint fd, gpointer buf, size_t len) |
| Read the complete buffer ``buf'' of size ``len'' from file descriptor ``fd''. | |
| gboolean | adns_do_write (gint fd, gpointer buf, size_t len) |
| Write the complete buffer ``buf'' of size ``len'' to file descriptor ``fd''. | |
| void | adns_gethostbyname (const struct adns_request *req, struct adns_response *ans) |
| Copies user_callback and user_data from the query buffer to the reply buffer. | |
| void | adns_helper (gint fd_in, gint fd_out) |
| The ``main'' function of the adns helper process (server). | |
| void | adns_invoke_user_callback (const struct adns_response *ans) |
| void | adns_fallback (const struct adns_request *req) |
| Handles the query in synchronous (blocking) mode and is used if the dns helper is busy i.e., the pipe buffer is full or in case the dns helper is dead. | |
| void | adns_reply_ready (const struct adns_response *ans) |
| void | adns_reply_callback (gpointer data, gint source, inputevt_cond_t condition) |
| Callback function for inputevt_add(). | |
| adns_async_write_t * | adns_async_write_alloc (const struct adns_request *req, gconstpointer buf, size_t size) |
| Allocate a "spill" buffer of size `size'. | |
| void | adns_async_write_free (adns_async_write_t *remain) |
| Dispose of the "spill" buffer. | |
| void | adns_query_callback (gpointer data, gint dest, inputevt_cond_t condition) |
| Callback function for inputevt_add(). | |
| void | adns_init (void) |
| Initializes the adns helper i.e., fork()s a child process which will be used to resolve hostnames asynchronously. | |
| gboolean | adns_send_request (const struct adns_request *req) |
| gboolean | adns_resolve (const gchar *hostname, enum net_type net, adns_callback_t user_callback, gpointer user_data) |
| Creates a DNS resolve query for ``hostname''. | |
| gboolean | adns_reverse_lookup (const host_addr_t addr, adns_reverse_callback_t user_callback, gpointer user_data) |
| Creates a DNS reverse lookup query for ``addr''. | |
| void | adns_close (void) |
| Removes the callback and frees the cache. | |
Variables | |
| guint32 | common_dbg = 0 |
| const gchar | adns_process_title [] = "DNS helper for gtk-gnutella" |
| adns_cache_t * | adns_cache = NULL |
| gint | adns_query_fd = -1 |
| guint | adns_query_event_id = 0 |
| guint | adns_reply_event_id = 0 |
| gboolean | is_helper = FALSE |
| Are we the DNS helper process? | |
|
|
Cache max. ADNS_CACHE_SIZE of adns_cache_entry_t entries. |
|
|
Cache entries will expire after ADNS_CACHE_TIMEOUT seconds.
|
|
|
Value: do { \ if (-1 != (fd)) { \ close(fd); \ fd = -1; \ } \ } while(0)
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||||
|
Allocate a "spill" buffer of size `size'.
|
|
|
Dispose of the "spill" buffer.
|
|
||||||||||||||||||||||||
|
Adds ``hostname'' and ``addr'' to the cache. The cache is implemented as a wrap-around FIFO. In case it's full, the oldest entry will be overwritten. |
|
|
|
|
|
Frees all memory allocated by the cache and returns NULL.
|
|
||||||||||||
|
|
|
||||||||||||
|
|
|
|
Private functions.
|
|
||||||||||||||||||||||||
|
Looks for ``hostname'' in ``cache'' wrt to cache->timeout. If ``hostname'' is not found or the entry is expired, FALSE will be returned. Expired entries will be removed! ``addr'' is allowed to be NULL, otherwise the cached IP will be stored into the variable ``addr'' points to.
|
|
|
Removes the callback and frees the cache.
|
|
||||||||||||||||
|
Read the complete buffer ``buf'' of size ``len'' from file descriptor ``fd''.
|
|
||||||||||||||||||||
|
Transfers the data in `buf' of size `len' through `fd'. If `do_write' is FALSE the buffer will be filled from `fd'. Otherwise, the data from the buffer will be written to `fd'. The function returns only if all data has been transferred or if an unrecoverable error occurs. This function should only be used with a blocking `fd'. |
|
||||||||||||||||
|
Write the complete buffer ``buf'' of size ``len'' to file descriptor ``fd''.
|
|
|
Handles the query in synchronous (blocking) mode and is used if the dns helper is busy i.e., the pipe buffer is full or in case the dns helper is dead.
|
|
||||||||||||
|
Copies user_callback and user_data from the query buffer to the reply buffer. This function won't fail. However, if gethostbyname() fails ``reply->addr'' will be set to zero. |
|
||||||||||||
|
The ``main'' function of the adns helper process (server). Simply reads requests (queries) from fd_in, performs a DNS lookup for it and writes the result to fd_out. All operations should be blocking. Exits in case of non-recoverable error during read or write. |
|
|
Initializes the adns helper i.e., fork()s a child process which will be used to resolve hostnames asynchronously. Close all standard FILEs so that they don't keep a reference to the log files when they are reopened by the main process on SIGHUP. This means there will be no visible messages from ADNS at all. |
|
|
|
|
||||||||||||||||
|
Callback function for inputevt_add(). This function pipes the query to the server using the pipe in non-blocking mode, partial writes are handled appropriately. In case of an unrecoverable error the query pipe will be closed and the blocking adns_fallback() will be invoked. |
|
||||||||||||||||
|
Callback function for inputevt_add(). This function invokes the callback function given in DNS query on the client-side i.e., gtk-gnutella itself. It handles partial reads if necessary. In case of an unrecoverable error the reply pipe will be closed and the callback will be lost. |
|
|
|
|
||||||||||||||||||||
|
Creates a DNS resolve query for ``hostname''. The given function ``user_callback'' (which MUST NOT be NULL) will be invoked with the resolved IP address and ``user_data'' as its parameters. The IP address 0.0.0.0 i.e., ``(guint32) 0'' is used to indicate a failure. In case the hostname is given as an IP string, it will be directly converted and the callback immediately invoked. If the adns helper process is ``out of service'' the query will be resolved synchronously.
|
|
||||||||||||||||
|
Creates a DNS reverse lookup query for ``addr''. The given function ``user_callback'' (which MUST NOT be NULL) will be invoked with the resolved hostname and ``user_data'' as its parameters. If the lookup failed, the callback will be invoked with ``hostname'' NULL. If the adns helper process is ``out of service'' the query will be processed synchronously.
|
|
|
|
|
||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Are we the DNS helper process?
|
1.3.9.1