MCPcopy Create free account
hub / github.com/nodejs/node / buildConnectRequest

Method buildConnectRequest

deps/undici/src/lib/core/socks5-client.js:294–313  ·  view source on GitHub ↗

* Build a SOCKS5 request

(command, address, port)

Source from the content-addressed store, hash-verified

292 * Build a SOCKS5 request
293 */
294 buildConnectRequest (command, address, port) {
295 // Parse address to determine type and buffer
296 const { type: addressType, buffer: addressBuffer } = parseAddress(address)
297
298 // Build request
299 // +----+-----+-------+------+----------+----------+
300 // |VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT |
301 // +----+-----+-------+------+----------+----------+
302 // | 1 | 1 | X'00' | 1 | Variable | 2 |
303 // +----+-----+-------+------+----------+----------+
304 const request = Buffer.alloc(4 + addressBuffer.length + 2)
305 request[0] = SOCKS_VERSION
306 request[1] = command
307 request[2] = 0x00 // Reserved
308 request[3] = addressType
309 addressBuffer.copy(request, 4)
310 request.writeUInt16BE(port, 4 + addressBuffer.length)
311
312 return request
313 }
314
315 /**
316 * Handle CONNECT response

Callers 1

connectMethod · 0.95

Calls 3

allocMethod · 0.80
parseAddressFunction · 0.70
copyMethod · 0.65

Tested by

no test coverage detected