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
f475f2ca
Commit
f475f2ca
authored
Jul 26, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper db refresh & bootstrap
parent
0ee76b06
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
34 deletions
+36
-34
README
README
+1
-1
db.py
db.py
+31
-29
registry.py
registry.py
+2
-2
vifibnet.py
vifibnet.py
+2
-2
No files found.
README
View file @
f475f2ca
...
...
@@ -137,7 +137,7 @@ OPTIONS : VIFIBNET.PY
Default : 0
--registry address
Complete publi ( reachable from the internet ) address of the machine
Complete publi
c
( reachable from the internet ) address of the machine
running a registry. Will be used to get the pirvate address of the
registry and/or bootstrap peers
...
...
db.py
View file @
f475f2ca
import
sqlite3
,
socket
,
xmlrpclib
,
time
,
os
import
sqlite3
,
socket
,
subprocess
,
xmlrpclib
,
time
,
os
import
utils
class
PeerManager
:
# internal ip = temp arg/attribute
...
...
@@ -41,38 +40,16 @@ class PeerManager:
name text primary key,
value text)"""
)
try
:
a
=
self
.
_db
.
execute
(
"SELECT value FROM config WHERE name='registry'"
).
next
()
a
,
=
self
.
_db
.
execute
(
"SELECT value FROM config WHERE name='registry'"
).
next
()
except
StopIteration
:
proxy
=
xmlrpclib
.
ServerProxy
(
registry
)
a
=
proxy
.
getPrivateAddress
()
self
.
_db
.
execute
(
"INSERT INTO config VALUES ('registry',?)"
,
a
)
self
.
_db
.
execute
(
"INSERT INTO config VALUES ('registry',?)"
,
(
a
,)
)
self
.
_proxy
=
xmlrpclib
.
ServerProxy
(
a
)
utils
.
log
(
'Database prepared'
,
5
)
self
.
next_refresh
=
time
.
time
()
def
_boot
(
self
):
utils
.
log
(
'Getting Boot peer...'
,
3
)
try
:
utils
.
log
(
"Contacting registry's private address"
,
5
)
bootpeer
=
self
.
_proxy
.
getBootstrapPeer
(
self
.
_prefix
).
data
except
socket
.
error
,
e
:
utils
.
log
(
"""Registry's private address unreachable,
trying public address"""
)
proxy
=
xmlrpclib
.
ServerProxy
(
self
.
_registry
)
bootpeer
=
proxy
.
getBootstrapPeer
(
self
.
_prefix
).
data
utils
.
log
(
'Boot peer received from server'
,
4
)
p
=
subprocess
.
Popen
((
'openssl'
,
'rsautl'
,
'-decrypt'
,
'-inkey'
,
self
.
_key_path
),
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
try
:
prefix
,
address
=
p
.
communicate
(
bootpeer
).
split
()
except
ValueError
:
# DO something
pass
self
.
db
.
execute
(
"INSERT INTO peers (prefix, address) VALUES (?,?)"
,
(
prefix
,
address
))
utils
.
log
(
'Boot peer added'
,
4
)
def
clear_blacklist
(
self
,
flag
):
utils
.
log
(
'Clearing blacklist from flag %u'
%
(
flag
,),
3
)
self
.
_db
.
execute
(
"DELETE FROM blacklist WHERE flag = ?"
,
...
...
@@ -98,10 +75,12 @@ class PeerManager:
self
.
_populate
()
utils
.
log
(
'DB refreshed'
,
3
)
self
.
next_refresh
=
time
.
time
()
+
self
.
_refresh_time
return
True
except
socket
.
error
,
e
:
utils
.
log
(
e
,
4
)
utils
.
log
(
'Connection to server failed, retrying in 30s'
,
2
)
self
.
next_refresh
=
time
.
time
()
+
30
return
False
def
_declare
(
self
):
if
self
.
_address
!=
None
:
...
...
@@ -129,9 +108,32 @@ class PeerManager:
utils
.
log
(
'New peers : %s'
%
', '
.
join
(
map
(
str
,
new_peer_list
)),
5
)
def
getUnusedPeers
(
self
,
peer_count
):
return
self
.
_db
.
execute
(
"""SELECT prefix, address FROM peers WHERE used
<= 0 ORDER BY used DESC,RANDOM() LIMIT ?"""
,
(
peer_count
,))
for
populate
in
self
.
refresh
,
self
.
_bootstrap
,
bool
:
peer_list
=
self
.
_db
.
execute
(
"""SELECT prefix, address FROM peers WHERE used
<= 0 ORDER BY used DESC,RANDOM() LIMIT ?"""
,
(
peer_count
,)).
fetchall
()
if
peer_list
or
populate
():
return
peer_list
def
_bootstrap
(
self
):
utils
.
log
(
'Getting Boot peer...'
,
3
)
proxy
=
xmlrpclib
.
ServerProxy
(
self
.
_registry
)
try
:
bootpeer
=
proxy
.
getBootstrapPeer
(
self
.
_prefix
).
data
utils
.
log
(
'Boot peer received from server'
,
4
)
p
=
subprocess
.
Popen
((
'openssl'
,
'rsautl'
,
'-decrypt'
,
'-inkey'
,
self
.
_key_path
),
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
bootpeer
=
p
.
communicate
(
bootpeer
).
split
()
self
.
db
.
execute
(
"INSERT INTO peers (prefix, address) VALUES (?,?)"
,
bootpeer
)
utils
.
log
(
'Boot peer added'
,
4
)
return
True
except
socket
.
error
:
pass
except
sqlite3
.
IntegrityError
,
e
:
import
pdb
;
pdb
.
set_trace
()
if
e
.
args
[
0
]
!=
''
:
raise
return
False
def
usePeer
(
self
,
prefix
):
utils
.
log
(
'Updating peers database : using peer '
+
str
(
prefix
),
5
)
...
...
registry.py
View file @
f475f2ca
#!/usr/bin/env python
import
argparse
,
math
,
random
,
select
,
smtplib
,
sqlite3
,
string
,
socket
,
time
,
import
subprocess
,
threading
,
traceback
,
errno
import
argparse
,
math
,
random
,
select
,
smtplib
,
sqlite3
,
string
,
socket
import
subprocess
,
t
ime
,
t
hreading
,
traceback
,
errno
from
SimpleXMLRPCServer
import
SimpleXMLRPCServer
,
SimpleXMLRPCRequestHandler
from
email.mime.text
import
MIMEText
from
OpenSSL
import
crypto
...
...
vifibnet.py
View file @
f475f2ca
...
...
@@ -19,7 +19,7 @@ class ArgParser(ArgumentParser):
def
ovpnArgs
(
optional_args
,
ca_path
,
cert_path
,
key_path
):
# Treat openvpn arguments
if
optional_args
[
0
]
==
"--"
:
if
optional_args
and
optional_args
[
0
]
==
"--"
:
del
optional_args
[
0
]
optional_args
.
append
(
'--ca'
)
optional_args
.
append
(
ca_path
)
...
...
@@ -122,7 +122,7 @@ def main():
except
upnpigd
.
NoUPnPDevice
:
utils
.
log
(
'No upnp device found'
,
4
)
peer_db
=
db
.
PeerManager
(
config
.
state
,
config
.
registry
,
peer_db
=
db
.
PeerManager
(
config
.
state
,
config
.
registry
,
config
.
key
,
config
.
peers_db_refresh
,
config
.
address
,
internal_ip
,
prefix
,
manual
,
config
.
pp
,
200
)
tunnel_manager
=
tunnel
.
TunnelManager
(
write_pipe
,
peer_db
,
openvpn_args
,
...
...
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