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
e7229916
Commit
e7229916
authored
Apr 12, 2021
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getCountry RPC
parent
0f97c026
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
re6st/registry.py
re6st/registry.py
+21
-0
No files found.
re6st/registry.py
View file @
e7229916
...
@@ -59,6 +59,9 @@ class RegistryServer(object):
...
@@ -59,6 +59,9 @@ class RegistryServer(object):
peers
=
0
,
()
peers
=
0
,
()
cert_duration
=
365
*
86400
cert_duration
=
365
*
86400
def
_geoiplookup
(
self
,
ip
):
raise
HTTPError
(
httplib
.
BAD_REQUEST
)
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
self
.
config
=
config
self
.
config
=
config
self
.
lock
=
threading
.
Lock
()
self
.
lock
=
threading
.
Lock
()
...
@@ -103,6 +106,20 @@ class RegistryServer(object):
...
@@ -103,6 +106,20 @@ class RegistryServer(object):
self
.
ctl
=
ctl
.
Babel
(
os
.
path
.
join
(
config
.
run
,
'babeld.sock'
),
self
.
ctl
=
ctl
.
Babel
(
os
.
path
.
join
(
config
.
run
,
'babeld.sock'
),
weakref
.
proxy
(
self
),
self
.
network
)
weakref
.
proxy
(
self
),
self
.
network
)
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
elif
self
.
config
.
same_country
:
sys
.
exit
(
"Can not respect 'same_country' network configuration"
" (GEOIP2_MMDB not set)"
)
self
.
onTimeout
()
self
.
onTimeout
()
if
self
.
prefix
:
if
self
.
prefix
:
with
self
.
db
:
with
self
.
db
:
...
@@ -504,6 +521,10 @@ class RegistryServer(object):
...
@@ -504,6 +521,10 @@ class RegistryServer(object):
logging
.
info
(
"Timeout while querying address for %s/%s"
,
logging
.
info
(
"Timeout while querying address for %s/%s"
,
int
(
peer
,
2
),
len
(
peer
))
int
(
peer
,
2
),
len
(
peer
))
@
rpc
def
getCountry
(
self
,
cn
,
address
):
return
self
.
_geoiplookup
(
address
)
@
rpc
@
rpc
def
getBootstrapPeer
(
self
,
cn
):
def
getBootstrapPeer
(
self
,
cn
):
with
self
.
peers_lock
:
with
self
.
peers_lock
:
...
...
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