misc: Remove some dead code
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Mar 19, 2018 at 02:09 UTC
ae528640d90a8322c28a82b536d33c861c44871b
19 files changed
+21
-216
cmd/ipfs/main.go
+2
-37
@@ -7,8 +7,6 @@ import (
7
"fmt"
8
"io"
9
"math/rand"
10
- "net"
11
- "net/url"
10
"os"
11
"os/signal"
12
"path/filepath"
@@ -49,18 +47,6 @@ const (
47
heapProfile = "ipfs.memprof"
48
)
49
52
-type cmdInvocation struct {
53
- req *cmds.Request
54
- node *core.IpfsNode
55
- ctx *oldcmds.Context
56
-}
57
-
58
-type exitErr int
59
-
60
-func (e exitErr) Error() string {
61
- return fmt.Sprint("exit code", int(e))
62
-}
63
-
50
// main roadmap:
51
// - parse the commandline to get a cmdInvocation
52
// - if user requests help, print it and exit.
@@ -171,7 +157,7 @@ func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) {
157
return nil, err
158
}
159
174
- client, err := commandShouldRunOnDaemon(*details, req, Root, env.(*oldcmds.Context))
160
+ client, err := commandShouldRunOnDaemon(*details, req, env.(*oldcmds.Context))
161
if err != nil {
162
return nil, err
163
}
@@ -241,7 +227,7 @@ func commandDetails(path []string, root *cmds.Command) (*cmdDetails, error) {
227
// It returns a client if the command should be executed on a daemon and nil if
228
// it should be executed on a client. It returns an error if the command must
229
// NOT be executed on either.
244
-func commandShouldRunOnDaemon(details cmdDetails, req *cmds.Request, root *cmds.Command, cctx *oldcmds.Context) (http.Client, error) {
230
+func commandShouldRunOnDaemon(details cmdDetails, req *cmds.Request, cctx *oldcmds.Context) (http.Client, error) {
231
path := req.Path
232
// root command.
233
if len(path) < 1 {
@@ -478,24 +464,3 @@ func apiClientForAddr(addr ma.Multiaddr) (http.Client, error) {
464
465
return http.NewClient(host, http.ClientWithAPIPrefix(corehttp.APIPath)), nil
466
}
481
-
482
-func isConnRefused(err error) bool {
483
- // unwrap url errors from http calls
484
- if urlerr, ok := err.(*url.Error); ok {
485
- err = urlerr.Err
486
- }
487
-
488
- netoperr, ok := err.(*net.OpError)
489
- if !ok {
490
- return false
491
- }
492
-
493
- return netoperr.Op == "dial"
494
-}
495
-
496
-func wrapContextCanceled(err error) error {
497
- if strings.Contains(err.Error(), "request canceled") {
498
- err = errRequestCanceled
499
- }
500
- return err
501
-}
commands/legacy/responseemitter.go
deleted
-55
@@ -1,55 +0,0 @@
1
-package legacy
2
-
3
-import (
4
- "fmt"
5
- "io"
6
-
7
- "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
8
-
9
- oldcmds "github.com/ipfs/go-ipfs/commands"
10
-)
11
-
12
-// wrappedResponseEmitter implements a ResponseEmitter by forwarding everything to an oldcmds.Response
13
-type wrappedResponseEmitter struct {
14
- r oldcmds.Response
15
-}
16
-
17
-// SetLength forwards the call to the underlying oldcmds.Response
18
-func (re *wrappedResponseEmitter) SetLength(l uint64) {
19
- re.r.SetLength(l)
20
-}
21
-
22
-// SetError forwards the call to the underlying oldcmds.Response
23
-func (re *wrappedResponseEmitter) SetError(err interface{}, code cmdkit.ErrorType) {
24
- re.r.SetError(fmt.Errorf("%v", err), code)
25
-}
26
-
27
-// Close forwards the call to the underlying oldcmds.Response
28
-func (re *wrappedResponseEmitter) Close() error {
29
- return re.r.Close()
30
-}
31
-
32
-// Emit sends the value to the underlying oldcmds.Response
33
-func (re *wrappedResponseEmitter) Emit(v interface{}) error {
34
- if re.r.Output() == nil {
35
- switch c := v.(type) {
36
- case io.Reader:
37
- re.r.SetOutput(c)
38
- return nil
39
- case chan interface{}:
40
- re.r.SetOutput(c)
41
- return nil
42
- case <-chan interface{}:
43
- re.r.SetOutput(c)
44
- return nil
45
- default:
46
- re.r.SetOutput(make(chan interface{}))
47
- }
48
- }
49
-
50
- go func() {
51
- re.r.Output().(chan interface{}) <- v
52
- }()
53
-
54
- return nil
55
-}
core/commands/dag/dag.go
-3
@@ -13,7 +13,6 @@ import (
13
path "github.com/ipfs/go-ipfs/path"
14
pin "github.com/ipfs/go-ipfs/pin"
15
16
- logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
16
mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash"
17
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
18
cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
@@ -21,8 +20,6 @@ import (
20
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
21
)
22
24
-var log = logging.Logger("cmds/files")
25
-
23
var DagCmd = &cmds.Command{
24
Helptext: cmdkit.HelpText{
25
Tagline: "Interact with ipld dag objects.",
core/commands/filestore.go
+1
-6
@@ -7,11 +7,11 @@ import (
7
"os"
8
9
oldCmds "github.com/ipfs/go-ipfs/commands"
10
+ lgc "github.com/ipfs/go-ipfs/commands/legacy"
11
"github.com/ipfs/go-ipfs/core"
12
e "github.com/ipfs/go-ipfs/core/commands/e"
13
"github.com/ipfs/go-ipfs/filestore"
14
14
- lgc "github.com/ipfs/go-ipfs/commands/legacy"
15
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
16
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
17
cmds "gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
@@ -28,11 +28,6 @@ var FileStoreCmd = &cmds.Command{
28
},
29
}
30
31
-type lsEncoder struct {
32
- errors bool
33
- w io.Writer
34
-}
35
-
31
var lsFileStore = &cmds.Command{
32
Helptext: cmdkit.HelpText{
33
Tagline: "List objects in filestore.",
core/commands/object/object.go
+1
-1
@@ -686,7 +686,7 @@ func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error)
686
}
687
688
func NodeEmpty(node *Node) bool {
689
- return (node.Data == "" && len(node.Links) == 0)
689
+ return node.Data == "" && len(node.Links) == 0
690
}
691
692
// copy+pasted from ../commands.go
core/commands/pin.go
+4
-4
@@ -305,9 +305,9 @@ Example:
305
var keys map[string]RefKeyObject
306
307
if len(req.Arguments()) > 0 {
308
- keys, err = pinLsKeys(req.Arguments(), typeStr, req.Context(), n)
308
+ keys, err = pinLsKeys(req.Context(), req.Arguments(), typeStr, n)
309
} else {
310
- keys, err = pinLsAll(typeStr, req.Context(), n)
310
+ keys, err = pinLsAll(typeStr, n)
311
}
312
313
if err != nil {
@@ -492,7 +492,7 @@ type RefKeyList struct {
492
Keys map[string]RefKeyObject
493
}
494
495
-func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsNode) (map[string]RefKeyObject, error) {
495
+func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode) (map[string]RefKeyObject, error) {
496
497
mode, ok := pin.StringToMode(typeStr)
498
if !ok {
@@ -539,7 +539,7 @@ func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsN
539
return keys, nil
540
}
541
542
-func pinLsAll(typeStr string, ctx context.Context, n *core.IpfsNode) (map[string]RefKeyObject, error) {
542
+func pinLsAll(typeStr string, n *core.IpfsNode) (map[string]RefKeyObject, error) {
543
544
keys := make(map[string]RefKeyObject)
545
core/core.go
+3
-4
@@ -245,7 +245,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
245
}
246
247
// Ok, now we're ready to listen.
248
- if err := startListening(ctx, n.PeerHost, cfg); err != nil {
248
+ if err := startListening(n.PeerHost, cfg); err != nil {
249
return err
250
}
251
@@ -452,9 +452,8 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
452
n.PeerHost = rhost.Wrap(host, n.Routing)
453
454
// setup exchange service
455
- const alwaysSendToPeer = true // use YesManStrategy
455
bitswapNetwork := bsnet.NewFromIpfsHost(n.PeerHost, n.Routing)
457
- n.Exchange = bitswap.New(ctx, n.Identity, bitswapNetwork, n.Blockstore, alwaysSendToPeer)
456
+ n.Exchange = bitswap.New(ctx, bitswapNetwork, n.Blockstore)
457
458
size, err := n.getCacheSize()
459
if err != nil {
@@ -919,7 +918,7 @@ func composeAddrsFactory(f, g p2pbhost.AddrsFactory) p2pbhost.AddrsFactory {
918
}
919
920
// startListening on the network addresses
922
-func startListening(ctx context.Context, host p2phost.Host, cfg *config.Config) error {
921
+func startListening(host p2phost.Host, cfg *config.Config) error {
922
listenAddrs, err := listenAddresses(cfg)
923
if err != nil {
924
return err
core/coreunix/add.go
-28
@@ -9,9 +9,7 @@ import (
9
gopath "path"
10
"strconv"
11
12
- bserv "github.com/ipfs/go-ipfs/blockservice"
12
core "github.com/ipfs/go-ipfs/core"
14
- "github.com/ipfs/go-ipfs/exchange/offline"
13
balanced "github.com/ipfs/go-ipfs/importer/balanced"
14
ihelper "github.com/ipfs/go-ipfs/importer/helpers"
15
trickle "github.com/ipfs/go-ipfs/importer/trickle"
@@ -20,8 +18,6 @@ import (
18
"github.com/ipfs/go-ipfs/pin"
19
unixfs "github.com/ipfs/go-ipfs/unixfs"
20
23
- ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
24
- syncds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync"
21
logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
22
bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
23
chunker "gx/ipfs/QmWo8jYc19ppG7YoTsrr2kEtLRbARTJho5oNXFTR6B7Peq/go-ipfs-chunker"
@@ -49,22 +45,6 @@ type Object struct {
45
Size string
46
}
47
52
-type hiddenFileError struct {
53
- fileName string
54
-}
55
-
56
-func (e *hiddenFileError) Error() string {
57
- return fmt.Sprintf("%s is a hidden file", e.fileName)
58
-}
59
-
60
-type ignoreFileError struct {
61
- fileName string
62
-}
63
-
64
-func (e *ignoreFileError) Error() string {
65
- return fmt.Sprintf("%s is an ignored file", e.fileName)
66
-}
67
-
48
type AddedObject struct {
49
Name string
50
Hash string `json:",omitempty"`
@@ -573,14 +553,6 @@ func outputDagnode(out chan interface{}, name string, dn ipld.Node) error {
553
return nil
554
}
555
576
-// NewMemoryDagService builds and returns a new mem-datastore.
577
-func NewMemoryDagService() ipld.DAGService {
578
- // build mem-datastore for editor's intermediary nodes
579
- bs := bstore.NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
580
- bsrv := bserv.New(bs, offline.Exchange(bs))
581
- return dag.NewDAGService(bsrv)
582
-}
583
-
556
// from core/commands/object.go
557
func getOutput(dagnode ipld.Node) (*Object, error) {
558
c := dagnode.Cid()
exchange/bitswap/bitswap.go
+2
-2
@@ -66,8 +66,8 @@ var rebroadcastDelay = delay.Fixed(time.Minute)
66
// BitSwapNetwork. This function registers the returned instance as the network
67
// delegate.
68
// Runs until context is cancelled.
69
-func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
70
- bstore blockstore.Blockstore, nice bool) exchange.Interface {
69
+func New(parent context.Context, network bsnet.BitSwapNetwork,
70
+ bstore blockstore.Blockstore) exchange.Interface {
71
72
// important to use provided parent context (since it may include important
73
// loggable data). It's probably not a good idea to allow bitswap to be
exchange/bitswap/testutils.go
+1
-3
@@ -99,9 +99,7 @@ func MkSession(ctx context.Context, net tn.Network, p testutil.Identity) Instanc
99
panic(err.Error()) // FIXME perhaps change signature and return error.
100
}
101
102
- const alwaysSendToPeer = true
103
-
104
- bs := New(ctx, p.ID(), adapter, bstore, alwaysSendToPeer).(*Bitswap)
102
+ bs := New(ctx, adapter, bstore).(*Bitswap)
103
104
return Instance{
105
Peer: p.ID(),
fuse/ipns/writerat.go
deleted
-29
@@ -1,29 +0,0 @@
1
-package ipns
2
-
3
-import "io"
4
-
5
-type WriteAtBuf interface {
6
- io.WriterAt
7
- Bytes() []byte
8
-}
9
-
10
-type writerAt struct {
11
- buf []byte
12
-}
13
-
14
-func NewWriterAtFromBytes(b []byte) WriteAtBuf {
15
- return &writerAt{b}
16
-}
17
-
18
-// TODO: make this better in the future, this is just a quick hack for now
19
-func (wa *writerAt) WriteAt(p []byte, off int64) (int, error) {
20
- if off+int64(len(p)) > int64(len(wa.buf)) {
21
- wa.buf = append(wa.buf, make([]byte, (int(off)+len(p))-len(wa.buf))...)
22
- }
23
- copy(wa.buf[off:], p)
24
- return len(p), nil
25
-}
26
-
27
-func (wa *writerAt) Bytes() []byte {
28
- return wa.buf
29
-}
importer/helpers/helpers.go
+2
-2
@@ -7,8 +7,8 @@ import (
7
8
dag "github.com/ipfs/go-ipfs/merkledag"
9
ft "github.com/ipfs/go-ipfs/unixfs"
10
- pi "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
10
11
+ pi "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo"
12
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
13
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
14
)
@@ -32,7 +32,7 @@ var roughLinkSize = 34 + 8 + 5 // sha256 multihash + size + no name + protobuf
32
// var DefaultLinksPerBlock = (roughLinkBlockSize / roughLinkSize)
33
//
34
// See calc_test.go
35
-var DefaultLinksPerBlock = (roughLinkBlockSize / roughLinkSize)
35
+var DefaultLinksPerBlock = roughLinkBlockSize / roughLinkSize
36
37
// ErrSizeLimitExceeded signals that a block is larger than BlockSizeLimit.
38
var ErrSizeLimitExceeded = fmt.Errorf("object size limit exceeded")
importer/importer.go
-25
@@ -3,11 +3,7 @@
3
package importer
4
5
import (
6
- "fmt"
7
- "os"
8
-
6
chunker "gx/ipfs/QmWo8jYc19ppG7YoTsrr2kEtLRbARTJho5oNXFTR6B7Peq/go-ipfs-chunker"
10
- "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit/files"
7
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
8
9
bal "github.com/ipfs/go-ipfs/importer/balanced"
@@ -15,27 +11,6 @@ import (
11
trickle "github.com/ipfs/go-ipfs/importer/trickle"
12
)
13
18
-// BuildDagFromFile builds a DAG from the given file, writing created blocks to
19
-// disk as they are created.
20
-func BuildDagFromFile(fpath string, ds ipld.DAGService) (ipld.Node, error) {
21
- stat, err := os.Lstat(fpath)
22
- if err != nil {
23
- return nil, err
24
- }
25
-
26
- if stat.IsDir() {
27
- return nil, fmt.Errorf("`%s` is a directory", fpath)
28
- }
29
-
30
- f, err := files.NewSerialFile(fpath, fpath, false, stat)
31
- if err != nil {
32
- return nil, err
33
- }
34
- defer f.Close()
35
-
36
- return BuildDagFromReader(ds, chunker.DefaultSplitter(f))
37
-}
38
-
14
// BuildDagFromReader creates a DAG given a DAGService and a Splitter
15
// implementation (Splitters are io.Readers), using a Balanced layout.
16
func BuildDagFromReader(ds ipld.DAGService, spl chunker.Splitter) (ipld.Node, error) {
merkledag/merkledag.go
-12
@@ -180,18 +180,6 @@ func FetchGraph(ctx context.Context, root *cid.Cid, serv ipld.DAGService) error
180
return EnumerateChildrenAsync(ctx, GetLinksDirect(ng), root, visit)
181
}
182
183
-// FindLinks searches this nodes links for the given key,
184
-// returns the indexes of any links pointing to it
185
-func FindLinks(links []*cid.Cid, c *cid.Cid, start int) []int {
186
- var out []int
187
- for i, lnkC := range links[start:] {
188
- if c.Equals(lnkC) {
189
- out = append(out, i+start)
190
- }
191
- }
192
- return out
193
-}
194
-
183
// GetMany gets many nodes from the DAG at once.
184
//
185
// This method may not return all requested nodes (and may or may not return an
path/path.go
+1
-1
@@ -62,7 +62,7 @@ func (p Path) String() string {
62
// IsJustAKey returns true if the path is of the form <key> or /ipfs/<key>.
63
func (p Path) IsJustAKey() bool {
64
parts := p.Segments()
65
- return (len(parts) == 2 && parts[0] == "ipfs")
65
+ return len(parts) == 2 && parts[0] == "ipfs"
66
}
67
68
// PopLastSegment returns a new Path without its final segment, and the final
path/path_test.go
+1
-1
@@ -22,7 +22,7 @@ func TestPathParsing(t *testing.T) {
22
23
for p, expected := range cases {
24
_, err := ParsePath(p)
25
- valid := (err == nil)
25
+ valid := err == nil
26
if valid != expected {
27
t.Fatalf("expected %s to have valid == %t", p, expected)
28
}
test/api-startup/main.go
+1
-1
@@ -9,7 +9,7 @@ import (
9
)
10
11
func main() {
12
- when := make(chan (time.Time), 2)
12
+ when := make(chan time.Time, 2)
13
var wg sync.WaitGroup
14
wg.Add(2)
15
for _, port := range []string{"5001", "8080"} {
unixfs/archive/archive.go
+1
-1
@@ -81,7 +81,7 @@ func DagArchive(ctx context.Context, nd ipld.Node, name string, dag ipld.DAGServ
81
// the case for 1. archive, and 2. not archived and not compressed, in which tar is used anyway as a transport format
82
83
// construct the tar writer
84
- w, err := tar.NewWriter(ctx, dag, archive, compression, maybeGzw)
84
+ w, err := tar.NewWriter(ctx, dag, maybeGzw)
85
if checkErrAndClosePipe(err) {
86
return nil, err
87
}
unixfs/archive/tar/writer.go
+1
-1
@@ -30,7 +30,7 @@ type Writer struct {
30
}
31
32
// NewWriter wraps given io.Writer.
33
-func NewWriter(ctx context.Context, dag ipld.DAGService, archive bool, compression int, w io.Writer) (*Writer, error) {
33
+func NewWriter(ctx context.Context, dag ipld.DAGService, w io.Writer) (*Writer, error) {
34
return &Writer{
35
Dag: dag,
36
TarW: tar.NewWriter(w),