5.4 KiB
title | description | image |
---|---|---|
Using a proxy | You can use a proxy with MadelineProto. | https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png |
Using a proxy
You can use a proxy with MadelineProto.
- How to set a proxy
- Multiple proxies with automatic switch
- Use pre-built MTProxy
- Use pre-built Socks5 proxy
- Use pre-built HTTP proxy
- Build your own proxy
How to set a proxy
In order to set a proxy for MadelineProto, you have to modify the settings.
Legacy proxy names are allowed (\HttpProxy
, \SocksProxy
), but not recommended.
The recommended way of getting proxy names to set in the settings is through the getName
method of the new proxy interface.
use danog\MadelineProto\Stream\MTProtoTransport\ObfuscatedStream;
use danog\MadelineProto\Stream\Proxy\HttpProxy;
use danog\MadelineProto\Stream\Proxy\SocksProxy;
use my\Custom\Namespace\MyProxy;
$settings['connection_settings']['all']['proxy'] = ObfuscatedStream::getName();
// ...
$settings['connection_settings']['all']['proxy'] = HttpProxy::getName();
// ...
$settings['connection_settings']['all']['proxy'] = SocksProxy::getName();
// ...
$settings['connection_settings']['all']['proxy'] = MyProxy::getName();
You can also set multiple proxies:
Multiple proxies with automatic switch
To set multiple proxies, and let MadelineProto choose the best one, simply assign arrays of proxy and proxy extras to the appropriate settings.
You can also use iterable objects instead of arrays of proxy settings to dynamically change the proxies used without reloading the settings.
use danog\MadelineProto\Stream\MTProtoTransport\ObfuscatedStream;
use danog\MadelineProto\Stream\Proxy\HttpProxy;
use danog\MadelineProto\Stream\Proxy\SocksProxy;
use my\Custom\Namespace\MyProxy;
$settings['connection_settings']['all']['proxy'] = [
ObfuscatedStream::getName(),
ObfuscatedStream::getName(),
HttpProxy::getName(),
SocksProxy::getName(),
MyProxy::getName()
];
$settings['connection_settings']['all']['proxy_extra'] = [
[
'address' => 'magtg.com',
'port' => 443,
'secret' => 'dd.....'
],
[
'address' => '1.2.3.4',
'port' => 443,
'secret' => 'dd.....'
],
[
'address' => '0.0.0.0',
'port' => 80,
'username' => 'user',
'password' => 'pass'
],
[
'address' => '0.0.0.0',
'port' => 242,
'username' => 'user',
'password' => 'pass'
],
[
'address' => '0.0.0.0',
'port' => 242,
'custom' => 'args',
],
];
MTProxy
use danog\MadelineProto\Stream\MTProtoTransport\ObfuscatedStream;
$settings['connection_settings']['all']['proxy'] = ObfuscatedStream::getName();
$settings['connection_settings']['all']['proxy_extra'] = [
'address' => '0.0.0.0',
'port' => 443,
'secret' => 'dd.....'
];
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);
Both normal and dd
secrets are supported, the transport is changed automatically by MadelineProto.
Socks5 proxy
No password:
use danog\MadelineProto\Stream\Proxy\SocksProxy;
$settings['connection_settings']['all']['proxy'] = SocksProxy::getName();
$settings['connection_settings']['all']['proxy_extra'] = [
'address' => '0.0.0.0',
'port' => 2343,
];
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);
With password:
use danog\MadelineProto\Stream\Proxy\SocksProxy;
$settings['connection_settings']['all']['proxy'] = SocksProxy::getName();
$settings['connection_settings']['all']['proxy_extra'] = [
'address' => '0.0.0.0',
'port' => 2343,
'username' => 'username',
'password' => 'password',
];
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);
HTTP proxy
No password:
use danog\MadelineProto\Stream\Proxy\HttpProxy;
$settings['connection_settings']['all']['proxy'] = HttpProxy::getName();
$settings['connection_settings']['all']['proxy_extra'] = [
'address' => '0.0.0.0',
'port' => 2343,
];
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);
With password:
use danog\MadelineProto\Stream\Proxy\HttpProxy;
$settings['connection_settings']['all']['proxy'] = HttpProxy::getName();
$settings['connection_settings']['all']['proxy_extra'] = [
'address' => '0.0.0.0',
'port' => 2343,
'username' => 'username',
'password' => 'password',
];
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);
Build your proxy
In order to build your proxy, you have to use the new MadelineProto stream API to create your own proxy class.
Feel free to study existing proxies and the stream API: it's well structured and well documented, so feel free to read the code.
Don't forget to add support for TLS connections as well!