#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_query |
struct | adns_async_write |
struct | adns_cache_entry |
struct | adns_cache_struct |
Defines | |
#define | ADNS_CACHE_TIMEOUT (5 * 60) |
Cache entries will expire after ADNS_CACHE_TIMEOUT seconds. | |
#define | ADNS_CACHED_NUM (1024) |
Cache max. | |
#define | ADNS_PROCESS_TITLE "DNS helper for gtk-gnutella" |
#define | CLOSE_IF_VALID(fd) |
Private macros. | |
Typedefs | |
typedef adns_query | adns_query_t |
typedef adns_async_write | adns_async_write_t |
typedef adns_cache_entry | adns_cache_entry_t |
typedef adns_cache_struct | adns_cache_t |
Functions | |
RCSID ("$Id:adns.c, v 1.27 2005/12/17 10:37:15 cbiere Exp $") | |
adns_cache_t * | adns_cache_init (void) |
Private functions. | |
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 addr) |
Adds ``hostname'' and ``addr'' to the cache. | |
gboolean | adns_cache_lookup (adns_cache_t *cache, time_t now, const gchar *hostname, host_addr_t *addr) |
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 adns_query_t *query, adns_query_t *reply) |
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 (adns_query_t *reply) |
void | adns_fallback (const adns_query_t *query) |
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_callback (gpointer data, gint source, inputevt_cond_t condition) |
Callback function for inputevt_add(). | |
adns_async_write_t * | adns_async_write_alloc (const adns_query_t *query, size_t n) |
Allocate a the "spill" buffer for the query, with `n' bytes being already written into the pipe. | |
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_query (const adns_query_t *query) |
gboolean | adns_resolve (const gchar *hostname, 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 |
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 entries will expire after ADNS_CACHE_TIMEOUT seconds.
|
|
Cache max. ADNS_CACHED_NUM of adns_cache_entry_t entries. |
|
|
|
Value: do { \ if (-1 != (fd)) { \ close(fd); \ fd = -1; \ } \ } while(0)
|
|
|
|
|
|
|
|
|
|
Allocate a the "spill" buffer for the query, with `n' bytes being already written into the pipe. The query is cloned. |
|
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.
|
|
|
|
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?
|