Configuration.acceptSOCKS()
Description
Appends an acceptSOCKS filter to the current pipeline layout.
An acceptSOCKS filter implements SOCKS protocol on the server side.
- INPUT - Data stream received from the client with a leading SOCKS connection request.
- OUTPUT - Data stream to send to the client with a leading SOCKS connection response.
- SUB-INPUT - Data stream received from the client via SOCKS.
- SUB-OUTPUT - Data stream to send to the client via SOCKS.
An acceptSOCKS filter decodes the connection request from its input stream, and calls back a user function with the connection parameters including:
- host - Destination address, could be an IPv4 address or a domain name
- port - Destination port number
- id - Username if any
If the callback returns true, the request will be accepted, and a sub-pipeline will be created. All subsequently received Data from the client is forwarded to it. Output Data from the sub-pipeline is sent back to the client.
If the callback returns false, the request will be rejected, and no sub-pipelines will be created.
Syntax
pipy().pipeline().acceptSOCKS((host, port, id) => shouldAcceptSession(host, port, id)).to(subPipelineLayout)
Parameters
acceptSOCKS(handler)
A function that receives host, port and username of the SOCKS request and returns true to accept the connection or false to refuse it
The same Configuration object.
Example
pipy({_host: '',_port: 0,}).listen(1080).acceptSOCKS((host, port) => (_host = host,_port = port,true // return true to accept the session)).to($=>$.connect(() => `${_host}:${_port}`))