@cryptotaxi247 / kubo / commits / e8403b1f1

removed dead code

- old http server (superseeded by core/corehttp) - unused makeDatastore() helpers

Henry committed Mar 7, 2015 at 10:28 UTC e8403b1f11a4e9906cfd2f9ca2218946c6c44473
4 files changed -280
core/datastore.go deleted
-52
@@ -1,52 +0,0 @@
1 -package core
2 -
3 -import (
4 - ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
5 - fsds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/fs"
6 - ktds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/keytransform"
7 - lds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/leveldb"
8 - syncds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
9 - ldbopts "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/opt"
10 -
11 - config "github.com/jbenet/go-ipfs/repo/config"
12 - u "github.com/jbenet/go-ipfs/util"
13 - ds2 "github.com/jbenet/go-ipfs/util/datastore2"
14 - "github.com/jbenet/go-ipfs/util/debugerror"
15 -)
16 -
17 -func makeDatastore(cfg config.Datastore) (ds2.ThreadSafeDatastoreCloser, error) {
18 - if len(cfg.Type) == 0 {
19 - return nil, debugerror.Errorf("config datastore.type required")
20 - }
21 -
22 - switch cfg.Type {
23 - case "leveldb":
24 - return makeLevelDBDatastore(cfg)
25 -
26 - case "memory":
27 - return ds2.CloserWrap(syncds.MutexWrap(ds.NewMapDatastore())), nil
28 -
29 - case "fs":
30 - log.Warning("using fs.Datastore at .datastore for testing.")
31 - d, err := fsds.NewDatastore(".datastore") // for testing!!
32 - if err != nil {
33 - return nil, err
34 - }
35 - ktd := ktds.Wrap(d, u.B58KeyConverter)
36 - return ds2.CloserWrap(syncds.MutexWrap(ktd)), nil
37 - }
38 -
39 - return nil, debugerror.Errorf("Unknown datastore type: %s", cfg.Type)
40 -}
41 -
42 -func makeLevelDBDatastore(cfg config.Datastore) (ds2.ThreadSafeDatastoreCloser, error) {
43 - if len(cfg.Path) == 0 {
44 - return nil, debugerror.Errorf("config datastore.path required for leveldb")
45 - }
46 -
47 - ds, err := lds.NewDatastore(cfg.Path, &lds.Options{
48 - // TODO don't import ldbopts. Get from go-datastore.leveldb
49 - Compression: ldbopts.NoCompression,
50 - })
51 - return ds, debugerror.Wrap(err)
52 -}
server/http/http.go deleted
-78
@@ -1,78 +0,0 @@
1 -// package http implements an http server that serves static content from ipfs
2 -package http
3 -
4 -import (
5 - "fmt"
6 - "io"
7 - "net/http"
8 -
9 - mux "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gorilla/mux"
10 - ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
11 - manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
12 - mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
13 -
14 - core "github.com/jbenet/go-ipfs/core"
15 -)
16 -
17 -type handler struct {
18 - ipfs
19 -}
20 -
21 -// Serve starts the http server
22 -func Serve(address ma.Multiaddr, node *core.IpfsNode) error {
23 - r := mux.NewRouter()
24 - handler := &handler{&ipfsHandler{node}}
25 -
26 - r.HandleFunc("/ipfs/", handler.postHandler).Methods("POST")
27 - r.PathPrefix("/ipfs/").Handler(handler).Methods("GET")
28 -
29 - http.Handle("/", r)
30 -
31 - _, host, err := manet.DialArgs(address)
32 - if err != nil {
33 - return err
34 - }
35 -
36 - return http.ListenAndServe(host, nil)
37 -}
38 -
39 -func (i *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
40 - path := r.URL.Path[5:]
41 -
42 - nd, err := i.ResolvePath(path)
43 - if err != nil {
44 - w.WriteHeader(http.StatusInternalServerError)
45 - fmt.Println(err)
46 - return
47 - }
48 -
49 - dr, err := i.NewDagReader(nd)
50 - if err != nil {
51 - // TODO: return json object containing the tree data if it's a directory (err == ErrIsDir)
52 - w.WriteHeader(http.StatusInternalServerError)
53 - fmt.Println(err)
54 - return
55 - }
56 -
57 - io.Copy(w, dr)
58 -}
59 -
60 -func (i *handler) postHandler(w http.ResponseWriter, r *http.Request) {
61 - nd, err := i.NewDagFromReader(r.Body)
62 - if err != nil {
63 - w.WriteHeader(http.StatusInternalServerError)
64 - fmt.Println(err)
65 - return
66 - }
67 -
68 - k, err := i.AddNodeToDAG(nd)
69 - if err != nil {
70 - w.WriteHeader(http.StatusInternalServerError)
71 - fmt.Println(err)
72 - return
73 - }
74 -
75 - //TODO: return json representation of list instead
76 - w.WriteHeader(http.StatusCreated)
77 - w.Write([]byte(mh.Multihash(k).B58String()))
78 -}
server/http/http_test.go deleted
-108
@@ -1,108 +0,0 @@
1 -package http
2 -
3 -import (
4 - "bytes"
5 - "errors"
6 - "io"
7 - "io/ioutil"
8 - "net/http"
9 - "net/http/httptest"
10 - "strings"
11 - "testing"
12 -
13 - dag "github.com/jbenet/go-ipfs/merkledag"
14 - u "github.com/jbenet/go-ipfs/util"
15 -)
16 -
17 -type test struct {
18 - url string
19 - code int
20 - reqbody string
21 - respbody string
22 -}
23 -
24 -func TestServeHTTP(t *testing.T) {
25 - testhandler := &handler{&testIpfsHandler{}}
26 - tests := []test{
27 - {"/ipfs/", http.StatusInternalServerError, "", ""},
28 - {"/ipfs/hash", http.StatusOK, "", "some fine data"},
29 - {"/ipfs/hash2", http.StatusInternalServerError, "", ""},
30 - }
31 -
32 - for _, test := range tests {
33 - req, _ := http.NewRequest("GET", test.url, nil)
34 - resp := httptest.NewRecorder()
35 - testhandler.ServeHTTP(resp, req)
36 -
37 - if resp.Code != test.code {
38 - t.Error("expected status code", test.code, "received", resp.Code)
39 - }
40 -
41 - if resp.Body.String() != test.respbody {
42 - t.Error("expected body:", test.respbody)
43 - t.Error("received body:", resp.Body)
44 - }
45 - }
46 -}
47 -
48 -func TestPostHandler(t *testing.T) {
49 - testhandler := &handler{&testIpfsHandler{}}
50 - tests := []test{
51 - {"/ifps/", http.StatusInternalServerError, "", ""},
52 - {"/ipfs/", http.StatusInternalServerError, "something that causes an error in adding to DAG", ""},
53 - {"/ipfs/", http.StatusCreated, "some fine data", "jSQBpNSebeYbPBjs1vp"},
54 - }
55 -
56 - for _, test := range tests {
57 - req, _ := http.NewRequest("POST", test.url, strings.NewReader(test.reqbody))
58 - resp := httptest.NewRecorder()
59 - testhandler.postHandler(resp, req)
60 -
61 - if resp.Code != test.code {
62 - t.Error("expected status code", test.code, "received", resp.Code)
63 - }
64 -
65 - if resp.Body.String() != test.respbody {
66 - t.Error("expected body:", test.respbody)
67 - t.Error("received body:", resp.Body)
68 - }
69 - }
70 -}
71 -
72 -type testIpfsHandler struct{}
73 -
74 -func (i *testIpfsHandler) ResolvePath(path string) (*dag.Node, error) {
75 - if path == "/hash" {
76 - return &dag.Node{Data: []byte("some fine data")}, nil
77 - }
78 -
79 - if path == "/hash2" {
80 - return &dag.Node{Data: []byte("data that breaks dagreader")}, nil
81 - }
82 -
83 - return nil, errors.New("")
84 -}
85 -
86 -func (i *testIpfsHandler) NewDagFromReader(r io.Reader) (*dag.Node, error) {
87 - if data, err := ioutil.ReadAll(r); err == nil {
88 - return &dag.Node{Data: data}, nil
89 - }
90 -
91 - return nil, errors.New("")
92 -}
93 -
94 -func (i *testIpfsHandler) AddNodeToDAG(nd *dag.Node) (u.Key, error) {
95 - if len(nd.Data) != 0 && string(nd.Data) != "something that causes an error in adding to DAG" {
96 - return u.Key(nd.Data), nil
97 - }
98 -
99 - return "", errors.New("")
100 -}
101 -
102 -func (i *testIpfsHandler) NewDagReader(nd *dag.Node) (io.Reader, error) {
103 - if string(nd.Data) != "data that breaks dagreader" {
104 - return bytes.NewReader(nd.Data), nil
105 - }
106 -
107 - return nil, errors.New("")
108 -}
server/http/ipfs.go deleted
-42
@@ -1,42 +0,0 @@
1 -package http
2 -
3 -import (
4 - "io"
5 -
6 - context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
7 - core "github.com/jbenet/go-ipfs/core"
8 - "github.com/jbenet/go-ipfs/importer"
9 - chunk "github.com/jbenet/go-ipfs/importer/chunk"
10 - dag "github.com/jbenet/go-ipfs/merkledag"
11 - path "github.com/jbenet/go-ipfs/path"
12 - uio "github.com/jbenet/go-ipfs/unixfs/io"
13 - u "github.com/jbenet/go-ipfs/util"
14 -)
15 -
16 -type ipfs interface {
17 - ResolvePath(string) (*dag.Node, error)
18 - NewDagFromReader(io.Reader) (*dag.Node, error)
19 - AddNodeToDAG(nd *dag.Node) (u.Key, error)
20 - NewDagReader(nd *dag.Node) (io.Reader, error)
21 -}
22 -
23 -type ipfsHandler struct {
24 - node *core.IpfsNode
25 -}
26 -
27 -func (i *ipfsHandler) ResolvePath(fpath string) (*dag.Node, error) {
28 - return i.node.Resolver.ResolvePath(path.Path(fpath))
29 -}
30 -
31 -func (i *ipfsHandler) NewDagFromReader(r io.Reader) (*dag.Node, error) {
32 - return importer.BuildDagFromReader(
33 - r, i.node.DAG, i.node.Pinning.GetManual(), chunk.DefaultSplitter)
34 -}
35 -
36 -func (i *ipfsHandler) AddNodeToDAG(nd *dag.Node) (u.Key, error) {
37 - return i.node.DAG.Add(nd)
38 -}
39 -
40 -func (i *ipfsHandler) NewDagReader(nd *dag.Node) (io.Reader, error) {
41 - return uio.NewDagReader(context.TODO(), nd, i.node.DAG)
42 -}