-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,29 @@ | ||
import posix, asyncnet, asyncdispatch | ||
import ../src/proxyproto | ||
|
||
proc processClient(client: AsyncSocket) {.async.} = | ||
while true: | ||
let line = await client.recvLine() | ||
await client.send(line & "\c\L") | ||
var | ||
slen: SockLen | ||
src: SockAddr_in | ||
|
||
if getpeername(client.getFd(), cast[ptr SockAddr](addr src), addr slen) == 0: | ||
echo "remote ip ", inet_ntoa(src.sin_addr) | ||
|
||
proc serve() {.async.} = | ||
var server = newAsyncSocket() | ||
server.bindAddr(Port(6001)) | ||
server.listen() | ||
|
||
while true: | ||
try: | ||
let client = await server.accept() | ||
discard processClient(client) | ||
except: | ||
discard | ||
|
||
|
||
asyncCheck serve() | ||
runForever() |