mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
simplify docserver
This commit is contained in:
parent
97ab1abc1b
commit
a7804860c9
3 changed files with 4 additions and 23 deletions
|
|
@ -495,7 +495,7 @@ func (self *bzzProtocol) storeRequest(key Key) {
|
||||||
peerKey := make([]byte, 64)
|
peerKey := make([]byte, 64)
|
||||||
copy(peerKey, self.key())
|
copy(peerKey, self.key())
|
||||||
copy(peerKey[32:], key[:])
|
copy(peerKey[32:], key[:])
|
||||||
dpaLogger.Debugf("enter store request %x", peerKey)
|
dpaLogger.Debugf("enter store request %x into db", peerKey)
|
||||||
self.requestDb.Put(peerKey, []byte{0})
|
self.requestDb.Put(peerKey, []byte{0})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,29 +9,17 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// http://golang.org/pkg/net/http/#RoundTripper
|
|
||||||
var (
|
|
||||||
schemes = map[string]func(*DocServer) http.RoundTripper{
|
|
||||||
// Simple File server from local disk file:///etc/passwd :)
|
|
||||||
"file": fileServerOnDocRoot,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func fileServerOnDocRoot(ds *DocServer) http.RoundTripper {
|
|
||||||
return http.NewFileTransport(http.Dir(ds.DocRoot))
|
|
||||||
}
|
|
||||||
|
|
||||||
type DocServer struct {
|
type DocServer struct {
|
||||||
*http.Transport
|
*http.Transport
|
||||||
DocRoot string
|
DocRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(docRoot string) (self *DocServer, err error) {
|
func New(docRoot string) (self *DocServer) {
|
||||||
self = &DocServer{
|
self = &DocServer{
|
||||||
Transport: &http.Transport{},
|
Transport: &http.Transport{},
|
||||||
DocRoot: docRoot,
|
DocRoot: docRoot,
|
||||||
}
|
}
|
||||||
err = self.RegisterProtocols(schemes)
|
self.RegisterProtocol("file", http.NewFileTransport(http.Dir(self.DocRoot)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,13 +33,6 @@ func (self *DocServer) Client() *http.Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *DocServer) RegisterProtocols(schemes map[string]func(*DocServer) http.RoundTripper) (err error) {
|
|
||||||
for scheme, rtf := range schemes {
|
|
||||||
self.RegisterProtocol(scheme, rtf(self))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *DocServer) GetAuthContent(uri string, hash common.Hash) (content []byte, err error) {
|
func (self *DocServer) GetAuthContent(uri string, hash common.Hash) (content []byte, err error) {
|
||||||
// retrieve content
|
// retrieve content
|
||||||
resp, err := self.Client().Get(uri)
|
resp, err := self.Client().Get(uri)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ func TestGetAuthContent(t *testing.T) {
|
||||||
copy(hash[:], crypto.Sha3([]byte(text)))
|
copy(hash[:], crypto.Sha3([]byte(text)))
|
||||||
ioutil.WriteFile("/tmp/test.content", []byte(text), os.ModePerm)
|
ioutil.WriteFile("/tmp/test.content", []byte(text), os.ModePerm)
|
||||||
|
|
||||||
ds, err := New("/tmp/")
|
ds := New("/tmp/")
|
||||||
content, err := ds.GetAuthContent("file:///test.content", hash)
|
content, err := ds.GetAuthContent("file:///test.content", hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("no error expected, got %v", err)
|
t.Errorf("no error expected, got %v", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue