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
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:
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
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:
def
unusePeer
(
self
,
prefix
):
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
):
script_type
,
arg
=
msg
.
split
()
...
...
@@ -72,7 +72,7 @@ class PeerManager:
[
external_ip
,
external_port
,
'tcp-client'
]]
if
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
()
else
:
utils
.
log
(
'Unknow message recieved from the openvpn pipe : '
+
msg
,
1
)
tunnel.py
View file @
8e011be5
...
...
@@ -7,8 +7,7 @@ smooth = 0.3
class
Connection
:
def
__init__
(
self
,
address
,
write_pipe
,
hello
,
iface
,
prefix
,
ovpn_args
):
self
.
process
=
plib
.
client
(
address
,
write_pipe
,
hello
,
'--dev'
,
iface
,
'--proto'
,
proto
,
'--rport'
,
str
(
port
),
self
.
process
=
plib
.
client
(
address
,
write_pipe
,
hello
,
'--dev'
,
iface
,
*
ovpn_args
,
stdout
=
os
.
open
(
os
.
path
.
join
(
log
,
'vifibnet.client.%s.log'
%
(
prefix
,)),
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_TRUNC
)
)
...
...
@@ -16,13 +15,14 @@ class Connection:
self
.
iface
=
iface
self
.
_lastTrafic
=
self
.
_getTrafic
()
self
.
_bandwidth
=
None
self
.
_prefix
=
prefix
# TODO : update the stats
def
refresh
(
self
):
# Check that the connection is alive
if
self
.
process
.
poll
()
!=
None
:
utils
.
log
(
'Connection with %s has failed with return code %s'
%
(
prefix
,
self
.
process
.
returncode
),
3
)
%
(
self
.
_
prefix
,
self
.
process
.
returncode
),
3
)
return
False
trafic
=
self
.
_getTrafic
()
...
...
@@ -40,7 +40,7 @@ class Connection:
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'
)
return
int
(
f_rx
.
read
())
+
int
(
f_tx
.
read
())
except
Exception
:
# TODO : change this
except
Exception
:
return
0
class
TunnelManager
:
...
...
@@ -97,7 +97,7 @@ class TunnelManager:
try
:
for
prefix
,
address
in
self
.
_peer_db
.
getUnusedPeers
(
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
()
self
.
_connection_dict
[
prefix
]
=
Connection
(
address
,
self
.
_write_pipe
,
self
.
_hello
,
iface
,
...
...
@@ -105,6 +105,6 @@ class TunnelManager:
self
.
_peer_db
.
usePeer
(
prefix
)
except
KeyError
:
utils
.
log
(
"""Can't establish connection with %s
: no available interface"""
%
prefix
,
2
)
: no available interface"""
%
prefix
,
2
)
except
Exception
:
traceback
.
print_exc
()
vifibnet.py
View file @
8e011be5
...
...
@@ -97,8 +97,8 @@ def main():
config
.
address
=
[[
external_ip
,
external_port
,
'udp'
],
[
external_ip
,
external_port
,
'tcp-client'
]]
except
Exception
:
utils
.
log
(
'An atempt to forward a port via UPnP failed'
,
3
)
raise
RuntimeError
utils
.
log
(
'An atempt to forward a port via UPnP failed'
,
4
)
#raise RuntimeError => this shouldn't raise an error since upnp is not mandatory
peer_db
=
db
.
PeerManager
(
config
.
db
,
config
.
server
,
config
.
server_port
,
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