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
c1749ede
Commit
c1749ede
authored
May 12, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect when network prefix has changed
parent
c61cab22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
16 deletions
+25
-16
re6st/db.py
re6st/db.py
+23
-14
re6stnet
re6stnet
+2
-2
No files found.
re6st/db.py
View file @
c1749ede
...
@@ -5,7 +5,8 @@ from . import utils
...
@@ -5,7 +5,8 @@ from . import utils
class
PeerDB
(
object
):
class
PeerDB
(
object
):
# internal ip = temp arg/attribute
# internal ip = temp arg/attribute
def
__init__
(
self
,
db_path
,
registry
,
key_path
,
prefix
,
db_size
=
200
):
def
__init__
(
self
,
db_path
,
registry
,
key_path
,
network
,
prefix
,
db_size
=
200
):
self
.
_prefix
=
prefix
self
.
_prefix
=
prefix
self
.
_db_size
=
db_size
self
.
_db_size
=
db_size
self
.
_key_path
=
key_path
self
.
_key_path
=
key_path
...
@@ -31,21 +32,29 @@ class PeerDB(object):
...
@@ -31,21 +32,29 @@ class PeerDB(object):
try
:
try
:
a
=
q
(
"SELECT value FROM config WHERE name='registry'"
).
next
()[
0
]
a
=
q
(
"SELECT value FROM config WHERE name='registry'"
).
next
()[
0
]
except
StopIteration
:
except
StopIteration
:
logging
.
info
(
"Private IP of registry not in cache."
a
=
self
.
_updateRegistryIP
()
" Asking registry via its public IP ..."
)
else
:
retry
=
1
self
.
registry_ip
=
utils
.
binFromIp
(
a
)
while
True
:
if
not
self
.
registry_ip
.
startswith
(
network
):
try
:
a
=
self
.
_updateRegistryIP
()
a
=
self
.
_registry
.
getPrivateAddress
(
self
.
_prefix
)
break
except
socket
.
error
,
e
:
logging
.
warning
(
e
)
time
.
sleep
(
retry
)
retry
=
min
(
60
,
retry
*
2
)
q
(
"INSERT INTO config VALUES ('registry',?)"
,
(
a
,))
self
.
registry_ip
=
utils
.
binFromIp
(
a
)
logging
.
info
(
"Cache initialized. Registry IP is %s"
,
a
)
logging
.
info
(
"Cache initialized. Registry IP is %s"
,
a
)
def
_updateRegistryIP
(
self
):
logging
.
info
(
"Asking registry its private IP..."
)
retry
=
1
while
True
:
try
:
a
=
self
.
_registry
.
getPrivateAddress
(
self
.
_prefix
)
break
except
socket
.
error
,
e
:
logging
.
warning
(
e
)
time
.
sleep
(
retry
)
retry
=
min
(
60
,
retry
*
2
)
self
.
_db
.
execute
(
"INSERT OR REPLACE INTO config VALUES ('registry',?)"
,
(
a
,))
self
.
registry_ip
=
utils
.
binFromIp
(
a
)
return
a
def
log
(
self
):
def
log
(
self
):
if
logging
.
getLogger
().
isEnabledFor
(
5
):
if
logging
.
getLogger
().
isEnabledFor
(
5
):
logging
.
trace
(
"Cache:"
)
logging
.
trace
(
"Cache:"
)
...
...
re6stnet
View file @
c1749ede
...
@@ -150,7 +150,6 @@ def main():
...
@@ -150,7 +150,6 @@ def main():
ca
=
crypto
.
load_certificate
(
crypto
.
FILETYPE_PEM
,
f
.
read
())
ca
=
crypto
.
load_certificate
(
crypto
.
FILETYPE_PEM
,
f
.
read
())
with
open
(
config
.
cert
)
as
f
:
with
open
(
config
.
cert
)
as
f
:
cert
=
crypto
.
load_certificate
(
crypto
.
FILETYPE_PEM
,
f
.
read
())
cert
=
crypto
.
load_certificate
(
crypto
.
FILETYPE_PEM
,
f
.
read
())
network
=
utils
.
networkFromCa
(
ca
)
prefix
=
utils
.
binFromSubnet
(
utils
.
subnetFromCert
(
cert
))
prefix
=
utils
.
binFromSubnet
(
utils
.
subnetFromCert
(
cert
))
config
.
openvpn_args
+=
(
config
.
openvpn_args
+=
(
'--ca'
,
config
.
ca
,
'--ca'
,
config
.
ca
,
...
@@ -181,6 +180,7 @@ def main():
...
@@ -181,6 +180,7 @@ def main():
ca
,
ca_renew
=
maybe_renew
(
config
.
ca
,
ca
,
"CA Certificate"
,
registry
.
getCa
)
ca
,
ca_renew
=
maybe_renew
(
config
.
ca
,
ca
,
"CA Certificate"
,
registry
.
getCa
)
if
next_renew
>
ca_renew
:
if
next_renew
>
ca_renew
:
next_renew
=
ca_renew
next_renew
=
ca_renew
network
=
utils
.
networkFromCa
(
ca
)
if
config
.
max_clients
is
None
:
if
config
.
max_clients
is
None
:
config
.
max_clients
=
config
.
client_count
*
2
config
.
max_clients
=
config
.
client_count
*
2
...
@@ -270,7 +270,7 @@ def main():
...
@@ -270,7 +270,7 @@ def main():
# Create and open read_only pipe to get server events
# Create and open read_only pipe to get server events
r_pipe
,
write_pipe
=
os
.
pipe
()
r_pipe
,
write_pipe
=
os
.
pipe
()
read_pipe
=
os
.
fdopen
(
r_pipe
)
read_pipe
=
os
.
fdopen
(
r_pipe
)
peer_db
=
db
.
PeerDB
(
db_path
,
registry
,
config
.
key
,
prefix
)
peer_db
=
db
.
PeerDB
(
db_path
,
registry
,
config
.
key
,
network
,
prefix
)
tunnel_manager
=
tunnel
.
TunnelManager
(
write_pipe
,
peer_db
,
tunnel_manager
=
tunnel
.
TunnelManager
(
write_pipe
,
peer_db
,
config
.
openvpn_args
,
timeout
,
config
.
tunnel_refresh
,
config
.
openvpn_args
,
timeout
,
config
.
tunnel_refresh
,
config
.
client_count
,
config
.
iface_list
,
network
,
prefix
,
config
.
client_count
,
config
.
iface_list
,
network
,
prefix
,
...
...
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