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
zhifan huang
re6stnet
Commits
4d956fea
Commit
4d956fea
authored
Jul 10, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small fixes
parent
f4e39ebc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
9 deletions
+28
-9
registry.py
registry.py
+20
-7
setup.py
setup.py
+4
-1
vifibnet.py
vifibnet.py
+4
-1
No files found.
registry.py
View file @
4d956fea
#!/usr/bin/env python
import
argparse
,
math
,
random
,
smtplib
,
sqlite3
,
string
,
time
from
email.mime.text
import
MIMEText
from
SimpleXMLRPCServer
import
SimpleXMLRPCServer
from
functools
import
wraps
from
SimpleXMLRPCServer
import
SimpleXMLRPCServer
,
SimpleXMLRPCRequestHandler
from
OpenSSL
import
crypto
import
netaddr
import
traceback
class
RequestHandler
(
SimpleXMLRPCRequestHandler
):
def
_dispatch
(
self
,
method
,
params
):
return
self
.
server
.
_dispatch
(
method
,
(
self
,)
+
params
)
class
main
(
object
):
def
__init__
(
self
):
...
...
@@ -60,11 +65,11 @@ class main(object):
self
.
network
=
bin
(
self
.
ca
.
get_serial_number
())[
3
:]
# Starting server
server
=
SimpleXMLRPCServer
((
"localhost"
,
8000
),
allow_none
=
True
)
server
=
SimpleXMLRPCServer
((
"localhost"
,
8000
),
requestHandler
=
RequestHandler
,
allow_none
=
True
)
server
.
register_instance
(
self
)
server
.
serve_forever
()
def
requestToken
(
self
,
email
):
def
requestToken
(
self
,
handler
,
email
):
while
True
:
# Generating token
token
=
''
.
join
(
random
.
sample
(
string
.
ascii_lowercase
,
8
))
...
...
@@ -96,7 +101,7 @@ class main(object):
return
prefix
raise
RuntimeError
# TODO: raise better exception
def
requestCertificate
(
self
,
token
,
cert_req
):
def
requestCertificate
(
self
,
handler
,
token
,
cert_req
):
try
:
req
=
crypto
.
load_certificate_request
(
crypto
.
FILETYPE_PEM
,
cert_req
)
with
self
.
db
:
...
...
@@ -131,11 +136,19 @@ class main(object):
traceback
.
print_exc
()
raise
def
getCa
(
self
):
def
getCa
(
self
,
handler
):
return
crypto
.
dump_certificate
(
crypto
.
FILETYPE_PEM
,
self
.
ca
)
def
getPeerList
(
self
,
n
):
def
declare
(
self
,
handler
,
address
):
# guess prefix from handler.client_address
ip1
,
ip2
=
struct
.
unpack
(
'>QQ'
,
socket
.
inet_pton
(
socket
.
AF_INET6
,
handler
.
client_address
)))
prefix
=
bin
(
ip1
)[
2
:]
+
bin
(
ip2
)]
2
:]
ip
,
port
,
proto
=
address
self
.
db
.
execute
(
"INSERT INTO peers VALUES (?,?,?,?)"
,
(
prefix
,
ip
,
port
,
proto
))
def
getPeerList
(
self
,
handler
,
n
,
address
):
assert
0
<
n
<
1000
self
.
declare
(
handler
,
address
)
return
self
.
db
.
execute
(
"SELECT ip, port, proto FROM peers ORDER BY random() LIMIT ?"
,
(
n
,)).
fetchall
()
...
...
setup.py
View file @
4d956fea
#!/usr/bin/env python
from
OpenSSL
import
crypto
import
argparse
,
os
,
xmlrpclib
import
argparse
,
os
,
subprocess
,
xmlrpclib
def
main
():
parser
=
argparse
.
ArgumentParser
(
...
...
@@ -46,6 +46,9 @@ def main():
ca
=
s
.
getCa
()
cert
=
s
.
requestCertificate
(
token
,
req
)
# Generating dh file
subprocess
.
call
([
'openssl'
,
'dhparam'
,
'-out'
,
os
.
path
.
join
(
config
.
dir
,
'dh2048.pem'
),
'2048'
])
# Store cert and key
with
open
(
os
.
path
.
join
(
config
.
dir
,
'cert.key'
),
'w'
)
as
f
:
f
.
write
(
key
)
...
...
vifibnet.py
View file @
4d956fea
...
...
@@ -36,7 +36,9 @@ class PeersDB:
self
.
populateDB
(
100
)
def
populateDB
(
self
,
n
):
self
.
db
.
executemany
(
"INSERT INTO peers (ip, port, proto) VALUES ?"
,
self
.
proxy
.
getPeerList
(
n
))
(
ip
,
port
)
=
upnpigd
.
GetExternalInfo
(
1194
)
proto
=
'udp'
self
.
db
.
executemany
(
"INSERT INTO peers (ip, port, proto) VALUES ?"
,
self
.
proxy
.
getPeerList
(
n
,
port
,
proto
))
def
getUnusedPeers
(
self
,
nPeers
):
return
self
.
db
.
execute
(
"SELECT id, ip, port, proto FROM peers WHERE used = 0 "
...
...
@@ -191,6 +193,7 @@ def main():
# Get arguments
getConfig
()
log
.
verbose
=
config
.
verbose
# TODO: get proto to use ?
(
externalIp
,
externalPort
)
=
upnpigd
.
GetExternalInfo
(
1194
)
# Setup database
...
...
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