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
eb9a9237
Commit
eb9a9237
authored
Oct 21, 2013
by
Jondy Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tunnel.py: fix conflict
parent
50275cc2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
43 deletions
+31
-43
re6st/tunnel.py
re6st/tunnel.py
+31
-43
No files found.
re6st/tunnel.py
View file @
eb9a9237
import
logging
,
platform
,
random
,
socket
,
subprocess
,
sys
,
time
from
collections
import
deque
from
itertools
import
chain
from
.
import
plib
,
utils
PORT
=
326
RTF_CACHE
=
0x01000000
# cache entry
# Be careful the refresh interval should let the routes be established
...
...
@@ -64,6 +62,7 @@ class Connection(object):
'--tls-remote'
,
'%u/%u'
%
(
int
(
self
.
_prefix
,
2
),
len
(
self
.
_prefix
)),
'--resolv-retry'
,
'0'
,
'--connect-retry-max'
,
'3'
,
'--tls-exit'
,
'--remap-usr1'
,
'SIGTERM'
,
'--ping-exit'
,
str
(
timeout
),
'--route-up'
,
'%s %s'
%
(
plib
.
ovpn_client
,
utils
.
get_pipename
(
write_pipe
)),
*
ovpn_args
)
...
...
@@ -277,8 +276,6 @@ class TunnelManager(object):
count
-=
self
.
_makeTunnel
(
peer
,
address
)
else
:
ip
=
utils
.
ipFromBin
(
self
.
_network
+
peer
)
# TODO: Send at least 1 address. This helps the registry
# node filling its cache when building a new network.
try
:
self
.
sock
.
sendto
(
'
\
2
'
,
(
ip
,
PORT
))
except
socket
.
error
,
e
:
...
...
@@ -316,27 +313,21 @@ class TunnelManager(object):
del
self
.
_distant_peers
[:]
for
conn
in
self
.
_connection_dict
.
itervalues
():
conn
.
routes
=
0
a
=
len
(
self
.
_network
)
b
=
a
+
len
(
self
.
_prefix
)
other
=
[]
for
iface
,
ip
,
prefix_len
in
self
.
_iterRoutes
():
if
ip
[:
a
]
==
self
.
_network
and
ip
[
a
:
b
]
!=
self
.
_prefix
:
prefix
=
ip
[
a
:
prefix_len
]
logging
.
trace
(
'Route on iface %s detected to %s/%u'
,
iface
,
utils
.
ipFromBin
(
ip
),
prefix_len
)
nexthop
=
self
.
_iface_to_prefix
.
get
(
iface
)
if
nexthop
:
self
.
_connection_dict
[
nexthop
].
routes
+=
1
if
prefix
in
self
.
_served
or
prefix
in
self
.
_connection_dict
:
continue
if
iface
in
self
.
_iface_list
:
other
.
append
(
prefix
)
else
:
self
.
_distant_peers
.
append
(
prefix
)
is_registry
=
self
.
_peer_db
.
registry_ip
[
a
:].
startswith
if
is_registry
(
self
.
_prefix
)
or
any
(
is_registry
(
peer
)
for
peer
in
chain
(
self
.
_distant_peers
,
other
,
self
.
_served
,
self
.
_connection_dict
)):
for
iface
,
prefix
in
utils
.
iterRoutes
(
self
.
_network
,
self
.
_prefix
):
assert
iface
!=
'lo'
,
(
iface
,
prefix
)
nexthop
=
self
.
_iface_to_prefix
.
get
(
iface
)
if
nexthop
:
self
.
_connection_dict
[
nexthop
].
routes
+=
1
if
prefix
in
self
.
_served
or
prefix
in
self
.
_connection_dict
:
continue
if
iface
in
self
.
_iface_list
:
other
.
append
(
prefix
)
else
:
self
.
_distant_peers
.
append
(
prefix
)
registry
=
self
.
_peer_db
.
registry_prefix
if
registry
==
self
.
_prefix
or
any
(
registry
in
x
for
x
in
(
self
.
_distant_peers
,
other
,
self
.
_served
,
self
.
_connection_dict
)):
self
.
_disconnected
=
None
# XXX: When there is no new peer to connect when looking at routes
# coming from tunnels, we'd like to consider those discovered
...
...
@@ -400,37 +391,34 @@ class TunnelManager(object):
return
code
=
ord
(
msg
[
0
])
if
code
==
1
:
# answer
# We parse the message in a way to discard a truncated line.
for
peer
in
msg
[
1
:].
split
(
'
\
n
'
)[:
-
1
]:
try
:
prefix
,
address
=
peer
.
split
()
int
(
prefix
,
2
)
except
ValueError
:
break
# Old versions may send additional and obsolete addresses.
# Ignore them, as well as truncated lines.
try
:
prefix
,
address
=
msg
[
1
:
msg
.
index
(
'
\
n
'
)].
split
()
int
(
prefix
,
2
)
except
ValueError
:
pass
else
:
if
prefix
!=
self
.
_prefix
:
self
.
_peer_db
.
addPeer
(
prefix
,
address
)
try
:
self
.
_connecting
.
remove
(
prefix
)
except
KeyError
:
continue
self
.
_makeTunnel
(
prefix
,
address
)
pass
else
:
self
.
_makeTunnel
(
prefix
,
address
)
elif
code
==
2
:
# request
encode
=
'%s %s
\
n
'
.
__mod__
if
self
.
_address
:
msg
=
[
encode
((
self
.
_prefix
,
self
.
_address
))]
else
:
# I don't know my IP yet!
msg
=
[]
# Add an extra random peer, mainly for the registry.
if
random
.
randint
(
0
,
self
.
_peer_db
.
getPeerCount
()):
msg
.
append
(
encode
(
self
.
_peer_db
.
getPeerList
().
next
()))
if
msg
:
msg
=
'
\
1
%s %s
\
n
'
%
(
self
.
_prefix
,
self
.
_address
)
try
:
self
.
sock
.
sendto
(
'
\
1
'
+
''
.
join
(
msg
)
,
address
[:
2
])
self
.
sock
.
sendto
(
msg
,
address
[:
2
])
except
socket
.
error
,
e
:
logging
.
info
(
'Failed to reply to %s (%s)'
,
address
,
e
)
#else: # I don't know my IP yet!
elif
code
==
255
:
# the registry wants to know the topology for debugging purpose
if
utils
.
binFromIp
(
address
[
0
])
==
self
.
_peer_db
.
registry_ip
:
if
utils
.
binFromIp
(
address
[
0
])[
len
(
self
.
_network
):].
startswith
(
self
.
_peer_db
.
registry_prefix
):
msg
=
[
'
\
xfe
%s%u/%u
\
n
%u
\
n
'
%
(
msg
[
1
:],
int
(
self
.
_prefix
,
2
),
len
(
self
.
_prefix
),
len
(
self
.
_connection_dict
))]
...
...
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