From a7804860c9939396a656b67cb739cc111a057c6d Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 25 May 2015 09:30:00 +0100 Subject: [PATCH] simplify docserver --- bzz/protocol.go | 2 +- common/docserver/docserver.go | 23 ++--------------------- common/docserver/docserver_test.go | 2 +- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/bzz/protocol.go b/bzz/protocol.go index 74d6325a6d..8279109b4b 100644 --- a/bzz/protocol.go +++ b/bzz/protocol.go @@ -495,7 +495,7 @@ func (self *bzzProtocol) storeRequest(key Key) { peerKey := make([]byte, 64) copy(peerKey, self.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}) } diff --git a/common/docserver/docserver.go b/common/docserver/docserver.go index 5e076aa7ee..c95197863c 100644 --- a/common/docserver/docserver.go +++ b/common/docserver/docserver.go @@ -9,29 +9,17 @@ import ( "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 { *http.Transport DocRoot string } -func New(docRoot string) (self *DocServer, err error) { +func New(docRoot string) (self *DocServer) { self = &DocServer{ Transport: &http.Transport{}, DocRoot: docRoot, } - err = self.RegisterProtocols(schemes) + self.RegisterProtocol("file", http.NewFileTransport(http.Dir(self.DocRoot))) 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) { // retrieve content resp, err := self.Client().Get(uri) diff --git a/common/docserver/docserver_test.go b/common/docserver/docserver_test.go index 400d7447ac..e7656bb2d3 100644 --- a/common/docserver/docserver_test.go +++ b/common/docserver/docserver_test.go @@ -15,7 +15,7 @@ func TestGetAuthContent(t *testing.T) { copy(hash[:], crypto.Sha3([]byte(text))) ioutil.WriteFile("/tmp/test.content", []byte(text), os.ModePerm) - ds, err := New("/tmp/") + ds := New("/tmp/") content, err := ds.GetAuthContent("file:///test.content", hash) if err != nil { t.Errorf("no error expected, got %v", err)