Overview
Comment: | OFDNSResolver: Configurable timeout and retries |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
fb6ff94c5263b2f9815939df94a76ea4 |
User & Date: | js on 2018-08-13 21:22:30 |
Other Links: | manifest | tags |
Context
2018-08-13
| ||
21:37 | OFDNSResolver: Parse more options check-in: 0dc20b4226 user: js tags: trunk | |
21:22 | OFDNSResolver: Configurable timeout and retries check-in: fb6ff94c52 user: js tags: trunk | |
21:06 | OFDNSResolver: Reduce code size check-in: 5d169b2f58 user: js tags: trunk | |
Changes
Modified src/OFDNSResolver.h from [8f0a42e843] to [005150c49e].
︙ | ︙ | |||
73 74 75 76 77 78 79 80 81 82 83 84 85 86 | @interface OFDNSResolver: OFObject { OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC(OFString *) *) *_staticHosts; OFArray OF_GENERIC(OFString *) *_nameServers; OFString *_Nullable _localDomain; OFArray OF_GENERIC(OFString *) *_searchDomains; size_t _minNumberOfDotsInAbsoluteName; bool _usesTCP; of_time_interval_t _configReloadInterval; OFDate *_lastConfigReload; OFUDPSocket *_IPv4Socket; #ifdef OF_HAVE_IPV6 OFUDPSocket *_IPv6Socket; | > > | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | @interface OFDNSResolver: OFObject { OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC(OFString *) *) *_staticHosts; OFArray OF_GENERIC(OFString *) *_nameServers; OFString *_Nullable _localDomain; OFArray OF_GENERIC(OFString *) *_searchDomains; of_time_interval_t _timeout; unsigned int _maxRetries; size_t _minNumberOfDotsInAbsoluteName; bool _usesTCP; of_time_interval_t _configReloadInterval; OFDate *_lastConfigReload; OFUDPSocket *_IPv4Socket; #ifdef OF_HAVE_IPV6 OFUDPSocket *_IPv6Socket; |
︙ | ︙ | |||
110 111 112 113 114 115 116 117 118 119 120 121 122 123 | @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *localDomain; /*! * @brief The domains to search for queries for short names. */ @property (copy, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains; /*! * @brief The minimum number of dots for a name to be considered absolute. */ @property (nonatomic) size_t minNumberOfDotsInAbsoluteName; /*! * @brief Whether the resolver uses TCP to talk to a name server. | > > > > > > > > > > > > > | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *localDomain; /*! * @brief The domains to search for queries for short names. */ @property (copy, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains; /*! * @brief The timeout, in seconds, after which the next name server should be * tried. */ @property (nonatomic) of_time_interval_t timeout; /*! * @brief The number of retries after which to give up resolving a host. * * Trying all name servers once is considered a single retry. */ @property (nonatomic) unsigned int maxRetries; /*! * @brief The minimum number of dots for a name to be considered absolute. */ @property (nonatomic) size_t minNumberOfDotsInAbsoluteName; /*! * @brief Whether the resolver uses TCP to talk to a name server. |
︙ | ︙ |
Modified src/OFDNSResolver.m from [b4efbde4c5] to [30c75fb63e].
︙ | ︙ | |||
53 54 55 56 57 58 59 | * RFC 1035 doesn't specify if pointers to pointers are allowed, and if so how * many. Since it's unspecified, we have to assume that it might happen, but we * also want to limit it to avoid DoS. Limiting it to 16 levels of pointers and * immediately rejecting pointers to itself seems like a fair balance. */ #define MAX_ALLOWED_POINTERS 16 | < < < | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | * RFC 1035 doesn't specify if pointers to pointers are allowed, and if so how * many. Since it's unspecified, we have to assume that it might happen, but we * also want to limit it to avoid DoS. Limiting it to 16 levels of pointers and * immediately rejecting pointers to itself seems like a fair balance. */ #define MAX_ALLOWED_POINTERS 16 #if defined(OF_HAIKU) # define HOSTS_PATH @"/system/settings/network/hosts" # define RESOLV_CONF_PATH @"/system/settings/network/resolv.conf" #elif defined(OF_MORPHOS) # define HOSTS_PATH @"ENV:sys/net/hosts" # define RESOLV_CONF_PATH @"ENV:sys/net/resolv.conf" #elif defined(OF_AMIGAOS4) |
︙ | ︙ | |||
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | @public OFString *_host, *_domainName; of_dns_resource_record_class_t _recordClass; of_dns_resource_record_type_t _recordType; OFNumber *_ID; OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains; size_t _nameServersIndex, _searchDomainsIndex; size_t _attempt; id _target; SEL _selector; id _context; OFData *_queryData; OFTimer *_cancelTimer; } - (instancetype)initWithHost: (OFString *)host domainName: (OFString *)domainName recordClass: (of_dns_resource_record_class_t)recordClass recordType: (of_dns_resource_record_type_t)recordType ID: (OFNumber *)ID nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains target: (id)target selector: (SEL)selector context: (id)context; @end @interface OFDNSResolver () - (void)of_parseConfig; #ifdef OF_HAVE_FILES - (void)of_parseHosts: (OFString *)path; # ifndef OF_WINDOWS - (void)of_parseResolvConf: (OFString *)path; - (void)of_parseResolvConfOption: (OFString *)option; # endif | > > > > > | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | @public OFString *_host, *_domainName; of_dns_resource_record_class_t _recordClass; of_dns_resource_record_type_t _recordType; OFNumber *_ID; OFArray OF_GENERIC(OFString *) *_nameServers, *_searchDomains; size_t _nameServersIndex, _searchDomainsIndex; of_time_interval_t _timeout; unsigned int _maxRetries; size_t _attempt; id _target; SEL _selector; id _context; OFData *_queryData; OFTimer *_cancelTimer; } - (instancetype)initWithHost: (OFString *)host domainName: (OFString *)domainName recordClass: (of_dns_resource_record_class_t)recordClass recordType: (of_dns_resource_record_type_t)recordType ID: (OFNumber *)ID nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains timeout: (of_time_interval_t)timeout maxRetries: (unsigned int)maxRetries target: (id)target selector: (SEL)selector context: (id)context; @end @interface OFDNSResolver () - (void)of_setDefaults; - (void)of_parseConfig; #ifdef OF_HAVE_FILES - (void)of_parseHosts: (OFString *)path; # ifndef OF_WINDOWS - (void)of_parseResolvConf: (OFString *)path; - (void)of_parseResolvConfOption: (OFString *)option; # endif |
︙ | ︙ | |||
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | - (instancetype)initWithHost: (OFString *)host domainName: (OFString *)domainName recordClass: (of_dns_resource_record_class_t)recordClass recordType: (of_dns_resource_record_type_t)recordType ID: (OFNumber *)ID nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains target: (id)target selector: (SEL)selector context: (id)context { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableData *queryData; uint16_t tmp; _host = [host copy]; _domainName = [domainName copy]; _recordClass = recordClass; _recordType = recordType; _ID = [ID retain]; _nameServers = [nameServers copy]; _searchDomains = [searchDomains copy]; _target = [target retain]; _selector = selector; _context = [context retain]; queryData = [OFMutableData dataWithCapacity: 512]; /* Header */ | > > > > | 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | - (instancetype)initWithHost: (OFString *)host domainName: (OFString *)domainName recordClass: (of_dns_resource_record_class_t)recordClass recordType: (of_dns_resource_record_type_t)recordType ID: (OFNumber *)ID nameServers: (OFArray OF_GENERIC(OFString *) *)nameServers searchDomains: (OFArray OF_GENERIC(OFString *) *)searchDomains timeout: (of_time_interval_t)timeout maxRetries: (unsigned int)maxRetries target: (id)target selector: (SEL)selector context: (id)context { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableData *queryData; uint16_t tmp; _host = [host copy]; _domainName = [domainName copy]; _recordClass = recordClass; _recordType = recordType; _ID = [ID retain]; _nameServers = [nameServers copy]; _searchDomains = [searchDomains copy]; _timeout = timeout; _maxRetries = maxRetries; _target = [target retain]; _selector = selector; _context = [context retain]; queryData = [OFMutableData dataWithCapacity: 512]; /* Header */ |
︙ | ︙ | |||
628 629 630 631 632 633 634 635 636 637 638 639 640 641 | [super dealloc]; } @end @implementation OFDNSResolver @synthesize staticHosts = _staticHosts, nameServers = _nameServers; @synthesize localDomain = _localDomain, searchDomains = _searchDomains; @synthesize minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName; @synthesize usesTCP = _usesTCP, configReloadInterval = _configReloadInterval; + (instancetype)resolver { return [[[self alloc] init] autorelease]; } | > | 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | [super dealloc]; } @end @implementation OFDNSResolver @synthesize staticHosts = _staticHosts, nameServers = _nameServers; @synthesize localDomain = _localDomain, searchDomains = _searchDomains; @synthesize timeout = _timeout, maxRetries = _maxRetries; @synthesize minNumberOfDotsInAbsoluteName = _minNumberOfDotsInAbsoluteName; @synthesize usesTCP = _usesTCP, configReloadInterval = _configReloadInterval; + (instancetype)resolver { return [[[self alloc] init] autorelease]; } |
︙ | ︙ | |||
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | } @catch (id e) { [self release]; @throw e; } return self; } - (void)of_parseConfig { void *pool = objc_autoreleasePoolPush(); #ifdef OF_WINDOWS OFString *path; #endif | > > > > > > > > > < < < < | 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 | } @catch (id e) { [self release]; @throw e; } return self; } - (void)of_setDefaults { _timeout = 2; _maxRetries = 3; _minNumberOfDotsInAbsoluteName = 1; _usesTCP = false; _configReloadInterval = 2; } - (void)of_parseConfig { void *pool = objc_autoreleasePoolPush(); #ifdef OF_WINDOWS OFString *path; #endif #if defined(OF_WINDOWS) # ifdef OF_HAVE_FILES path = [[OFWindowsRegistryKey localMachineKey] stringForValue: @"DataBasePath" subKeyPath: @"SYSTEM\\CurrentControlSet\\Services\\" @"Tcpip\\Parameters"]; path = [path stringByAppendingPathComponent: @"hosts"]; |
︙ | ︙ | |||
972 973 974 975 976 977 978 | [_localDomain release]; _localDomain = nil; [_searchDomains release]; _searchDomains = nil; | < | < | 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 | [_localDomain release]; _localDomain = nil; [_searchDomains release]; _searchDomains = nil; [self of_setDefaults]; [_lastConfigReload release]; _lastConfigReload = nil; [self of_parseConfig]; } |
︙ | ︙ | |||
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | initWithHost: host domainName: domainName recordClass: recordClass recordType: recordType ID: ID nameServers: _nameServers searchDomains: _searchDomains target: target selector: selector context: context] autorelease]; [_queries setObject: query forKey: ID]; [self of_sendQuery: query]; objc_autoreleasePoolPop(pool); } - (void)of_sendQuery: (OFDNSResolverQuery *)query { of_socket_address_t address; OFUDPSocket *sock; [query->_cancelTimer invalidate]; [query->_cancelTimer release]; query->_cancelTimer = nil; query->_cancelTimer = [[OFTimer | > > | | 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 | initWithHost: host domainName: domainName recordClass: recordClass recordType: recordType ID: ID nameServers: _nameServers searchDomains: _searchDomains timeout: _timeout maxRetries: _maxRetries target: target selector: selector context: context] autorelease]; [_queries setObject: query forKey: ID]; [self of_sendQuery: query]; objc_autoreleasePoolPop(pool); } - (void)of_sendQuery: (OFDNSResolverQuery *)query { of_socket_address_t address; OFUDPSocket *sock; [query->_cancelTimer invalidate]; [query->_cancelTimer release]; query->_cancelTimer = nil; query->_cancelTimer = [[OFTimer scheduledTimerWithTimeInterval: query->_timeout target: self selector: @selector(of_queryWithIDTimedOut:) object: query repeats: false] retain]; address = of_socket_address_parse_ip( [query->_nameServers objectAtIndex: query->_nameServersIndex], 53); |
︙ | ︙ | |||
1109 1110 1111 1112 1113 1114 1115 | if (query->_nameServersIndex + 1 < [query->_nameServers count]) { query->_nameServersIndex++; [self of_sendQuery: query]; return; } | | | 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 | if (query->_nameServersIndex + 1 < [query->_nameServers count]) { query->_nameServersIndex++; [self of_sendQuery: query]; return; } if (query->_attempt < query->_maxRetries) { query->_attempt++; query->_nameServersIndex = 0; [self of_sendQuery: query]; return; } query = [[query retain] autorelease]; |
︙ | ︙ |