Using with the brook proxy server
srgl opened this issue · 6 comments
I am trying to work with the google smtp server through the brook proxy server (https://github.com/txthinking/brook), here is the sample code:
let {SocksClient} = require('socks')
const options = {
proxy: {
ipaddress: '35.174.27.1',
port: 1080,
type: 5,
userId: 'bouncedoc',
password: 'password'
},
command: 'connect',
destination: {
host: 'gmail-smtp-in.l.google.com',
port: 25
}
};
(async function test () {
let results = 0
for (let i = 0; i < 20; i++) {
let info = SocksClient.createConnection(options, (err, info) => {
if (err) return console.error(err)
info.socket.on('data', data => {
console.log(data.toString())
results += 1
})
})
}
setTimeout(() => {
console.log(`${results}/20`)
}, 3000)
})()
Running brook on aws in container:
docker run -d -e "ARGS=socks5 -l :1080 -i 0.0.0.0 --username bouncedoc --password password" -p 1080:1080 chenhw2/brook
Sometimes the data
handler receives non-ascii chars, sometimes it completely fails with Received invalid Socks5 final handshake response
.
Expected receiving something like 220 mx.google.com ESMTP x37si5670929qtx.226 - gsmtp
This will be fixed at the same time the other is fixed.
@srgl I publish a beta version to npm, can you test to see if this new version fixes both issues on your end?
npm install socks@2.1.4
I'm not seeing either issue anymore.
The main change is buffering all incoming data in an internal receive buffer, and processing the next steps in the SOCKS handshake when all the required data is in the buffer. Then once the SOCKS handshake is done, any excess data received is emitted as a 'data' event on the socket itself, so nothing should be lost.
@JoshGlazebrook Are you working on windows? Because on linux it throws Cannot find module '../common/receivebuffer'
. Except this I do not see those two issues, everything works smooth now. Thank you!
@srgl No windows here, but I fixed that issue with 2.1.4 (also published under the beta tag). Not sure why typescript didn't catch that :-/
I'll do additional testing this evening and publish an official version either later tonight or tomorrow.
This was fixed by #26 and is published to npm at 2.1.5