diff --git a/src/mtp_config.erl b/src/mtp_config.erl index 768a580..27f49c9 100644 --- a/src/mtp_config.erl +++ b/src/mtp_config.erl @@ -110,7 +110,8 @@ code_change(_OldVsn, State, _Extra) -> update(#state{tab = Tab}, force) -> update_key(Tab), - update_config(Tab); + update_config(Tab), + update_ip(); update(State, _) -> try update(State, force) catch Class:Reason -> @@ -161,6 +162,16 @@ update_downstreams(Downstreams, Tab) -> update_range(Range, Tab) -> true = ets:insert(Tab, {id_range, Range}). +update_ip() -> + case application:get_env(?APP, ip_lookup_service) of + undefined -> false; + {ok, URL} -> + {ok, {{_, 200, _}, _, Body}} = httpc:request(URL), + IpStr= string:trim(Body), + {ok, _} = inet:parse_ipv4strict_address(IpStr), %assert + application:set_env(?APP, external_ip, IpStr) + end. + -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). diff --git a/src/mtproto_proxy.app.src b/src/mtproto_proxy.app.src index 81cde09..469347c 100644 --- a/src/mtproto_proxy.app.src +++ b/src/mtproto_proxy.app.src @@ -13,18 +13,33 @@ stdlib ]}, {env,[ + %% Close connection if it failed to perform handshake in this many seconds {init_timeout_sec, 60}, {hibernate_timeout_sec, 60}, + %% Close connection after this many seconds of inactivity {ready_timeout_sec, 1200}, - {ip, {0, 0, 0, 0}}, + %% Telegram server uses your external IP address as part of encryption + %% key, so, you should know it. + %% You can configure IP lookup service by `ip_lookup_service' (should + %% return my IP address as one line from this URL) or set IP address + %% statically by `external_ip' (not both). + %% If both are unset, we will try to guess IP address + %% from getsockname(). + {ip_lookup_service, "https://digitalresistance.dog/myIp"}, %% {external_ip, "YOUR.SERVER.EXTERNAL.IP"}, + + %% Interface to listen for incoming connections + {ip, {0, 0, 0, 0}}, + %% You can add as much as you want. Names and ports should be unique {ports, [#{name => mtp_handler, port => 1443, + %% secret should be 32 hex chars [0-9a-f] secret => <<"d0d6e111bada5511fcce9584deadbeef">>, + %% tag is what you get from @MTProxybot tag => <<"dcbe8f1493fa4cd9ab300891c0b5b326">>}]}, {num_acceptors, 60}, - {max_connections, 20480} + {max_connections, 40960} ]}, {modules, []},