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
Boris Kocherov
re6stnet
Commits
aba0e94d
Commit
aba0e94d
authored
Feb 24, 2015
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Network parameters will be also cached so rename a few things
db.py -> cache.py PeerDB -> Cache peers.db -> cache.db
parent
acc0568a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
26 deletions
+27
-26
re6st/cache.py
re6st/cache.py
+1
-1
re6st/tunnel.py
re6st/tunnel.py
+18
-18
re6stnet
re6stnet
+8
-7
No files found.
re6st/
db
.py
→
re6st/
cache
.py
View file @
aba0e94d
...
@@ -2,7 +2,7 @@ import logging, os, sqlite3, socket, subprocess, time
...
@@ -2,7 +2,7 @@ import logging, os, sqlite3, socket, subprocess, time
from
re6st.registry
import
RegistryClient
from
re6st.registry
import
RegistryClient
from
.
import
utils
from
.
import
utils
class
PeerDB
(
object
):
class
Cache
(
object
):
# internal ip = temp arg/attribute
# internal ip = temp arg/attribute
def
__init__
(
self
,
db_path
,
registry
,
cert
,
db_size
=
200
):
def
__init__
(
self
,
db_path
,
registry
,
cert
,
db_size
=
200
):
...
...
re6st/tunnel.py
View file @
aba0e94d
...
@@ -79,11 +79,11 @@ class Connection(object):
...
@@ -79,11 +79,11 @@ class Connection(object):
def
connected
(
self
):
def
connected
(
self
):
i
=
self
.
_retry
-
1
i
=
self
.
_retry
-
1
self
.
_retry
=
None
self
.
_retry
=
None
db
=
self
.
tunnel_manager
.
peer_db
cache
=
self
.
tunnel_manager
.
cache
if
i
:
if
i
:
db
.
addPeer
(
self
.
_prefix
,
','
.
join
(
self
.
address_list
[
i
]),
True
)
cache
.
addPeer
(
self
.
_prefix
,
','
.
join
(
self
.
address_list
[
i
]),
True
)
else
:
else
:
db
.
connecting
(
self
.
_prefix
,
0
)
cache
.
connecting
(
self
.
_prefix
,
0
)
def
close
(
self
):
def
close
(
self
):
try
:
try
:
...
@@ -164,11 +164,11 @@ class BaseTunnelManager(object):
...
@@ -164,11 +164,11 @@ class BaseTunnelManager(object):
_forward
=
None
_forward
=
None
def
__init__
(
self
,
peer_db
,
cert
,
cert_renew
,
address
=
()):
def
__init__
(
self
,
cache
,
cert
,
cert_renew
,
address
=
()):
self
.
cert
=
cert
self
.
cert
=
cert
self
.
_network
=
cert
.
network
self
.
_network
=
cert
.
network
self
.
_prefix
=
cert
.
prefix
self
.
_prefix
=
cert
.
prefix
self
.
peer_db
=
peer_db
self
.
cache
=
cache
self
.
_connecting
=
set
()
self
.
_connecting
=
set
()
self
.
_connection_dict
=
{}
self
.
_connection_dict
=
{}
self
.
_served
=
set
()
self
.
_served
=
set
()
...
@@ -322,7 +322,7 @@ class BaseTunnelManager(object):
...
@@ -322,7 +322,7 @@ class BaseTunnelManager(object):
elif
code
==
1
:
# address
elif
code
==
1
:
# address
if
msg
:
if
msg
:
if
peer
:
if
peer
:
self
.
peer_db
.
addPeer
(
peer
,
msg
)
self
.
cache
.
addPeer
(
peer
,
msg
)
try
:
try
:
self
.
_connecting
.
remove
(
peer
)
self
.
_connecting
.
remove
(
peer
)
except
KeyError
:
except
KeyError
:
...
@@ -347,7 +347,7 @@ class BaseTunnelManager(object):
...
@@ -347,7 +347,7 @@ class BaseTunnelManager(object):
return
version
.
version
return
version
.
version
elif
code
==
5
:
elif
code
==
5
:
# the registry wants to know the topology for debugging purpose
# the registry wants to know the topology for debugging purpose
if
not
peer
or
peer
==
self
.
peer_db
.
registry_prefix
:
if
not
peer
or
peer
==
self
.
cache
.
registry_prefix
:
return
str
(
len
(
self
.
_connection_dict
))
+
''
.
join
(
return
str
(
len
(
self
.
_connection_dict
))
+
''
.
join
(
' %s/%s'
%
(
int
(
x
,
2
),
len
(
x
))
' %s/%s'
%
(
int
(
x
,
2
),
len
(
x
))
for
x
in
(
self
.
_connection_dict
,
self
.
_served
)
for
x
in
(
self
.
_connection_dict
,
self
.
_served
)
...
@@ -356,11 +356,11 @@ class BaseTunnelManager(object):
...
@@ -356,11 +356,11 @@ class BaseTunnelManager(object):
class
TunnelManager
(
BaseTunnelManager
):
class
TunnelManager
(
BaseTunnelManager
):
def
__init__
(
self
,
control_socket
,
peer_db
,
cert
,
cert_renew
,
openvpn_args
,
def
__init__
(
self
,
control_socket
,
cache
,
cert
,
cert_renew
,
openvpn_args
,
timeout
,
refresh
,
client_count
,
iface_list
,
address
,
timeout
,
refresh
,
client_count
,
iface_list
,
address
,
ip_changed
,
encrypt
,
remote_gateway
,
disable_proto
,
ip_changed
,
encrypt
,
remote_gateway
,
disable_proto
,
neighbour_list
=
()):
neighbour_list
=
()):
super
(
TunnelManager
,
self
).
__init__
(
peer_db
,
cert
,
cert_renew
,
address
)
super
(
TunnelManager
,
self
).
__init__
(
cache
,
cert
,
cert_renew
,
address
)
self
.
ctl
=
ctl
.
Babel
(
control_socket
,
weakref
.
proxy
(
self
),
self
.
_network
)
self
.
ctl
=
ctl
.
Babel
(
control_socket
,
weakref
.
proxy
(
self
),
self
.
_network
)
self
.
encrypt
=
encrypt
self
.
encrypt
=
encrypt
self
.
ovpn_args
=
openvpn_args
self
.
ovpn_args
=
openvpn_args
...
@@ -460,7 +460,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -460,7 +460,7 @@ class TunnelManager(BaseTunnelManager):
if
remove
:
if
remove
:
self
.
_removeSomeTunnels
()
self
.
_removeSomeTunnels
()
self
.
resetTunnelRefresh
()
self
.
resetTunnelRefresh
()
self
.
peer_db
.
log
()
self
.
cache
.
log
()
self
.
_makeNewTunnels
(
True
)
self
.
_makeNewTunnels
(
True
)
# XXX: Commented code is an attempt to clean up unused interfaces
# XXX: Commented code is an attempt to clean up unused interfaces
# but babeld does not leave ipv6 membership for deleted taps,
# but babeld does not leave ipv6 membership for deleted taps,
...
@@ -531,7 +531,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -531,7 +531,7 @@ class TunnelManager(BaseTunnelManager):
assert
prefix
!=
self
.
_prefix
,
self
.
__dict__
assert
prefix
!=
self
.
_prefix
,
self
.
__dict__
address
=
[
x
for
x
in
utils
.
parse_address
(
address
)
address
=
[
x
for
x
in
utils
.
parse_address
(
address
)
if
x
[
2
]
not
in
self
.
_disable_proto
]
if
x
[
2
]
not
in
self
.
_disable_proto
]
self
.
peer_db
.
connecting
(
prefix
,
1
)
self
.
cache
.
connecting
(
prefix
,
1
)
if
not
address
:
if
not
address
:
return
False
return
False
logging
.
info
(
'Establishing a connection with %u/%u'
,
logging
.
info
(
'Establishing a connection with %u/%u'
,
...
@@ -567,7 +567,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -567,7 +567,7 @@ class TunnelManager(BaseTunnelManager):
distant_peers
[:]
=
peers
.
difference
(
neighbours
)
distant_peers
[:]
=
peers
.
difference
(
neighbours
)
distant_peers
.
sort
(
key
=
self
.
_newTunnelScore
)
distant_peers
.
sort
(
key
=
self
.
_newTunnelScore
)
# Check whether we're connected to the network.
# Check whether we're connected to the network.
registry
=
self
.
peer_db
.
registry_prefix
registry
=
self
.
cache
.
registry_prefix
if
registry
==
self
.
_prefix
:
if
registry
==
self
.
_prefix
:
if
not
distant_peers
:
if
not
distant_peers
:
# Faster recovery of registry node: use cache instead
# Faster recovery of registry node: use cache instead
...
@@ -590,7 +590,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -590,7 +590,7 @@ class TunnelManager(BaseTunnelManager):
if
peers
:
if
peers
:
# We aren't the only disconnected node
# We aren't the only disconnected node
# so force rebootstrapping.
# so force rebootstrapping.
peer
=
self
.
peer_db
.
getBootstrapPeer
()
peer
=
self
.
cache
.
getBootstrapPeer
()
if
not
peer
:
if
not
peer
:
# Registry dead ? Assume we're connected after all.
# Registry dead ? Assume we're connected after all.
distant_peers
=
self
.
_distant_peers
distant_peers
=
self
.
_distant_peers
...
@@ -612,7 +612,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -612,7 +612,7 @@ class TunnelManager(BaseTunnelManager):
# routing table.
# routing table.
while
count
and
distant_peers
:
while
count
and
distant_peers
:
peer
=
distant_peers
.
pop
()
peer
=
distant_peers
.
pop
()
address
=
self
.
peer_db
.
getAddress
(
peer
)
address
=
self
.
cache
.
getAddress
(
peer
)
if
address
:
if
address
:
count
-=
self
.
_makeTunnel
(
peer
,
address
)
count
-=
self
.
_makeTunnel
(
peer
,
address
)
elif
self
.
sendto
(
peer
,
'
\
1
'
):
elif
self
.
sendto
(
peer
,
'
\
1
'
):
...
@@ -623,7 +623,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -623,7 +623,7 @@ class TunnelManager(BaseTunnelManager):
# up. Select peers from cache for which we have no route.
# up. Select peers from cache for which we have no route.
new
=
0
new
=
0
bootstrap
=
True
bootstrap
=
True
for
peer
,
address
in
self
.
peer_db
.
getPeerList
():
for
peer
,
address
in
self
.
cache
.
getPeerList
():
if
peer
not
in
peers
:
if
peer
not
in
peers
:
bootstrap
=
False
bootstrap
=
False
if
self
.
_makeTunnel
(
peer
,
address
):
if
self
.
_makeTunnel
(
peer
,
address
):
...
@@ -635,12 +635,12 @@ class TunnelManager(BaseTunnelManager):
...
@@ -635,12 +635,12 @@ class TunnelManager(BaseTunnelManager):
if
not
(
new
or
peers
):
if
not
(
new
or
peers
):
if
bootstrap
and
registry
!=
self
.
_prefix
:
if
bootstrap
and
registry
!=
self
.
_prefix
:
# Startup without any good address in the cache.
# Startup without any good address in the cache.
peer
=
self
.
peer_db
.
getBootstrapPeer
()
peer
=
self
.
cache
.
getBootstrapPeer
()
if
peer
and
self
.
_makeTunnel
(
*
peer
):
if
peer
and
self
.
_makeTunnel
(
*
peer
):
return
return
# Failed to bootstrap ! Last chance to connect is to
# Failed to bootstrap ! Last chance to connect is to
# retry an address that already failed :(
# retry an address that already failed :(
for
peer
in
self
.
peer_db
.
getPeerList
(
1
):
for
peer
in
self
.
cache
.
getPeerList
(
1
):
if
self
.
_makeTunnel
(
*
peer
):
if
self
.
_makeTunnel
(
*
peer
):
break
break
...
@@ -666,7 +666,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -666,7 +666,7 @@ class TunnelManager(BaseTunnelManager):
self
.
_gateway_manager
.
add
(
trusted_ip
,
False
)
self
.
_gateway_manager
.
add
(
trusted_ip
,
False
)
if
prefix
in
self
.
_connection_dict
and
self
.
_prefix
<
prefix
:
if
prefix
in
self
.
_connection_dict
and
self
.
_prefix
<
prefix
:
self
.
_kill
(
prefix
)
self
.
_kill
(
prefix
)
self
.
peer_db
.
connecting
(
prefix
,
0
)
self
.
cache
.
connecting
(
prefix
,
0
)
def
_ovpn_client_disconnect
(
self
,
common_name
,
trusted_ip
):
def
_ovpn_client_disconnect
(
self
,
common_name
,
trusted_ip
):
prefix
=
utils
.
binFromSubnet
(
common_name
)
prefix
=
utils
.
binFromSubnet
(
common_name
)
...
...
re6stnet
View file @
aba0e94d
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
import
atexit
,
errno
,
logging
,
os
,
signal
,
socket
import
atexit
,
errno
,
logging
,
os
,
signal
,
socket
import
subprocess
,
sys
,
time
,
threading
import
subprocess
,
sys
,
time
,
threading
from
collections
import
deque
from
collections
import
deque
from
re6st
import
ctl
,
db
,
plib
,
tunnel
,
utils
,
version
,
x509
from
re6st
import
ctl
,
plib
,
tunnel
,
utils
,
version
,
x509
from
re6st.cache
import
Cache
from
re6st.utils
import
exit
,
ReexecException
from
re6st.utils
import
exit
,
ReexecException
def
getConfig
():
def
getConfig
():
...
@@ -26,7 +27,7 @@ def getConfig():
...
@@ -26,7 +27,7 @@ def getConfig():
"- <iface>.log: 1 file per spawned OpenVPN
\
n
"
)
"- <iface>.log: 1 file per spawned OpenVPN
\
n
"
)
_
(
'-s'
,
'--state'
,
default
=
'/var/lib/re6stnet'
,
_
(
'-s'
,
'--state'
,
default
=
'/var/lib/re6stnet'
,
help
=
"Path to re6stnet state directory:
\
n
"
help
=
"Path to re6stnet state directory:
\
n
"
"-
peers.db: cache of
peer addresses
\
n
"
"-
cache.db: cache of network parameters and
peer addresses
\
n
"
"- babeld.state: see option -S of babeld
\
n
"
)
"- babeld.state: see option -S of babeld
\
n
"
)
_
(
'-v'
,
'--verbose'
,
default
=
1
,
type
=
int
,
metavar
=
'LEVEL'
,
_
(
'-v'
,
'--verbose'
,
default
=
1
,
type
=
int
,
metavar
=
'LEVEL'
,
help
=
"Log level of re6stnet itself. 0 disables logging."
help
=
"Log level of re6stnet itself. 0 disables logging."
...
@@ -136,7 +137,7 @@ def main():
...
@@ -136,7 +137,7 @@ def main():
logging
.
trace
(
"Environment: %r"
,
os
.
environ
)
logging
.
trace
(
"Environment: %r"
,
os
.
environ
)
logging
.
trace
(
"Configuration: %r"
,
config
)
logging
.
trace
(
"Configuration: %r"
,
config
)
utils
.
makedirs
(
config
.
state
)
utils
.
makedirs
(
config
.
state
)
db_path
=
os
.
path
.
join
(
config
.
state
,
'
peers
.db'
)
db_path
=
os
.
path
.
join
(
config
.
state
,
'
cache
.db'
)
if
config
.
ovpnlog
:
if
config
.
ovpnlog
:
plib
.
ovpn_log
=
config
.
log
plib
.
ovpn_log
=
config
.
log
...
@@ -253,11 +254,11 @@ def main():
...
@@ -253,11 +254,11 @@ def main():
# Init db and tunnels
# Init db and tunnels
tunnel_interfaces
=
server_tunnels
.
keys
()
tunnel_interfaces
=
server_tunnels
.
keys
()
timeout
=
4
*
config
.
hello
timeout
=
4
*
config
.
hello
peer_db
=
db
.
PeerDB
(
db_path
,
config
.
registry
,
cert
)
cache
=
Cache
(
db_path
,
config
.
registry
,
cert
)
cleanup
=
[
lambda
:
peer_db
.
cacheMinimize
(
config
.
client_count
)]
cleanup
=
[
lambda
:
cache
.
cacheMinimize
(
config
.
client_count
)]
if
config
.
client_count
and
not
config
.
client
:
if
config
.
client_count
and
not
config
.
client
:
tunnel_manager
=
tunnel
.
TunnelManager
(
config
.
control_socket
,
tunnel_manager
=
tunnel
.
TunnelManager
(
config
.
control_socket
,
peer_db
,
cert
,
next_renew
,
config
.
openvpn_args
,
timeout
,
cache
,
cert
,
next_renew
,
config
.
openvpn_args
,
timeout
,
config
.
tunnel_refresh
,
config
.
client_count
,
config
.
iface_list
,
config
.
tunnel_refresh
,
config
.
client_count
,
config
.
iface_list
,
address
,
ip_changed
,
config
.
encrypt
,
remote_gateway
,
address
,
ip_changed
,
config
.
encrypt
,
remote_gateway
,
config
.
disable_proto
,
config
.
neighbour
)
config
.
disable_proto
,
config
.
neighbour
)
...
@@ -265,7 +266,7 @@ def main():
...
@@ -265,7 +266,7 @@ def main():
write_pipe
=
tunnel_manager
.
write_pipe
write_pipe
=
tunnel_manager
.
write_pipe
else
:
else
:
write_pipe
=
None
write_pipe
=
None
tunnel_manager
=
tunnel
.
BaseTunnelManager
(
peer_db
,
cert
,
next_renew
)
tunnel_manager
=
tunnel
.
BaseTunnelManager
(
cache
,
cert
,
next_renew
)
cleanup
.
append
(
tunnel_manager
.
sock
.
close
)
cleanup
.
append
(
tunnel_manager
.
sock
.
close
)
try
:
try
:
...
...
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