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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
re6stnet
Commits
b7453ca8
Commit
b7453ca8
authored
Jul 18, 2012
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use lowercase for variables
parent
ed6df9d4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
18 deletions
+19
-18
db.py
db.py
+4
-4
plib.py
plib.py
+4
-4
propagation.py
propagation.py
+4
-3
upnpigd.py
upnpigd.py
+7
-7
No files found.
db.py
View file @
b7453ca8
...
...
@@ -3,7 +3,7 @@ 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
...
...
@@ -13,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"
)
...
...
@@ -44,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 @
b7453ca8
...
...
@@ -21,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
,
...
...
@@ -35,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 @
b7453ca8
...
...
@@ -18,17 +18,17 @@ class RingMember:
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 :
...
...
@@ -71,6 +71,7 @@ class Ring:
# 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});
...
...
upnpigd.py
View file @
b7453ca8
...
...
@@ -2,18 +2,18 @@ import miniupnpc
import
socket
# return (address, port)
def
ForwardViaUPnP
(
local
P
ort
):
def
ForwardViaUPnP
(
local
_p
ort
):
u
=
miniupnpc
.
UPnP
()
u
.
discoverdelay
=
200
u
.
discover
()
u
.
selectigd
()
external
P
ort
=
1194
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
:
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
,
localP
ort
,
'Vifib openvpn server'
,
''
):
return
(
u
.
externalipaddress
(),
external
P
ort
)
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
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