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
3a498f20
Commit
3a498f20
authored
Jul 17, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed some typos
parent
33822341
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
19 deletions
+27
-19
TODO
TODO
+2
-0
db.py
db.py
+15
-14
registry.py
registry.py
+1
-1
tunnel.py
tunnel.py
+1
-1
utils.py
utils.py
+1
-1
vifibnet.py
vifibnet.py
+7
-2
No files found.
TODO
View file @
3a498f20
Bugs :
When no peer is avalaible without the --no-boot option, it crash => see below
Once in a while, when exiting vifibnet ( not very properly, via Ctrl+C ), processes ( openvpn and babel )
still remain and disturb further attemps ( must be killed for vifibnet to work again )
To be done :
Replace comments at the beginning of functions with docstrings & give all fn docstrings
...
...
db.py
View file @
3a498f20
...
...
@@ -4,39 +4,40 @@ import utils
class
PeerManager
:
def
__init__
(
self
,
dbPath
):
def
__init__
(
self
,
dbPath
,
server
,
port
):
utils
.
log
(
'Connectiong to peers database'
,
4
)
self
.
db
=
sqlite3
.
connect
(
dbPath
,
isolation_level
=
None
)
self
.
_db
=
sqlite3
.
connect
(
dbPath
,
isolation_level
=
None
)
self
.
_server
=
server
self
.
_port
=
port
utils
.
log
(
'Preparing peers database'
,
4
)
try
:
self
.
db
.
execute
(
"UPDATE peers SET used = 0"
)
self
.
_
db
.
execute
(
"UPDATE peers SET used = 0"
)
except
sqlite3
.
OperationalError
,
e
:
if
e
.
args
[
0
]
==
'no such table: peers'
:
raise
RuntimeError
def
populate
(
self
,
n
):
def
populate
(
self
,
n
,
address
):
# address = (internal_ip, external_ip, port, proto)
# TODO: don't reconnect to server each time ?
utils
.
log
(
'Connecting to remote server'
,
3
)
self
.
proxy
=
xmlrpclib
.
ServerProxy
(
'http://%s:%u'
%
(
utils
.
config
.
server
,
utils
.
config
.
server
_port
))
self
.
_proxy
=
xmlrpclib
.
ServerProxy
(
'http://%s:%u'
%
(
self
.
_server
,
self
.
_port
))
utils
.
log
(
'Updating peers database : populating'
,
2
)
# TODO: determine port and proto
port
=
1194
proto
=
'udp'
new_peer_list
=
self
.
proxy
.
getPeerList
(
n
,
(
utils
.
config
.
internal_ip
,
utils
.
config
.
external_ip
,
port
,
proto
))
self
.
db
.
executemany
(
"INSERT OR IGNORE INTO peers (ip, port, proto, used) VALUES (?,?,?,0)"
,
new_peer_list
)
self
.
db
.
execute
(
"DELETE FROM peers WHERE ip = ?"
,
(
utils
.
config
.
external_ip
,))
_
,
external_ip
,
_
,
_
=
address
new_peer_list
=
self
.
_proxy
.
getPeerList
(
n
,
address
)
self
.
_db
.
executemany
(
"INSERT OR IGNORE INTO peers (ip, port, proto, used) VALUES (?,?,?,0)"
,
new_peer_list
)
self
.
_db
.
execute
(
"DELETE FROM peers WHERE ip = ?"
,
(
external_ip
,))
def
getUnusedPeers
(
self
,
nPeers
):
return
self
.
db
.
execute
(
"SELECT id, ip, port, proto FROM peers WHERE used = 0 "
return
self
.
_
db
.
execute
(
"SELECT id, ip, port, proto FROM peers WHERE used = 0 "
"ORDER BY RANDOM() LIMIT ?"
,
(
nPeers
,))
def
usePeer
(
self
,
id
):
utils
.
log
(
'Updating peers database : using peer '
+
str
(
id
),
5
)
self
.
db
.
execute
(
"UPDATE peers SET used = 1 WHERE id = ?"
,
(
id
,))
self
.
_
db
.
execute
(
"UPDATE peers SET used = 1 WHERE id = ?"
,
(
id
,))
def
unusePeer
(
self
,
id
):
utils
.
log
(
'Updating peers database : unusing peer '
+
str
(
id
),
5
)
self
.
db
.
execute
(
"UPDATE peers SET used = 0 WHERE id = ?"
,
(
id
,))
self
.
_
db
.
execute
(
"UPDATE peers SET used = 0 WHERE id = ?"
,
(
id
,))
def
handle_message
(
self
,
msg
):
script_type
,
arg
=
msg
.
split
()
...
...
registry.py
View file @
3a498f20
...
...
@@ -179,7 +179,7 @@ class main(object):
def
declare
(
self
,
handler
,
address
):
client_address
,
ip
,
port
,
proto
=
address
#client_address, _ = handler.client_address
client_ip
=
binFromIp
(
client_address
)
client_ip
=
utils
.
binFromIp
(
client_address
)
if
client_ip
.
startswith
(
self
.
network
):
prefix
=
client_ip
[
len
(
self
.
network
):]
prefix
,
=
self
.
db
.
execute
(
"SELECT prefix FROM vifib WHERE prefix <= ? ORDER BY prefix DESC LIMIT 1"
,
(
prefix
,)).
next
()
...
...
tunnel.py
View file @
3a498f20
...
...
@@ -33,7 +33,7 @@ class TunnelManager:
def
_removeSomeTunnels
(
self
):
for
i
in
range
(
0
,
max
(
0
,
len
(
self
.
_connection_dict
)
-
self
.
_client_count
+
self
.
_refresh_count
)):
peer_id
=
random
.
choice
(
self
.
_connection_dict
.
keys
())
kill
(
peer_id
)
self
.
_
kill
(
peer_id
)
def
_kill
(
self
,
peer_id
):
utils
.
log
(
'Killing the connection with id '
+
str
(
peer_id
),
2
)
...
...
utils.py
View file @
3a498f20
...
...
@@ -10,7 +10,7 @@ def log(message, verbose_level):
def
binFromIp
(
ip
):
ip1
,
ip2
=
struct
.
unpack
(
'>QQ'
,
socket
.
inet_pton
(
socket
.
AF_INET6
,
ip
))
return
bin
(
client_ip1
)[
2
:].
rjust
(
64
,
'0'
)
+
bin
(
client_
ip2
)[
2
:].
rjust
(
64
,
'0'
)
return
bin
(
ip1
)[
2
:].
rjust
(
64
,
'0'
)
+
bin
(
ip2
)[
2
:].
rjust
(
64
,
'0'
)
def
ipFromBin
(
prefix
):
prefix
=
hex
(
int
(
prefix
,
2
))[
2
:]
...
...
vifibnet.py
View file @
3a498f20
...
...
@@ -48,6 +48,11 @@ def main():
network
=
utils
.
networkFromCa
(
config
.
ca
)
internal_ip
=
utils
.
ipFromCert
(
network
,
config
.
cert
)
openvpn_args
=
utils
.
ovpnArgs
(
config
.
openvpn_args
,
config
.
ca
,
config
.
cert
)
# Get real port and proto ?
port
=
1194
proto
=
'udp'
# Set global variables
tunnel
.
log
=
config
.
log
utils
.
verbose
=
plib
.
verbose
=
config
.
verbose
...
...
@@ -58,7 +63,7 @@ def main():
read_pipe
=
os
.
fdopen
(
r_pipe
)
# Init db and tunnels
peer_db
=
db
.
PeerManager
(
config
.
db
)
peer_db
=
db
.
PeerManager
(
config
.
db
,
config
.
server
,
config
.
server_port
)
tunnel_manager
=
tunnel
.
TunnelManager
(
write_pipe
,
peer_db
,
config
.
client_count
,
config
.
refresh_count
,
openvpn_args
)
# Launch babel on all interfaces. WARNING : you have to be root to start babeld
...
...
@@ -84,7 +89,7 @@ def main():
if
ready
:
peer_db
.
handle_message
(
read_pipe
.
readline
())
if
time
.
time
()
>=
next_refresh
:
peer_db
.
populate
(
100
)
peer_db
.
populate
(
100
,
(
internal_ip
,
config
.
external_ip
,
port
,
proto
)
)
tunnel_manager
.
refresh
()
next_refresh
=
time
.
time
()
+
config
.
refresh_time
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