︙ | | | ︙ | |
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
_exception = [exception retain];
[self didConnect];
return;
}
data = [OFData dataWithItems: "\x05\x01\x00" count: 3];
_SOCKS5State = OF_SOCKS5_STATE_SEND_AUTHENTICATION;
[_socket asyncWriteData: data
runLoopMode: [OFRunLoop currentRunLoop].currentMode];
}
- (bool)stream: (OFStream *)sock
didReadIntoBuffer: (void *)buffer
length: (size_t)length
|
|
|
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
_exception = [exception retain];
[self didConnect];
return;
}
data = [OFData dataWithItems: "\x05\x01\x00" count: 3];
_SOCKS5State = OFSOCKS5StateSendAuthentication;
[_socket asyncWriteData: data
runLoopMode: [OFRunLoop currentRunLoop].currentMode];
}
- (bool)stream: (OFStream *)sock
didReadIntoBuffer: (void *)buffer
length: (size_t)length
|
︙ | | | ︙ | |
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
[self didConnect];
return false;
}
runLoopMode = [OFRunLoop currentRunLoop].currentMode;
switch (_SOCKS5State) {
case OF_SOCKS5_STATE_READ_VERSION:
SOCKSVersion = buffer;
if (SOCKSVersion[0] != 5 || SOCKSVersion[1] != 0) {
_exception = [[OFConnectionFailedException alloc]
initWithHost: _host
port: _port
socket: self
|
|
|
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
[self didConnect];
return false;
}
runLoopMode = [OFRunLoop currentRunLoop].currentMode;
switch (_SOCKS5State) {
case OFSOCKS5StateReadVersion:
SOCKSVersion = buffer;
if (SOCKSVersion[0] != 5 || SOCKSVersion[1] != 0) {
_exception = [[OFConnectionFailedException alloc]
initWithHost: _host
port: _port
socket: self
|
︙ | | | ︙ | |
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
[_request addItem: &hostLength];
[_request addItems: _host.UTF8String count: hostLength];
port[0] = _port >> 8;
port[1] = _port & 0xFF;
[_request addItems: port count: 2];
_SOCKS5State = OF_SOCKS5_STATE_SEND_REQUEST;
[_socket asyncWriteData: _request runLoopMode: runLoopMode];
return false;
case OF_SOCKS5_STATE_READ_RESPONSE:
response = buffer;
if (response[0] != 5 || response[2] != 0) {
_exception = [[OFConnectionFailedException alloc]
initWithHost: _host
port: _port
socket: self
|
|
|
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
[_request addItem: &hostLength];
[_request addItems: _host.UTF8String count: hostLength];
port[0] = _port >> 8;
port[1] = _port & 0xFF;
[_request addItems: port count: 2];
_SOCKS5State = OFSOCKS5StateSendRequest;
[_socket asyncWriteData: _request runLoopMode: runLoopMode];
return false;
case OFSOCKS5StateReadResponse:
response = buffer;
if (response[0] != 5 || response[2] != 0) {
_exception = [[OFConnectionFailedException alloc]
initWithHost: _host
port: _port
socket: self
|
︙ | | | ︙ | |
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
[self didConnect];
return false;
}
/* Skip the rest of the response */
switch (response[3]) {
case 1: /* IPv4 */
_SOCKS5State = OF_SOCKS5_STATE_READ_ADDRESS;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 4 + 2
runLoopMode: runLoopMode];
return false;
case 3: /* Domain name */
_SOCKS5State = OF_SOCKS5_STATE_READ_ADDRESS_LENGTH;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 1
runLoopMode: runLoopMode];
return false;
case 4: /* IPv6 */
_SOCKS5State = OF_SOCKS5_STATE_READ_ADDRESS;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 16 + 2
runLoopMode: runLoopMode];
return false;
default:
_exception = [[OFConnectionFailedException alloc]
initWithHost: _host
port: _port
socket: self
errNo: EPROTONOSUPPORT];
[self didConnect];
return false;
}
return false;
case OF_SOCKS5_STATE_READ_ADDRESS:
[self didConnect];
return false;
case OF_SOCKS5_STATE_READ_ADDRESS_LENGTH:
addressLength = buffer;
_SOCKS5State = OF_SOCKS5_STATE_READ_ADDRESS;
[_socket asyncReadIntoBuffer: _buffer
exactLength: addressLength[0] + 2
runLoopMode: runLoopMode];
return false;
default:
assert(0);
return false;
|
|
|
|
|
|
|
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
[self didConnect];
return false;
}
/* Skip the rest of the response */
switch (response[3]) {
case 1: /* IPv4 */
_SOCKS5State = OFSOCKS5StateReadAddress;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 4 + 2
runLoopMode: runLoopMode];
return false;
case 3: /* Domain name */
_SOCKS5State = OFSOCKS5StateReadAddressLength;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 1
runLoopMode: runLoopMode];
return false;
case 4: /* IPv6 */
_SOCKS5State = OFSOCKS5StateReadAddress;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 16 + 2
runLoopMode: runLoopMode];
return false;
default:
_exception = [[OFConnectionFailedException alloc]
initWithHost: _host
port: _port
socket: self
errNo: EPROTONOSUPPORT];
[self didConnect];
return false;
}
return false;
case OFSOCKS5StateReadAddress:
[self didConnect];
return false;
case OFSOCKS5StateReadAddressLength:
addressLength = buffer;
_SOCKS5State = OFSOCKS5StateReadAddress;
[_socket asyncReadIntoBuffer: _buffer
exactLength: addressLength[0] + 2
runLoopMode: runLoopMode];
return false;
default:
assert(0);
return false;
|
︙ | | | ︙ | |
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
[self didConnect];
return nil;
}
runLoopMode = [OFRunLoop currentRunLoop].currentMode;
switch (_SOCKS5State) {
case OF_SOCKS5_STATE_SEND_AUTHENTICATION:
_SOCKS5State = OF_SOCKS5_STATE_READ_VERSION;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 2
runLoopMode: runLoopMode];
return nil;
case OF_SOCKS5_STATE_SEND_REQUEST:
[_request release];
_request = nil;
_SOCKS5State = OF_SOCKS5_STATE_READ_RESPONSE;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 4
runLoopMode: runLoopMode];
return nil;
default:
assert(0);
return nil;
}
}
@end
|
|
|
|
|
|
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
[self didConnect];
return nil;
}
runLoopMode = [OFRunLoop currentRunLoop].currentMode;
switch (_SOCKS5State) {
case OFSOCKS5StateSendAuthentication:
_SOCKS5State = OFSOCKS5StateReadVersion;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 2
runLoopMode: runLoopMode];
return nil;
case OFSOCKS5StateSendRequest:
[_request release];
_request = nil;
_SOCKS5State = OFSOCKS5StateReadResponse;
[_socket asyncReadIntoBuffer: _buffer
exactLength: 4
runLoopMode: runLoopMode];
return nil;
default:
assert(0);
return nil;
}
}
@end
|