Skip to content

Commit 7707b4e

Browse files
committed
Use SocksClient
1 parent 540c5a4 commit 7707b4e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/client/udp-tracker.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import arrayRemove from 'unordered-array-remove'
22
import clone from 'clone'
33
import Debug from 'debug'
44
import dgram from 'dgram'
5-
import Socks from 'socks'
5+
import { SocksClient } from 'socks'
66
import { concat, hex2arr, randomBytes } from 'uint8-util'
77

88
import common from '../common.js'
@@ -93,8 +93,8 @@ class UDPTracker extends Tracker {
9393
const proxyOpts = this.client._proxyOpts && clone(this.client._proxyOpts.socksProxy)
9494
if (proxyOpts) {
9595
if (!proxyOpts.proxy) proxyOpts.proxy = {}
96-
// UDP requests uses the associate command
97-
proxyOpts.proxy.command = 'associate'
96+
// UDP requests uses the associate type
97+
proxyOpts.proxy.type = 'associate'
9898
if (!proxyOpts.target) {
9999
// This should contain client IP and port but can be set to 0 if we don't have this information
100100
proxyOpts.target = {
@@ -104,20 +104,20 @@ class UDPTracker extends Tracker {
104104
}
105105

106106
if (proxyOpts.proxy.type === 5) {
107-
Socks.createConnection(proxyOpts, onGotConnection)
107+
SocksClient.createConnection(proxyOpts)
108+
.then(info => onGotConnection(info.socket, info))
109+
.catch(onError)
108110
} else {
109111
debug('Ignoring Socks proxy for UDP request because type 5 is required')
110-
onGotConnection(null)
112+
onGotConnection()
111113
}
112114
} else {
113-
onGotConnection(null)
115+
onGotConnection()
114116
}
115117

116118
this.cleanupFns.push(cleanup)
117119

118-
function onGotConnection (err, s, info) {
119-
if (err) return onError(err)
120-
120+
function onGotConnection (s, info) {
121121
proxySocket = s
122122
socket = dgram.createSocket('udp4')
123123
relay = info
@@ -260,7 +260,10 @@ class UDPTracker extends Tracker {
260260

261261
function send (message, proxyInfo) {
262262
if (proxyInfo) {
263-
const pack = Socks.createUDPFrame({ host: hostname, port }, message)
263+
const pack = SocksClient.createUDPFrame({
264+
remoteHost: { host: hostname, port },
265+
data: message
266+
})
264267
socket.send(pack, 0, pack.length, proxyInfo.port, proxyInfo.host)
265268
} else {
266269
socket.send(message, 0, message.length, port, hostname)

0 commit comments

Comments
 (0)