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
8e011be5
Commit
8e011be5
authored
Jul 20, 2012
by
Ulysse Beaugnon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Solving all the bugs that were their when I arrived this morning.
parent
aefcb9de
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
10 deletions
+17
-10
TODO
TODO
+7
-0
db.py
db.py
+2
-2
tunnel.py
tunnel.py
+6
-6
vifibnet.py
vifibnet.py
+2
-2
No files found.
TODO
View file @
8e011be5
...
@@ -71,3 +71,10 @@ To be discussed:
...
@@ -71,3 +71,10 @@ To be discussed:
enought DB to ensure we can still choose a peer as if it was choosen
enought DB to ensure we can still choose a peer as if it was choosen
directly from the server. The requiered db size can be calculated from
directly from the server. The requiered db size can be calculated from
the number of connections and the refresh time.
the number of connections and the refresh time.
U : Why are --ip and internal-port mutually exclusive ?
Currently upnp only forward via UDP. Should he also forward via TCP ?
Why dont we only use UDP ?
No error should be raised when no upnp is detected : we should allow
machines having public IP to do an automatic configuration using the
discovery by an other peer
db.py
View file @
8e011be5
...
@@ -57,7 +57,7 @@ class PeerManager:
...
@@ -57,7 +57,7 @@ class PeerManager:
def
unusePeer
(
self
,
prefix
):
def
unusePeer
(
self
,
prefix
):
utils
.
log
(
'Updating peers database : unusing peer '
+
str
(
prefix
),
5
)
utils
.
log
(
'Updating peers database : unusing peer '
+
str
(
prefix
),
5
)
self
.
_db
.
execute
(
"UPDATE peers SET used = 0 WHERE
id
= ?"
,
(
prefix
,))
self
.
_db
.
execute
(
"UPDATE peers SET used = 0 WHERE
prefix
= ?"
,
(
prefix
,))
def
handle_message
(
self
,
msg
):
def
handle_message
(
self
,
msg
):
script_type
,
arg
=
msg
.
split
()
script_type
,
arg
=
msg
.
split
()
...
@@ -72,7 +72,7 @@ class PeerManager:
...
@@ -72,7 +72,7 @@ class PeerManager:
[
external_ip
,
external_port
,
'tcp-client'
]]
[
external_ip
,
external_port
,
'tcp-client'
]]
if
self
.
_address
!=
new_address
:
if
self
.
_address
!=
new_address
:
self
.
_address
=
new_address
self
.
_address
=
new_address
utils
.
log
(
'Received new external configuration : %:%s'
%
(
external_ip
,
external_port
),
3
)
utils
.
log
(
'Received new external configuration : %
s
:%s'
%
(
external_ip
,
external_port
),
3
)
self
.
_declare
()
self
.
_declare
()
else
:
else
:
utils
.
log
(
'Unknow message recieved from the openvpn pipe : '
+
msg
,
1
)
utils
.
log
(
'Unknow message recieved from the openvpn pipe : '
+
msg
,
1
)
tunnel.py
View file @
8e011be5
...
@@ -7,8 +7,7 @@ smooth = 0.3
...
@@ -7,8 +7,7 @@ smooth = 0.3
class
Connection
:
class
Connection
:
def
__init__
(
self
,
address
,
write_pipe
,
hello
,
iface
,
prefix
,
def
__init__
(
self
,
address
,
write_pipe
,
hello
,
iface
,
prefix
,
ovpn_args
):
ovpn_args
):
self
.
process
=
plib
.
client
(
address
,
write_pipe
,
hello
,
self
.
process
=
plib
.
client
(
address
,
write_pipe
,
hello
,
'--dev'
,
iface
,
'--dev'
,
iface
,
'--proto'
,
proto
,
'--rport'
,
str
(
port
),
*
ovpn_args
,
stdout
=
os
.
open
(
os
.
path
.
join
(
log
,
*
ovpn_args
,
stdout
=
os
.
open
(
os
.
path
.
join
(
log
,
'vifibnet.client.%s.log'
%
(
prefix
,)),
'vifibnet.client.%s.log'
%
(
prefix
,)),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
)
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
)
...
@@ -16,13 +15,14 @@ class Connection:
...
@@ -16,13 +15,14 @@ class Connection:
self
.
iface
=
iface
self
.
iface
=
iface
self
.
_lastTrafic
=
self
.
_getTrafic
()
self
.
_lastTrafic
=
self
.
_getTrafic
()
self
.
_bandwidth
=
None
self
.
_bandwidth
=
None
self
.
_prefix
=
prefix
# TODO : update the stats
# TODO : update the stats
def
refresh
(
self
):
def
refresh
(
self
):
# Check that the connection is alive
# Check that the connection is alive
if
self
.
process
.
poll
()
!=
None
:
if
self
.
process
.
poll
()
!=
None
:
utils
.
log
(
'Connection with %s has failed with return code %s'
utils
.
log
(
'Connection with %s has failed with return code %s'
%
(
prefix
,
self
.
process
.
returncode
),
3
)
%
(
self
.
_
prefix
,
self
.
process
.
returncode
),
3
)
return
False
return
False
trafic
=
self
.
_getTrafic
()
trafic
=
self
.
_getTrafic
()
...
@@ -40,7 +40,7 @@ class Connection:
...
@@ -40,7 +40,7 @@ class Connection:
f_rx
=
open
(
'/sys/class/net/%s/statistics/rx_bytes'
%
self
.
iface
,
'r'
)
f_rx
=
open
(
'/sys/class/net/%s/statistics/rx_bytes'
%
self
.
iface
,
'r'
)
f_tx
=
open
(
'/sys/class/net/%s/statistics/tx_bytes'
%
self
.
iface
,
'r'
)
f_tx
=
open
(
'/sys/class/net/%s/statistics/tx_bytes'
%
self
.
iface
,
'r'
)
return
int
(
f_rx
.
read
())
+
int
(
f_tx
.
read
())
return
int
(
f_rx
.
read
())
+
int
(
f_tx
.
read
())
except
Exception
:
# TODO : change this
except
Exception
:
return
0
return
0
class
TunnelManager
:
class
TunnelManager
:
...
@@ -97,7 +97,7 @@ class TunnelManager:
...
@@ -97,7 +97,7 @@ class TunnelManager:
try
:
try
:
for
prefix
,
address
in
self
.
_peer_db
.
getUnusedPeers
(
for
prefix
,
address
in
self
.
_peer_db
.
getUnusedPeers
(
self
.
_client_count
-
len
(
self
.
_connection_dict
)):
self
.
_client_count
-
len
(
self
.
_connection_dict
)):
utils
.
log
(
'Establishing a connection with %s
(%s:%s)
'
%
prefix
,
2
)
utils
.
log
(
'Establishing a connection with %s'
%
prefix
,
2
)
iface
=
self
.
free_interface_set
.
pop
()
iface
=
self
.
free_interface_set
.
pop
()
self
.
_connection_dict
[
prefix
]
=
Connection
(
address
,
self
.
_connection_dict
[
prefix
]
=
Connection
(
address
,
self
.
_write_pipe
,
self
.
_hello
,
iface
,
self
.
_write_pipe
,
self
.
_hello
,
iface
,
...
@@ -105,6 +105,6 @@ class TunnelManager:
...
@@ -105,6 +105,6 @@ class TunnelManager:
self
.
_peer_db
.
usePeer
(
prefix
)
self
.
_peer_db
.
usePeer
(
prefix
)
except
KeyError
:
except
KeyError
:
utils
.
log
(
"""Can't establish connection with %s
utils
.
log
(
"""Can't establish connection with %s
: no available interface"""
%
prefix
,
2
)
: no available interface"""
%
prefix
,
2
)
except
Exception
:
except
Exception
:
traceback
.
print_exc
()
traceback
.
print_exc
()
vifibnet.py
View file @
8e011be5
...
@@ -97,8 +97,8 @@ def main():
...
@@ -97,8 +97,8 @@ def main():
config
.
address
=
[[
external_ip
,
external_port
,
'udp'
],
config
.
address
=
[[
external_ip
,
external_port
,
'udp'
],
[
external_ip
,
external_port
,
'tcp-client'
]]
[
external_ip
,
external_port
,
'tcp-client'
]]
except
Exception
:
except
Exception
:
utils
.
log
(
'An atempt to forward a port via UPnP failed'
,
3
)
utils
.
log
(
'An atempt to forward a port via UPnP failed'
,
4
)
raise
RuntimeError
#raise RuntimeError => this shouldn't raise an error since upnp is not mandatory
peer_db
=
db
.
PeerManager
(
config
.
db
,
config
.
server
,
config
.
server_port
,
peer_db
=
db
.
PeerManager
(
config
.
db
,
config
.
server
,
config
.
server_port
,
config
.
peers_db_refresh
,
config
.
address
,
internal_ip
,
prefix
,
manual
,
200
)
config
.
peers_db_refresh
,
config
.
address
,
internal_ip
,
prefix
,
manual
,
200
)
...
...
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