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
b2bf1ae6
Commit
b2bf1ae6
authored
Jun 21, 2023
by
Joanne Hugé
Committed by
Tom Niget
Jun 18, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python2 to python3: Use 2to3 script
parent
f2fd7247
Changes
20
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
144 additions
and
145 deletions
+144
-145
demo/demo
demo/demo
+23
-23
demo/fixnemu.py
demo/fixnemu.py
+5
-5
demo/ping.py
demo/ping.py
+1
-1
demo/py
demo/py
+1
-1
demo/test_hmac.py
demo/test_hmac.py
+2
-2
re6st/cache.py
re6st/cache.py
+7
-9
re6st/cli/conf.py
re6st/cli/conf.py
+8
-8
re6st/cli/node.py
re6st/cli/node.py
+7
-7
re6st/cli/registry.py
re6st/cli/registry.py
+5
-5
re6st/ctl.py
re6st/ctl.py
+3
-3
re6st/debug.py
re6st/debug.py
+3
-2
re6st/plib.py
re6st/plib.py
+1
-1
re6st/registry.py
re6st/registry.py
+40
-40
re6st/tests/test_unit/test_conf.py
re6st/tests/test_unit/test_conf.py
+1
-1
re6st/tests/test_unit/test_registry.py
re6st/tests/test_unit/test_registry.py
+4
-4
re6st/tests/test_unit/test_registry_client.py
re6st/tests/test_unit/test_registry_client.py
+5
-5
re6st/tunnel.py
re6st/tunnel.py
+18
-18
re6st/upnpigd.py
re6st/upnpigd.py
+4
-4
re6st/utils.py
re6st/utils.py
+5
-5
setup.py
setup.py
+1
-1
No files found.
demo/demo
View file @
b2bf1ae6
...
@@ -72,7 +72,7 @@ if args.duration:
...
@@ -72,7 +72,7 @@ if args.duration:
signal.signal(signal.SIGALRM, handler)
signal.signal(signal.SIGALRM, handler)
signal.alarm(args.duration)
signal.alarm(args.duration)
exec
file("fixnemu.py"
)
exec
(compile(open("fixnemu.py", "rb").read(), "fixnemu.py", 'exec')
)
# create nodes
# create nodes
for name in """internet=I registry=R
for name in """internet=I registry=R
...
@@ -89,9 +89,9 @@ for name in """internet=I registry=R
...
@@ -89,9 +89,9 @@ for name in """internet=I registry=R
'net.ipv4.icmp_echo_ignore_broadcasts=0')).wait()
'net.ipv4.icmp_echo_ignore_broadcasts=0')).wait()
node._screen = node.Popen((SCREEN, '-DmS', name))
node._screen = node.Popen((SCREEN, '-DmS', name))
node.screen = (lambda name: lambda *cmd:
node.screen = (lambda name: lambda *cmd:
subprocess.call([SCREEN, '-r', name, '-X', 'eval'] + map(
subprocess.call([SCREEN, '-r', name, '-X', 'eval'] +
list(
map(
"""screen sh -c 'set %s; "\$@"; echo "\$@"; exec $SHELL'"""
"""screen sh -c 'set %s; "\$@"; echo "\$@"; exec $SHELL'"""
.__mod__, cmd)))(name)
.__mod__, cmd)))
)
(name)
# create switch
# create switch
switch1 = nemu.Switch()
switch1 = nemu.Switch()
...
@@ -208,10 +208,10 @@ for m in machine6, machine7, machine8:
...
@@ -208,10 +208,10 @@ for m in machine6, machine7, machine8:
null = file(os.devnull, "r+")
null = file(os.devnull, "r+")
for ip in '10.1.1.2', '10.1.1.3', '10.2.1.2', '10.2.1.3':
for ip in '10.1.1.2', '10.1.1.3', '10.2.1.2', '10.2.1.3':
if machine1.Popen(('ping', '-c1', ip), stdout=null).wait():
if machine1.Popen(('ping', '-c1', ip), stdout=null).wait():
print
'Failed to ping %s' % ip
print
('Failed to ping %s' % ip)
break
break
else:
else:
print
"Connectivity IPv4 OK!"
print
("Connectivity IPv4 OK!")
nodes = []
nodes = []
gateway1.screen('miniupnpd -d -f miniupnpd.conf -P miniupnpd.pid'
gateway1.screen('miniupnpd -d -f miniupnpd.conf -P miniupnpd.pid'
...
@@ -297,7 +297,7 @@ if args.ping:
...
@@ -297,7 +297,7 @@ if args.ping:
'2001:db8:43:1::1' if i == 10 else
'2001:db8:43:1::1' if i == 10 else
# Only 1 address for machine2 because prefix_len = 80,+48 = 128
# Only 1 address for machine2 because prefix_len = 80,+48 = 128
'2001:db8:42:%s::1' % i
'2001:db8:42:%s::1' % i
for i in
x
range(11)
for i in range(11)
if i != j]
if i != j]
name = machine.name if machine.short[0] == 'R' else 'm' + machine.short
name = machine.name if machine.short[0] == 'R' else 'm' + machine.short
machine.screen('python ping.py {} {}'.format(name, ' '.join(ips)))
machine.screen('python ping.py {} {}'.format(name, ' '.join(ips)))
...
@@ -314,30 +314,30 @@ class testHMAC(Thread):
...
@@ -314,30 +314,30 @@ class testHMAC(Thread):
reg1_db.text_factory = reg2_db.text_factory = str
reg1_db.text_factory = reg2_db.text_factory = str
m_net1 = 'registry', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8'
m_net1 = 'registry', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8'
m_net2 = 'registry2', 'm10'
m_net2 = 'registry2', 'm10'
print
'Testing HMAC, letting the time to machines to create tunnels...'
print
('Testing HMAC, letting the time to machines to create tunnels...')
time.sleep(45)
time.sleep(45)
print
'Check that the initial HMAC config is deployed on network 1'
print
('Check that the initial HMAC config is deployed on network 1')
test_hmac.checkHMAC(reg1_db, m_net1)
test_hmac.checkHMAC(reg1_db, m_net1)
print
'Test that a HMAC update works with nodes that are up'
print
('Test that a HMAC update works with nodes that are up')
registry.backticks_raise(updateHMAC)
registry.backticks_raise(updateHMAC)
print
'Updated HMAC (config = hmac0
&
hmac1), waiting...'
print
('Updated HMAC (config = hmac0
&
hmac1), waiting...')
time.sleep(60)
time.sleep(60)
print
'Checking HMAC on machines connected to registry 1...'
print
('Checking HMAC on machines connected to registry 1...')
test_hmac.checkHMAC(reg1_db, m_net1)
test_hmac.checkHMAC(reg1_db, m_net1)
print
('Test that machines can update upon reboot ' +
print
(
('Test that machines can update upon reboot ' +
'when they were off during a HMAC update.')
'when they were off during a HMAC update.')
)
test_hmac.killRe6st(machine1)
test_hmac.killRe6st(machine1)
print
'Re6st on machine 1 is stopped'
print
('Re6st on machine 1 is stopped')
time.sleep(5)
time.sleep(5)
registry.backticks_raise(updateHMAC)
registry.backticks_raise(updateHMAC)
print
'Updated HMAC on registry (config = hmac1
&
hmac2), waiting...'
print
('Updated HMAC on registry (config = hmac1
&
hmac2), waiting...')
time.sleep(60)
time.sleep(60)
machine1.screen(machine1.re6st_cmdline)
machine1.screen(machine1.re6st_cmdline)
print
'Started re6st on machine 1, waiting for it to get new conf'
print
('Started re6st on machine 1, waiting for it to get new conf')
time.sleep(60)
time.sleep(60)
print
'Checking HMAC on machines connected to registry 1...'
print
('Checking HMAC on machines connected to registry 1...')
test_hmac.checkHMAC(reg1_db, m_net1)
test_hmac.checkHMAC(reg1_db, m_net1)
print
'Testing of HMAC done!'
print
('Testing of HMAC done!')
# TODO: missing last step
# TODO: missing last step
reg1_db.close()
reg1_db.close()
reg2_db.close()
reg2_db.close()
...
@@ -399,7 +399,7 @@ def route_svg(ipv4, z = 4, default = type('', (), {'short': None})):
...
@@ -399,7 +399,7 @@ def route_svg(ipv4, z = 4, default = type('', (), {'short': None})):
gv.append('%s[pos="%s,%s!"];'
gv.append('%s[pos="%s,%s!"];'
% (n.name, z * math.cos(a * i), z * math.sin(a * i)))
% (n.name, z * math.cos(a * i), z * math.sin(a * i)))
l = []
l = []
for p, r in graph[n].ite
rite
ms():
for p, r in graph[n].items():
j = abs(nodes.index(p[0]) - i)
j = abs(nodes.index(p[0]) - i)
l.append((min(j, N - j), p, r))
l.append((min(j, N - j), p, r))
for j, (l, (p, t), r) in enumerate(sorted(l)):
for j, (l, (p, t), r) in enumerate(sorted(l)):
...
@@ -427,9 +427,9 @@ def route_svg(ipv4, z = 4, default = type('', (), {'short': None})):
...
@@ -427,9 +427,9 @@ def route_svg(ipv4, z = 4, default = type('', (), {'short': None})):
).communicate('\n'.join(gv))[0]
).communicate('\n'.join(gv))[0]
if args.port:
if args.port:
import
SimpleHTTPServer, SocketS
erver
import
http.server, sockets
erver
class Handler(
SimpleHTTPS
erver.SimpleHTTPRequestHandler):
class Handler(
http.s
erver.SimpleHTTPRequestHandler):
_path_match = re.compile('/(.+)\.(html|svg)$').match
_path_match = re.compile('/(.+)\.(html|svg)$').match
pages = 'ipv6', 'ipv4', 'tunnels'
pages = 'ipv6', 'ipv4', 'tunnels'
...
@@ -439,7 +439,7 @@ if args.port:
...
@@ -439,7 +439,7 @@ if args.port:
try:
try:
name, ext = self._path_match(self.path).groups()
name, ext = self._path_match(self.path).groups()
page = self.pages.index(name)
page = self.pages.index(name)
except AttributeError
,
ValueError:
except AttributeError
as
ValueError:
if self.path == '/':
if self.path == '/':
self.send_response(302)
self.send_response(302)
self.send_header('Location', self.pages[0] + '.html')
self.send_header('Location', self.pages[0] + '.html')
...
@@ -513,7 +513,7 @@ if args.port:
...
@@ -513,7 +513,7 @@ if args.port:
self
.
end_headers
()
self
.
end_headers
()
self
.
wfile
.
write
(
body
)
self
.
wfile
.
write
(
body
)
class
TCPServer
(
SocketS
erver
.
TCPServer
)
:
class
TCPServer
(
sockets
erver
.
TCPServer
)
:
allow_reuse_address =
True
allow_reuse_address =
True
TCPServer
(('',
args
.
port
),
Handler
).
serve_forever
()
TCPServer
(('',
args
.
port
),
Handler
).
serve_forever
()
...
...
demo/fixnemu.py
View file @
b2bf1ae6
...
@@ -56,7 +56,7 @@ def _get_all_route_data():
...
@@ -56,7 +56,7 @@ def _get_all_route_data():
metric))
metric))
return ret
return ret
get_all_route_data.
func_code = _get_all_route_data.func_code
get_all_route_data.
__code__ = _get_all_route_data.__code__
interface__init__ = interface.__init__
interface__init__ = interface.__init__
def __init__(self, *args, **kw):
def __init__(self, *args, **kw):
...
@@ -65,12 +65,12 @@ def __init__(self, *args, **kw):
...
@@ -65,12 +65,12 @@ def __init__(self, *args, **kw):
self.name = self.name.split('
@
',1)[0]
self.name = self.name.split('
@
',1)[0]
interface.__init__ = __init__
interface.__init__ = __init__
get_addr_data.orig = function(get_addr_data.
func_code
,
get_addr_data.orig = function(get_addr_data.
__code__
,
get_addr_data.
func_globals
)
get_addr_data.
__globals__
)
def _get_addr_data():
def _get_addr_data():
byidx, bynam = get_addr_data.orig()
byidx, bynam = get_addr_data.orig()
return byidx, {name.split('
@
',1)[0]: a for name, a in bynam.ite
rite
ms()}
return byidx, {name.split('
@
',1)[0]: a for name, a in bynam.items()}
get_addr_data.
func_code = _get_addr_data.func_code
get_addr_data.
__code__ = _get_addr_data.__code__
@staticmethod
@staticmethod
def _gen_if_name():
def _gen_if_name():
...
...
demo/ping.py
View file @
b2bf1ae6
...
@@ -64,7 +64,7 @@ class Ping(Thread):
...
@@ -64,7 +64,7 @@ class Ping(Thread):
os
.
utime
(
csv_path
,
(
time
.
time
(),
time
.
time
()))
os
.
utime
(
csv_path
,
(
time
.
time
(),
time
.
time
()))
for
add
in
no_responses
:
for
add
in
no_responses
:
print
(
'No response from %s with seq no %d'
%
(
add
,
seq
))
print
(
(
'No response from %s with seq no %d'
%
(
add
,
seq
)
))
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'n'
,
help
=
'my machine name (m1,m2...)'
)
parser
.
add_argument
(
'n'
,
help
=
'my machine name (m1,m2...)'
)
...
...
demo/py
View file @
b2bf1ae6
...
@@ -30,4 +30,4 @@ def __file__():
...
@@ -30,4 +30,4 @@ def __file__():
return
os
.
path
.
join
(
sys
.
path
[
0
],
sys
.
argv
[
1
])
return
os
.
path
.
join
(
sys
.
path
[
0
],
sys
.
argv
[
1
])
__file__
=
__file__
()
__file__
=
__file__
()
exec
file
(
__file__
)
exec
(
compile
(
open
(
__file__
,
"rb"
).
read
(),
__file__
,
'exec'
)
)
demo/test_hmac.py
View file @
b2bf1ae6
...
@@ -34,10 +34,10 @@ def checkHMAC(db, machines):
...
@@ -34,10 +34,10 @@ def checkHMAC(db, machines):
else
:
else
:
i
=
0
if
hmac
[
0
]
else
1
i
=
0
if
hmac
[
0
]
else
1
if
hmac
[
i
]
!=
sign
or
hmac
[
i
+
1
]
!=
accept
:
if
hmac
[
i
]
!=
sign
or
hmac
[
i
+
1
]
!=
accept
:
print
'HMAC config wrong for in %s'
%
args
print
(
'HMAC config wrong for in %s'
%
args
)
rc
=
False
rc
=
False
if
rc
:
if
rc
:
print
(
'All nodes use Babel with the correct HMAC configuration'
)
print
(
'All nodes use Babel with the correct HMAC configuration'
)
else
:
else
:
print
(
'Expected config: %s'
%
dict
(
zip
(
BABEL_HMAC
,
hmac
)))
print
(
(
'Expected config: %s'
%
dict
(
list
(
zip
(
BABEL_HMAC
,
hmac
))
)))
return
rc
return
rc
re6st/cache.py
View file @
b2bf1ae6
...
@@ -93,20 +93,18 @@ class Cache(object):
...
@@ -93,20 +93,18 @@ class Cache(object):
self
.
_registry
.
getNetworkConfig
(
self
.
_prefix
)))
self
.
_registry
.
getNetworkConfig
(
self
.
_prefix
)))
base64
=
x
.
pop
(
''
,
())
base64
=
x
.
pop
(
''
,
())
config
=
{}
config
=
{}
for
k
,
v
in
x
.
ite
rite
ms
():
for
k
,
v
in
x
.
items
():
k
=
str
(
k
)
k
=
str
(
k
)
if
k
.
startswith
(
'babel_hmac'
):
if
k
.
startswith
(
'babel_hmac'
):
if
v
:
if
v
:
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
:
v
=
str
(
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
:
...
@@ -135,11 +133,11 @@ class Cache(object):
...
@@ -135,11 +133,11 @@ class Cache(object):
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
,
buffer
(
v
)
if
k
in
base64
or
k
.
startswith
(
'babel_hmac'
)
else
v
)
k
.
startswith
(
'babel_hmac'
)
else
v
)
for
k
,
v
in
config
.
ite
rite
ms
()))
for
k
,
v
in
config
.
items
()))
self
.
_loadConfig
(
config
.
iteritems
(
))
self
.
_loadConfig
(
iter
(
config
.
items
()
))
return
[
k
[:
-
5
]
if
k
.
endswith
(
':json'
)
else
k
return
[
k
[:
-
5
]
if
k
.
endswith
(
':json'
)
else
k
for
k
in
chain
(
remove
,
(
k
for
k
in
chain
(
remove
,
(
k
for
k
,
v
in
config
.
ite
rite
ms
()
for
k
,
v
in
config
.
items
()
if
k
not
in
old
or
old
[
k
]
!=
v
))]
if
k
not
in
old
or
old
[
k
]
!=
v
))]
def
warnProtocol
(
self
):
def
warnProtocol
(
self
):
...
@@ -240,7 +238,7 @@ class Cache(object):
...
@@ -240,7 +238,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 +274,5 @@ class Cache(object):
...
@@ -276,5 +274,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/cli/conf.py
View file @
b2bf1ae6
...
@@ -101,7 +101,7 @@ def main():
...
@@ -101,7 +101,7 @@ def main():
if
config
.
req
:
if
config
.
req
:
components
.
update
(
config
.
req
)
components
.
update
(
config
.
req
)
subj
=
req
.
get_subject
()
subj
=
req
.
get_subject
()
for
k
,
v
in
components
.
iteritems
(
):
for
k
,
v
in
list
(
components
.
items
()
):
if
k
in
reserved
:
if
k
in
reserved
:
sys
.
exit
(
k
+
" field is reserved."
)
sys
.
exit
(
k
+
" field is reserved."
)
if
v
:
if
v
:
...
@@ -116,11 +116,11 @@ def main():
...
@@ -116,11 +116,11 @@ def main():
token
=
''
token
=
''
elif
not
token
:
elif
not
token
:
if
not
config
.
email
:
if
not
config
.
email
:
config
.
email
=
raw_input
(
'Please enter your email address: '
)
config
.
email
=
eval
(
input
(
'Please enter your email address: '
)
)
s
.
requestToken
(
config
.
email
)
s
.
requestToken
(
config
.
email
)
token_advice
=
"Use --token to retry without asking a new token
\
n
"
token_advice
=
"Use --token to retry without asking a new token
\
n
"
while
not
token
:
while
not
token
:
token
=
raw_input
(
'Please enter your token: '
)
token
=
eval
(
input
(
'Please enter your token: '
)
)
try
:
try
:
with
open
(
key_path
)
as
f
:
with
open
(
key_path
)
as
f
:
...
@@ -131,7 +131,7 @@ def main():
...
@@ -131,7 +131,7 @@ def main():
if
e
.
errno
!=
errno
.
ENOENT
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
raise
bits
=
ca
.
get_pubkey
().
bits
()
bits
=
ca
.
get_pubkey
().
bits
()
print
"Generating %s-bit key ..."
%
bits
print
((
"Generating %s-bit key ..."
%
bits
))
pkey
=
crypto
.
PKey
()
pkey
=
crypto
.
PKey
()
pkey
.
generate_key
(
crypto
.
TYPE_RSA
,
bits
)
pkey
.
generate_key
(
crypto
.
TYPE_RSA
,
bits
)
key
=
crypto
.
dump_privatekey
(
crypto
.
FILETYPE_PEM
,
pkey
)
key
=
crypto
.
dump_privatekey
(
crypto
.
FILETYPE_PEM
,
pkey
)
...
@@ -164,13 +164,13 @@ def main():
...
@@ -164,13 +164,13 @@ def main():
cert
=
loadCert
(
cert
)
cert
=
loadCert
(
cert
)
not_after
=
x509
.
notAfter
(
cert
)
not_after
=
x509
.
notAfter
(
cert
)
print
(
"Setup complete. Certificate is valid until %s UTC"
print
(
(
"Setup complete. Certificate is valid until %s UTC"
" and will be automatically renewed after %s UTC.
\
n
"
" and will be automatically renewed after %s UTC.
\
n
"
"Do not forget to backup to your private key (%s) or"
"Do not forget to backup to your private key (%s) or"
" you will lose your assigned subnet."
%
(
" you will lose your assigned subnet."
%
(
time
.
asctime
(
time
.
gmtime
(
not_after
)),
time
.
asctime
(
time
.
gmtime
(
not_after
)),
time
.
asctime
(
time
.
gmtime
(
not_after
-
registry
.
RENEW_PERIOD
)),
time
.
asctime
(
time
.
gmtime
(
not_after
-
registry
.
RENEW_PERIOD
)),
key_path
))
key_path
))
)
if
not
os
.
path
.
lexists
(
conf_path
):
if
not
os
.
path
.
lexists
(
conf_path
):
create
(
conf_path
,
"""
\
create
(
conf_path
,
"""
\
...
@@ -193,8 +193,8 @@ key %s
...
@@ -193,8 +193,8 @@ key %s
cn
=
x509
.
subnetFromCert
(
cert
)
cn
=
x509
.
subnetFromCert
(
cert
)
subnet
=
network
+
utils
.
binFromSubnet
(
cn
)
subnet
=
network
+
utils
.
binFromSubnet
(
cn
)
print
"Your subnet: %s/%u (CN=%s)"
\
print
((
"Your subnet: %s/%u (CN=%s)"
\
%
(
utils
.
ipFromBin
(
subnet
),
len
(
subnet
),
cn
)
%
(
utils
.
ipFromBin
(
subnet
),
len
(
subnet
),
cn
)
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
main
()
main
()
re6st/cli/node.py
View file @
b2bf1ae6
...
@@ -246,7 +246,7 @@ def main():
...
@@ -246,7 +246,7 @@ def main():
try
:
try
:
from
re6st.upnpigd
import
Forwarder
from
re6st.upnpigd
import
Forwarder
forwarder
=
Forwarder
(
're6stnet openvpn server'
)
forwarder
=
Forwarder
(
're6stnet openvpn server'
)
except
Exception
,
e
:
except
Exception
as
e
:
if
ipv4
:
if
ipv4
:
raise
raise
logging
.
info
(
"%s: assume we are not NATed"
,
e
)
logging
.
info
(
"%s: assume we are not NATed"
,
e
)
...
@@ -256,10 +256,10 @@ def main():
...
@@ -256,10 +256,10 @@ def main():
forwarder
.
addRule
(
port
,
proto
)
forwarder
.
addRule
(
port
,
proto
)
address
.
append
(
forwarder
.
checkExternalIp
())
address
.
append
(
forwarder
.
checkExternalIp
())
elif
'any'
not
in
ipv4
:
elif
'any'
not
in
ipv4
:
address
+=
map
(
ip_changed
,
ipv4
)
address
+=
list
(
map
(
ip_changed
,
ipv4
)
)
ipv4_any
=
()
ipv4_any
=
()
if
ipv6
:
if
ipv6
:
address
+=
map
(
ip_changed
,
ipv6
)
address
+=
list
(
map
(
ip_changed
,
ipv6
)
)
ipv6_any
=
()
ipv6_any
=
()
else
:
else
:
ip_changed
=
remote_gateway
=
None
ip_changed
=
remote_gateway
=
None
...
@@ -299,7 +299,7 @@ def main():
...
@@ -299,7 +299,7 @@ def main():
timeout
=
4
*
cache
.
hello
timeout
=
4
*
cache
.
hello
cleanup
=
[
lambda
:
cache
.
cacheMinimize
(
config
.
client_count
),
cleanup
=
[
lambda
:
cache
.
cacheMinimize
(
config
.
client_count
),
lambda
:
shutil
.
rmtree
(
config
.
run
,
True
)]
lambda
:
shutil
.
rmtree
(
config
.
run
,
True
)]
utils
.
makedirs
(
config
.
run
,
0700
)
utils
.
makedirs
(
config
.
run
,
0
o
700
)
control_socket
=
os
.
path
.
join
(
config
.
run
,
'babeld.sock'
)
control_socket
=
os
.
path
.
join
(
config
.
run
,
'babeld.sock'
)
if
config
.
client_count
and
not
config
.
client
:
if
config
.
client_count
and
not
config
.
client
:
tunnel_manager
=
tunnel
.
TunnelManager
(
control_socket
,
tunnel_manager
=
tunnel
.
TunnelManager
(
control_socket
,
...
@@ -362,7 +362,7 @@ def main():
...
@@ -362,7 +362,7 @@ def main():
if
not
dh
:
if
not
dh
:
dh
=
os
.
path
.
join
(
config
.
state
,
"dh.pem"
)
dh
=
os
.
path
.
join
(
config
.
state
,
"dh.pem"
)
cache
.
getDh
(
dh
)
cache
.
getDh
(
dh
)
for
iface
,
(
port
,
proto
)
in
server_tunnels
.
ite
rite
ms
():
for
iface
,
(
port
,
proto
)
in
server_tunnels
.
items
():
r
,
x
=
socket
.
socketpair
(
socket
.
AF_UNIX
,
socket
.
SOCK_DGRAM
)
r
,
x
=
socket
.
socketpair
(
socket
.
AF_UNIX
,
socket
.
SOCK_DGRAM
)
utils
.
setCloexec
(
r
)
utils
.
setCloexec
(
r
)
cleanup
.
append
(
plib
.
server
(
iface
,
config
.
max_clients
,
cleanup
.
append
(
plib
.
server
(
iface
,
config
.
max_clients
,
...
@@ -442,7 +442,7 @@ def main():
...
@@ -442,7 +442,7 @@ def main():
except
:
except
:
pass
pass
exit
.
release
()
exit
.
release
()
except
ReexecException
,
e
:
except
ReexecException
as
e
:
logging
.
info
(
e
)
logging
.
info
(
e
)
except
Exception
:
except
Exception
:
utils
.
log_exception
()
utils
.
log_exception
()
...
@@ -455,7 +455,7 @@ def main():
...
@@ -455,7 +455,7 @@ def main():
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
try
:
try
:
main
()
main
()
except
SystemExit
,
e
:
except
SystemExit
as
e
:
if
type
(
e
.
code
)
is
str
:
if
type
(
e
.
code
)
is
str
:
if
hasattr
(
logging
,
'trace'
):
# utils.setupLog called
if
hasattr
(
logging
,
'trace'
):
# utils.setupLog called
logging
.
critical
(
e
.
code
)
logging
.
critical
(
e
.
code
)
...
...
re6st/cli/registry.py
View file @
b2bf1ae6
#!/usr/bin/python2
#!/usr/bin/python2
import
http
lib
,
logging
,
os
,
socket
,
sys
import
http
.client
,
logging
,
os
,
socket
,
sys
from
BaseHTTPS
erver
import
BaseHTTPRequestHandler
from
http.s
erver
import
BaseHTTPRequestHandler
from
SocketS
erver
import
ThreadingTCPServer
from
sockets
erver
import
ThreadingTCPServer
from
urlparse
import
parse_qsl
from
url
lib.
parse
import
parse_qsl
if
're6st'
not
in
sys
.
modules
:
if
're6st'
not
in
sys
.
modules
:
sys
.
path
[
0
]
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
sys
.
path
[
0
]))
sys
.
path
[
0
]
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
sys
.
path
[
0
]))
from
re6st
import
registry
,
utils
,
version
from
re6st
import
registry
,
utils
,
version
...
@@ -36,7 +36,7 @@ class RequestHandler(BaseHTTPRequestHandler):
...
@@ -36,7 +36,7 @@ class RequestHandler(BaseHTTPRequestHandler):
return
self
.
server
.
handle_request
(
self
,
path
,
query
)
return
self
.
server
.
handle_request
(
self
,
path
,
query
)
except
Exception
:
except
Exception
:
logging
.
info
(
self
.
requestline
,
exc_info
=
1
)
logging
.
info
(
self
.
requestline
,
exc_info
=
1
)
self
.
send_error
(
http
lib
.
BAD_REQUEST
)
self
.
send_error
(
http
.
client
.
BAD_REQUEST
)
def
log_error
(
*
args
):
def
log_error
(
*
args
):
pass
pass
...
...
re6st/ctl.py
View file @
b2bf1ae6
...
@@ -44,7 +44,7 @@ class Array(object):
...
@@ -44,7 +44,7 @@ class Array(object):
r
=
[]
r
=
[]
o
=
offset
+
2
o
=
offset
+
2
decode
=
self
.
_item
.
decode
decode
=
self
.
_item
.
decode
for
i
in
x
range
(
*
uint16
.
unpack_from
(
buffer
,
offset
)):
for
i
in
range
(
*
uint16
.
unpack_from
(
buffer
,
offset
)):
o
,
x
=
decode
(
buffer
,
o
)
o
,
x
=
decode
(
buffer
,
o
)
r
.
append
(
x
)
r
.
append
(
x
)
return
o
,
r
return
o
,
r
...
@@ -206,7 +206,7 @@ class Babel(object):
...
@@ -206,7 +206,7 @@ class Babel(object):
def
select
(
*
args
):
def
select
(
*
args
):
try
:
try
:
s
.
connect
(
self
.
socket_path
)
s
.
connect
(
self
.
socket_path
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
logging
.
debug
(
"Can't connect to %r (%r)"
,
self
.
socket_path
,
e
)
logging
.
debug
(
"Can't connect to %r (%r)"
,
self
.
socket_path
,
e
)
return
e
return
e
s
.
send
(
"
\
1
"
)
s
.
send
(
"
\
1
"
)
...
@@ -323,7 +323,7 @@ class iterRoutes(object):
...
@@ -323,7 +323,7 @@ class iterRoutes(object):
c
.
select
(
*
args
)
c
.
select
(
*
args
)
utils
.
select
(
*
args
)
utils
.
select
(
*
args
)
return
(
prefix
return
(
prefix
for
neigh_routes
in
c
.
neighbours
.
iter
values
()
for
neigh_routes
in
c
.
neighbours
.
values
()
for
prefix
in
neigh_routes
[
1
]
for
prefix
in
neigh_routes
[
1
]
if
prefix
)
if
prefix
)
...
...
re6st/debug.py
View file @
b2bf1ae6
...
@@ -37,7 +37,8 @@ class Socket(object):
...
@@ -37,7 +37,8 @@ class Socket(object):
try
:
try
:
self
.
_socket
.
recv
(
0
)
self
.
_socket
.
recv
(
0
)
return
True
return
True
except
socket
.
error
,
(
err
,
_
):
except
socket
.
error
as
e
:
(
err
,
_
)
=
e
if
err
!=
errno
.
EAGAIN
:
if
err
!=
errno
.
EAGAIN
:
raise
raise
self
.
_socket
.
setblocking
(
1
)
self
.
_socket
.
setblocking
(
1
)
...
@@ -52,7 +53,7 @@ class Console(object):
...
@@ -52,7 +53,7 @@ class Console(object):
socket
.
SOCK_STREAM
|
socket
.
SOCK_CLOEXEC
)
socket
.
SOCK_STREAM
|
socket
.
SOCK_CLOEXEC
)
try
:
try
:
self
.
_removeSocket
()
self
.
_removeSocket
()
except
OSError
,
e
:
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
raise
s
.
bind
(
path
)
s
.
bind
(
path
)
...
...
re6st/plib.py
View file @
b2bf1ae6
...
@@ -132,7 +132,7 @@ def router(ip, ip4, rt6, hello_interval, log_path, state_path, pidfile,
...
@@ -132,7 +132,7 @@ def router(ip, ip4, rt6, hello_interval, log_path, state_path, pidfile,
# WKRD: babeld fails to start if pidfile already exists
# WKRD: babeld fails to start if pidfile already exists
try
:
try
:
os
.
remove
(
pidfile
)
os
.
remove
(
pidfile
)
except
OSError
,
e
:
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
ENOENT
:
if
e
.
errno
!=
errno
.
ENOENT
:
raise
raise
logging
.
info
(
'%r'
,
cmd
)
logging
.
info
(
'%r'
,
cmd
)
...
...
re6st/registry.py
View file @
b2bf1ae6
This diff is collapsed.
Click to expand it.
re6st/tests/test_unit/test_conf.py
View file @
b2bf1ae6
...
@@ -6,7 +6,7 @@ import os
...
@@ -6,7 +6,7 @@ import os
import
sys
import
sys
import
unittest
import
unittest
from
shutil
import
rmtree
from
shutil
import
rmtree
from
StringIO
import
StringIO
from
io
import
StringIO
from
mock
import
patch
from
mock
import
patch
from
OpenSSL
import
crypto
from
OpenSSL
import
crypto
...
...
re6st/tests/test_unit/test_registry.py
View file @
b2bf1ae6
...
@@ -3,7 +3,7 @@ import os
...
@@ -3,7 +3,7 @@ import os
import
random
import
random
import
string
import
string
import
json
import
json
import
http
lib
import
http
.client
import
base64
import
base64
import
unittest
import
unittest
import
hmac
import
hmac
...
@@ -162,7 +162,7 @@ class TestRegistryServer(unittest.TestCase):
...
@@ -162,7 +162,7 @@ class TestRegistryServer(unittest.TestCase):
[(
hashlib
.
sha1
(
key
).
digest
(),
protocol
)])
[(
hashlib
.
sha1
(
key
).
digest
(),
protocol
)])
func
.
assert_called_once_with
(
**
params
)
func
.
assert_called_once_with
(
**
params
)
# http response check
# http response check
request
.
send_response
.
assert_called_once_with
(
http
lib
.
OK
)
request
.
send_response
.
assert_called_once_with
(
http
.
client
.
OK
)
request
.
send_header
.
assert_any_call
(
"Content-Length"
,
str
(
len
(
result
)))
request
.
send_header
.
assert_any_call
(
"Content-Length"
,
str
(
len
(
result
)))
request
.
send_header
.
assert_any_call
(
request
.
send_header
.
assert_any_call
(
registry
.
HMAC_HEADER
,
registry
.
HMAC_HEADER
,
...
@@ -189,8 +189,8 @@ class TestRegistryServer(unittest.TestCase):
...
@@ -189,8 +189,8 @@ class TestRegistryServer(unittest.TestCase):
self
.
server
.
handle_request
(
request_bad
,
method
,
params
)
self
.
server
.
handle_request
(
request_bad
,
method
,
params
)
func
.
assert_called_once_with
(
**
params
)
func
.
assert_called_once_with
(
**
params
)
request_bad
.
send_error
.
assert_called_once_with
(
http
lib
.
FORBIDDEN
)
request_bad
.
send_error
.
assert_called_once_with
(
http
.
client
.
FORBIDDEN
)
request_good
.
send_response
.
assert_called_once_with
(
http
lib
.
NO_CONTENT
)
request_good
.
send_response
.
assert_called_once_with
(
http
.
client
.
NO_CONTENT
)
# will cause valueError, if a node send hello twice to a registry
# will cause valueError, if a node send hello twice to a registry
def
test_getPeerProtocol
(
self
):
def
test_getPeerProtocol
(
self
):
...
...
re6st/tests/test_unit/test_registry_client.py
View file @
b2bf1ae6
...
@@ -2,7 +2,7 @@ import sys
...
@@ -2,7 +2,7 @@ import sys
import
os
import
os
import
unittest
import
unittest
import
hmac
import
hmac
import
http
lib
import
http
.client
import
base64
import
base64
import
hashlib
import
hashlib
from
mock
import
Mock
,
patch
from
mock
import
Mock
,
patch
...
@@ -26,15 +26,15 @@ class TestRegistryClient(unittest.TestCase):
...
@@ -26,15 +26,15 @@ class TestRegistryClient(unittest.TestCase):
self
.
assertEqual
(
client1
.
_path
,
"/example"
)
self
.
assertEqual
(
client1
.
_path
,
"/example"
)
self
.
assertEqual
(
client1
.
_conn
.
host
,
"localhost"
)
self
.
assertEqual
(
client1
.
_conn
.
host
,
"localhost"
)
self
.
assertIsInstance
(
client1
.
_conn
,
http
lib
.
HTTPSConnection
)
self
.
assertIsInstance
(
client1
.
_conn
,
http
.
client
.
HTTPSConnection
)
self
.
assertIsInstance
(
client2
.
_conn
,
http
lib
.
HTTPConnection
)
self
.
assertIsInstance
(
client2
.
_conn
,
http
.
client
.
HTTPConnection
)
def
test_rpc_hello
(
self
):
def
test_rpc_hello
(
self
):
prefix
=
"0000000011111111"
prefix
=
"0000000011111111"
protocol
=
"7"
protocol
=
"7"
body
=
"a_hmac_key"
body
=
"a_hmac_key"
query
=
"/hello?client_prefix=0000000011111111&protocol=7"
query
=
"/hello?client_prefix=0000000011111111&protocol=7"
response
=
fakeResponse
(
body
,
http
lib
.
OK
)
response
=
fakeResponse
(
body
,
http
.
client
.
OK
)
self
.
client
.
_conn
.
getresponse
.
return_value
=
response
self
.
client
.
_conn
.
getresponse
.
return_value
=
response
res
=
self
.
client
.
hello
(
prefix
,
protocol
)
res
=
self
.
client
.
hello
(
prefix
,
protocol
)
...
@@ -58,7 +58,7 @@ class TestRegistryClient(unittest.TestCase):
...
@@ -58,7 +58,7 @@ class TestRegistryClient(unittest.TestCase):
key
=
hashlib
.
sha1
(
key
).
digest
()
key
=
hashlib
.
sha1
(
key
).
digest
()
# response part
# response part
body
=
None
body
=
None
response
=
fakeResponse
(
body
,
http
lib
.
NO_CONTENT
)
response
=
fakeResponse
(
body
,
http
.
client
.
NO_CONTENT
)
response
.
msg
=
dict
(
Re6stHMAC
=
hmac
.
HMAC
(
key
,
body
,
hashlib
.
sha1
).
digest
())
response
.
msg
=
dict
(
Re6stHMAC
=
hmac
.
HMAC
(
key
,
body
,
hashlib
.
sha1
).
digest
())
self
.
client
.
_conn
.
getresponse
.
return_value
=
response
self
.
client
.
_conn
.
getresponse
.
return_value
=
response
...
...
re6st/tunnel.py
View file @
b2bf1ae6
...
@@ -242,14 +242,14 @@ class BaseTunnelManager(object):
...
@@ -242,14 +242,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
.
itervalues
(
))
cache
.
my_address
=
';'
.
join
(
iter
(
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
)
...
@@ -346,7 +346,7 @@ class BaseTunnelManager(object):
...
@@ -346,7 +346,7 @@ class BaseTunnelManager(object):
def
_sendto
(
self
,
to
,
msg
,
peer
=
None
):
def
_sendto
(
self
,
to
,
msg
,
peer
=
None
):
try
:
try
:
r
=
self
.
sock
.
sendto
(
peer
.
encode
(
msg
)
if
peer
else
msg
,
to
)
r
=
self
.
sock
.
sendto
(
peer
.
encode
(
msg
)
if
peer
else
msg
,
to
)
except
socket
.
error
,
e
:
except
socket
.
error
as
e
:
(
logging
.
info
if
e
.
errno
==
errno
.
ENETUNREACH
else
logging
.
error
)(
(
logging
.
info
if
e
.
errno
==
errno
.
ENETUNREACH
else
logging
.
error
)(
'Failed to send message to %s (%s)'
,
to
,
e
)
'Failed to send message to %s (%s)'
,
to
,
e
)
return
return
...
@@ -410,7 +410,7 @@ class BaseTunnelManager(object):
...
@@ -410,7 +410,7 @@ class BaseTunnelManager(object):
serial
=
cert
.
get_serial_number
()
serial
=
cert
.
get_serial_number
()
if
serial
in
self
.
cache
.
crl
:
if
serial
in
self
.
cache
.
crl
:
raise
ValueError
(
"revoked"
)
raise
ValueError
(
"revoked"
)
except
(
x509
.
VerifyError
,
ValueError
)
,
e
:
except
(
x509
.
VerifyError
,
ValueError
)
as
e
:
if
retry
:
if
retry
:
return
True
return
True
logging
.
debug
(
'ignored invalid certificate from %r (%s)'
,
logging
.
debug
(
'ignored invalid certificate from %r (%s)'
,
...
@@ -467,8 +467,8 @@ class BaseTunnelManager(object):
...
@@ -467,8 +467,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
.
itervalues
(
)).
split
(
';'
))
';'
.
join
(
iter
(
self
.
_address
.
values
()
)).
split
(
';'
))
return
';'
.
join
(
self
.
_address
.
itervalues
(
))
return
';'
.
join
(
iter
(
self
.
_address
.
values
()
))
elif
not
code
:
# network version
elif
not
code
:
# network version
if
peer
:
if
peer
:
try
:
try
:
...
@@ -553,8 +553,8 @@ class BaseTunnelManager(object):
...
@@ -553,8 +553,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
.
itervalues
(
))
or
not
all
(
crl
.
isdisjoint
(
iter
(
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
)
...
@@ -606,7 +606,7 @@ class BaseTunnelManager(object):
...
@@ -606,7 +606,7 @@ class BaseTunnelManager(object):
with
open
(
'/proc/net/ipv6_route'
,
"r"
,
4096
)
as
f
:
with
open
(
'/proc/net/ipv6_route'
,
"r"
,
4096
)
as
f
:
try
:
try
:
routing_table
=
f
.
read
()
routing_table
=
f
.
read
()
except
IOError
,
e
:
except
IOError
as
e
:
# ???: If someone can explain why the kernel sometimes fails
# ???: If someone can explain why the kernel sometimes fails
# even when there's a lot of free memory.
# even when there's a lot of free memory.
if
e
.
errno
!=
errno
.
ENOMEM
:
if
e
.
errno
!=
errno
.
ENOMEM
:
...
@@ -683,7 +683,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -683,7 +683,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
):
...
@@ -752,7 +752,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -752,7 +752,7 @@ class TunnelManager(BaseTunnelManager):
def
babel_dump
(
self
):
def
babel_dump
(
self
):
t
=
time
.
time
()
t
=
time
.
time
()
if
self
.
_killing
:
if
self
.
_killing
:
for
prefix
,
tunnel_killer
in
self
.
_killing
.
items
(
):
for
prefix
,
tunnel_killer
in
list
(
self
.
_killing
.
items
()
):
if
tunnel_killer
.
timeout
<
t
:
if
tunnel_killer
.
timeout
<
t
:
if
tunnel_killer
.
state
!=
'unlocking'
:
if
tunnel_killer
.
state
!=
'unlocking'
:
logging
.
info
(
logging
.
info
(
...
@@ -780,7 +780,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -780,7 +780,7 @@ class TunnelManager(BaseTunnelManager):
def
_cleanDeads
(
self
):
def
_cleanDeads
(
self
):
disconnected
=
False
disconnected
=
False
for
prefix
in
self
.
_connection_dict
.
keys
(
):
for
prefix
in
list
(
self
.
_connection_dict
.
keys
()
):
status
=
self
.
_connection_dict
[
prefix
].
refresh
()
status
=
self
.
_connection_dict
[
prefix
].
refresh
()
if
status
:
if
status
:
disconnected
|=
status
>
0
disconnected
|=
status
>
0
...
@@ -902,7 +902,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -902,7 +902,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.
...
@@ -987,7 +987,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -987,7 +987,7 @@ class TunnelManager(BaseTunnelManager):
break
break
def
killAll
(
self
):
def
killAll
(
self
):
for
prefix
in
self
.
_connection_dict
.
keys
(
):
for
prefix
in
list
(
self
.
_connection_dict
.
keys
()
):
self
.
_kill
(
prefix
)
self
.
_kill
(
prefix
)
def
handleClientEvent
(
self
):
def
handleClientEvent
(
self
):
...
@@ -999,7 +999,7 @@ class TunnelManager(BaseTunnelManager):
...
@@ -999,7 +999,7 @@ class TunnelManager(BaseTunnelManager):
if
c
and
c
.
time
<
float
(
time
):
if
c
and
c
.
time
<
float
(
time
):
try
:
try
:
c
.
connected
(
serial
)
c
.
connected
(
serial
)
except
(
KeyError
,
TypeError
)
,
e
:
except
(
KeyError
,
TypeError
)
as
e
:
logging
.
error
(
"%s (route_up %s)"
,
e
,
common_name
)
logging
.
error
(
"%s (route_up %s)"
,
e
,
common_name
)
else
:
else
:
logging
.
info
(
"ignore route_up notification for %s %r"
,
logging
.
info
(
"ignore route_up notification for %s %r"
,
...
@@ -1010,10 +1010,10 @@ class TunnelManager(BaseTunnelManager):
...
@@ -1010,10 +1010,10 @@ 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
.
itervalues
(
))
self
.
cache
.
my_address
=
';'
.
join
(
iter
(
self
.
_address
.
values
()
))
def
broadcastNewVersion
(
self
):
def
broadcastNewVersion
(
self
):
self
.
_babel_dump_new_version
()
self
.
_babel_dump_new_version
()
for
prefix
,
c
in
self
.
_connection_dict
.
items
(
):
for
prefix
,
c
in
list
(
self
.
_connection_dict
.
items
()
):
if
c
.
serial
in
self
.
cache
.
crl
:
if
c
.
serial
in
self
.
cache
.
crl
:
self
.
_kill
(
prefix
)
self
.
_kill
(
prefix
)
re6st/upnpigd.py
View file @
b2bf1ae6
...
@@ -40,7 +40,7 @@ class Forwarder(object):
...
@@ -40,7 +40,7 @@ class Forwarder(object):
def
wrapper
(
*
args
,
**
kw
):
def
wrapper
(
*
args
,
**
kw
):
try
:
try
:
return
wrapped
(
*
args
,
**
kw
)
return
wrapped
(
*
args
,
**
kw
)
except
Exception
,
e
:
except
Exception
as
e
:
raise
UPnPException
(
str
(
e
))
raise
UPnPException
(
str
(
e
))
return
wraps
(
wrapped
)(
wrapper
)
return
wraps
(
wrapped
)(
wrapper
)
...
@@ -68,14 +68,14 @@ class Forwarder(object):
...
@@ -68,14 +68,14 @@ class Forwarder(object):
else
:
else
:
try
:
try
:
return
self
.
_refresh
()
return
self
.
_refresh
()
except
UPnPException
,
e
:
except
UPnPException
as
e
:
logging
.
debug
(
"UPnP failure"
,
exc_info
=
1
)
logging
.
debug
(
"UPnP failure"
,
exc_info
=
1
)
self
.
clear
()
self
.
clear
()
try
:
try
:
self
.
discover
()
self
.
discover
()
self
.
selectigd
()
self
.
selectigd
()
return
self
.
_refresh
()
return
self
.
_refresh
()
except
UPnPException
,
e
:
except
UPnPException
as
e
:
self
.
next_refresh
=
self
.
_next_retry
=
time
.
time
()
+
60
self
.
next_refresh
=
self
.
_next_retry
=
time
.
time
()
+
60
logging
.
info
(
str
(
e
))
logging
.
info
(
str
(
e
))
self
.
clear
()
self
.
clear
()
...
@@ -109,7 +109,7 @@ class Forwarder(object):
...
@@ -109,7 +109,7 @@ class Forwarder(object):
try
:
try
:
self
.
addportmapping
(
port
,
*
args
)
self
.
addportmapping
(
port
,
*
args
)
break
break
except
UPnPException
,
e
:
except
UPnPException
as
e
:
if
str
(
e
)
!=
'ConflictInMappingEntry'
:
if
str
(
e
)
!=
'ConflictInMappingEntry'
:
raise
raise
port
=
None
port
=
None
...
...
re6st/utils.py
View file @
b2bf1ae6
...
@@ -164,7 +164,7 @@ class Popen(subprocess.Popen):
...
@@ -164,7 +164,7 @@ class Popen(subprocess.Popen):
self
.
_args
=
tuple
(
args
[
0
]
if
args
else
kw
[
'args'
])
self
.
_args
=
tuple
(
args
[
0
]
if
args
else
kw
[
'args'
])
try
:
try
:
super
(
Popen
,
self
).
__init__
(
*
args
,
**
kw
)
super
(
Popen
,
self
).
__init__
(
*
args
,
**
kw
)
except
OSError
,
e
:
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
ENOMEM
:
if
e
.
errno
!=
errno
.
ENOMEM
:
raise
raise
self
.
returncode
=
-
1
self
.
returncode
=
-
1
...
@@ -209,7 +209,7 @@ def select(R, W, T):
...
@@ -209,7 +209,7 @@ def select(R, W, T):
def
makedirs
(
*
args
):
def
makedirs
(
*
args
):
try
:
try
:
os
.
makedirs
(
*
args
)
os
.
makedirs
(
*
args
)
except
OSError
,
e
:
except
OSError
as
e
:
if
e
.
errno
!=
errno
.
EEXIST
:
if
e
.
errno
!=
errno
.
EEXIST
:
raise
raise
...
@@ -240,7 +240,7 @@ def parse_address(address_list):
...
@@ -240,7 +240,7 @@ def parse_address(address_list):
a
=
address
.
split
(
','
)
a
=
address
.
split
(
','
)
int
(
a
[
1
])
# Check if port is an int
int
(
a
[
1
])
# Check if port is an int
yield
tuple
(
a
[:
4
])
yield
tuple
(
a
[:
4
])
except
ValueError
,
e
:
except
ValueError
as
e
:
logging
.
warning
(
"Failed to parse node address %r (%s)"
,
logging
.
warning
(
"Failed to parse node address %r (%s)"
,
address
,
e
)
address
,
e
)
...
@@ -262,7 +262,7 @@ newHmacSecret = newHmacSecret()
...
@@ -262,7 +262,7 @@ newHmacSecret = newHmacSecret()
# - the 3 first bits code the number of bytes
# - the 3 first bits code the number of bytes
def
packInteger
(
i
):
def
packInteger
(
i
):
for
n
in
x
range
(
8
):
for
n
in
range
(
8
):
x
=
32
<<
8
*
n
x
=
32
<<
8
*
n
if
i
<
x
:
if
i
<
x
:
return
struct
.
pack
(
"!Q"
,
i
+
n
*
x
)[
7
-
n
:]
return
struct
.
pack
(
"!Q"
,
i
+
n
*
x
)[
7
-
n
:]
...
@@ -275,7 +275,7 @@ def unpackInteger(x):
...
@@ -275,7 +275,7 @@ def unpackInteger(x):
i
,
=
struct
.
unpack
(
"!Q"
,
'
\
0
'
*
(
7
-
n
)
+
x
[:
n
+
1
])
i
,
=
struct
.
unpack
(
"!Q"
,
'
\
0
'
*
(
7
-
n
)
+
x
[:
n
+
1
])
except
struct
.
error
:
except
struct
.
error
:
return
return
return
sum
((
32
<<
8
*
i
for
i
in
x
range
(
n
)),
return
sum
((
32
<<
8
*
i
for
i
in
range
(
n
)),
i
-
(
n
*
32
<<
8
*
n
)),
n
+
1
i
-
(
n
*
32
<<
8
*
n
)),
n
+
1
###
###
...
...
setup.py
View file @
b2bf1ae6
...
@@ -14,7 +14,7 @@ def copy_file(self, infile, outfile, *args, **kw):
...
@@ -14,7 +14,7 @@ def copy_file(self, infile, outfile, *args, **kw):
if
not
self
.
dry_run
:
if
not
self
.
dry_run
:
log
.
info
(
"generating %s -> %s"
,
infile
,
outfile
)
log
.
info
(
"generating %s -> %s"
,
infile
,
outfile
)
with
open
(
outfile
,
"wb"
)
as
f
:
with
open
(
outfile
,
"wb"
)
as
f
:
for
x
in
sorted
(
version
.
ite
rite
ms
()):
for
x
in
sorted
(
version
.
items
()):
if
not
x
[
0
].
startswith
(
"_"
):
if
not
x
[
0
].
startswith
(
"_"
):
f
.
write
(
"%s = %r
\
n
"
%
x
)
f
.
write
(
"%s = %r
\
n
"
%
x
)
return
outfile
,
1
return
outfile
,
1
...
...
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