-
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
13 changed files
with
485 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
## Todo | ||
|
||
- [ ] Implementation of server (Connect | Bind | Associate) | ||
- [ ] Implementation of client (Connect | Bind | Associate) | ||
- [ ] Complete documentation | ||
- [ ] Complete test coverage | ||
|
||
### In Progress | ||
|
||
- [ ] Implementation of server Bind | ||
- [ ] Implementation of client Bind | ||
- [ ] Complete documentation | ||
- [ ] Complete test coverage | ||
|
||
### Done ✓ | ||
|
||
- [x] Implementation of server Connect | ||
- [x] Implementation of client Connect | ||
- [x] Implementation of server Associate | ||
- [x] Implementation of client Associate | ||
- [x] Implementation of server Bind | ||
- [x] Implementation of client Bind |
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
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
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,45 @@ | ||
import * as net from 'net' | ||
import Reply from './reply' | ||
import { SOCKS5REPLY } from './constants' | ||
import { Info } from './handler' | ||
import Address from './address' | ||
|
||
class TcpRelay { | ||
/** | ||
* TCP socket | ||
*/ | ||
private tcpRelay: net.Server | ||
|
||
public port: number | ||
|
||
constructor(port: number, info: Info, socket: net.Socket) { | ||
this.port = port | ||
this.tcpRelay = net.createServer((remoteSocket) => { | ||
remoteSocket.on('data', (data) => { | ||
socket.write(data) | ||
}) | ||
}) | ||
this.tcpRelay.on('connection', (remoteSocket) => { | ||
const remote = remoteSocket.address() | ||
if ('port' in remote && 'address' in remote) { | ||
const relayAddress = new Address(remote.port, remote.address) | ||
const reply = new Reply( | ||
info.version, | ||
SOCKS5REPLY.succeeded.code, | ||
relayAddress | ||
) | ||
socket.write(reply.toBuffer()) | ||
} | ||
}) | ||
this.tcpRelay.listen(this.port, '127.0.0.1') | ||
} | ||
/** | ||
* Close Relay's socket | ||
* @param callback - Called when the socket has been closed | ||
*/ | ||
close(callback?: () => void) { | ||
this.tcpRelay.close(callback) | ||
} | ||
} | ||
|
||
export default TcpRelay |
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
Oops, something went wrong.