///
///
/**
* A UDP-based "relay" server intended for use as part of a SOCKS5 proxy:
* http://www.ietf.org/rfc/rfc1928.txt
*
* Briefly, here's how to use this:
* - create an instance of this class
* - call bind (you probably want to specify port zero to have the system
* pick a free port)
* - call getInfo, to discover on which port the relay is listening
* - (the caller can now return the address and port back to the SOCKS
* client)
* - call setDataReceivedHandler
* - this class will invoke the setDataReceivedHandler each time a datagram
* is received on the socket; the full message is sent, including SOCKS
* UDP headers
* - (the caller can relay the message across the datachannel)
* - call sendRemoteReply for each datagram received from remote hosts; this
* will be sent to the client, and should include the same SOCKS UDP
* header received in the original request
* - call destroy to clean up, typically when the TCP connection on which
* the UDP_ASSOCIATE was negotiated is terminated
*
* One relay should be created in response to each UDP_ASSOCIATE command.
*
* Other notes:
* - while the RFC states that the relay MUST drop any message originating
* from an IP other than that which requested the association, this
* implementation makes no effort to do so (this isn't urgent because we
* typically only listen locally)
* - similarly, we make no effort to respect the DST.PORT and DST.ADDR fields
* specified by the client during the handshake: having run various proxy
* clients it seems that these are rarely specified anyway (which is fine
* according to section 6 of the RFC)
* and, in any case, we are typically only listening locally
* - we make no attempt to implement fragmentation (see section 7 of the
* RFC)
*
* TODO: this is so similar to udprelay.ts that they can almost certainly
* be merged into one
*/
declare class UdpRelay {
private socket_;
private address_;
private port_;
private clientAddress_;
private clientPort_;
/**
* Function to be called when data is received.
*/
private dataReceivedHandler;
constructor();
/**
* Returns a promise to create a socket, bind to the specified address and
* port, and start relaying events. Specify port zero to have the system
* choose a free port.
*/
bind(address: string, port: number): any;
/**
* Listens for onData events.
* The socket must be bound.
*/
private attachSocketHandler_;
private onSocksClientData_;
/**
* Sets the function to be called when data is received from the client.
* This is intended for relaying datagrams from the client across the
* datachannel from a remote server. The full datagram as received from the
* client is sent, complete with SOCKS headers.
*/
setDataReceivedHandler(callback: (buffer: ArrayBuffer) => void): void;
/**
* Returns a promise to send data to the client.
* This is intended for relaying responses from remote servers back to
* the client.
*/
sendRemoteReply(buffer: ArrayBuffer): Promise;
/**
* Returns the address on which the local socket associated with this
* relay is listening.
*/
getAddress: () => string;
/**
* Returns the port on which the local socket associated with this
* relay is listening.
*/
getPort: () => number;
}
export = UdpRelay;