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
213e2d91
Commit
213e2d91
authored
May 27, 2021
by
Joanne Hugé
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove geoip2
parent
cbf3d89e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
18 deletions
+35
-18
re6st/cache.py
re6st/cache.py
+6
-0
re6st/tunnel.py
re6st/tunnel.py
+29
-18
No files found.
re6st/cache.py
View file @
213e2d91
...
...
@@ -249,6 +249,12 @@ class Cache(object):
return
prefix
,
address
logging
.
warning
(
'Buggy registry sent us our own address'
)
def
removePeer
(
self
,
prefix
):
logging
.
debug
(
'Removing peer %s'
,
prefix
)
with
self
.
_db
as
db
:
db
.
execute
(
"DELETE FROM peer WHERE prefix=?"
,
(
prefix
,))
def
addPeer
(
self
,
prefix
,
address
,
set_preferred
=
False
):
logging
.
debug
(
'Adding peer %s: %s'
,
prefix
,
address
)
with
self
.
_db
:
...
...
re6st/tunnel.py
View file @
213e2d91
...
...
@@ -195,7 +195,6 @@ class BaseTunnelManager(object):
'babel_hmac_sign'
,
'encrypt'
,
'hello'
,
'ipv4'
,
'ipv4_sublen'
))
_geoiplookup
=
None
_forward
=
None
_next_rina
=
True
...
...
@@ -231,23 +230,10 @@ class BaseTunnelManager(object):
else
:
del
cache
.
my_address
db
=
os
.
getenv
(
'GEOIP2_MMDB'
)
if
db
:
from
geoip2
import
database
,
errors
country
=
database
.
Reader
(
db
).
country
def
geoiplookup
(
ip
):
try
:
return
country
(
ip
).
country
.
iso_code
.
encode
()
except
errors
.
AddressNotFoundError
:
return
self
.
_geoiplookup
=
geoiplookup
if
cache
.
same_country
:
self
.
_country
=
{}
address_dict
=
{
family
:
self
.
_updateCountry
(
address
)
for
family
,
address
in
address_dict
.
iteritems
()}
elif
cache
.
same_country
:
sys
.
exit
(
"Can not respect 'same_country' network configuration"
" (GEOIP2_MMDB not set)"
)
self
.
_address
=
{
family
:
utils
.
dump_address
(
address
)
for
family
,
address
in
address_dict
.
iteritems
()
if
address
}
...
...
@@ -465,6 +451,24 @@ class BaseTunnelManager(object):
elif
code
==
1
:
# address
if
msg
:
if
peer
:
# Ask registry for the country if we didn't get one
def
updateMsg
():
address_list
=
utils
.
parse_address
(
msg
)
for
a
in
address_list
:
if
len
(
a
)
>
3
:
return
msg
family
,
ip
=
resolve
(
*
a
[:
3
])
for
ip
in
ip
:
try
:
country
=
self
.
cache
.
_registry
.
getCountry
(
self
.
_prefix
,
ip
)
except
(
socket
.
error
,
subprocess
.
CalledProcessError
,
ValueError
),
e
:
logging
.
warning
(
'Failed to get country (%s)'
,
ip
)
else
:
return
utils
.
dump_address
([
a
[:
3
]
+
(
country
,)
for
a
in
address_list
])
msg
=
updateMsg
()
if
not
msg
:
return
self
.
cache
.
addPeer
(
peer
,
msg
)
try
:
self
.
_connecting
.
remove
(
peer
)
...
...
@@ -895,9 +899,15 @@ class TunnelManager(BaseTunnelManager):
family
,
ip
=
resolve
(
*
x
[:
3
])
my_country
=
self
.
_country
.
get
(
family
,
self
.
_conf_country
)
if
my_country
:
if
len
(
x
)
<=
3
:
self
.
cache
.
removePeer
(
prefix
)
if
self
.
_disconnected
:
return
False
self
.
sendto
(
peer
,
'
\
1
'
)
self
.
_connecting
.
add
(
peer
)
return
True
for
ip
in
ip
:
# Use geoip if there is no country in the address
country
=
x
[
3
]
if
len
(
x
)
>
3
else
self
.
_geoiplookup
(
ip
)
country
=
x
[
3
]
if
country
and
(
country
!=
my_country
if
my_country
in
same_country
else
country
in
same_country
):
...
...
@@ -1040,9 +1050,10 @@ class TunnelManager(BaseTunnelManager):
logging
.
info
(
"ignore route_up notification for %s %r"
,
common_name
,
tuple
(
self
.
_connection_dict
))
if
self
.
_ip_changed
:
family
,
address
=
self
.
_ip_changed
(
ip
)
if
address
:
if
self
.
_geoiplookup
or
self
.
_conf
_country
:
if
self
.
cache
.
same
_country
:
address
=
self
.
_updateCountry
(
address
)
self
.
_address
[
family
]
=
utils
.
dump_address
(
address
)
self
.
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
itervalues
())
...
...
Joanne Hugé
@jhuge
mentioned in merge request
nexedi/re6stnet!32 (merged)
·
Jun 02, 2021
mentioned in merge request
nexedi/re6stnet!32 (merged)
mentioned in merge request nexedi/re6stnet!32
Toggle commit list
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