mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
GET requests served from Swarm
This commit is contained in:
parent
dd1f9885af
commit
84c8a1452e
2 changed files with 47 additions and 1 deletions
43
bzz/httpaccess.go
Normal file
43
bzz/httpaccess.go
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
A simple http server interface to Swarm
|
||||||
|
*/
|
||||||
|
package bzz
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"net/http"
|
||||||
|
"regexp"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
port = ":8500"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
uriMatcher = regexp.MustCompile("^/raw/[0-9A-Fa-f]{64}$")
|
||||||
|
)
|
||||||
|
|
||||||
|
func handler(w http.ResponseWriter, r *http.Request, dpa *DPA) {
|
||||||
|
uri := r.RequestURI
|
||||||
|
switch {
|
||||||
|
case r.Method == "PUT":
|
||||||
|
case r.Method == "GET":
|
||||||
|
if uriMatcher.MatchString(uri) {
|
||||||
|
name := uri[5:]
|
||||||
|
key := ethutil.Hex2Bytes(name)
|
||||||
|
http.ServeContent(w, r, name+".bin", time.Unix(0, 0), dpa.Retrieve(key))
|
||||||
|
} else {
|
||||||
|
http.Error(w, "Object "+uri+" not found.", http.StatusNotFound)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
http.Error(w, "Method "+r.Method+" is not supported.", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func StartHttpServer(dpa *DPA) {
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
handler(w, r, dpa)
|
||||||
|
})
|
||||||
|
http.ListenAndServe(port, nil)
|
||||||
|
}
|
||||||
|
|
@ -135,11 +135,14 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
eth.blockPool = NewBlockPool(hasBlock, insertChain, ezp.Verify)
|
eth.blockPool = NewBlockPool(hasBlock, insertChain, ezp.Verify)
|
||||||
|
|
||||||
ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool)
|
ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool)
|
||||||
|
netStore := bzz.NewNetStore(config.DataDir + "/bzz")
|
||||||
protocols := []p2p.Protocol{
|
protocols := []p2p.Protocol{
|
||||||
ethProto,
|
ethProto,
|
||||||
eth.whisper.Protocol(),
|
eth.whisper.Protocol(),
|
||||||
bzz.BzzProtocol(bzz.NewNetStore(config.DataDir + "/bzz")),
|
bzz.BzzProtocol(netStore),
|
||||||
}
|
}
|
||||||
|
// dpa :=
|
||||||
|
bzz.StartHttpServer(nil)
|
||||||
|
|
||||||
nat, err := p2p.ParseNAT(config.NATType, config.PMPGateway)
|
nat, err := p2p.ParseNAT(config.NATType, config.PMPGateway)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue