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
Rafael Monnerat
re6stnet
Commits
11f6f9df
Commit
11f6f9df
authored
Jul 18, 2012
by
Ulysse Beaugnon
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://git.erp5.org/repos/vifibnet
parents
5d9fa24a
b7453ca8
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
47 additions
and
52 deletions
+47
-52
db.py
db.py
+6
-7
plib.py
plib.py
+4
-5
propagation.py
propagation.py
+7
-7
registry.py
registry.py
+2
-2
simulation/graph.cpp
simulation/graph.cpp
+5
-5
simulation/main.cpp
simulation/main.cpp
+6
-6
simulation/main.h
simulation/main.h
+2
-2
simulation/results.cpp
simulation/results.cpp
+2
-2
tunnel.py
tunnel.py
+0
-1
upnpigd.py
upnpigd.py
+13
-14
utils.py
utils.py
+0
-1
No files found.
db.py
View file @
11f6f9df
#!/usr/bin/env python
import
sqlite3
,
xmlrpclib
,
time
import
utils
class
PeerManager
:
def
__init__
(
self
,
db
P
ath
,
server
,
server_port
,
refresh_time
,
external_ip
,
internal_ip
,
port
,
proto
,
db_size
):
def
__init__
(
self
,
db
_p
ath
,
server
,
server_port
,
refresh_time
,
external_ip
,
internal_ip
,
port
,
proto
,
db_size
):
self
.
_refresh_time
=
refresh_time
self
.
_external_ip
=
external_ip
self
.
_internal_ip
=
internal_ip
...
...
@@ -14,7 +13,7 @@ class PeerManager:
self
.
_proxy
=
xmlrpclib
.
ServerProxy
(
'http://%s:%u'
%
(
server
,
server_port
))
utils
.
log
(
'Connectiong to peers database'
,
4
)
self
.
_db
=
sqlite3
.
connect
(
db
P
ath
,
isolation_level
=
None
)
self
.
_db
=
sqlite3
.
connect
(
db
_p
ath
,
isolation_level
=
None
)
utils
.
log
(
'Preparing peers database'
,
4
)
try
:
self
.
_db
.
execute
(
"UPDATE peers SET used = 0"
)
...
...
@@ -32,12 +31,12 @@ class PeerManager:
def
_declare
(
self
):
if
self
.
_external_ip
!=
None
:
utils
.
log
(
'Declaring our connections info'
,
3
)
utils
.
log
(
'Declaring our connections info'
,
3
)
self
.
_proxy
.
declare
((
self
.
_internal_ip
,
self
.
_external_ip
,
self
.
_external_port
,
self
.
_proto
))
else
:
utils
.
log
(
'Warning : could not declare the external ip because it is unknown'
,
4
)
def
_populate
(
self
):
def
_populate
(
self
):
utils
.
log
(
'Populating the peers DB'
,
2
)
new_peer_list
=
self
.
_proxy
.
getPeerList
(
self
.
_db_size
,
self
.
_internal_ip
)
self
.
_db
.
executemany
(
"INSERT OR IGNORE INTO peers (ip, port, proto, used) VALUES (?,?,?,0)"
,
new_peer_list
)
...
...
@@ -45,9 +44,9 @@ class PeerManager:
self
.
_db
.
execute
(
"DELETE FROM peers WHERE ip = ?"
,
(
self
.
_external_ip
,))
utils
.
log
(
'New peers : %s'
%
', '
.
join
(
map
(
str
,
new_peer_list
)),
5
)
def
getUnusedPeers
(
self
,
nPeers
):
def
getUnusedPeers
(
self
,
peer_count
):
return
self
.
_db
.
execute
(
"SELECT id, ip, port, proto FROM peers WHERE used = 0 "
"ORDER BY RANDOM() LIMIT ?"
,
(
nPeers
,))
"ORDER BY RANDOM() LIMIT ?"
,
(
peer_count
,))
def
usePeer
(
self
,
id
):
utils
.
log
(
'Updating peers database : using peer '
+
str
(
id
),
5
)
...
...
plib.py
View file @
11f6f9df
#!/usr/bin/env python
import
os
,
subprocess
import
utils
...
...
@@ -22,12 +21,12 @@ def openvpn(*args, **kw):
# TODO : set iface up when creating a server/client
# ! check working directory before launching up script ?
def
server
(
server
I
p
,
network
,
max_clients
,
dh_path
,
pipe_fd
,
port
,
proto
,
*
args
,
**
kw
):
def
server
(
server
_i
p
,
network
,
max_clients
,
dh_path
,
pipe_fd
,
port
,
proto
,
*
args
,
**
kw
):
utils
.
log
(
'Starting server'
,
3
)
return
openvpn
(
'--tls-server'
,
'--mode'
,
'server'
,
'--up'
,
'ovpn-server %s/%u'
%
(
server
I
p
,
len
(
network
)),
'--up'
,
'ovpn-server %s/%u'
%
(
server
_i
p
,
len
(
network
)),
'--client-connect'
,
'ovpn-server '
+
str
(
pipe_fd
),
'--client-disconnect'
,
'ovpn-server '
+
str
(
pipe_fd
),
'--dh'
,
dh_path
,
...
...
@@ -36,12 +35,12 @@ def server(serverIp, network, max_clients, dh_path, pipe_fd, port, proto, *args,
'--proto'
,
proto
,
*
args
,
**
kw
)
def
client
(
server
I
p
,
pipe_fd
,
*
args
,
**
kw
):
def
client
(
server
_i
p
,
pipe_fd
,
*
args
,
**
kw
):
utils
.
log
(
'Starting client'
,
5
)
return
openvpn
(
'--nobind'
,
'--client'
,
'--remote'
,
server
I
p
,
'--remote'
,
server
_i
p
,
'--up'
,
'ovpn-client'
,
'--route-up'
,
'ovpn-client '
+
str
(
pipe_fd
),
*
args
,
**
kw
)
...
...
propagation.py
View file @
11f6f9df
#!/usr/bin/env python
import
socket
,
uuid
import
log
...
...
@@ -18,18 +17,18 @@ class RingMember:
return
str
(
self
.
id
)
+
' '
+
self
.
ip
+
' '
+
str
(
self
.
port
)
class
Ring
:
def
__init__
(
self
,
entry
P
oint
):
def
__init__
(
self
,
entry
_p
oint
):
# initialize the connection
self
.
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
self
.
sock
.
bind
((
''
,
0
))
self
.
me
=
RingMember
(
uuid
.
uuid1
().
int
,
''
,
self
.
sock
.
getsockname
()[
1
])
# TODO : get the address
# to enter the ring
self
.
predecessor
=
None
if
entry
P
oint
==
None
:
if
entry
_p
oint
==
None
:
self
.
successor
=
self
.
me
else
:
self
.
send
(
'FIND_SUCCESSOR '
+
str
(
self
.
me
.
id
)
+
' '
+
self
.
me
.
toString
(),
entry
P
oint
)
self
.
send
(
'FIND_SUCCESSOR '
+
str
(
self
.
me
.
id
)
+
' '
+
self
.
me
.
toString
(),
entry
_p
oint
)
log
.
log
(
'Init the ring with me = '
+
self
.
me
.
toString
(),
3
)
# TODO :
...
...
@@ -65,16 +64,17 @@ class Ring:
# if n < x && x < self.successor:
# self.successor = x
# SEND notify self.ip, self.id TO self.successor
# def notify(self, n2)
# if self.predecessor == None || (predecessor < n2 && n2 < n):
# self.predecessor = n2
# to be called periodically
# def fixFingers(self)
# # XXX: naming - should be finger_count
# next = (next + 1) mod (nFingers) # Or Random, cf google
# finger[next] = find_successor(n+2^{next-1});
# to be called periodically
# def checkPredecessor(self)
# if NO PING from self.predecessor:
...
...
registry.py
View file @
11f6f9df
...
...
@@ -86,7 +86,7 @@ class main(object):
server4
.
register_instance
(
self
)
server6
=
SimpleXMLRPCServer6
((
'::'
,
self
.
config
.
port
),
requestHandler
=
RequestHandler
,
allow_none
=
True
)
server6
.
register_instance
(
self
)
# Main loop
while
True
:
try
:
...
...
@@ -169,7 +169,7 @@ class main(object):
return
crypto
.
dump_certificate
(
crypto
.
FILETYPE_PEM
,
self
.
ca
)
def
getBootstrapPeer
(
self
,
handler
):
# TODO: Insert a flag column for bootstrap ready servers in peers
# TODO: Insert a flag column for bootstrap ready servers in peers
# ( servers which shouldn't go down or change ip and port as opposed to servers owned by particulars )
# that way, we also ascertain that the server sent is not the new node....
ip
,
port
,
proto
=
self
.
db
.
execute
(
"SELECT ip, port, proto FROM peers ORDER BY random() LIMIT 1"
).
next
()
...
...
simulation/graph.cpp
View file @
11f6f9df
...
...
@@ -3,7 +3,7 @@
#include <map>
#include <queue>
Graph
::
Graph
(
int
size
,
int
k
,
int
maxPeers
,
mt19937
&
rng
)
:
Graph
::
Graph
(
int
size
,
int
k
,
int
maxPeers
,
mt19937
&
rng
)
:
distrib
(
uniform_int_distribution
<
int
>
(
0
,
size
-
1
)),
size
(
size
),
generator
(
rng
)
{
...
...
@@ -17,9 +17,9 @@ Graph::Graph(int size, int k, int maxPeers, mt19937& rng) :
{
int
otherNode
;
while
(
alreadyConnected
.
count
(
otherNode
=
distrib
(
rng
))
==
1
while
(
alreadyConnected
.
count
(
otherNode
=
distrib
(
rng
))
==
1
||
otherNode
>
i
&&
adjacency
[
otherNode
].
size
()
>
maxPeers
-
10
||
adjacency
[
otherNode
].
size
()
>
maxPeers
)
||
adjacency
[
otherNode
].
size
()
>
maxPeers
)
{
}
adjacency
[
i
].
push_back
(
otherNode
);
adjacency
[
otherNode
].
push_back
(
i
);
...
...
@@ -75,7 +75,7 @@ int Graph::CountUnreachableFrom(int node)
unAccessible
--
;
toVisit
.
pop
();
}
return
unAccessible
;
}
...
...
@@ -156,7 +156,7 @@ void MinCutGraph::Merge(int nMerge, mt19937& rng)
int
n1
=
edges
[
eId
].
v
.
first
;
int
n2
=
edges
[
eId
].
v
.
second
;
// anilate n2
nodes
[
n2
].
null
=
true
;
...
...
simulation/main.cpp
View file @
11f6f9df
...
...
@@ -49,16 +49,16 @@ int main(int argc, char** argv)
for
(
float
a
=
0.01
;
a
<=
1
;
a
+=
0.05
)
{
int
seed
=
rng
();
outputStrings
.
push_back
(
async
(
launch
::
async
,
[
seed
,
n
,
k
,
a
]()
outputStrings
.
push_back
(
async
(
launch
::
async
,
[
seed
,
n
,
k
,
a
]()
{
Results
results
=
Simulate
(
seed
,
n
,
k
,
3
*
k
,
10000
,
a
,
1
);
ostringstream
out
;
out
<<
n
<<
","
<<
k
<<
","
<<
a
<<
","
<<
3
*
k
<<
","
<<
results
.
avgDistance
<<
","
<<
results
.
disconnected
<<
","
<<
results
.
disconnectionProba
<<
","
out
<<
n
<<
","
<<
k
<<
","
<<
a
<<
","
<<
3
*
k
<<
","
<<
results
.
avgDistance
<<
","
<<
results
.
disconnected
<<
","
<<
results
.
disconnectionProba
<<
","
<<
results
.
maxDistanceReached
<<
","
<<
results
.
arityDistrib
[
3
*
k
]
<<
","
<<
results
.
arityDistrib
[
3
*
k
]
<<
","
<<
results
.
minKConnexity
<<
","
<<
results
.
avgAccessibility
<<
endl
;
...
...
simulation/main.h
View file @
11f6f9df
...
...
@@ -9,7 +9,7 @@ using namespace std;
template
<
class
T
>
struct
nullable
{
{
T
v
;
bool
null
;
...
...
@@ -75,7 +75,7 @@ public:
double
arityTooBig
;
double
distanceTooBig
;
int64_t
disconnected
;
int
maxArity
;
int
maxDistance
;
...
...
simulation/results.cpp
View file @
11f6f9df
#include "main.h"
Results
::
Results
(
int
maxArity
,
int
maxDistance
)
:
Results
::
Results
(
int
maxArity
,
int
maxDistance
)
:
maxArity
(
maxArity
),
maxDistance
(
maxDistance
)
{
arityDistrib
=
new
double
[
maxArity
+
1
];
...
...
@@ -54,7 +54,7 @@ void Results::AddDistanceSample(int distance)
{
if
(
distance
==
-
1
)
disconnected
++
;
else
else
{
avgDistance
+=
distance
;
if
(
distance
<=
maxDistance
)
...
...
tunnel.py
View file @
11f6f9df
#!/usr/bin/env python
import
os
,
random
,
traceback
,
time
import
plib
,
utils
,
db
...
...
upnpigd.py
View file @
11f6f9df
#!/usr/bin/env python
import
miniupnpc
import
socket
# return (address, port)
def
ForwardViaUPnP
(
local
P
ort
):
u
=
miniupnpc
.
UPnP
()
u
.
discoverdelay
=
200
u
.
discover
()
u
.
selectigd
()
externalP
ort
=
1194
while
True
:
while
u
.
getspecificportmapping
(
externalP
ort
,
'UDP'
)
!=
None
:
externalP
ort
=
max
(
externalPort
+
1
,
49152
)
if
externalP
ort
==
65536
:
raise
Exception
if
u
.
addportmapping
(
externalPort
,
'UDP'
,
u
.
lanaddr
,
localP
ort
,
'Vifib openvpn server'
,
''
):
return
(
u
.
externalipaddress
(),
externalP
ort
)
def
ForwardViaUPnP
(
local
_p
ort
):
u
=
miniupnpc
.
UPnP
()
u
.
discoverdelay
=
200
u
.
discover
()
u
.
selectigd
()
external_p
ort
=
1194
while
True
:
while
u
.
getspecificportmapping
(
external_p
ort
,
'UDP'
)
!=
None
:
external_p
ort
=
max
(
externalPort
+
1
,
49152
)
if
external_p
ort
==
65536
:
raise
Exception
if
u
.
addportmapping
(
external_port
,
'UDP'
,
u
.
lanaddr
,
local_p
ort
,
'Vifib openvpn server'
,
''
):
return
(
u
.
externalipaddress
(),
external_p
ort
)
# TODO : specify a lease duration
utils.py
View file @
11f6f9df
#!/usr/bin/env python
import
argparse
,
time
,
struct
,
socket
from
OpenSSL
import
crypto
...
...
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