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
18dee845
Commit
18dee845
authored
Jul 04, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://git.erp5.org/repos/vifibnet
Conflicts: main.py
parents
ec7c78d6
f9beed0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
5 deletions
+64
-5
main.py
main.py
+63
-4
upnpigd.py
upnpigd.py
+1
-1
No files found.
main.py
View file @
18dee845
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
argparse
,
errno
,
os
,
subprocess
,
sys
,
time
import
argparse
,
errno
,
os
,
subprocess
,
sys
,
time
import
upnpigd
import
upnpigd
import
openvpn
import
openvpn
import
random
VIFIB_NET
=
"2001:db8:42::/48"
VIFIB_NET
=
"2001:db8:42::/48"
...
@@ -31,6 +32,13 @@ def getConfig():
...
@@ -31,6 +32,13 @@ def getConfig():
global
config
global
config
parser
=
argparse
.
ArgumentParser
(
description
=
'Resilient virtual private network application'
)
parser
=
argparse
.
ArgumentParser
(
description
=
'Resilient virtual private network application'
)
_
=
parser
.
add_argument
_
=
parser
.
add_argument
_
(
'--max-peer'
,
help
=
'the number of peers that can connect to the server'
,
default
=
'10'
)
# TODO : use it
_
(
'--client-count'
,
help
=
'the number servers the peers try to connect to'
,
default
=
'2'
)
_
(
'--refresh-time'
,
help
=
'the time (seconds) to wait before changing the connections'
,
default
=
'20'
)
# TODO : use it
_
(
'--refresh-count'
,
help
=
'The number of connections to drop when refreshing the connections'
,
default
=
'1'
)
# TODO : use it
_
(
'--dh'
,
required
=
True
,
_
(
'--dh'
,
required
=
True
,
help
=
'Path to dh file'
)
help
=
'Path to dh file'
)
_
(
'--babel-state'
,
_
(
'--babel-state'
,
...
@@ -46,13 +54,64 @@ def getConfig():
...
@@ -46,13 +54,64 @@ def getConfig():
if
config
.
openvpn_args
[
0
]
==
"--"
:
if
config
.
openvpn_args
[
0
]
==
"--"
:
del
config
.
openvpn_args
[
0
]
del
config
.
openvpn_args
[
0
]
def
startNewConnection
():
try
:
peer
=
random
.
choice
(
avalaiblePeers
.
keys
())
if
config
.
verbose
>
2
:
print
'Establishing a connection with '
+
peer
del
avalaiblePeers
[
peer
]
connections
[
peer
]
=
openvpn
.
client
(
config
,
peer
)
except
Exception
:
pass
# TODO :
def
killConnection
(
peer
):
if
config
.
verbose
>
2
:
print
'Killing the connection with '
+
peer
subprocess
.
Popen
.
kill
(
connections
[
peer
])
del
connections
[
peer
]
avalaiblePeers
[
peer
]
=
1194
# TODO : give the real port
def
refreshConnections
():
try
:
for
i
in
range
(
0
,
int
(
config
.
refresh_count
)):
peer
=
random
.
choice
(
connections
.
keys
())
killConnection
(
peer
)
except
Exception
:
pass
for
i
in
range
(
len
(
connections
),
int
(
config
.
client_count
)):
startNewConnection
()
def
main
():
def
main
():
# init variables
global
connections
global
avalaiblePeers
# the list of peers we can connect to
avalaiblePeers
=
{
'10.1.4.2'
:
1194
,
'10.1.4.3'
:
1194
,
'10.1.3.2'
:
1194
}
connections
=
{}
# to remember current connections
getConfig
()
getConfig
()
if
config
.
ip
!=
'none'
:
(
externalIp
,
externalPort
)
=
upnpigd
.
GetExternalInfo
(
1194
)
serverProcess
=
openvpn
.
server
(
config
.
ip
,
"--dev"
,
"server"
)
try
:
else
:
del
avalaiblePeers
[
externalIp
]
client1Process
=
openvpn
.
client
(
'10.1.4.2'
)
except
Exception
:
pass
# establish connections
serverProcess
=
openvpn
.
server
(
config
,
config
.
ip
)
for
i
in
range
(
0
,
int
(
config
.
client_count
)):
startNewConnection
()
# main loop
try
:
while
True
:
time
.
sleep
(
float
(
config
.
refresh_time
))
refreshConnections
()
except
KeyboardInterrupt
:
pass
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
main
()
main
()
# TODO : pass the remote port as an argument to openvpn
# TODO : remove incomming connections from avalaible peers
upnpigd.py
View file @
18dee845
...
@@ -22,7 +22,7 @@ def ForwardViaUPnP(localPort):
...
@@ -22,7 +22,7 @@ def ForwardViaUPnP(localPort):
def
GetLocalIp
():
def
GetLocalIp
():
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
s
.
connect
((
'
8
.8.8.8'
,
0
))
s
.
connect
((
'
10
.8.8.8'
,
0
))
return
s
.
getsockname
()[
0
]
return
s
.
getsockname
()[
0
]
...
...
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