-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added proxy support #21
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the right approach but this isn't mergeable yet.
Can you implement it for async too?
src/irc.nim
Outdated
p[0] = cast[char](irc.port.uint16 shr 8) | ||
p[1] = cast[char](irc.port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need to cast here, can't you do a simple type conversion? It's much safer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trying type conversion for line 307 results in
Error: unhandled exception: value out of range [RangeError]
casting seems to be the only way I can get it to work. Unless there's a way to convert it I'm not seeing?
src/irc.nim
Outdated
|
||
# proc connect*(s: ProxySocket, address: string, port: Port) = | ||
# ## Connect by FQDN/hostname or IP address | ||
# ## echo repr port.uint16.toHex().fromHex() | ||
# var p = " " | ||
# p[0] = cast[char](port.uint16 shr 8) | ||
# p[1] = cast[char](port) | ||
|
||
# s.inner.send("\x05\x01\x00\x03" & address.len.char & address & p) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. Will do
src/irc.nim
Outdated
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
src/irc.nim
Outdated
irc.sock.send("\x05\x01\x00") # connect with no auth | ||
let resp = irc.sock.recv(2, 1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this defined? Can you link to the spec/RFC? Reading 2 bytes looks suspicious to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats getting the proxy response.
waiting for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're still casting, and now have 4(!?) copies of the same code?
I tried type conversion, but it doesn't work without it. With type conversion it will compile, but won't work for some reason, as in it wont connect. |
I'll fix the 4 copies |
I fixed the copies, but the casting is confusing me. Why does type conversion not connect, but with casting it does? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the binary files as well.
var p = " " | ||
p[0] = char(irc.port.uint16 shr 8) | ||
p[1] = cast[char](irc.port) | ||
|
||
# connect to proxy with not authentication | ||
await irc.sock.connect(irc.proxyAddr, irc.proxyPort) | ||
await irc.sock.send("\x05\x01\x00") # connect with no auth | ||
# get proxy response | ||
let resp = await irc.sock.recv(2) | ||
if resp != "\x05\x00": # check the proxy response | ||
raise newException(Exception, "Unexpected proxy response: " & resp.toHex()) | ||
|
||
await irc.sock.send("\x05\x01\x00\x03" & irc.address.len.char & irc.address & p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reduce duplication even further:
proc connectProxy(irc: Irc | AsyncIrc) {.multisync.} =
var p = " "
p[0] = char(irc.port.uint16 shr 8)
p[1] = cast[char](irc.port)
# connect to proxy with not authentication
await irc.sock.connect(irc.proxyAddr, irc.proxyPort)
await irc.sock.send("\x05\x01\x00") # connect with no auth
# get proxy response
let resp = await irc.sock.recv(2)
if resp != "\x05\x00": # check the proxy response
raise newException(Exception, "Unexpected proxy response: " & resp.toHex())
await irc.sock.send("\x05\x01\x00\x03" & irc.address.len.char & irc.address & p)
await connectProxy(irc) # and without await above.
proxyAddr: string | ||
proxyPort: Port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I assume that this is a socks proxy, change all proxy
to socksProxy
. Not just here, but below as well.
proxyAddr: string | |
proxyPort: Port | |
socksProxyAddr: string | |
socksProxyPort: Port |
ping |
Regarding the proxy support, this seems to work. Instead of complicating things with tor.nim, this seems WAY easier to maintain.