Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mtproto_proxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mtproto_proxy
Commits
2b108644
Unverified
Commit
2b108644
authored
Oct 03, 2018
by
Сергей Прохоров
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add multiple fallback IP lookup services
parent
b37c0195
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
10 deletions
+26
-10
mtp_config.erl
src/mtp_config.erl
+17
-6
mtproto_proxy.app.src
src/mtproto_proxy.app.src
+9
-4
No files found.
src/mtp_config.erl
View file @
2b108644
...
...
@@ -163,14 +163,25 @@ update_range(Range, Tab) ->
true
=
ets
:
insert
(
Tab
,
{
id_range
,
Range
}).
update_ip
()
->
case
application
:
get_env
(
?
APP
,
ip_lookup_service
)
of
case
application
:
get_env
(
?
APP
,
ip_lookup_service
s
)
of
undefined
->
false
;
{
ok
,
URL
}
->
{
ok
,
{{_,
200
,
_},
_,
Body
}}
=
httpc
:
request
(
URL
),
{
ok
,
URLs
}
->
update_ip
(
URLs
)
end
.
update_ip
([
Url
|
Fallbacks
])
->
try
{
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
.
catch
Class
:
Reason
->
lager
:
error
(
"Failed to update IP with
~s
service:
~s
"
,
[
Url
,
lager
:
pr_stacktrace
(
erlang
:
get_stacktrace
(),
{
Class
,
Reason
})]),
update_ip
(
Fallbacks
)
end
;
update_ip
([])
->
error
(
ip_lookup_failed
).
-
ifdef
(
TEST
).
...
...
src/mtproto_proxy.app.src
View file @
2b108644
{application, mtproto_proxy,
[{description, "An OTP application"},
{vsn, "0.
1
.0"},
{vsn, "0.
2
.0"},
{registered, []},
{mod, { mtproto_proxy_app, []}},
{applications,
...
...
@@ -21,12 +21,17 @@
%% 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
%% You can configure IP lookup service
s by `ip_lookup_services
' (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
%% If both are unset,
proxy
will try to guess IP address
%% from getsockname().
{ip_lookup_service, "https://digitalresistance.dog/myIp"},
%% `ip_lookup_services' will be tried one-by-one: if 1st is not responding,
%% 2nd one will be tried and so on
{ip_lookup_services,
["http://ip.seriyps.ru/",
"https://digitalresistance.dog/myIp",
"http://ipv4.myexternalip.com/raw"]},
%% {external_ip, "YOUR.SERVER.EXTERNAL.IP"},
%% Interface to listen for incoming connections
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment