Changeset 1348


Ignore:
Timestamp:
Jun 7, 2007 3:47:31 PM (12 years ago)
Author:
bennylp
Message:

Another ticket #325: More tunable settings in DNS resolver

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c

    r1323 r1348  
    6363}; 
    6464 
     65static const char *state_names[3] = 
     66{ 
     67    "Probing", 
     68    "Active", 
     69    "Bad" 
     70}; 
     71 
     72 
    6573/*  
    6674 * Each nameserver entry. 
     
    217225 
    218226 
     227/* Initialize DNS settings with default values */ 
     228PJ_DEF(void) pj_dns_settings_default(pj_dns_settings *s) 
     229{ 
     230    pj_bzero(s, sizeof(pj_dns_settings)); 
     231    s->qretr_delay = PJ_DNS_RESOLVER_QUERY_RETRANSMIT_DELAY; 
     232    s->qretr_count = PJ_DNS_RESOLVER_QUERY_RETRANSMIT_COUNT; 
     233    s->cache_max_ttl = PJ_DNS_RESOLVER_MAX_TTL; 
     234    s->good_ns_ttl = PJ_DNS_RESOLVER_GOOD_NS_TTL; 
     235    s->bad_ns_ttl = PJ_DNS_RESOLVER_BAD_NS_TTL; 
     236} 
     237 
     238 
    219239/* 
    220240 * Create the resolver. 
     
    258278    resv->ioqueue = ioqueue; 
    259279    resv->last_id = 1; 
     280 
     281    pj_dns_settings_default(&resv->settings); 
    260282    resv->settings.options = options; 
    261     resv->settings.qretr_delay = PJ_DNS_RESOLVER_QUERY_RETRANSMIT_DELAY; 
    262     resv->settings.qretr_count = PJ_DNS_RESOLVER_QUERY_RETRANSMIT_COUNT; 
    263     resv->settings.cache_max_ttl = PJ_DNS_RESOLVER_MAX_TTL; 
    264283 
    265284    /* Create the timer heap if one is not specified */ 
     
    791810{ 
    792811    struct nameserver *ns = &resolver->ns[index]; 
     812    enum ns_state old_state = ns->state; 
    793813 
    794814    ns->state = state; 
     
    796816 
    797817    if (state == STATE_PROBING) 
    798         ns->state_expiry.sec += ((PJ_DNS_RESOLVER_QUERY_RETRANSMIT_COUNT + 2) * 
    799                                  PJ_DNS_RESOLVER_QUERY_RETRANSMIT_DELAY) / 1000; 
     818        ns->state_expiry.sec += ((resolver->settings.qretr_count + 2) * 
     819                                 resolver->settings.qretr_delay) / 1000; 
    800820    else if (state == STATE_ACTIVE) 
    801         ns->state_expiry.sec += PJ_DNS_RESOLVER_GOOD_NS_TTL; 
     821        ns->state_expiry.sec += resolver->settings.good_ns_ttl; 
    802822    else 
    803         ns->state_expiry.sec += PJ_DNS_RESOLVER_BAD_NS_TTL; 
    804  
     823        ns->state_expiry.sec += resolver->settings.bad_ns_ttl; 
     824 
     825    PJ_LOG(5, (resolver->name.ptr, "Nameserver %s:%d state changed %s --> %s", 
     826               pj_inet_ntoa(ns->addr.sin_addr), 
     827               (int)pj_ntohs(ns->addr.sin_port), 
     828               state_names[old_state], state_names[state])); 
    805829} 
    806830 
     
    10711095 
    10721096    /* Check to see if we should retransmit instead of time out */ 
    1073     if (q->transmit_cnt < PJ_DNS_RESOLVER_QUERY_RETRANSMIT_COUNT) { 
     1097    if (q->transmit_cnt < resolver->settings.qretr_count) { 
    10741098        status = transmit_query(resolver, q); 
    10751099        if (status == PJ_SUCCESS) { 
     
    12041228    if (!q) { 
    12051229        PJ_LOG(5,(resolver->name.ptr,  
    1206                   "Unable to find query for DNS response id=%d from %s:%d " 
    1207                   "(the query may had been answered by other name servers)", 
    1208                   (unsigned)dns_pkt->hdr.id, 
     1230                  "DNS response from %s:%d id=%d discarded", 
    12091231                  pj_inet_ntoa(resolver->udp_src_addr.sin_addr),  
    1210                   pj_ntohs(resolver->udp_src_addr.sin_port))); 
     1232                  pj_ntohs(resolver->udp_src_addr.sin_port), 
     1233                  (unsigned)dns_pkt->hdr.id)); 
    12111234        goto read_next_packet; 
    12121235    } 
Note: See TracChangeset for help on using the changeset viewer.