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
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
nexedi
re6stnet
Commits
47d374bc
Commit
47d374bc
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
e7229916
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
14 deletions
+27
-14
re6st/cache.py
re6st/cache.py
+6
-0
re6st/cli/node.py
re6st/cli/node.py
+1
-1
re6st/tunnel.py
re6st/tunnel.py
+20
-13
No files found.
re6st/cache.py
View file @
47d374bc
...
@@ -272,3 +272,9 @@ class Cache(object):
...
@@ -272,3 +272,9 @@ class Cache(object):
if
a
!=
address
:
if
a
!=
address
:
q
(
"INSERT OR REPLACE INTO peer VALUES (?,?)"
,
(
prefix
,
address
))
q
(
"INSERT OR REPLACE INTO peer VALUES (?,?)"
,
(
prefix
,
address
))
q
(
"INSERT OR REPLACE INTO volatile.stat VALUES (?,0)"
,
(
prefix
,))
q
(
"INSERT OR REPLACE INTO volatile.stat VALUES (?,0)"
,
(
prefix
,))
def
getCountry
(
self
,
ip
):
try
:
return
self
.
_registry
.
getCountry
(
self
.
_prefix
,
ip
)
except
socket
.
error
,
e
:
logging
.
warning
(
'Failed to get country (%s)'
,
ip
)
re6st/cli/node.py
View file @
47d374bc
...
@@ -67,7 +67,7 @@ def getConfig():
...
@@ -67,7 +67,7 @@ def getConfig():
"to access it."
)
"to access it."
)
_
(
'--country'
,
metavar
=
'CODE'
,
_
(
'--country'
,
metavar
=
'CODE'
,
help
=
"Country code that is advertised to other nodes"
help
=
"Country code that is advertised to other nodes"
"(default: country is
fetched from MaxMind database
)"
)
"(default: country is
resolved by the registry
)"
)
_
=
parser
.
add_argument_group
(
'routing'
).
add_argument
_
=
parser
.
add_argument_group
(
'routing'
).
add_argument
_
(
'-B'
,
dest
=
'babel_args'
,
metavar
=
'ARG'
,
action
=
'append'
,
default
=
[],
_
(
'-B'
,
dest
=
'babel_args'
,
metavar
=
'ARG'
,
action
=
'append'
,
default
=
[],
...
...
re6st/tunnel.py
View file @
47d374bc
...
@@ -213,17 +213,22 @@ class BaseTunnelManager(object):
...
@@ -213,17 +213,22 @@ 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
else
:
# prevent interaction with registry
address
=
cache
.
my_address
cache_address
=
cache
.
my_address
if
address
:
if
cache_address
:
for
address
in
utils
.
parse_address
(
address
):
cache_dict
=
defaultdict
(
list
)
try
:
for
address
in
utils
.
parse_address
(
cache_address
):
proto
=
proto_dict
[
address
[
2
]]
try
:
except
KeyError
:
proto
=
proto_dict
[
address
[
2
]]
continue
except
KeyError
:
address_dict
[
proto
[
0
]].
append
(
address
)
continue
cache_dict
[
proto
[
0
]].
append
(
address
)
if
{
proto
:
cache_dict
[
proto
][:
3
]
for
proto
in
cache_dict
}
==
address_dict
:
address_dict
=
cache_dict
db
=
os
.
getenv
(
'GEOIP2_MMDB'
)
db
=
os
.
getenv
(
'GEOIP2_MMDB'
)
if
db
:
if
db
:
from
geoip2
import
database
,
errors
from
geoip2
import
database
,
errors
...
@@ -234,6 +239,7 @@ class BaseTunnelManager(object):
...
@@ -234,6 +239,7 @@ class BaseTunnelManager(object):
except
errors
.
AddressNotFoundError
:
except
errors
.
AddressNotFoundError
:
return
return
self
.
_geoiplookup
=
geoiplookup
self
.
_geoiplookup
=
geoiplookup
if
cache
.
same_country
:
self
.
_country
=
{}
self
.
_country
=
{}
address_dict
=
{
family
:
self
.
_updateCountry
(
address
)
address_dict
=
{
family
:
self
.
_updateCountry
(
address
)
...
@@ -244,6 +250,7 @@ class BaseTunnelManager(object):
...
@@ -244,6 +250,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
}
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 +671,7 @@ class BaseTunnelManager(object):
...
@@ -664,7 +671,7 @@ 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
)
country
=
a
[
3
]
if
len
(
a
)
>
3
else
self
.
cache
.
getCountry
(
ip
)
if
country
:
if
country
:
if
self
.
_country
.
get
(
family
)
!=
country
:
if
self
.
_country
.
get
(
family
)
!=
country
:
self
.
_country
[
family
]
=
country
self
.
_country
[
family
]
=
country
...
@@ -1029,7 +1036,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -1029,7 +1036,7 @@ class TunnelManager(BaseTunnelManager):
if
self
.
_ip_changed
:
if
self
.
_ip_changed
:
family
,
address
=
self
.
_ip_changed
(
ip
)
family
,
address
=
self
.
_ip_changed
(
ip
)
if
address
:
if
address
:
if
self
.
_geoiplookup
or
self
.
_conf
_country
:
if
self
.
cache
.
same
_country
:
address
=
self
.
_updateCountry
(
address
)
address
=
self
.
_updateCountry
(
address
)
self
.
_address
[
family
]
=
utils
.
dump_address
(
address
)
self
.
_address
[
family
]
=
utils
.
dump_address
(
address
)
self
.
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
itervalues
())
self
.
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
itervalues
())
...
...
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