Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
215d3d28
Commit
215d3d28
authored
8 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
http server: add cmd arguments
parent
43a345ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/tools/http_server.py
+16
-6
16 additions, 6 deletions
python/tools/http_server.py
with
16 additions
and
6 deletions
python/tools/http_server.py
100644 → 100755
+
16
−
6
View file @
215d3d28
...
...
@@ -17,6 +17,7 @@
from
twisted.web
import
server
,
resource
from
twisted.internet
import
reactor
,
endpoints
from
urllib.parse
import
urlparse
import
opendht
as
dht
import
base64
,
json
...
...
@@ -25,14 +26,15 @@ class DhtServer(resource.Resource):
isLeaf
=
True
node
=
dht
.
DhtRunner
()
def
__init__
(
self
):
self
.
node
.
run
()
self
.
node
.
bootstrap
(
"
bootstrap.ring.cx
"
,
"
4222
"
)
def
__init__
(
self
,
port
,
bootstrap
):
self
.
node
.
run
(
port
=
port
)
b_url
=
urlparse
(
'
//
'
+
bootstrap
)
self
.
node
.
bootstrap
(
b_url
.
hostname
,
str
(
b_url
.
port
)
if
b_url
.
port
else
'
4222
'
)
def
render_GET
(
self
,
req
):
uri
=
req
.
uri
[
1
:]
h
=
dht
.
InfoHash
(
uri
)
if
len
(
uri
)
==
40
else
dht
.
InfoHash
.
get
(
uri
.
decode
())
print
(
'
GET
'
,
h
)
print
(
'
GET
'
,
'"'
+
uri
.
decode
()
+
'"'
,
h
)
res
=
self
.
node
.
get
(
h
)
req
.
setHeader
(
b
"
content-type
"
,
b
"
application/json
"
)
return
json
.
dumps
({
'
{:x}
'
.
format
(
v
.
id
):{
'
base64
'
:
base64
.
b64encode
(
v
.
data
).
decode
()}
for
v
in
res
}).
encode
()
...
...
@@ -52,5 +54,13 @@ class DhtServer(resource.Resource):
req
.
setResponseCode
(
400
)
return
json
.
dumps
({
'
success
'
:
False
,
'
error
'
:
'
no data parameter
'
}).
encode
()
endpoints
.
serverFromString
(
reactor
,
"
tcp:8080
"
).
listen
(
server
.
Site
(
DhtServer
()))
reactor
.
run
()
if
__name__
==
'
__main__
'
:
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
'
Launch an OpenDHT node with an HTTP control interface
'
)
parser
.
add_argument
(
'
-p
'
,
'
--port
'
,
help
=
'
OpenDHT port to bind
'
,
type
=
int
,
default
=
4222
)
parser
.
add_argument
(
'
-hp
'
,
'
--http-port
'
,
help
=
'
HTTP port to bind
'
,
type
=
int
,
default
=
8080
)
parser
.
add_argument
(
'
-b
'
,
'
--bootstrap
'
,
help
=
'
bootstrap address
'
,
default
=
"
bootstrap.ring.cx:4222
"
)
args
=
parser
.
parse_args
()
endpoints
.
serverFromString
(
reactor
,
"
tcp:
"
+
str
(
args
.
http_port
)).
listen
(
server
.
Site
(
DhtServer
(
args
.
port
,
args
.
bootstrap
)))
reactor
.
run
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment