diff --git a/cmd/ipfs/main.go b/cmd/ipfs/main.go index 3dcc2433f..334eceaf8 100644 --- a/cmd/ipfs/main.go +++ b/cmd/ipfs/main.go @@ -7,8 +7,6 @@ import ( "fmt" "io" "math/rand" - "net" - "net/url" "os" "os/signal" "path/filepath" @@ -49,18 +47,6 @@ const ( heapProfile = "ipfs.memprof" ) -type cmdInvocation struct { - req *cmds.Request - node *core.IpfsNode - ctx *oldcmds.Context -} - -type exitErr int - -func (e exitErr) Error() string { - return fmt.Sprint("exit code", int(e)) -} - // main roadmap: // - parse the commandline to get a cmdInvocation // - if user requests help, print it and exit. @@ -171,7 +157,7 @@ func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) { return nil, err } - client, err := commandShouldRunOnDaemon(*details, req, Root, env.(*oldcmds.Context)) + client, err := commandShouldRunOnDaemon(*details, req, env.(*oldcmds.Context)) if err != nil { return nil, err } @@ -241,7 +227,7 @@ func commandDetails(path []string, root *cmds.Command) (*cmdDetails, error) { // It returns a client if the command should be executed on a daemon and nil if // it should be executed on a client. It returns an error if the command must // NOT be executed on either. -func commandShouldRunOnDaemon(details cmdDetails, req *cmds.Request, root *cmds.Command, cctx *oldcmds.Context) (http.Client, error) { +func commandShouldRunOnDaemon(details cmdDetails, req *cmds.Request, cctx *oldcmds.Context) (http.Client, error) { path := req.Path // root command. if len(path) < 1 { @@ -478,24 +464,3 @@ func apiClientForAddr(addr ma.Multiaddr) (http.Client, error) { return http.NewClient(host, http.ClientWithAPIPrefix(corehttp.APIPath)), nil } - -func isConnRefused(err error) bool { - // unwrap url errors from http calls - if urlerr, ok := err.(*url.Error); ok { - err = urlerr.Err - } - - netoperr, ok := err.(*net.OpError) - if !ok { - return false - } - - return netoperr.Op == "dial" -} - -func wrapContextCanceled(err error) error { - if strings.Contains(err.Error(), "request canceled") { - err = errRequestCanceled - } - return err -} diff --git a/commands/legacy/responseemitter.go b/commands/legacy/responseemitter.go deleted file mode 100644 index 923b5ff29..000000000 --- a/commands/legacy/responseemitter.go +++ /dev/null @@ -1,55 +0,0 @@ -package legacy - -import ( - "fmt" - "io" - - "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit" - - oldcmds "github.com/ipfs/go-ipfs/commands" -) - -// wrappedResponseEmitter implements a ResponseEmitter by forwarding everything to an oldcmds.Response -type wrappedResponseEmitter struct { - r oldcmds.Response -} - -// SetLength forwards the call to the underlying oldcmds.Response -func (re *wrappedResponseEmitter) SetLength(l uint64) { - re.r.SetLength(l) -} - -// SetError forwards the call to the underlying oldcmds.Response -func (re *wrappedResponseEmitter) SetError(err interface{}, code cmdkit.ErrorType) { - re.r.SetError(fmt.Errorf("%v", err), code) -} - -// Close forwards the call to the underlying oldcmds.Response -func (re *wrappedResponseEmitter) Close() error { - return re.r.Close() -} - -// Emit sends the value to the underlying oldcmds.Response -func (re *wrappedResponseEmitter) Emit(v interface{}) error { - if re.r.Output() == nil { - switch c := v.(type) { - case io.Reader: - re.r.SetOutput(c) - return nil - case chan interface{}: - re.r.SetOutput(c) - return nil - case <-chan interface{}: - re.r.SetOutput(c) - return nil - default: - re.r.SetOutput(make(chan interface{})) - } - } - - go func() { - re.r.Output().(chan interface{}) <- v - }() - - return nil -} diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index 1e65f665f..299d86375 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -13,7 +13,6 @@ import ( path "github.com/ipfs/go-ipfs/path" pin "github.com/ipfs/go-ipfs/pin" - logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log" mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash" cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid" cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit" @@ -21,8 +20,6 @@ import ( ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format" ) -var log = logging.Logger("cmds/files") - var DagCmd = &cmds.Command{ Helptext: cmdkit.HelpText{ Tagline: "Interact with ipld dag objects.", diff --git a/core/commands/filestore.go b/core/commands/filestore.go index 691d00586..95d463d06 100644 --- a/core/commands/filestore.go +++ b/core/commands/filestore.go @@ -7,11 +7,11 @@ import ( "os" oldCmds "github.com/ipfs/go-ipfs/commands" + lgc "github.com/ipfs/go-ipfs/commands/legacy" "github.com/ipfs/go-ipfs/core" e "github.com/ipfs/go-ipfs/core/commands/e" "github.com/ipfs/go-ipfs/filestore" - lgc "github.com/ipfs/go-ipfs/commands/legacy" cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid" "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit" cmds "gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds" @@ -28,11 +28,6 @@ var FileStoreCmd = &cmds.Command{ }, } -type lsEncoder struct { - errors bool - w io.Writer -} - var lsFileStore = &cmds.Command{ Helptext: cmdkit.HelpText{ Tagline: "List objects in filestore.", diff --git a/core/commands/object/object.go b/core/commands/object/object.go index 94646c49c..3e86479f3 100644 --- a/core/commands/object/object.go +++ b/core/commands/object/object.go @@ -686,7 +686,7 @@ func deserializeNode(nd *Node, dataFieldEncoding string) (*dag.ProtoNode, error) } func NodeEmpty(node *Node) bool { - return (node.Data == "" && len(node.Links) == 0) + return node.Data == "" && len(node.Links) == 0 } // copy+pasted from ../commands.go diff --git a/core/commands/pin.go b/core/commands/pin.go index f85a2e400..2e2bfab39 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -305,9 +305,9 @@ Example: var keys map[string]RefKeyObject if len(req.Arguments()) > 0 { - keys, err = pinLsKeys(req.Arguments(), typeStr, req.Context(), n) + keys, err = pinLsKeys(req.Context(), req.Arguments(), typeStr, n) } else { - keys, err = pinLsAll(typeStr, req.Context(), n) + keys, err = pinLsAll(typeStr, n) } if err != nil { @@ -492,7 +492,7 @@ type RefKeyList struct { Keys map[string]RefKeyObject } -func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsNode) (map[string]RefKeyObject, error) { +func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode) (map[string]RefKeyObject, error) { mode, ok := pin.StringToMode(typeStr) if !ok { @@ -539,7 +539,7 @@ func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsN return keys, nil } -func pinLsAll(typeStr string, ctx context.Context, n *core.IpfsNode) (map[string]RefKeyObject, error) { +func pinLsAll(typeStr string, n *core.IpfsNode) (map[string]RefKeyObject, error) { keys := make(map[string]RefKeyObject) diff --git a/core/core.go b/core/core.go index 6bf6f1c7b..36346bb3e 100644 --- a/core/core.go +++ b/core/core.go @@ -245,7 +245,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin } // Ok, now we're ready to listen. - if err := startListening(ctx, n.PeerHost, cfg); err != nil { + if err := startListening(n.PeerHost, cfg); err != nil { return err } @@ -452,9 +452,8 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost n.PeerHost = rhost.Wrap(host, n.Routing) // setup exchange service - const alwaysSendToPeer = true // use YesManStrategy bitswapNetwork := bsnet.NewFromIpfsHost(n.PeerHost, n.Routing) - n.Exchange = bitswap.New(ctx, n.Identity, bitswapNetwork, n.Blockstore, alwaysSendToPeer) + n.Exchange = bitswap.New(ctx, bitswapNetwork, n.Blockstore) size, err := n.getCacheSize() if err != nil { @@ -919,7 +918,7 @@ func composeAddrsFactory(f, g p2pbhost.AddrsFactory) p2pbhost.AddrsFactory { } // startListening on the network addresses -func startListening(ctx context.Context, host p2phost.Host, cfg *config.Config) error { +func startListening(host p2phost.Host, cfg *config.Config) error { listenAddrs, err := listenAddresses(cfg) if err != nil { return err diff --git a/core/coreunix/add.go b/core/coreunix/add.go index 9134c9dc3..3def45910 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -9,9 +9,7 @@ import ( gopath "path" "strconv" - bserv "github.com/ipfs/go-ipfs/blockservice" core "github.com/ipfs/go-ipfs/core" - "github.com/ipfs/go-ipfs/exchange/offline" balanced "github.com/ipfs/go-ipfs/importer/balanced" ihelper "github.com/ipfs/go-ipfs/importer/helpers" trickle "github.com/ipfs/go-ipfs/importer/trickle" @@ -20,8 +18,6 @@ import ( "github.com/ipfs/go-ipfs/pin" unixfs "github.com/ipfs/go-ipfs/unixfs" - ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore" - syncds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/sync" logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log" bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore" chunker "gx/ipfs/QmWo8jYc19ppG7YoTsrr2kEtLRbARTJho5oNXFTR6B7Peq/go-ipfs-chunker" @@ -49,22 +45,6 @@ type Object struct { Size string } -type hiddenFileError struct { - fileName string -} - -func (e *hiddenFileError) Error() string { - return fmt.Sprintf("%s is a hidden file", e.fileName) -} - -type ignoreFileError struct { - fileName string -} - -func (e *ignoreFileError) Error() string { - return fmt.Sprintf("%s is an ignored file", e.fileName) -} - type AddedObject struct { Name string Hash string `json:",omitempty"` @@ -573,14 +553,6 @@ func outputDagnode(out chan interface{}, name string, dn ipld.Node) error { return nil } -// NewMemoryDagService builds and returns a new mem-datastore. -func NewMemoryDagService() ipld.DAGService { - // build mem-datastore for editor's intermediary nodes - bs := bstore.NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore())) - bsrv := bserv.New(bs, offline.Exchange(bs)) - return dag.NewDAGService(bsrv) -} - // from core/commands/object.go func getOutput(dagnode ipld.Node) (*Object, error) { c := dagnode.Cid() diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index a1404a8de..5d2db1ebd 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -66,8 +66,8 @@ var rebroadcastDelay = delay.Fixed(time.Minute) // BitSwapNetwork. This function registers the returned instance as the network // delegate. // Runs until context is cancelled. -func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork, - bstore blockstore.Blockstore, nice bool) exchange.Interface { +func New(parent context.Context, network bsnet.BitSwapNetwork, + bstore blockstore.Blockstore) exchange.Interface { // important to use provided parent context (since it may include important // loggable data). It's probably not a good idea to allow bitswap to be diff --git a/exchange/bitswap/testutils.go b/exchange/bitswap/testutils.go index 1c0979af5..a27ccd99f 100644 --- a/exchange/bitswap/testutils.go +++ b/exchange/bitswap/testutils.go @@ -99,9 +99,7 @@ func MkSession(ctx context.Context, net tn.Network, p testutil.Identity) Instanc panic(err.Error()) // FIXME perhaps change signature and return error. } - const alwaysSendToPeer = true - - bs := New(ctx, p.ID(), adapter, bstore, alwaysSendToPeer).(*Bitswap) + bs := New(ctx, adapter, bstore).(*Bitswap) return Instance{ Peer: p.ID(), diff --git a/fuse/ipns/writerat.go b/fuse/ipns/writerat.go deleted file mode 100644 index c5ddf5c5c..000000000 --- a/fuse/ipns/writerat.go +++ /dev/null @@ -1,29 +0,0 @@ -package ipns - -import "io" - -type WriteAtBuf interface { - io.WriterAt - Bytes() []byte -} - -type writerAt struct { - buf []byte -} - -func NewWriterAtFromBytes(b []byte) WriteAtBuf { - return &writerAt{b} -} - -// TODO: make this better in the future, this is just a quick hack for now -func (wa *writerAt) WriteAt(p []byte, off int64) (int, error) { - if off+int64(len(p)) > int64(len(wa.buf)) { - wa.buf = append(wa.buf, make([]byte, (int(off)+len(p))-len(wa.buf))...) - } - copy(wa.buf[off:], p) - return len(p), nil -} - -func (wa *writerAt) Bytes() []byte { - return wa.buf -} diff --git a/importer/helpers/helpers.go b/importer/helpers/helpers.go index a6d8ca069..15fa5440c 100644 --- a/importer/helpers/helpers.go +++ b/importer/helpers/helpers.go @@ -7,8 +7,8 @@ import ( dag "github.com/ipfs/go-ipfs/merkledag" ft "github.com/ipfs/go-ipfs/unixfs" - pi "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo" + pi "gx/ipfs/Qmb3jLEFAQrqdVgWUajqEyuuDoavkSq1XQXz6tWdFWF995/go-ipfs-posinfo" cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid" ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format" ) @@ -32,7 +32,7 @@ var roughLinkSize = 34 + 8 + 5 // sha256 multihash + size + no name + protobuf // var DefaultLinksPerBlock = (roughLinkBlockSize / roughLinkSize) // // See calc_test.go -var DefaultLinksPerBlock = (roughLinkBlockSize / roughLinkSize) +var DefaultLinksPerBlock = roughLinkBlockSize / roughLinkSize // ErrSizeLimitExceeded signals that a block is larger than BlockSizeLimit. var ErrSizeLimitExceeded = fmt.Errorf("object size limit exceeded") diff --git a/importer/importer.go b/importer/importer.go index a6fa415de..1e05b2ad7 100644 --- a/importer/importer.go +++ b/importer/importer.go @@ -3,11 +3,7 @@ package importer import ( - "fmt" - "os" - chunker "gx/ipfs/QmWo8jYc19ppG7YoTsrr2kEtLRbARTJho5oNXFTR6B7Peq/go-ipfs-chunker" - "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit/files" ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format" bal "github.com/ipfs/go-ipfs/importer/balanced" @@ -15,27 +11,6 @@ import ( trickle "github.com/ipfs/go-ipfs/importer/trickle" ) -// BuildDagFromFile builds a DAG from the given file, writing created blocks to -// disk as they are created. -func BuildDagFromFile(fpath string, ds ipld.DAGService) (ipld.Node, error) { - stat, err := os.Lstat(fpath) - if err != nil { - return nil, err - } - - if stat.IsDir() { - return nil, fmt.Errorf("`%s` is a directory", fpath) - } - - f, err := files.NewSerialFile(fpath, fpath, false, stat) - if err != nil { - return nil, err - } - defer f.Close() - - return BuildDagFromReader(ds, chunker.DefaultSplitter(f)) -} - // BuildDagFromReader creates a DAG given a DAGService and a Splitter // implementation (Splitters are io.Readers), using a Balanced layout. func BuildDagFromReader(ds ipld.DAGService, spl chunker.Splitter) (ipld.Node, error) { diff --git a/merkledag/merkledag.go b/merkledag/merkledag.go index 197785d39..4ece495f5 100644 --- a/merkledag/merkledag.go +++ b/merkledag/merkledag.go @@ -180,18 +180,6 @@ func FetchGraph(ctx context.Context, root *cid.Cid, serv ipld.DAGService) error return EnumerateChildrenAsync(ctx, GetLinksDirect(ng), root, visit) } -// FindLinks searches this nodes links for the given key, -// returns the indexes of any links pointing to it -func FindLinks(links []*cid.Cid, c *cid.Cid, start int) []int { - var out []int - for i, lnkC := range links[start:] { - if c.Equals(lnkC) { - out = append(out, i+start) - } - } - return out -} - // GetMany gets many nodes from the DAG at once. // // This method may not return all requested nodes (and may or may not return an diff --git a/path/path.go b/path/path.go index 924aa5dc1..ac9348b56 100644 --- a/path/path.go +++ b/path/path.go @@ -62,7 +62,7 @@ func (p Path) String() string { // IsJustAKey returns true if the path is of the form or /ipfs/. func (p Path) IsJustAKey() bool { parts := p.Segments() - return (len(parts) == 2 && parts[0] == "ipfs") + return len(parts) == 2 && parts[0] == "ipfs" } // PopLastSegment returns a new Path without its final segment, and the final diff --git a/path/path_test.go b/path/path_test.go index c3bdcd59e..b095ffd98 100644 --- a/path/path_test.go +++ b/path/path_test.go @@ -22,7 +22,7 @@ func TestPathParsing(t *testing.T) { for p, expected := range cases { _, err := ParsePath(p) - valid := (err == nil) + valid := err == nil if valid != expected { t.Fatalf("expected %s to have valid == %t", p, expected) } diff --git a/test/api-startup/main.go b/test/api-startup/main.go index 7346f16f4..fd82f5a4a 100644 --- a/test/api-startup/main.go +++ b/test/api-startup/main.go @@ -9,7 +9,7 @@ import ( ) func main() { - when := make(chan (time.Time), 2) + when := make(chan time.Time, 2) var wg sync.WaitGroup wg.Add(2) for _, port := range []string{"5001", "8080"} { diff --git a/unixfs/archive/archive.go b/unixfs/archive/archive.go index 7a561992e..aeaffe78e 100644 --- a/unixfs/archive/archive.go +++ b/unixfs/archive/archive.go @@ -81,7 +81,7 @@ func DagArchive(ctx context.Context, nd ipld.Node, name string, dag ipld.DAGServ // the case for 1. archive, and 2. not archived and not compressed, in which tar is used anyway as a transport format // construct the tar writer - w, err := tar.NewWriter(ctx, dag, archive, compression, maybeGzw) + w, err := tar.NewWriter(ctx, dag, maybeGzw) if checkErrAndClosePipe(err) { return nil, err } diff --git a/unixfs/archive/tar/writer.go b/unixfs/archive/tar/writer.go index 4503f5593..eddb44673 100644 --- a/unixfs/archive/tar/writer.go +++ b/unixfs/archive/tar/writer.go @@ -30,7 +30,7 @@ type Writer struct { } // NewWriter wraps given io.Writer. -func NewWriter(ctx context.Context, dag ipld.DAGService, archive bool, compression int, w io.Writer) (*Writer, error) { +func NewWriter(ctx context.Context, dag ipld.DAGService, w io.Writer) (*Writer, error) { return &Writer{ Dag: dag, TarW: tar.NewWriter(w),