Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joanne Hugé
re6stnet
Commits
231e21eb
Commit
231e21eb
authored
Apr 29, 2021
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make nodes ask registry for their country
parent
d20879fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
11 deletions
+24
-11
re6st/tunnel.py
re6st/tunnel.py
+24
-11
No files found.
re6st/tunnel.py
View file @
231e21eb
...
@@ -213,17 +213,24 @@ class BaseTunnelManager(object):
...
@@ -213,17 +213,24 @@ class BaseTunnelManager(object):
address_dict
=
defaultdict
(
list
)
address_dict
=
defaultdict
(
list
)
for
family
,
address
in
address
:
for
family
,
address
in
address
:
address_dict
[
family
]
+=
address
address_dict
[
family
]
+=
address
if
any
(
address_dict
.
itervalues
()):
del
cache
.
my_address
# Cache may contain our country, we want to use it if possible to
# prevent interaction with registry
cache_dict
=
defaultdict
(
list
)
cache_address
=
cache
.
my_address
if
cache_address
:
for
address
in
utils
.
parse_address
(
cache_address
):
try
:
proto
=
proto_dict
[
address
[
2
]]
except
KeyError
:
continue
cache_dict
[
proto
[
0
]].
append
(
address
)
if
{
proto
:
cache_dict
[
proto
][:
3
]
for
proto
in
cache_dict
}
==
address_dict
:
address_dict
=
cache_dict
else
:
else
:
address
=
cache
.
my_address
del
cache
.
my_address
if
address
:
for
address
in
utils
.
parse_address
(
address
):
try
:
proto
=
proto_dict
[
address
[
2
]]
except
KeyError
:
continue
address_dict
[
proto
[
0
]].
append
(
address
)
db
=
os
.
getenv
(
'GEOIP2_MMDB'
)
db
=
os
.
getenv
(
'GEOIP2_MMDB'
)
if
db
:
if
db
:
from
geoip2
import
database
,
errors
from
geoip2
import
database
,
errors
...
@@ -244,6 +251,7 @@ class BaseTunnelManager(object):
...
@@ -244,6 +251,7 @@ class BaseTunnelManager(object):
self
.
_address
=
{
family
:
utils
.
dump_address
(
address
)
self
.
_address
=
{
family
:
utils
.
dump_address
(
address
)
for
family
,
address
in
address_dict
.
iteritems
()
for
family
,
address
in
address_dict
.
iteritems
()
if
address
}
if
address
}
self
.
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
itervalues
())
self
.
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
self
.
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
|
socket
.
SOCK_CLOEXEC
)
socket
.
SOCK_DGRAM
|
socket
.
SOCK_CLOEXEC
)
...
@@ -664,7 +672,12 @@ class BaseTunnelManager(object):
...
@@ -664,7 +672,12 @@ class BaseTunnelManager(object):
for
a
in
address
:
for
a
in
address
:
family
,
ip
=
resolve
(
*
a
[:
3
])
family
,
ip
=
resolve
(
*
a
[:
3
])
for
ip
in
ip
:
for
ip
in
ip
:
country
=
a
[
3
]
if
len
(
a
)
>
3
else
self
.
_geoiplookup
(
ip
)
try
:
country
=
a
[
3
]
if
len
(
a
)
>
3
\
else
self
.
cache
.
_registry
.
getCountry
(
self
.
_prefix
,
ip
)
except
(
socket
.
error
,
subprocess
.
CalledProcessError
,
ValueError
),
e
:
logging
.
warning
(
'Failed to get country (%s)'
,
ip
)
country
=
None
if
country
:
if
country
:
if
self
.
_country
.
get
(
family
)
!=
country
:
if
self
.
_country
.
get
(
family
)
!=
country
:
self
.
_country
[
family
]
=
country
self
.
_country
[
family
]
=
country
...
...
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