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
Yohann D'Anello
re6stnet
Commits
5cd60b35
Commit
5cd60b35
authored
Jul 17, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://git.erp5.org/repos/vifibnet
Conflicts: tunnelmanager.py
parents
8c83df36
fffa5011
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
24 deletions
+26
-24
TODO
TODO
+1
-0
tunnelmanager.py
tunnelmanager.py
+24
-23
vifibnet.py
vifibnet.py
+1
-1
No files found.
TODO
View file @
5cd60b35
...
@@ -4,6 +4,7 @@ Bugs :
...
@@ -4,6 +4,7 @@ Bugs :
To be done :
To be done :
Replace comments at the beginning of functions with docstrings
Replace comments at the beginning of functions with docstrings
Do a clean-up in the import
Do a clean-up in the import
Remove the parameters to choose the number of clients
To be discuss:
To be discuss:
Remove the --no-boot option since we know when no node is avalaible
Remove the --no-boot option since we know when no node is avalaible
...
...
tunnelmanager.py
View file @
5cd60b35
...
@@ -5,55 +5,56 @@ import plib, utils, db
...
@@ -5,55 +5,56 @@ import plib, utils, db
class
TunnelManager
:
class
TunnelManager
:
def
__init__
(
self
,
write_pipe
,
peers_db
,
client_count
,
refresh_count
):
def
__init__
(
self
,
write_pipe
,
peers_db
):
self
.
write_pipe
=
write_pipe
self
.
_
write_pipe
=
write_pipe
self
.
peers_db
=
peers_db
self
.
_
peers_db
=
peers_db
self
.
connection_dict
=
{}
self
.
_
connection_dict
=
{}
self
.
client_count
=
client_count
self
.
client_count
=
client_count
self
.
refresh_count
=
refresh_count
self
.
refresh_count
=
refresh_count
self
.
free_interface_set
=
set
((
'client1'
,
'client2'
,
'client3'
,
'client4'
,
'client5'
,
self
.
free_interface_set
=
set
((
'client1'
,
'client2'
,
'client3'
,
'client4'
,
'client5'
,
'client6'
,
'client7'
,
'client8'
,
'client9'
,
'client10'
))
'client6'
,
'client7'
,
'client8'
,
'client9'
,
'client10'
))
def
refresh
(
self
):
def
refresh
(
self
):
self
.
cleanDeads
()
self
.
_
cleanDeads
()
self
.
removeSomeTunnels
()
self
.
_
removeSomeTunnels
()
self
.
makeNewTunnels
()
self
.
_
makeNewTunnels
()
def
cleanDeads
(
self
):
def
_
cleanDeads
(
self
):
for
id
in
self
.
connection_dict
.
keys
():
for
id
in
self
.
_
connection_dict
.
keys
():
p
,
iface
=
self
.
connection_dict
[
id
]
p
,
iface
=
self
.
_
connection_dict
[
id
]
if
p
.
poll
()
!=
None
:
if
p
.
poll
()
!=
None
:
utils
.
log
(
'Connection with %s has failed with return code %s'
%
(
id
,
p
.
returncode
),
3
)
utils
.
log
(
'Connection with %s has failed with return code %s'
%
(
id
,
p
.
returncode
),
3
)
self
.
free_interface_set
.
add
(
iface
)
self
.
free_interface_set
.
add
(
iface
)
self
.
peers_db
.
unusePeer
(
id
)
self
.
peers_db
.
unusePeer
(
id
)
del
self
.
connection_dict
[
id
]
del
self
.
connection_dict
[
id
]
def
removeSomeTunnels
(
self
):
def
_
removeSomeTunnels
(
self
):
for
i
in
range
(
0
,
max
(
0
,
len
(
self
.
connection_dict
)
-
self
.
client_count
+
self
.
refresh_count
)):
for
i
in
range
(
0
,
max
(
0
,
len
(
self
.
_connection_dict
)
-
self
.
_clientCount
+
self
.
_
refresh_count
)):
peer_id
=
random
.
choice
(
self
.
connection_dict
.
keys
())
peer_id
=
random
.
choice
(
self
.
_
connection_dict
.
keys
())
kill
(
peer_id
)
kill
(
peer_id
)
def
kill
(
self
,
peer_id
):
def
_
kill
(
self
,
peer_id
):
utils
.
log
(
'Killing the connection with id '
+
str
(
peer_id
),
2
)
utils
.
log
(
'Killing the connection with id '
+
str
(
peer_id
),
2
)
p
,
iface
=
self
.
connection_dict
.
pop
(
peer_id
)
p
,
iface
=
self
.
_
connection_dict
.
pop
(
peer_id
)
p
.
kill
()
p
.
kill
()
self
.
free_interface_set
.
add
(
iface
)
self
.
free_interface_set
.
add
(
iface
)
self
.
peers_db
.
unusePeer
(
peer_id
)
self
.
_
peers_db
.
unusePeer
(
peer_id
)
def
makeNewTunnels
(
self
):
def
_
makeNewTunnels
(
self
):
try
:
try
:
for
peer_id
,
ip
,
port
,
proto
in
self
.
peers_db
.
getUnusedPeers
(
self
.
client_count
-
len
(
self
.
connection_dict
),
self
.
write_pipe
):
for
peer_id
,
ip
,
port
,
proto
in
self
.
_peers_db
.
getUnusedPeers
(
self
.
_client_count
-
len
(
self
.
_connection_dict
),
self
.
_
write_pipe
):
utils
.
log
(
'Establishing a connection with id %s (%s:%s)'
%
(
peer_id
,
ip
,
port
),
2
)
utils
.
log
(
'Establishing a connection with id %s (%s:%s)'
%
(
peer_id
,
ip
,
port
),
2
)
iface
=
self
.
free_interface_set
.
pop
()
iface
=
self
.
free_interface_set
.
pop
()
self
.
connection_dict
[
peer_id
]
=
(
plib
.
client
(
ip
,
write_pipe
,
'--dev'
,
iface
,
'--proto'
,
proto
,
'--rport'
,
str
(
port
),
self
.
_connection_dict
[
peer_id
]
=
(
openvpn
.
client
(
ip
,
write_pipe
,
'--dev'
,
iface
,
'--proto'
,
proto
,
'--rport'
,
str
(
port
),
stdout
=
os
.
open
(
os
.
path
.
join
(
utils
.
config
.
log
,
'vifibnet.client.%s.log'
%
(
peer_id
,)),
stdout
=
os
.
open
(
os
.
path
.
join
(
utils
.
config
.
log
,
'vifibnet.client.%s.log'
%
(
peer_id
,)),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
),
iface
)
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
),
self
.
peers_db
.
usePeer
(
peer_id
)
iface
)
self
.
_peers_db
.
usePeer
(
peer_id
)
except
KeyError
:
except
KeyError
:
utils
.
log
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
utils
.
log
(
"Can't establish connection with %s : no available interface"
%
ip
,
2
)
except
Exception
:
except
Exception
:
traceback
.
print_exc
()
traceback
.
print_exc
()
def
handle_message
(
msg
):
def
handle_message
(
msg
):
script_type
,
arg
=
msg
.
split
()
script_type
,
arg
=
msg
.
split
()
if
script_type
==
'client-connect'
:
if
script_type
==
'client-connect'
:
...
...
vifibnet.py
View file @
5cd60b35
...
@@ -75,7 +75,7 @@ def main():
...
@@ -75,7 +75,7 @@ def main():
if
ready
:
if
ready
:
tunnelManager
.
handle_message
(
read_pipe
.
readline
())
tunnelManager
.
handle_message
(
read_pipe
.
readline
())
if
time
.
time
()
>=
next_refresh
:
if
time
.
time
()
>=
next_refresh
:
peers_db
.
populate
(
10
)
peers_db
.
populate
(
10
0
)
tunnelManager
.
refresh
()
tunnelManager
.
refresh
()
next_refresh
=
time
.
time
()
+
utils
.
config
.
refresh_time
next_refresh
=
time
.
time
()
+
utils
.
config
.
refresh_time
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
...
...
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