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
Xiaowu Zhang
re6stnet
Commits
7152bb0d
Commit
7152bb0d
authored
Aug 16, 2012
by
Ulysse Beaugnon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using set instead of sets
using the same socket for sending and listenning
parent
a00f6201
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
13 deletions
+14
-13
re6st/db.py
re6st/db.py
+6
-1
re6st/tunnel.py
re6st/tunnel.py
+2
-4
re6stnet
re6stnet
+6
-8
No files found.
re6st/db.py
View file @
7152bb0d
...
@@ -22,6 +22,10 @@ class PeerManager:
...
@@ -22,6 +22,10 @@ class PeerManager:
self
.
_manual
=
manual
self
.
_manual
=
manual
self
.
tunnel_manager
=
None
self
.
tunnel_manager
=
None
self
.
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
self
.
sock
.
bind
((
self
.
_internal_ip
,
326
))
self
.
socket_file
=
self
.
_sock
.
makefile
()
logging
.
info
(
'Connecting to peers database...'
)
logging
.
info
(
'Connecting to peers database...'
)
self
.
_db
=
sqlite3
.
connect
(
db_path
,
isolation_level
=
None
)
self
.
_db
=
sqlite3
.
connect
(
db_path
,
isolation_level
=
None
)
logging
.
debug
(
'Database opened'
)
logging
.
debug
(
'Database opened'
)
...
@@ -165,7 +169,8 @@ class PeerManager:
...
@@ -165,7 +169,8 @@ class PeerManager:
logging
.
debug
(
'Unknow message recieved from the openvpn pipe : %s'
logging
.
debug
(
'Unknow message recieved from the openvpn pipe : %s'
%
msg
)
%
msg
)
def
readSocket
(
self
,
msg
):
def
readSocket
(
self
):
msg
=
self
.
socket_file
.
readline
()
peer
=
msg
.
replace
(
'
\
n
'
,
''
).
split
(
' '
)
peer
=
msg
.
replace
(
'
\
n
'
,
''
).
split
(
' '
)
if
len
(
peer
)
!=
2
:
if
len
(
peer
)
!=
2
:
logging
.
debug
(
'Invalid package recieved : %s'
%
msg
)
logging
.
debug
(
'Invalid package recieved : %s'
%
msg
)
...
...
re6st/tunnel.py
View file @
7152bb0d
import
os
,
traceback
,
time
,
subprocess
,
logging
import
os
,
traceback
,
time
,
subprocess
,
logging
import
socket
import
socket
import
sets
import
random
import
random
import
plib
import
plib
import
utils
import
utils
...
@@ -127,7 +126,7 @@ class TunnelManager:
...
@@ -127,7 +126,7 @@ class TunnelManager:
def
_countRoutes
(
self
):
def
_countRoutes
(
self
):
logging
.
debug
(
'Starting to count the routes on each interface...'
)
logging
.
debug
(
'Starting to count the routes on each interface...'
)
self
.
_peer_db
.
clear_blacklist
(
0
)
self
.
_peer_db
.
clear_blacklist
(
0
)
possiblePeers
=
set
s
.
Set
([]
)
possiblePeers
=
set
(
)
for
iface
in
self
.
_iface_to_prefix
.
keys
():
for
iface
in
self
.
_iface_to_prefix
.
keys
():
self
.
_connection_dict
[
self
.
_iface_to_prefix
[
iface
]].
routes
=
0
self
.
_connection_dict
[
self
.
_iface_to_prefix
[
iface
]].
routes
=
0
for
line
in
open
(
'/proc/net/ipv6_route'
):
for
line
in
open
(
'/proc/net/ipv6_route'
):
...
@@ -180,8 +179,7 @@ class TunnelManager:
...
@@ -180,8 +179,7 @@ class TunnelManager:
ip
=
'%s:%s:%s:%s:%s:%s:%s:%s'
%
(
peerIp
[
0
:
4
],
peerIp
[
4
:
8
],
peerIp
[
8
:
12
],
ip
=
'%s:%s:%s:%s:%s:%s:%s:%s'
%
(
peerIp
[
0
:
4
],
peerIp
[
4
:
8
],
peerIp
[
8
:
12
],
peerIp
[
12
:
16
],
peerIp
[
16
:
20
],
peerIp
[
20
:
24
],
peerIp
[
24
:
28
],
peerIp
[
28
:
32
])
peerIp
[
12
:
16
],
peerIp
[
16
:
20
],
peerIp
[
20
:
24
],
peerIp
[
24
:
28
],
peerIp
[
28
:
32
])
logging
.
trace
(
'Notifying peer %s'
%
ip
)
logging
.
trace
(
'Notifying peer %s'
%
ip
)
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
self
.
peer_db
.
sock
.
sendto
(
'%s %s
\
n
'
%
(
self
.
_prefix
,
utils
.
address_str
(
self
.
_peer_db
.
address
)),
(
ip
,
326
))
sock
.
sendto
(
'%s %s
\
n
'
%
(
self
.
_prefix
,
utils
.
address_str
(
self
.
_peer_db
.
address
)),
(
ip
,
326
))
except
socket
.
error
,
e
:
except
socket
.
error
,
e
:
logging
.
debug
(
'Unable to notify %s'
%
ip
)
logging
.
debug
(
'Unable to notify %s'
%
ip
)
logging
.
debug
(
'socket.error : %s'
%
e
)
logging
.
debug
(
'socket.error : %s'
%
e
)
re6stnet
View file @
7152bb0d
...
@@ -144,11 +144,6 @@ def main():
...
@@ -144,11 +144,6 @@ def main():
config
.
iface_list
,
network
,
prefix
,
2
,
config
.
encrypt
)
config
.
iface_list
,
network
,
prefix
,
2
,
config
.
encrypt
)
peer_db
.
tunnel_manager
=
tunnel_manager
peer_db
.
tunnel_manager
=
tunnel_manager
# Create the socket to listen on
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
sock
.
bind
((
'::'
,
326
))
socket_file
=
sock
.
makefile
()
# Launch routing protocol. WARNING : you have to be root to start babeld
# Launch routing protocol. WARNING : you have to be root to start babeld
interface_list
=
list
(
tunnel_manager
.
free_interface_set
)
\
interface_list
=
list
(
tunnel_manager
.
free_interface_set
)
\
+
config
.
iface_list
+
list
(
iface
+
config
.
iface_list
+
list
(
iface
...
@@ -181,7 +176,10 @@ def main():
...
@@ -181,7 +176,10 @@ def main():
if
forwarder
!=
None
:
if
forwarder
!=
None
:
nextUpdate
=
min
(
nextUpdate
,
forwarder
.
next_refresh
)
nextUpdate
=
min
(
nextUpdate
,
forwarder
.
next_refresh
)
nextUpdate
=
max
(
0
,
nextUpdate
-
time
.
time
())
nextUpdate
=
max
(
0
,
nextUpdate
-
time
.
time
())
ready
,
tmp1
,
tmp2
=
select
.
select
([
read_pipe
,
socket_file
],
[],
[],
nextUpdate
)
select_list
=
[
read_pipe
]
if
peer_db
.
socket_file
:
select_list
.
append
(
peer_db
.
socket_file
)
ready
,
tmp1
,
tmp2
=
select
.
select
(
select_list
,
[],
[],
nextUpdate
)
if
read_pipe
in
ready
:
if
read_pipe
in
ready
:
peer_db
.
handle_message
(
read_pipe
.
readline
())
peer_db
.
handle_message
(
read_pipe
.
readline
())
if
time
.
time
()
>=
peer_db
.
next_refresh
:
if
time
.
time
()
>=
peer_db
.
next_refresh
:
...
@@ -190,8 +188,8 @@ def main():
...
@@ -190,8 +188,8 @@ def main():
tunnel_manager
.
refresh
()
tunnel_manager
.
refresh
()
if
forwarder
!=
None
and
time
.
time
()
>
forwarder
.
next_refresh
:
if
forwarder
!=
None
and
time
.
time
()
>
forwarder
.
next_refresh
:
forwarder
.
refresh
()
forwarder
.
refresh
()
if
socket_file
in
ready
:
if
peer_db
.
socket_file
in
ready
:
peer_db
.
readSocket
(
socket_file
.
readline
()
)
peer_db
.
readSocket
()
finally
:
finally
:
for
p
in
[
router
]
+
server_process
:
for
p
in
[
router
]
+
server_process
:
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