MadelineProto/docs/docs/PROXY.md

123 lines
3.8 KiB
Markdown
Raw Normal View History

# Using a proxy
You can use a proxy with MadelineProto.
There are two ways to do this: either buy a pre-made Socks5 or HTTP proxy for 10$, or build your own proxy.
## Buying a proxy class
Just send 10$ to paypal.me/danog, specifying the the proxy you wish to receive and your telegram username.
## Building a proxy class
2018-03-20 13:04:44 +01:00
```php
class MyProxy implements \danog\MadelineProto\Proxy
{
//...
}
$MadelineProto->settings['connection_settings']['all']['proxy'] = '\MyProxy';
```
Simply create a class that implements the `\danog\MadelineProto\Proxy` interface, and enter its name in the settings.
Your proxy class MUST use the `\Socket` class for all TCP/UDP communications.
Your proxy class can also have a setExtra method that accepts an array as the first parameter, to pass the values provided in the proxy_extra setting.
The `\Socket` class has the following methods (all of the following methods must also be implemented by your proxy class):
2018-03-20 13:04:44 +01:00
`public function __construct(int $domain, int $type, int $protocol);`
Works exactly like the [socket_connect](http://php.net/manual/en/function.socket-connect.php) function.
2018-03-20 13:04:44 +01:00
`public function setOption(int $level, int $name, $value);`
Works exactly like the [socket_set_option](http://php.net/manual/en/function.socket-set-option.php) function.
2018-03-20 13:04:44 +01:00
`public function getOption(int $name, $value);`
Works exactly like the [socket_get_option](http://php.net/manual/en/function.socket-get-option.php) function.
2018-03-20 13:04:44 +01:00
`public function setBlocking(bool $blocking);`
Works like the [socket_block](http://php.net/manual/en/function.socket-set-block.php) or [socket_nonblock](http://php.net/manual/en/function.socket-set-nonblock.php) functions.
2018-03-20 13:04:44 +01:00
`public function bind(string $address, [ int $port = 0 ]);`
Works exactly like the [socket_bind](http://php.net/manual/en/function.socket-bind.php) function.
2018-03-20 13:04:44 +01:00
`public function listen([ int $backlog = 0 ]);`
Works exactly like the [socket_listen](http://php.net/manual/en/function.socket-listen.php) function.
2018-03-20 13:04:44 +01:00
`public function accept();`
Works exactly like the [socket_accept](http://php.net/manual/en/function.socket-accept.php) function.
2018-03-20 13:04:44 +01:00
`public function connect(string $address, [ int $port = 0 ]);`
Works exactly like the [socket_accept](http://php.net/manual/en/function.socket-connect.php) function.
2018-03-20 13:04:44 +01:00
`public function select(array &$read, array &$write, array &$except, int $tv_sec, int $tv_usec = 0);`
Works exactly like the [socket_select](http://php.net/manual/en/function.socket-select.php) function.
2018-03-20 13:04:44 +01:00
`public function read(int $length, [ int $flags = 0 ]);`
Works exactly like the [socket_read](http://php.net/manual/en/function.socket-read.php) function.
2018-03-20 13:04:44 +01:00
`public function write(string $buffer, [ int $length ]);`
Works exactly like the [socket_read](http://php.net/manual/en/function.socket-write.php) function.
2018-03-20 13:04:44 +01:00
`public function send(string $data, int $length, int $flags);`
Works exactly like the [socket_send](http://php.net/manual/en/function.socket-send.php) function.
2018-03-20 13:04:44 +01:00
`public function close();`
Works exactly like the [socket_close](http://php.net/manual/en/function.socket-close.php) function.
2018-03-20 13:04:44 +01:00
`public function getPeerName(bool $port = true);`
Works like [socket_getpeername](http://php.net/manual/en/function.socket-getpeername.php): the difference is that it returns an array with the `host` and the `port`.
2018-03-20 13:04:44 +01:00
`public function getSockName(bool $port = true);`
Works like [socket_getsockname](http://php.net/manual/en/function.socket-getsockname.php): the difference is that it returns an array with the `host` and the `port`.
`public function getProxyHeaders();`
2018-03-20 16:02:36 +01:00
Can return additional HTTP headers to use when the HTTP protocol is being used.
2018-03-21 10:53:02 +01:00
<form action="https://docs.madelineproto.xyz/docs/LUA.html"><input type="submit" value="Previous section" /></form><form action="https://docs.madelineproto.xyz/docs/CONTRIB.html"><input type="submit" value="Next section" /></form>