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
zhifan huang
re6stnet
Commits
d41daa7d
Commit
d41daa7d
authored
May 03, 2022
by
zhifan huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tunnel update -> 3
parent
5609588d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
31 deletions
+32
-31
re6st/cache.py
re6st/cache.py
+7
-7
re6st/tests/test_unit/test_tunnel/test_base_tunnel_manager.py
...t/tests/test_unit/test_tunnel/test_base_tunnel_manager.py
+2
-3
re6st/tests/test_unit/test_tunnel/test_multi_gateway_manager.py
...tests/test_unit/test_tunnel/test_multi_gateway_manager.py
+3
-4
re6st/tests/tools.py
re6st/tests/tools.py
+4
-4
re6st/tunnel.py
re6st/tunnel.py
+10
-10
re6st/x509.py
re6st/x509.py
+6
-3
No files found.
re6st/cache.py
View file @
d41daa7d
...
@@ -65,7 +65,7 @@ class Cache(object):
...
@@ -65,7 +65,7 @@ class Cache(object):
@
staticmethod
@
staticmethod
def
_selectConfig
(
execute
):
# BBB: blob
def
_selectConfig
(
execute
):
# BBB: blob
return
((
k
,
str
(
v
)
if
type
(
v
)
is
buffer
else
v
)
return
((
k
,
str
(
v
)
if
type
(
v
)
is
memoryview
else
v
)
for
k
,
v
in
execute
(
"SELECT * FROM config"
))
for
k
,
v
in
execute
(
"SELECT * FROM config"
))
def
_loadConfig
(
self
,
config
):
def
_loadConfig
(
self
,
config
):
...
@@ -100,13 +100,13 @@ class Cache(object):
...
@@ -100,13 +100,13 @@ class Cache(object):
v
=
self
.
_decrypt
(
v
.
decode
(
'base64'
))
v
=
self
.
_decrypt
(
v
.
decode
(
'base64'
))
elif
k
in
base64
:
elif
k
in
base64
:
v
=
v
.
decode
(
'base64'
)
v
=
v
.
decode
(
'base64'
)
elif
type
(
v
)
is
unicode
:
elif
type
(
v
)
is
str
:
v
=
str
(
v
)
v
=
bytes
(
v
)
elif
isinstance
(
v
,
(
list
,
dict
)):
elif
isinstance
(
v
,
(
list
,
dict
)):
k
+=
':json'
k
+=
':json'
v
=
json
.
dumps
(
v
)
v
=
json
.
dumps
(
v
)
config
[
k
]
=
v
config
[
k
]
=
v
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
logging
.
warning
(
e
)
logging
.
warning
(
e
)
return
return
except
Exception
:
except
Exception
:
...
@@ -133,7 +133,7 @@ class Cache(object):
...
@@ -133,7 +133,7 @@ class Cache(object):
# BBB: Use buffer because of http://bugs.python.org/issue13676
# BBB: Use buffer because of http://bugs.python.org/issue13676
# on Python 2.6
# on Python 2.6
db
.
executemany
(
"INSERT OR REPLACE INTO config VALUES(?,?)"
,
db
.
executemany
(
"INSERT OR REPLACE INTO config VALUES(?,?)"
,
((
k
,
buffer
(
v
)
if
k
in
base64
or
((
k
,
memoryview
(
v
)
if
k
in
base64
or
k
.
startswith
(
'babel_hmac'
)
else
v
)
k
.
startswith
(
'babel_hmac'
)
else
v
)
for
k
,
v
in
config
.
iteritems
()))
for
k
,
v
in
config
.
iteritems
()))
self
.
_loadConfig
(
config
.
iteritems
())
self
.
_loadConfig
(
config
.
iteritems
())
...
@@ -240,7 +240,7 @@ class Cache(object):
...
@@ -240,7 +240,7 @@ class Cache(object):
try
:
try
:
bootpeer
=
self
.
_registry
.
getBootstrapPeer
(
self
.
_prefix
)
bootpeer
=
self
.
_registry
.
getBootstrapPeer
(
self
.
_prefix
)
prefix
,
address
=
self
.
_decrypt
(
bootpeer
).
split
()
prefix
,
address
=
self
.
_decrypt
(
bootpeer
).
split
()
except
(
socket
.
error
,
subprocess
.
CalledProcessError
,
ValueError
)
,
e
:
except
(
socket
.
error
,
subprocess
.
CalledProcessError
,
ValueError
)
as
e
:
logging
.
warning
(
'Failed to bootstrap (%s)'
,
logging
.
warning
(
'Failed to bootstrap (%s)'
,
e
if
bootpeer
else
'no peer returned'
)
e
if
bootpeer
else
'no peer returned'
)
else
:
else
:
...
@@ -276,5 +276,5 @@ class Cache(object):
...
@@ -276,5 +276,5 @@ class Cache(object):
def
getCountry
(
self
,
ip
):
def
getCountry
(
self
,
ip
):
try
:
try
:
return
self
.
_registry
.
getCountry
(
self
.
_prefix
,
ip
)
return
self
.
_registry
.
getCountry
(
self
.
_prefix
,
ip
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
logging
.
warning
(
'Failed to get country (%s)'
,
ip
)
logging
.
warning
(
'Failed to get country (%s)'
,
ip
)
re6st/tests/test_unit/test_tunnel/test_base_tunnel_manager.py
View file @
d41daa7d
#!/usr/bin/python
2
#!/usr/bin/python
3
import
os
import
os
import
sys
import
sys
import
unittest
import
unittest
import
time
import
time
from
mock
import
patch
,
Mock
from
unittest.mock
import
patch
,
Mock
from
re6st
import
tunnel
from
re6st
import
tunnel
from
re6st
import
x509
from
re6st
import
x509
...
...
re6st/tests/test_unit/test_tunnel/test_multi_gateway_manager.py
View file @
d41daa7d
#!/usr/bin/python2
#!/usr/bin/python3
import
os
import
sys
import
unittest
import
unittest
from
mock
import
patch
from
unittest.
mock
import
patch
from
re6st
import
tunnel
from
re6st
import
tunnel
...
...
re6st/tests/tools.py
View file @
d41daa7d
...
@@ -66,9 +66,9 @@ def create_cert_file(pkey_file, cert_file, ca, ca_key, prefix, serial):
...
@@ -66,9 +66,9 @@ def create_cert_file(pkey_file, cert_file, ca, ca_key, prefix, serial):
pkey
,
csr
=
generate_csr
()
pkey
,
csr
=
generate_csr
()
cert
=
generate_cert
(
ca
,
ca_key
,
csr
,
prefix
,
serial
)
cert
=
generate_cert
(
ca
,
ca_key
,
csr
,
prefix
,
serial
)
with
open
(
pkey_file
,
'w'
)
as
f
:
with
open
(
pkey_file
,
'w'
)
as
f
:
f
.
write
(
pkey
)
f
.
write
(
pkey
.
decode
()
)
with
open
(
cert_file
,
'w'
)
as
f
:
with
open
(
cert_file
,
'w'
)
as
f
:
f
.
write
(
cert
)
f
.
write
(
cert
.
decode
()
)
return
pkey
,
cert
return
pkey
,
cert
...
@@ -94,9 +94,9 @@ def create_ca_file(pkey_file, cert_file, serial=0x120010db80042):
...
@@ -94,9 +94,9 @@ def create_ca_file(pkey_file, cert_file, serial=0x120010db80042):
cert
.
sign
(
key
,
"sha512"
)
cert
.
sign
(
key
,
"sha512"
)
with
open
(
pkey_file
,
'w'
)
as
pkey_file
:
with
open
(
pkey_file
,
'w'
)
as
pkey_file
:
pkey_file
.
write
(
crypto
.
dump_privatekey
(
crypto
.
FILETYPE_PEM
,
key
))
pkey_file
.
write
(
crypto
.
dump_privatekey
(
crypto
.
FILETYPE_PEM
,
key
)
.
decode
()
)
with
open
(
cert_file
,
'w'
)
as
cert_file
:
with
open
(
cert_file
,
'w'
)
as
cert_file
:
cert_file
.
write
(
crypto
.
dump_certificate
(
crypto
.
FILETYPE_PEM
,
cert
))
cert_file
.
write
(
crypto
.
dump_certificate
(
crypto
.
FILETYPE_PEM
,
cert
)
.
decode
()
)
return
key
,
cert
return
key
,
cert
...
...
re6st/tunnel.py
View file @
d41daa7d
...
@@ -243,14 +243,14 @@ class BaseTunnelManager(object):
...
@@ -243,14 +243,14 @@ class BaseTunnelManager(object):
self
.
_country
=
{}
self
.
_country
=
{}
address_dict
=
{
family
:
self
.
_updateCountry
(
address
)
address_dict
=
{
family
:
self
.
_updateCountry
(
address
)
for
family
,
address
in
address_dict
.
ite
rite
ms
()}
for
family
,
address
in
address_dict
.
items
()}
elif
cache
.
same_country
:
elif
cache
.
same_country
:
sys
.
exit
(
"Can not respect 'same_country' network configuration"
sys
.
exit
(
"Can not respect 'same_country' network configuration"
" (GEOIP2_MMDB not set)"
)
" (GEOIP2_MMDB not set)"
)
self
.
_address
=
{
family
:
utils
.
dump_address
(
address
)
self
.
_address
=
{
family
:
utils
.
dump_address
(
address
)
for
family
,
address
in
address_dict
.
ite
rite
ms
()
for
family
,
address
in
address_dict
.
items
()
if
address
}
if
address
}
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
iter
values
())
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
values
())
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
)
...
@@ -475,8 +475,8 @@ class BaseTunnelManager(object):
...
@@ -475,8 +475,8 @@ class BaseTunnelManager(object):
# Don't send country to old nodes
# Don't send country to old nodes
if
self
.
_getPeer
(
peer
).
protocol
<
7
:
if
self
.
_getPeer
(
peer
).
protocol
<
7
:
return
';'
.
join
(
','
.
join
(
a
.
split
(
','
)[:
3
])
for
a
in
return
';'
.
join
(
','
.
join
(
a
.
split
(
','
)[:
3
])
for
a
in
';'
.
join
(
self
.
_address
.
iter
values
()).
split
(
';'
))
';'
.
join
(
self
.
_address
.
values
()).
split
(
';'
))
return
';'
.
join
(
self
.
_address
.
iter
values
())
return
';'
.
join
(
self
.
_address
.
values
())
elif
not
code
:
# network version
elif
not
code
:
# network version
if
peer
:
if
peer
:
try
:
try
:
...
@@ -581,8 +581,8 @@ class BaseTunnelManager(object):
...
@@ -581,8 +581,8 @@ class BaseTunnelManager(object):
if
(
not
self
.
NEED_RESTART
.
isdisjoint
(
changed
)
if
(
not
self
.
NEED_RESTART
.
isdisjoint
(
changed
)
or
version
.
protocol
<
self
.
cache
.
min_protocol
or
version
.
protocol
<
self
.
cache
.
min_protocol
# TODO: With --management, we could kill clients without restarting.
# TODO: With --management, we could kill clients without restarting.
or
not
all
(
crl
.
isdisjoint
(
serials
.
iter
values
())
or
not
all
(
crl
.
isdisjoint
(
serials
.
values
())
for
serials
in
self
.
_served
.
iter
values
())):
for
serials
in
self
.
_served
.
values
())):
# Wait at least 1 second to broadcast new version to neighbours.
# Wait at least 1 second to broadcast new version to neighbours.
self
.
selectTimeout
(
time
.
time
()
+
1
+
self
.
cache
.
delay_restart
,
self
.
selectTimeout
(
time
.
time
()
+
1
+
self
.
cache
.
delay_restart
,
self
.
_restart
)
self
.
_restart
)
...
@@ -711,7 +711,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -711,7 +711,7 @@ class TunnelManager(BaseTunnelManager):
self
.
_client_count
=
client_count
self
.
_client_count
=
client_count
self
.
new_iface_list
=
deque
(
're6stnet'
+
str
(
i
)
self
.
new_iface_list
=
deque
(
're6stnet'
+
str
(
i
)
for
i
in
x
range
(
1
,
self
.
_client_count
+
1
))
for
i
in
range
(
1
,
self
.
_client_count
+
1
))
self
.
_free_iface_list
=
[]
self
.
_free_iface_list
=
[]
def
close
(
self
):
def
close
(
self
):
...
@@ -931,7 +931,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -931,7 +931,7 @@ class TunnelManager(BaseTunnelManager):
neighbours
=
self
.
ctl
.
neighbours
neighbours
=
self
.
ctl
.
neighbours
# Collect all nodes known by Babel
# Collect all nodes known by Babel
peers
=
{
prefix
peers
=
{
prefix
for
neigh_routes
in
neighbours
.
iter
values
()
for
neigh_routes
in
neighbours
.
values
()
for
prefix
in
neigh_routes
[
1
]
for
prefix
in
neigh_routes
[
1
]
if
prefix
}
if
prefix
}
# Keep only distant peers.
# Keep only distant peers.
...
@@ -1039,7 +1039,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -1039,7 +1039,7 @@ class TunnelManager(BaseTunnelManager):
if
self
.
cache
.
same_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
.
iter
values
())
self
.
cache
.
my_address
=
';'
.
join
(
self
.
_address
.
values
())
def
broadcastNewVersion
(
self
):
def
broadcastNewVersion
(
self
):
self
.
_babel_dump_new_version
()
self
.
_babel_dump_new_version
()
...
...
re6st/x509.py
View file @
d41daa7d
...
@@ -100,7 +100,8 @@ class Cert(object):
...
@@ -100,7 +100,8 @@ class Cert(object):
self
.
key
=
crypto
.
load_privatekey
(
crypto
.
FILETYPE_PEM
,
f
.
read
())
self
.
key
=
crypto
.
load_privatekey
(
crypto
.
FILETYPE_PEM
,
f
.
read
())
if
cert
:
if
cert
:
with
open
(
cert
)
as
f
:
with
open
(
cert
)
as
f
:
self
.
cert
=
self
.
loadVerify
(
f
.
read
())
# cert need to be bytes type
self
.
cert
=
self
.
loadVerify
(
f
.
read
().
encode
())
@
property
@
property
def
prefix
(
self
):
def
prefix
(
self
):
...
@@ -128,7 +129,8 @@ class Cert(object):
...
@@ -128,7 +129,8 @@ class Cert(object):
"CA Certificate"
,
registry
.
getCa
)
"CA Certificate"
,
registry
.
getCa
)
return
min
(
next_renew
,
ca_renew
)
return
min
(
next_renew
,
ca_renew
)
def
loadVerify
(
self
,
cert
,
strict
=
False
,
type
=
crypto
.
FILETYPE_PEM
):
# because use cert as para for communicate, so type should be bytes
def
loadVerify
(
self
,
cert
:
bytes
,
strict
=
False
,
type
=
crypto
.
FILETYPE_PEM
):
try
:
try
:
r
=
crypto
.
load_certificate
(
type
,
cert
)
r
=
crypto
.
load_certificate
(
type
,
cert
)
except
crypto
.
Error
:
except
crypto
.
Error
:
...
@@ -149,7 +151,8 @@ class Cert(object):
...
@@ -149,7 +151,8 @@ class Cert(object):
# error is printed to standard output.
# error is printed to standard output.
for
err
in
err
,
out
:
for
err
in
err
,
out
:
for
x
in
err
.
splitlines
():
for
x
in
err
.
splitlines
():
if
x
.
startswith
(
'error '
):
# here err and out is bytes
if
x
.
startswith
(
b'error '
):
x
,
msg
=
x
.
split
(
':'
,
1
)
x
,
msg
=
x
.
split
(
':'
,
1
)
_
,
code
,
_
,
depth
,
_
=
x
.
split
(
None
,
4
)
_
,
code
,
_
,
depth
,
_
=
x
.
split
(
None
,
4
)
raise
VerifyError
(
int
(
code
),
int
(
depth
),
msg
.
strip
())
raise
VerifyError
(
int
(
code
),
int
(
depth
),
msg
.
strip
())
...
...
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