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
50fae439
Commit
50fae439
authored
May 17, 2024
by
Tom Niget
Committed by
Tom Niget
Jun 14, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: add logs in registry
parent
1b8ad320
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
5 deletions
+22
-5
re6st/registry.py
re6st/registry.py
+22
-5
No files found.
re6st/registry.py
View file @
50fae439
...
@@ -99,7 +99,9 @@ class RegistryServer:
...
@@ -99,7 +99,9 @@ class RegistryServer:
"prefix TEXT PRIMARY KEY NOT NULL"
,
"prefix TEXT PRIMARY KEY NOT NULL"
,
"email TEXT"
,
"email TEXT"
,
"cert TEXT"
)
"cert TEXT"
)
logging
.
debug
(
"Checking for existing certs..."
)
if
not
self
.
db
.
execute
(
"SELECT 1 FROM cert LIMIT 1"
).
fetchone
():
if
not
self
.
db
.
execute
(
"SELECT 1 FROM cert LIMIT 1"
).
fetchone
():
logging
.
debug
(
"No existing certs found, creating a blank one..."
)
self
.
db
.
execute
(
"INSERT INTO cert VALUES ('',null,null)"
)
self
.
db
.
execute
(
"INSERT INTO cert VALUES ('',null,null)"
)
prev
=
'-'
prev
=
'-'
...
@@ -265,7 +267,7 @@ class RegistryServer:
...
@@ -265,7 +267,7 @@ class RegistryServer:
if
x
<=
old
:
if
x
<=
old
:
if
prefix
==
self
.
prefix
:
if
prefix
==
self
.
prefix
:
logging
.
critical
(
"Refuse to delete certificate"
logging
.
critical
(
"Refuse to delete certificate"
" of main node: wrong clock ?"
)
" of main node: wrong clock ?
Alternatively, try deleting .db
"
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
logging
.
info
(
"Delete %s: %s (invalid since %s)"
,
logging
.
info
(
"Delete %s: %s (invalid since %s)"
,
"certificate requested by '%s'"
%
email
"certificate requested by '%s'"
%
email
...
@@ -350,9 +352,11 @@ class RegistryServer:
...
@@ -350,9 +352,11 @@ class RegistryServer:
def
getCert
(
self
,
client_prefix
):
def
getCert
(
self
,
client_prefix
):
assert
self
.
lock
.
locked
()
assert
self
.
lock
.
locked
()
return
self
.
db
.
execute
(
"SELECT cert FROM cert"
cert
=
self
.
db
.
execute
(
"SELECT cert FROM cert"
" WHERE prefix=? AND cert IS NOT NULL"
,
" WHERE prefix=? AND cert IS NOT NULL"
,
(
client_prefix
,)).
fetchone
()
(
client_prefix
,)).
fetchone
()[
0
]
assert
cert
,
(
"cert query from db is None, should not happen"
,
self
.
db
.
execute
(
"SELECT * FROM cert"
).
fetchall
())
return
cert
[
0
]
@
rpc_private
@
rpc_private
def
isToken
(
self
,
token
):
def
isToken
(
self
,
token
):
...
@@ -433,6 +437,7 @@ class RegistryServer:
...
@@ -433,6 +437,7 @@ class RegistryServer:
return
default
return
default
def
mergePrefixes
(
self
):
def
mergePrefixes
(
self
):
logging
.
debug
(
"Merging prefixes"
)
q
=
self
.
db
.
execute
q
=
self
.
db
.
execute
prev_prefix
=
None
prev_prefix
=
None
max_len
=
128
,
max_len
=
128
,
...
@@ -455,6 +460,7 @@ class RegistryServer:
...
@@ -455,6 +460,7 @@ class RegistryServer:
prev_prefix
=
prefix
prev_prefix
=
prefix
def
newPrefix
(
self
,
prefix_len
,
community
):
def
newPrefix
(
self
,
prefix_len
,
community
):
logging
.
info
(
"Allocating /%u prefix for %s"
,
prefix_len
,
community
)
community_len
=
len
(
community
)
community_len
=
len
(
community
)
prefix_len
+=
community_len
prefix_len
+=
community_len
max_len
=
128
-
len
(
self
.
network
)
max_len
=
128
-
len
(
self
.
network
)
...
@@ -494,6 +500,7 @@ class RegistryServer:
...
@@ -494,6 +500,7 @@ class RegistryServer:
@
rpc
@
rpc
def
requestCertificate
(
self
,
token
,
req
,
location
=
''
,
ip
=
''
):
def
requestCertificate
(
self
,
token
,
req
,
location
=
''
,
ip
=
''
):
logging
.
debug
(
"Requesting certificate with token %s"
,
token
)
req
=
crypto
.
load_certificate_request
(
crypto
.
FILETYPE_PEM
,
req
)
req
=
crypto
.
load_certificate_request
(
crypto
.
FILETYPE_PEM
,
req
)
with
self
.
lock
:
with
self
.
lock
:
with
self
.
db
:
with
self
.
db
:
...
@@ -602,6 +609,7 @@ class RegistryServer:
...
@@ -602,6 +609,7 @@ class RegistryServer:
return
zlib
.
compress
(
json
.
dumps
(
config
).
encode
(
"utf-8"
))
return
zlib
.
compress
(
json
.
dumps
(
config
).
encode
(
"utf-8"
))
def
_queryAddress
(
self
,
peer
):
def
_queryAddress
(
self
,
peer
):
logging
.
info
(
"Querying address for %s/%s"
,
int
(
peer
,
2
),
len
(
peer
))
self
.
sendto
(
peer
,
1
)
self
.
sendto
(
peer
,
1
)
s
=
self
.
sock
,
s
=
self
.
sock
,
timeout
=
3
timeout
=
3
...
@@ -609,6 +617,7 @@ class RegistryServer:
...
@@ -609,6 +617,7 @@ class RegistryServer:
# Loop because there may be answers from previous requests.
# Loop because there may be answers from previous requests.
while
select
.
select
(
s
,
(),
(),
timeout
)[
0
]:
while
select
.
select
(
s
,
(),
(),
timeout
)[
0
]:
prefix
,
msg
=
self
.
recv
(
1
)
prefix
,
msg
=
self
.
recv
(
1
)
logging
.
info
(
"* received: %s - %s"
,
prefix
,
msg
)
if
prefix
==
peer
:
if
prefix
==
peer
:
return
msg
return
msg
timeout
=
max
(
0
,
end
-
time
.
time
())
timeout
=
max
(
0
,
end
-
time
.
time
())
...
@@ -622,6 +631,7 @@ class RegistryServer:
...
@@ -622,6 +631,7 @@ class RegistryServer:
@
rpc
@
rpc
def
getBootstrapPeer
(
self
,
cn
):
def
getBootstrapPeer
(
self
,
cn
):
logging
.
info
(
"Answering bootstrap peer for %s"
,
cn
)
with
self
.
peers_lock
:
with
self
.
peers_lock
:
age
,
peers
=
self
.
peers
age
,
peers
=
self
.
peers
if
age
<
time
.
time
()
or
not
peers
:
if
age
<
time
.
time
()
or
not
peers
:
...
@@ -633,6 +643,7 @@ class RegistryServer:
...
@@ -633,6 +643,7 @@ class RegistryServer:
peers
.
append
(
self
.
prefix
)
peers
.
append
(
self
.
prefix
)
random
.
shuffle
(
peers
)
random
.
shuffle
(
peers
)
self
.
peers
=
time
.
time
()
+
60
,
peers
self
.
peers
=
time
.
time
()
+
60
,
peers
logging
.
debug
(
"peers: %r"
,
peers
)
peer
=
peers
.
pop
()
peer
=
peers
.
pop
()
if
peer
==
cn
:
if
peer
==
cn
:
# Very unlikely (e.g. peer restarted with empty cache),
# Very unlikely (e.g. peer restarted with empty cache),
...
@@ -642,6 +653,7 @@ class RegistryServer:
...
@@ -642,6 +653,7 @@ class RegistryServer:
with
self
.
lock
:
with
self
.
lock
:
msg
=
self
.
_queryAddress
(
peer
)
msg
=
self
.
_queryAddress
(
peer
)
if
msg
is
None
:
if
msg
is
None
:
logging
.
info
(
"No address for %s, returning None"
,
peer
)
return
return
# Remove country for old nodes
# Remove country for old nodes
if
self
.
getPeerProtocol
(
cn
)
<
7
:
if
self
.
getPeerProtocol
(
cn
)
<
7
:
...
@@ -771,6 +783,7 @@ class RegistryServer:
...
@@ -771,6 +783,7 @@ class RegistryServer:
@
rpc_private
@
rpc_private
def
topology
(
self
):
def
topology
(
self
):
logging
.
info
(
"Computing topology"
)
p
=
lambda
p
:
'%s/%s'
%
(
int
(
p
,
2
),
len
(
p
))
p
=
lambda
p
:
'%s/%s'
%
(
int
(
p
,
2
),
len
(
p
))
peers
=
deque
((
p
(
self
.
prefix
),))
peers
=
deque
((
p
(
self
.
prefix
),))
graph
=
defaultdict
(
set
)
graph
=
defaultdict
(
set
)
...
@@ -780,6 +793,7 @@ class RegistryServer:
...
@@ -780,6 +793,7 @@ class RegistryServer:
r
,
w
,
_
=
select
.
select
(
s
,
s
if
peers
else
(),
(),
3
)
r
,
w
,
_
=
select
.
select
(
s
,
s
if
peers
else
(),
(),
3
)
if
r
:
if
r
:
prefix
,
x
=
self
.
recv
(
5
)
prefix
,
x
=
self
.
recv
(
5
)
logging
.
info
(
"Received %s %s"
,
prefix
,
x
)
if
prefix
and
x
:
if
prefix
and
x
:
prefix
=
p
(
prefix
)
prefix
=
p
(
prefix
)
x
=
x
.
split
()
x
=
x
.
split
()
...
@@ -794,8 +808,11 @@ class RegistryServer:
...
@@ -794,8 +808,11 @@ class RegistryServer:
graph
[
x
].
add
(
prefix
)
graph
[
x
].
add
(
prefix
)
graph
[
''
].
add
(
prefix
)
graph
[
''
].
add
(
prefix
)
if
w
:
if
w
:
self
.
sendto
(
utils
.
binFromSubnet
(
peers
.
popleft
()),
5
)
first
=
peers
.
popleft
()
logging
.
info
(
"Sending %s"
,
first
)
self
.
sendto
(
utils
.
binFromSubnet
(
first
),
5
)
elif
not
r
:
elif
not
r
:
logging
.
info
(
"No more sockets, stopping"
)
break
break
return
json
.
dumps
({
k
:
list
(
v
)
for
k
,
v
in
graph
.
items
()})
return
json
.
dumps
({
k
:
list
(
v
)
for
k
,
v
in
graph
.
items
()})
...
...
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