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
Yohann D'Anello
re6stnet
Commits
38aeb326
Commit
38aeb326
authored
Jul 06, 2021
by
Yohann D'Anello
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store neighbours of neighbours and ping them regurally
Signed-off-by:
Yohann D'ANELLO
<
ynerant@crans.org
>
parent
5744a9dd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
3 deletions
+35
-3
re6st/tunnel.py
re6st/tunnel.py
+35
-3
No files found.
re6st/tunnel.py
View file @
38aeb326
...
...
@@ -2,6 +2,7 @@ import errno, json, logging, os, platform, random, socket
import
subprocess
,
struct
,
sys
,
time
,
weakref
from
collections
import
defaultdict
,
deque
from
bisect
import
bisect
,
insort
from
datetime
import
datetime
from
OpenSSL
import
crypto
from
.
import
ctl
,
plib
,
rina
,
utils
,
version
,
x509
...
...
@@ -206,6 +207,9 @@ class BaseTunnelManager(object):
self
.
cache
=
cache
self
.
_connecting
=
set
()
self
.
_connection_dict
=
{}
self
.
_neighbours_of_neighbours
=
{}
self
.
_sent_pings_distance_2
=
{}
self
.
_received_pings_distance_2
=
{}
self
.
_served
=
defaultdict
(
dict
)
self
.
_version
=
cache
.
version
self
.
_conf_country
=
conf_country
...
...
@@ -535,9 +539,16 @@ class BaseTunnelManager(object):
# The peer announced its neighbours
plen
=
len
(
self
.
_prefix
)
prefixes
=
[
msg
[
i
*
plen
:(
i
+
1
)
*
plen
]
for
i
in
range
(
len
(
msg
)
//
plen
)]
# FIXME Store neighbours of the peer instead of printing them
print
(
utils
.
ipFromBin
(
self
.
_network
+
peer
)
+
" has neighbours: "
+
str
(
list
(
map
(
lambda
prefix
:
utils
.
ipFromBin
(
self
.
_network
+
prefix
),
prefixes
))))
self
.
_neighbours_of_neighbours
[
peer
]
=
prefixes
elif
code
==
9
:
# ping
if
msg
==
"
\
x00
"
:
# Pong !
self
.
sendto
(
peer
,
'
\
x09
\
x01
'
)
elif
msg
==
"
\
x01
"
:
self
.
_received_pings_distance_2
.
setdefault
(
peer
,
[])
self
.
_received_pings_distance_2
[
peer
].
append
(
datetime
.
now
())
else
:
print
(
"[ping] Unknown code: "
+
msg
)
def
askInfo
(
self
,
prefix
):
return
self
.
sendto
(
prefix
,
'
\
4
'
+
self
.
_info
(
True
))
...
...
@@ -802,6 +813,27 @@ class TunnelManager(BaseTunnelManager):
continue
self
.
sendNeighbours
(
neighbour
)
# Try to contact neighbours of neighbours
neighbours_order_2
=
set
()
for
neighbours
in
self
.
_neighbours_of_neighbours
.
values
():
neighbours_order_2
.
update
(
neighbours
)
# Don't considerate our neighbours, they have a distance 1
neighbours_order_2
.
difference_update
(
self
.
ctl
.
neighbours
.
keys
())
# Try to ping distant nodes
for
node
in
neighbours_order_2
:
self
.
sendto
(
node
,
'
\
x09
\
x00
'
)
self
.
_sent_pings_distance_2
.
setdefault
(
node
,
[])
# Store the sent ping
self
.
_sent_pings_distance_2
[
node
].
append
(
datetime
.
now
())
# Clean old pings
self
.
_sent_pings_distance_2
=
{
k
:
[
d
for
d
in
v
if
(
datetime
.
now
()
-
d
).
seconds
<
60
]
for
k
,
v
in
self
.
_sent_pings_distance_2
.
items
()}
self
.
_received_pings_distance_2
=
{
k
:
[
d
for
d
in
v
if
(
datetime
.
now
()
-
d
).
seconds
<
60
]
for
k
,
v
in
self
.
_received_pings_distance_2
.
items
()}
def
babel_dump
(
self
):
t
=
time
.
time
()
...
...
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