diff --git a/README.md b/README.md index 110b62c..92e364e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Erlang mtproto proxy This part of code was extracted from [@socksy_bot](https://t.me/socksy_bot). +This implementation supports promoted channels! See `mtproto_proxy_app.src` `tag` option. + How to start ------------ @@ -49,6 +51,7 @@ See `src/mtproto_proxy.app.src`. Secret key will be printed on start. + Helpers ------- diff --git a/src/mtp_handler.erl b/src/mtp_handler.erl index 62237f4..0e343da 100644 --- a/src/mtp_handler.erl +++ b/src/mtp_handler.erl @@ -11,7 +11,7 @@ %% API -export([start_link/4]). --export([hex/1]). +-export([hex/1, unhex/1]). -export([keys_str/0]). %% Callbacks @@ -103,8 +103,8 @@ init({_Ref, Socket, Transport, [Secret, Tag]}) -> Timer = gen_timeout:new( #{timeout => {env, ?APP, TimeoutKey, TimeoutDefault}}), State = #state{up_sock = Socket, - secret = Secret, - proxy_tag = Tag, + secret = unhex(Secret), + proxy_tag = unhex(Tag), up_transport = Transport, started_at = erlang:system_time(second), timer = Timer}, @@ -486,6 +486,13 @@ hex(Bin) -> end end || <> <= Bin>>. +unhex(Chars) -> + UnHChar = fun(C) when C < $W -> C - $0; + (C) when C > $W -> C - $W + end, + << <<(UnHChar(C)):4>> || <> <= Chars>>. + + track(Direction, Data) -> Size = byte_size(Data), metric:count_inc([?APP, tracker, bytes], Size, #{labels => [Direction]}), diff --git a/src/mtproto_proxy.app.src b/src/mtproto_proxy.app.src index 3d43e4b..a03fe59 100644 --- a/src/mtproto_proxy.app.src +++ b/src/mtproto_proxy.app.src @@ -19,8 +19,8 @@ %% {external_ip, "YOUR.SERVER.EXTERNAL.IP"}, {ports, [#{name => mtp_handler, port => 1443, - secret => <<208,214,225,17,186,218,85,17,252,206,149,132,222,173,190,239>>, - tag => <<220,190,143,20,147,250,76,217,171,48,8,145,192,181,179,38>>}]}, + secret => <<"d0d6e111bada5511fcce9584deadbeef">>, + tag => <<"dcbe8f1493fa4cd9ab300891c0b5b326">>}]}, {num_acceptors, 60}, {max_connections, 20480} ]}, diff --git a/src/mtproto_proxy_app.erl b/src/mtproto_proxy_app.erl index ae7c364..add1a10 100644 --- a/src/mtproto_proxy_app.erl +++ b/src/mtproto_proxy_app.erl @@ -42,8 +42,8 @@ start_proxy(#{name := Name, port := Port, secret := Secret, tag := Tag}) -> {num_acceptors, NumAcceptors}, {max_connections, MaxConnections}], mtp_handler, [Secret, Tag]), - io:format("Proxy started on ~s:~p with key: ~s~n", - [inet:ntoa(ListenIp), Port, mtp_handler:hex(Secret)]), + io:format("Proxy started on ~s:~p with secret: ~s~n", + [inet:ntoa(ListenIp), Port, Secret]), Res. stop_proxy(#{name := Name}) ->