ObjFW  Check-in [42cb3d287c]

Overview
Comment:OFDNSResolver: Multiple attempts for resolving
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 42cb3d287c969afa2ade364951cb5d9c9670e3e414c126b00d051f520b317347
User & Date: js on 2018-08-12 01:12:42
Other Links: manifest | tags
Context
2018-08-12
12:37
OFDNSResolver: Parse authority and additional RRs check-in: 6305a0c7a4 user: js tags: trunk
01:12
OFDNSResolver: Multiple attempts for resolving check-in: 42cb3d287c user: js tags: trunk
2018-08-11
21:53
Fix build on 3DS and Wii check-in: 9a494f183b user: js tags: trunk
Changes

Modified src/OFDNSResolver.m from [4bcaef27d1] to [f296db2c83].

53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100







+
















+















+







 * 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

#define TIMEOUT 2
#define ATTEMPTS 3

/*
 * TODO:
 *
 *  - Resolve with each search domain
 *  - Fallback to TCP
 */

@interface OFDNSResolverQuery: OFObject
{
	OFString *_host;
	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;
}

@property (readonly, nonatomic) OFString *host;
@property (readonly, nonatomic) of_dns_resource_record_class_t recordClass;
@property (readonly, nonatomic) of_dns_resource_record_type_t recordType;
@property (readonly, nonatomic) OFNumber *ID;
@property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *nameServers;
@property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains;
@property (nonatomic) size_t nameServersIndex;
@property (nonatomic) size_t searchDomainsIndex;
@property (nonatomic) size_t attempt;
@property (readonly, nonatomic) id target;
@property (readonly, nonatomic) SEL selector;
@property (readonly, nonatomic) id context;
@property (readonly, nonatomic) OFData *queryData;
@property (retain, nonatomic) OFTimer *cancelTimer;

- (instancetype)initWithHost: (OFString *)host
466
467
468
469
470
471
472
473
474
475



476
477
478
479
480
481
482
469
470
471
472
473
474
475



476
477
478
479
480
481
482
483
484
485







-
-
-
+
+
+







}

@implementation OFDNSResolverQuery
@synthesize host = _host, recordClass = _recordClass, recordType = _recordType;
@synthesize ID = _ID, nameServers = _nameServers;
@synthesize searchDomains = _searchDomains;
@synthesize nameServersIndex = _nameServersIndex;
@synthesize searchDomainsIndex = _searchDomainsIndex, target = _target;
@synthesize selector = _selector, context = _context, queryData = _queryData;
@synthesize cancelTimer = _cancelTimer;
@synthesize searchDomainsIndex = _searchDomainsIndex, attempt = _attempt;
@synthesize target = _target, selector = _selector, context = _context;
@synthesize queryData = _queryData, cancelTimer = _cancelTimer;

- (instancetype)initWithHost: (OFString *)host
		 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
1022
1023
1024
1025
1026
1027
1028







1029
1030
1031
1032
1033
1034
1035
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045







+
+
+
+
+
+
+







		return;

	if ([query nameServersIndex] + 1 < [[query nameServers] count]) {
		[query setNameServersIndex: [query nameServersIndex] + 1];
		[self of_sendQuery: query];
		return;
	}

	if ([query attempt] < ATTEMPTS) {
		[query setAttempt: [query attempt] + 1];
		[query setNameServersIndex: 0];
		[self of_sendQuery: query];
		return;
	}

	target = [[[query target] retain] autorelease];
	selector = [query selector];
	callback = (void (*)(id, SEL, OFArray *, id, id))
	    [target methodForSelector: selector];

	exception = [OFResolveHostFailedException