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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
re6stnet
Commits
f85a3905
Commit
f85a3905
authored
Jul 18, 2012
by
Ulysse Beaugnon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prepare the peer db to separate the server advertisment and the getPeersLists
parent
35b9ec40
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
23 deletions
+26
-23
TODO
TODO
+6
-13
db.py
db.py
+17
-8
vifibnet.py
vifibnet.py
+3
-2
No files found.
TODO
View file @
f85a3905
...
...
@@ -8,12 +8,11 @@ Bugs :
To be done :
Replace comments at the beginning of functions with docstrings & give all fn docstrings
Do a clean-up in the import
Remove the parameters to choose the number of clients
Use the server events ( client connection/deconnection ) to do something usefull
In peers DB, remove some peers when they are too many of them
Contact the server using vifibnet and not the underlying network when possible
Use a timeout for the peersDB
The peer DB size should depend on the number of connection and the refresh time
To be discuss:
U : Remove the --no-boot option since we know when no node is avalaible
...
...
@@ -21,16 +20,10 @@ To be discuss:
irl it should never happen, no-boot is a debug option
U : Ok, but the server knows when no peers is avalaible, doesn't he ?
How we choose which protocol we use :
IMO, we should use UDP. I've read many times than TCP other TCP can be catastrophic in terme of performance
Every time a packet is lost, it is resend 2 times, one for each TCP tunnel
And many GW allow UDP port forwarding (for bittorent, Xbox, ...) but not TCP port forwarding
Use peers_db.populate(100) every once in a while ?
G : yes but be warry of the refresh time ( populate the db once every 20s is bad.. )
U : I agree. Once evry hours should be sufficient, and when their too few peers avalaible.
G : don't reconnect to server each time we repopulate in peers_db ?
U : we might recontact the server evry 1H or even less. So i think it is a good thing not to keep the connection alive
U : From what I've read on the internet, when you create a server object, you don't connect to the server,
You only connect to the server once you send a request for a methode and then you can automatically use the same connection for 15sec
Is the bootstrap node used ?
W
hy --ping-exit had been removed form openvpn args ? without this we can have zombie connec
tions
W
e should separate the getNodesList and advertise op
tions
\ No newline at end of file
db.py
View file @
f85a3905
...
...
@@ -4,35 +4,44 @@ import utils
class
PeerManager
:
def
__init__
(
self
,
dbPath
,
server
,
port
,
refresh_time
,
external_ip
):
def
__init__
(
self
,
dbPath
,
server
,
server_port
,
refresh_time
,
external_ip
,
internal_ip
,
port
,
proto
,
db_size
):
self
.
_server_port
=
server_port
self
.
_refresh_time
=
refresh_time
self
.
_external_ip
=
external_ip
self
.
_internal_ip
=
internal_ip
self
.
_external_port
=
port
self
.
_proto
=
proto
self
.
_db_size
=
db_size
utils
.
log
(
'Connectiong to peers database'
,
4
)
self
.
_db
=
sqlite3
.
connect
(
dbPath
,
isolation_level
=
None
)
self
.
_server
=
server
self
.
_server_port
=
port
self
.
_refresh_time
=
refresh_time
self
.
_external_ip
=
external_ip
utils
.
log
(
'Preparing peers database'
,
4
)
try
:
self
.
_db
.
execute
(
"UPDATE peers SET used = 0"
)
except
sqlite3
.
OperationalError
,
e
:
if
e
.
args
[
0
]
==
'no such table: peers'
:
raise
RuntimeError
self
.
next_refresh
=
time
.
time
()
def
populate
(
self
,
n
,
internal_ip
,
port
,
proto
):
def
refresh
(
self
):
self
.
_populate
()
self
.
next_refresh
=
time
.
time
()
+
self
.
_refresh_time
def
_populate
(
self
):
if
self
.
_external_ip
!=
None
:
address
=
(
internal_ip
,
self
.
_external_ip
,
port
,
proto
)
address
=
(
self
.
_internal_ip
,
self
.
_external_ip
,
self
.
_external_port
,
self
.
_
proto
)
else
:
address
=
0
utils
.
log
(
'Connecting to remote server'
,
3
)
self
.
_proxy
=
xmlrpclib
.
ServerProxy
(
'http://%s:%u'
%
(
self
.
_server
,
self
.
_server_port
))
utils
.
log
(
'Updating peers database : populating'
,
2
)
new_peer_list
=
self
.
_proxy
.
getPeerList
(
n
,
address
)
new_peer_list
=
self
.
_proxy
.
getPeerList
(
self
.
_db_size
,
address
)
utils
.
log
(
'New peers recieved from %s'
%
self
.
_server
,
5
)
self
.
_db
.
executemany
(
"INSERT OR IGNORE INTO peers (ip, port, proto, used) VALUES (?,?,?,0)"
,
new_peer_list
)
if
self
.
_external_ip
!=
None
:
self
.
_db
.
execute
(
"DELETE FROM peers WHERE ip = ?"
,
(
self
.
_external_ip
,))
self
.
next_refresh
=
time
.
time
()
+
self
.
_refresh_time
utils
.
log
(
'New peers : %s'
%
', '
.
join
(
map
(
str
,
new_peer_list
)),
5
)
def
getUnusedPeers
(
self
,
nPeers
):
...
...
vifibnet.py
View file @
f85a3905
...
...
@@ -65,7 +65,8 @@ def main():
read_pipe
=
os
.
fdopen
(
r_pipe
)
# Init db and tunnels
peer_db
=
db
.
PeerManager
(
config
.
db
,
config
.
server
,
config
.
server_port
,
config
.
peers_db_refresh
,
config
.
external_ip
)
peer_db
=
db
.
PeerManager
(
config
.
db
,
config
.
server
,
config
.
server_port
,
config
.
peers_db_refresh
,
config
.
external_ip
,
internal_ip
,
config
.
external_port
,
config
.
proto
,
200
)
tunnel_manager
=
tunnel
.
TunnelManager
(
write_pipe
,
peer_db
,
openvpn_args
,
config
.
tunnel_refresh
,
config
.
connection_count
,
config
.
refresh_rate
)
# Launch babel on all interfaces. WARNING : you have to be root to start babeld
...
...
@@ -87,7 +88,7 @@ def main():
if
ready
:
peer_db
.
handle_message
(
read_pipe
.
readline
())
if
time
.
time
()
>=
peer_db
.
next_refresh
:
peer_db
.
populate
(
200
,
internal_ip
,
config
.
external_port
,
config
.
proto
)
peer_db
.
refresh
(
)
if
time
.
time
()
>=
tunnel_manager
.
next_refresh
:
tunnel_manager
.
refresh
()
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