⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resolver.h

📁 基于sip协议的网络电话源码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* $Id: resolver.h 974 2007-02-19 01:13:53Z bennylp $ *//*  * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  */#ifndef __PJLIB_UTIL_RESOLVER_H__#define __PJLIB_UTIL_RESOLVER_H__/** * @file resolver.h * @brief Asynchronous DNS resolver */#include <pjlib-util/dns.h>PJ_BEGIN_DECL/** * @defgroup PJ_DNS_RESOLVER DNS Asynchronous/Caching Resolution Engine * @ingroup PJ_DNS * @{ * * This module manages the host/server resolution by performing asynchronous * DNS queries and caching the results in the cache. It uses PJLIB-UTIL  * low-level DNS parsing functions (see @ref PJ_DNS) and currently supports * several types of DNS resource records such as A record (typical query with * gethostbyname()) and SRV record. * * \section PJ_DNS_RESOLVER_FEATURES Features * * \subsection PJ_DNS_RESOLVER_FEATURES_ASYNC Asynchronous Query and Query Aggregation *  * The DNS queries are performed asychronously, with timeout setting  * configured on per resolver instance basis. Application can issue multiple * asynchronous queries simultaneously. Subsequent queries to the same resource * (name and DNS resource type) while existing query is still pending will be * merged into one query, so that only one DNS request packet is issued. *  * \subsection PJ_DNS_RESOLVER_FEATURES_RETRANSMISSION Query Retransmission * * Asynchronous query will be retransmitted if no response is received * within the preconfigured time. Once maximum retransmission count is * exceeded and no response is received, the query will time out and the * callback will be called when error status. * * \subsection PJ_DNS_RESOLVER_FEATURES_CACHING Response Caching with TTL * * The resolver instance caches the results returned by nameservers, to * enhance the performance by minimizing the message round-trip to the server. * The TTL of the cached resposne is calculated from minimum TTL value found  * across all resource record (RR) TTL in the response and further more it can * be limited to some preconfigured maximum TTL in the resolver.  * * Response caching can be  disabled by setting the maximum TTL value of the  * resolver to zero. * * \subsection PJ_DNS_RESOLVER_FEATURES_PARALLEL Parallel and Backup Name Servers * * When the resolver is configured with multiple nameservers, initially the * queries will be issued to multiple name servers simultaneously to probe * which servers are not active. Once the probing stage is done, subsequent  * queries will be directed to only one ACTIVE server which provides the best * response time. * * Name servers are probed periodically to see which nameservers are active * and which are down. This probing is done when a query is sent, thus no * timer is needed to maintain this. Also probing will be done in parallel * so that there would be no additional delay for the query. * * * \subsection PJ_DNS_RESOLVER_FEATURES_REC Supported Resource Records * * The low-level DNS parsing utility (see @ref PJ_DNS) supports parsing of * the following DNS resource records (RR): *  - DNS A record *  - DNS SRV record *  - DNS PTR record *  - DNS NS record *  - DNS CNAME record * * For other types of record, application can parse the raw resource  * record data (rdata) from the parsed DNS packet (#pj_dns_parsed_packet). * * * \section PJ_DNS_RESOLVER_USING Using the Resolver * * To use the resolver, application first creates the resolver instance by * calling #pj_dns_resolver_create(). If application already has its own * timer and ioqueue instances, it can instruct the resolver to use these * instances so that application does not need to poll the resolver  * periodically to process events. If application does not specify the * timer and ioqueue instance for the resolver, an internal timer and * ioqueue will be created by the resolver. And since the resolver does not * create it's own thread, application MUST poll the resolver periodically * by calling #pj_dns_resolver_handle_events() to allow events (network and  * timer) to be processed. * * Next, application MUST configure the nameservers to be used by the * resolver, by calling #pj_dns_resolver_set_ns(). * * Application performs asynchronous query by submitting the query with * #pj_dns_resolver_start_query(). Once the query completes (either  * successfully or times out), the callback will be called. * * Application can cancel a pending query by calling #pj_dns_resolver_cancel_query(). * * Resolver must be destroyed by calling #pj_dns_resolver_destroy() to * release all resources back to the system. * * * \section PJ_DNS_RESOLVER_LIMITATIONS Resolver Limitations * * Current implementation mainly suffers from a growing memory problem, * which mainly is caused by the response caching. Although there is only * one cache entry per {query, name} combination, these cache entry will * never get deleted since there is no timer is created to invalidate these * entries. So the more unique names being queried by application, there more * enties will be created in the response cache. * * Note that a single response entry will occupy about 600-700 bytes of  * pool memory (the PJ_DNS_RESOLVER_RES_BUF_SIZE value plus internal * structure).  * * Application can work around this problem by doing one of these: *  - disable caching by setting PJ_DNS_RESOLVER_MAX_TTL and  *    PJ_DNS_RESOLVER_INVALID_TTL to zero. *  - periodically query #pj_dns_resolver_get_cached_count() and destroy- *    recreate the resolver to recycle the memory used by the resolver. * * Note that future improvement may solve this problem by introducing  * expiration timer to the cached entries. * * * \section PJ_DNS_RESOLVER_REFERENCE Reference * * The PJLIB-UTIL resolver was built from the information in the following * standards: *  - <A HREF="http://www.faqs.org/rfcs/rfc1035.html"> *    RFC 1035: "Domain names - implementation and specification"</A> *  - <A HREF="http://www.faqs.org/rfcs/rfc2782.html"> *    RFC 2782: "A DNS RR for specifying the location of services (DNS SRV)" *    </A> *//** * Opaque data type for DNS resolver object. */typedef struct pj_dns_resolver pj_dns_resolver;/** * Opaque data type for asynchronous DNS query object. */typedef struct pj_dns_async_query pj_dns_async_query;/** * Type of asynchronous callback which will be called when the asynchronous * query completes. * * @param user_data	The user data set by application when creating the *			asynchronous query. * @param status	Status of the DNS resolution. * @param response	The response packet received from the server. This *			argument may be NULL when status is not PJ_SUCCESS. */typedef void pj_dns_callback(void *user_data,			     pj_status_t status,			     pj_dns_parsed_packet *response);/** * This structure describes resolver settings. */typedef struct pj_dns_settings{    unsigned	options;	/**< Options flags.			    */    unsigned	qretr_delay;	/**< Query retransmit delay in msec.	    */    unsigned	qretr_count;	/**< Query maximum retransmission count.    */    unsigned	cache_max_ttl;	/**< Maximum TTL for cached responses. If the				     value is zero, caching is disabled.    */} pj_dns_settings;/** * Create DNS resolver instance. After the resolver is created, application * MUST configure the nameservers with #pj_dns_resolver_set_ns(). * * When creating the resolver, application may specify both timer heap * and ioqueue instance, so that it doesn't need to poll the resolver * periodically. *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -