1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 09:59:13 +08:00

Merge pull request #3949 from zramsay/fix/codebase-consistency

apply the megacheck code vetting tool for idiomatic go
This commit is contained in:
Jeromy Johnson
2017-06-06 19:54:15 -07:00
committed by GitHub
86 changed files with 188 additions and 547 deletions

View File

@ -11,6 +11,12 @@ exclude_paths:
engines: engines:
fixme: fixme:
enabled: true enabled: true
config:
strings:
- FIXME
- HACK
- XXX
- BUG
golint: golint:
enabled: true enabled: true
govet: govet:

View File

@ -67,7 +67,6 @@ include $(dir)/Rules.mk
# core targets # # core targets #
# -------------------- # # -------------------- #
build: $(TGT_BIN) build: $(TGT_BIN)
.PHONY: build .PHONY: build
@ -143,6 +142,7 @@ help:
@echo ' test_go_short' @echo ' test_go_short'
@echo ' test_go_expensive' @echo ' test_go_expensive'
@echo ' test_go_race' @echo ' test_go_race'
@echo ' test_go_megacheck' - Run the `megacheck` vetting tool
@echo ' test_sharness_short' @echo ' test_sharness_short'
@echo ' test_sharness_expensive' @echo ' test_sharness_expensive'
@echo ' test_sharness_race' @echo ' test_sharness_race'

View File

@ -91,9 +91,8 @@ func TestManualHash(t *testing.T) {
u.Debug = true u.Debug = true
block, err = NewBlockWithCid(data, c) _, err = NewBlockWithCid(data, c)
if err != ErrWrongHash { if err != ErrWrongHash {
t.Fatal(err) t.Fatal(err)
} }
} }

View File

@ -30,7 +30,7 @@ func testArcCached(ctx context.Context, bs Blockstore) (*arccache, error) {
func createStores(t *testing.T) (*arccache, Blockstore, *callbackDatastore) { func createStores(t *testing.T) (*arccache, Blockstore, *callbackDatastore) {
cd := &callbackDatastore{f: func() {}, ds: ds.NewMapDatastore()} cd := &callbackDatastore{f: func() {}, ds: ds.NewMapDatastore()}
bs := NewBlockstore(syncds.MutexWrap(cd)) bs := NewBlockstore(syncds.MutexWrap(cd))
arc, err := testArcCached(nil, bs) arc, err := testArcCached(context.TODO(), bs)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -102,10 +102,6 @@ func NewBlockstore(d ds.Batching) Blockstore {
type blockstore struct { type blockstore struct {
datastore ds.Batching datastore ds.Batching
lk sync.RWMutex
gcreq int32
gcreqlk sync.Mutex
rehash bool rehash bool
} }
@ -246,9 +242,8 @@ func NewGCLocker() GCLocker {
} }
type gclocker struct { type gclocker struct {
lk sync.RWMutex lk sync.RWMutex
gcreq int32 gcreq int32
gcreqlk sync.Mutex
} }
// Unlocker represents an object which can Unlock // Unlocker represents an object which can Unlock

View File

@ -118,7 +118,7 @@ func (b *bloomcache) hasCached(k *cid.Cid) (has bool, ok bool) {
} }
if b.BloomActive() { if b.BloomActive() {
blr := b.bloom.HasTS(k.Bytes()) blr := b.bloom.HasTS(k.Bytes())
if blr == false { // not contained in bloom is only conclusive answer bloom gives if !blr { // not contained in bloom is only conclusive answer bloom gives
b.hits.Inc() b.hits.Inc()
return false, true return false, true
} }

View File

@ -34,6 +34,9 @@ func TestPutManyAddsToBloom(t *testing.T) {
defer cancel() defer cancel()
cachedbs, err := testBloomCached(ctx, bs) cachedbs, err := testBloomCached(ctx, bs)
if err != nil {
t.Fatal(err)
}
select { select {
case <-cachedbs.rebuildChan: case <-cachedbs.rebuildChan:
@ -49,7 +52,7 @@ func TestPutManyAddsToBloom(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if has == false { if !has {
t.Fatal("added block is reported missing") t.Fatal("added block is reported missing")
} }
@ -57,7 +60,7 @@ func TestPutManyAddsToBloom(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if has == true { if has {
t.Fatal("not added block is reported to be in blockstore") t.Fatal("not added block is reported to be in blockstore")
} }
} }

View File

@ -1,26 +1,29 @@
package blockstore package blockstore
import "testing" import (
"context"
"testing"
)
func TestCachingOptsLessThanZero(t *testing.T) { func TestCachingOptsLessThanZero(t *testing.T) {
opts := DefaultCacheOpts() opts := DefaultCacheOpts()
opts.HasARCCacheSize = -1 opts.HasARCCacheSize = -1
if _, err := CachedBlockstore(nil, nil, opts); err == nil { if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
t.Error("wrong ARC setting was not detected") t.Error("wrong ARC setting was not detected")
} }
opts = DefaultCacheOpts() opts = DefaultCacheOpts()
opts.HasBloomFilterSize = -1 opts.HasBloomFilterSize = -1
if _, err := CachedBlockstore(nil, nil, opts); err == nil { if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
t.Error("negative bloom size was not detected") t.Error("negative bloom size was not detected")
} }
opts = DefaultCacheOpts() opts = DefaultCacheOpts()
opts.HasBloomFilterHashes = -1 opts.HasBloomFilterHashes = -1
if _, err := CachedBlockstore(nil, nil, opts); err == nil { if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
t.Error("negative hashes setting was not detected") t.Error("negative hashes setting was not detected")
} }
} }
@ -29,7 +32,7 @@ func TestBloomHashesAtZero(t *testing.T) {
opts := DefaultCacheOpts() opts := DefaultCacheOpts()
opts.HasBloomFilterHashes = 0 opts.HasBloomFilterHashes = 0
if _, err := CachedBlockstore(nil, nil, opts); err == nil { if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil {
t.Error("zero hashes setting with positive size was not detected") t.Error("zero hashes setting with positive size was not detected")
} }
} }

View File

@ -4,14 +4,11 @@
package set package set
import ( import (
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid" cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
"github.com/ipfs/go-ipfs/blocks/bloom" "github.com/ipfs/go-ipfs/blocks/bloom"
) )
var log = logging.Logger("blockset")
// BlockSet represents a mutable set of blocks CIDs. // BlockSet represents a mutable set of blocks CIDs.
type BlockSet interface { type BlockSet interface {
AddBlock(*cid.Cid) AddBlock(*cid.Cid)

View File

@ -25,15 +25,15 @@ func exampleKeys() []*cid.Cid {
func checkSet(set BlockSet, keySlice []*cid.Cid, t *testing.T) { func checkSet(set BlockSet, keySlice []*cid.Cid, t *testing.T) {
for i, key := range keySlice { for i, key := range keySlice {
if i&tReAdd == 0 { if i&tReAdd == 0 {
if set.HasKey(key) == false { if !set.HasKey(key) {
t.Error("key should be in the set") t.Error("key should be in the set")
} }
} else if i&tRemove == 0 { } else if i&tRemove == 0 {
if set.HasKey(key) == true { if set.HasKey(key) {
t.Error("key shouldn't be in the set") t.Error("key shouldn't be in the set")
} }
} else if i&tAdd == 0 { } else if i&tAdd == 0 {
if set.HasKey(key) == false { if !set.HasKey(key) {
t.Error("key should be in the set") t.Error("key should be in the set")
} }
} }
@ -70,7 +70,7 @@ func TestSetWorks(t *testing.T) {
bloom := set.GetBloomFilter() bloom := set.GetBloomFilter()
for _, key := range addedKeys { for _, key := range addedKeys {
if bloom.Find(key.Bytes()) == false { if !bloom.Find(key.Bytes()) {
t.Error("bloom doesn't contain expected key") t.Error("bloom doesn't contain expected key")
} }
} }

View File

@ -172,7 +172,7 @@ func (s *blockService) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block,
// the returned channel. // the returned channel.
// NB: No guarantees are made about order. // NB: No guarantees are made about order.
func (s *blockService) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block { func (s *blockService) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block {
out := make(chan blocks.Block, 0) out := make(chan blocks.Block)
go func() { go func() {
defer close(out) defer close(out)
var misses []*cid.Cid var misses []*cid.Cid

View File

@ -201,11 +201,9 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
ctx := req.InvocContext() ctx := req.InvocContext()
go func() { go func() {
select { <-req.Context().Done()
case <-req.Context().Done(): fmt.Println("Received interrupt signal, shutting down...")
fmt.Println("Received interrupt signal, shutting down...") fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)")
fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)")
}
}() }()
// check transport encryption flag. // check transport encryption flag.
@ -418,7 +416,6 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
} }
} }
return
} }
// serveHTTPApi collects options, creates listener, prints status message and starts serving requests // serveHTTPApi collects options, creates listener, prints status message and starts serving requests

View File

@ -44,12 +44,6 @@ func init() {
} }
} }
// isLocal returns true if the command should only be run locally (not sent to daemon), otherwise false
func isLocal(cmd *cmds.Command) bool {
_, found := localMap[cmd]
return found
}
// NB: when necessary, properties are described using negatives in order to // NB: when necessary, properties are described using negatives in order to
// provide desirable defaults // provide desirable defaults
type cmdDetails struct { type cmdDetails struct {
@ -85,11 +79,10 @@ func (d *cmdDetails) Loggable() map[string]interface{} {
} }
} }
func (d *cmdDetails) usesConfigAsInput() bool { return !d.doesNotUseConfigAsInput } func (d *cmdDetails) usesConfigAsInput() bool { return !d.doesNotUseConfigAsInput }
func (d *cmdDetails) doesNotPreemptAutoUpdate() bool { return !d.preemptsAutoUpdate } func (d *cmdDetails) canRunOnClient() bool { return !d.cannotRunOnClient }
func (d *cmdDetails) canRunOnClient() bool { return !d.cannotRunOnClient } func (d *cmdDetails) canRunOnDaemon() bool { return !d.cannotRunOnDaemon }
func (d *cmdDetails) canRunOnDaemon() bool { return !d.cannotRunOnDaemon } func (d *cmdDetails) usesRepo() bool { return !d.doesNotUseRepo }
func (d *cmdDetails) usesRepo() bool { return !d.doesNotUseRepo }
// "What is this madness!?" you ask. Our commands have the unfortunate problem of // "What is this madness!?" you ask. Our commands have the unfortunate problem of
// not being able to run on all the same contexts. This map describes these // not being able to run on all the same contexts. This map describes these

View File

@ -37,17 +37,12 @@ import (
// log is the command logger // log is the command logger
var log = logging.Logger("cmd/ipfs") var log = logging.Logger("cmd/ipfs")
var ( var errRequestCanceled = errors.New("request canceled")
errUnexpectedApiOutput = errors.New("api returned unexpected output")
errApiVersionMismatch = errors.New("api version mismatch")
errRequestCanceled = errors.New("request canceled")
)
const ( const (
EnvEnableProfiling = "IPFS_PROF" EnvEnableProfiling = "IPFS_PROF"
cpuProfile = "ipfs.cpuprof" cpuProfile = "ipfs.cpuprof"
heapProfile = "ipfs.memprof" heapProfile = "ipfs.memprof"
errorFormat = "ERROR: %v\n\n"
) )
type cmdInvocation struct { type cmdInvocation struct {
@ -492,7 +487,7 @@ func startProfiling() (func(), error) {
} }
pprof.StartCPUProfile(ofi) pprof.StartCPUProfile(ofi)
go func() { go func() {
for _ = range time.NewTicker(time.Second * 30).C { for range time.NewTicker(time.Second * 30).C {
err := writeHeapProfileToFile() err := writeHeapProfileToFile()
if err != nil { if err != nil {
log.Error(err) log.Error(err)
@ -546,7 +541,7 @@ func (ih *IntrHandler) Handle(handler func(count int, ih *IntrHandler), sigs ...
go func() { go func() {
defer ih.wg.Done() defer ih.wg.Done()
count := 0 count := 0
for _ = range ih.sig { for range ih.sig {
count++ count++
handler(count, ih) handler(count, ih)
} }

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"syscall"
commands "github.com/ipfs/go-ipfs/commands" commands "github.com/ipfs/go-ipfs/commands"
core "github.com/ipfs/go-ipfs/core" core "github.com/ipfs/go-ipfs/core"
@ -99,7 +100,7 @@ func run(ipfsPath, watchPath string) error {
} }
interrupts := make(chan os.Signal) interrupts := make(chan os.Signal)
signal.Notify(interrupts, os.Interrupt, os.Kill) signal.Notify(interrupts, os.Interrupt, syscall.SIGTERM)
for { for {
select { select {
@ -167,10 +168,7 @@ func addTree(w *fsnotify.Watcher, root string) error {
} }
return nil return nil
}) })
if err != nil { return err
return err
}
return nil
} }
func IsDirectory(path string) (bool, error) { func IsDirectory(path string) (bool, error) {

View File

@ -16,9 +16,6 @@ const (
variadicArg = "%v..." variadicArg = "%v..."
shortFlag = "-%v" shortFlag = "-%v"
longFlag = "--%v" longFlag = "--%v"
optionType = "(%v)"
whitespace = "\r\n\t "
indentStr = " " indentStr = " "
) )
@ -295,9 +292,7 @@ func optionText(cmd ...*cmds.Command) []string {
// get a slice of the options we want to list out // get a slice of the options we want to list out
options := make([]cmds.Option, 0) options := make([]cmds.Option, 0)
for _, c := range cmd { for _, c := range cmd {
for _, opt := range c.Options { options = append(options, c.Options...)
options = append(options, opt)
}
} }
// add option names to output (with each name aligned) // add option names to output (with each name aligned)
@ -427,13 +422,6 @@ func align(lines []string) []string {
return lines return lines
} }
func indent(lines []string, prefix string) []string {
for i, line := range lines {
lines[i] = prefix + indentString(line, prefix)
}
return lines
}
func indentString(line string, prefix string) string { func indentString(line string, prefix string) string {
return prefix + strings.Replace(line, "\n", "\n"+prefix, -1) return prefix + strings.Replace(line, "\n", "\n"+prefix, -1)
} }

View File

@ -59,11 +59,8 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
} }
err = cmd.CheckArguments(req) err = cmd.CheckArguments(req)
if err != nil {
return req, cmd, path, err
}
return req, cmd, path, nil return req, cmd, path, err
} }
func ParseArgs(req cmds.Request, inputs []string, stdin *os.File, argDefs []cmds.Argument, root *cmds.Command) ([]string, []files.File, error) { func ParseArgs(req cmds.Request, inputs []string, stdin *os.File, argDefs []cmds.Argument, root *cmds.Command) ([]string, []files.File, error) {

View File

@ -204,7 +204,7 @@ func TestArgumentParsing(t *testing.T) {
test := func(cmd words, f *os.File, res words) { test := func(cmd words, f *os.File, res words) {
if f != nil { if f != nil {
if _, err := f.Seek(0, os.SEEK_SET); err != nil { if _, err := f.Seek(0, io.SeekStart); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }

View File

@ -3,7 +3,6 @@ package commands
import "testing" import "testing"
func noop(req Request, res Response) { func noop(req Request, res Response) {
return
} }
func TestOptionValidation(t *testing.T) { func TestOptionValidation(t *testing.T) {

View File

@ -10,7 +10,6 @@ import (
const ( const (
multipartFormdataType = "multipart/form-data" multipartFormdataType = "multipart/form-data"
multipartMixedType = "multipart/mixed"
applicationDirectory = "application/x-directory" applicationDirectory = "application/x-directory"
applicationSymlink = "application/symlink" applicationSymlink = "application/symlink"

View File

@ -47,12 +47,9 @@ const (
extraContentLengthHeader = "X-Content-Length" extraContentLengthHeader = "X-Content-Length"
uaHeader = "User-Agent" uaHeader = "User-Agent"
contentTypeHeader = "Content-Type" contentTypeHeader = "Content-Type"
contentDispHeader = "Content-Disposition"
transferEncodingHeader = "Transfer-Encoding"
applicationJson = "application/json" applicationJson = "application/json"
applicationOctetStream = "application/octet-stream" applicationOctetStream = "application/octet-stream"
plainText = "text/plain" plainText = "text/plain"
originHeader = "origin"
) )
var AllowedExposedHeadersArr = []string{streamHeader, channelHeader, extraContentLengthHeader} var AllowedExposedHeadersArr = []string{streamHeader, channelHeader, extraContentLengthHeader}

View File

@ -147,10 +147,7 @@ func bootstrapRound(ctx context.Context, host host.Host, cfg BootstrapConfig) er
defer log.EventBegin(ctx, "bootstrapStart", id).Done() defer log.EventBegin(ctx, "bootstrapStart", id).Done()
log.Debugf("%s bootstrapping to %d nodes: %s", id, numToDial, randSubset) log.Debugf("%s bootstrapping to %d nodes: %s", id, numToDial, randSubset)
if err := bootstrapConnect(ctx, host, randSubset); err != nil { return bootstrapConnect(ctx, host, randSubset)
return err
}
return nil
} }
func bootstrapConnect(ctx context.Context, ph host.Host, peers []pstore.PeerInfo) error { func bootstrapConnect(ctx context.Context, ph host.Host, peers []pstore.PeerInfo) error {

View File

@ -65,6 +65,7 @@ func (cfg *BuildCfg) fillDefaults() error {
if cfg.Repo == nil { if cfg.Repo == nil {
var d ds.Datastore var d ds.Datastore
d = ds.NewMapDatastore() d = ds.NewMapDatastore()
if cfg.NilRepo { if cfg.NilRepo {
d = ds.NewNullDatastore() d = ds.NewNullDatastore()
} }
@ -230,10 +231,5 @@ func setupNode(ctx context.Context, n *IpfsNode, cfg *BuildCfg) error {
} }
n.Resolver = path.NewBasicResolver(n.DAG) n.Resolver = path.NewBasicResolver(n.DAG)
err = n.loadFilesRoot() return n.loadFilesRoot()
if err != nil {
return err
}
return nil
} }

View File

@ -70,7 +70,7 @@ Lists running and recently run commands.
var live time.Duration var live time.Duration
if req.Active { if req.Active {
live = time.Now().Sub(req.StartTime) live = time.Since(req.StartTime)
} else { } else {
live = req.EndTime.Sub(req.StartTime) live = req.EndTime.Sub(req.StartTime)
} }

View File

@ -288,10 +288,7 @@ It takes a list of base58 encoded multihashs to remove.
} }
err := util.ProcRmOutput(outChan, res.Stdout(), res.Stderr()) err := util.ProcRmOutput(outChan, res.Stdout(), res.Stderr())
if err != nil { return nil, err
return nil, err
}
return nil, nil
}, },
}, },
Type: util.RemovedBlock{}, Type: util.RemovedBlock{},

View File

@ -315,7 +315,6 @@ var bootstrapListCmd = &cmds.Command{
return return
} }
res.SetOutput(&BootstrapOutput{config.BootstrapPeerStrings(peers)}) res.SetOutput(&BootstrapOutput{config.BootstrapPeerStrings(peers)})
return
}, },
Type: BootstrapOutput{}, Type: BootstrapOutput{},
Marshalers: cmds.MarshalerMap{ Marshalers: cmds.MarshalerMap{

View File

@ -472,7 +472,7 @@ Examples:
return return
} }
_, err = rfd.Seek(int64(offset), os.SEEK_SET) _, err = rfd.Seek(int64(offset), io.SeekStart)
if err != nil { if err != nil {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
@ -651,7 +651,7 @@ stat' on the file or any of its ancestors.
return return
} }
_, err = wfd.Seek(int64(offset), os.SEEK_SET) _, err = wfd.Seek(int64(offset), io.SeekStart)
if err != nil { if err != nil {
log.Error("seekfail: ", err) log.Error("seekfail: ", err)
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
@ -669,7 +669,7 @@ stat' on the file or any of its ancestors.
r = io.LimitReader(r, int64(count)) r = io.LimitReader(r, int64(count))
} }
n, err := io.Copy(wfd, input) n, err := io.Copy(wfd, r)
if err != nil { if err != nil {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return

View File

@ -676,6 +676,10 @@ remove your filters from the ipfs config file.
} }
removed, err := filtersRemove(r, cfg, req.Arguments()) removed, err := filtersRemove(r, cfg, req.Arguments())
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(&stringList{removed}) res.SetOutput(&stringList{removed})
}, },

View File

@ -73,7 +73,7 @@ import (
) )
const IpnsValidatorTag = "ipns" const IpnsValidatorTag = "ipns"
const kSizeBlockstoreWriteCache = 100
const kReprovideFrequency = time.Hour * 12 const kReprovideFrequency = time.Hour * 12
const discoveryConnTimeout = time.Second * 30 const discoveryConnTimeout = time.Second * 30
@ -83,8 +83,7 @@ type mode int
const ( const (
// zero value is not a valid mode, must be explicitly set // zero value is not a valid mode, must be explicitly set
invalidMode mode = iota localMode mode = iota
localMode
offlineMode offlineMode
onlineMode onlineMode
) )
@ -341,12 +340,7 @@ func (n *IpfsNode) startOnlineServicesWithHost(ctx context.Context, host p2phost
n.Namesys = namesys.NewNameSystem(n.Routing, n.Repo.Datastore(), size) n.Namesys = namesys.NewNameSystem(n.Routing, n.Repo.Datastore(), size)
// setup ipns republishing // setup ipns republishing
err = n.setupIpnsRepublisher() return n.setupIpnsRepublisher()
if err != nil {
return err
}
return nil
} }
// getCacheSize returns cache life and cache size // getCacheSize returns cache life and cache size

View File

@ -427,11 +427,6 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
req.Host = "example.net" req.Host = "example.net"
req.Header.Set("X-Ipfs-Gateway-Prefix", "/bad-prefix") req.Header.Set("X-Ipfs-Gateway-Prefix", "/bad-prefix")
res, err = doWithoutRedirect(req)
if err != nil {
t.Fatal(err)
}
// make request to directory listing with evil prefix // make request to directory listing with evil prefix
req, err = http.NewRequest("GET", ts.URL, nil) req, err = http.NewRequest("GET", ts.URL, nil)
if err != nil { if err != nil {

View File

@ -18,12 +18,7 @@ import (
// default and 2) to avoid a circular dependency (it needs to be referenced in // default and 2) to avoid a circular dependency (it needs to be referenced in
// the core if it's going to be the default) // the core if it's going to be the default)
var ( var errServersMissing = errors.New("supernode routing client requires at least 1 server peer")
errHostMissing = errors.New("supernode routing client requires a Host component")
errIdentityMissing = errors.New("supernode routing server requires a peer ID identity")
errPeerstoreMissing = errors.New("supernode routing server requires a peerstore")
errServersMissing = errors.New("supernode routing client requires at least 1 server peer")
)
// SupernodeServer returns a configuration for a routing server that stores // SupernodeServer returns a configuration for a routing server that stores
// routing records to the provided datastore. Only routing records are store in // routing records to the provided datastore. Only routing records are store in

View File

@ -120,14 +120,10 @@ func TestAddGCLive(t *testing.T) {
pipew.Close() pipew.Close()
// receive next object from adder // receive next object from adder
select { o := <-out
case o := <-out: addedHashes[o.(*AddedObject).Hash] = struct{}{}
addedHashes[o.(*AddedObject).Hash] = struct{}{}
}
select { <-gcstarted
case <-gcstarted:
}
for r := range gcout { for r := range gcout {
if r.Error != nil { if r.Error != nil {
@ -197,7 +193,7 @@ func testAddWPosInfo(t *testing.T, rawLeaves bool) {
t.Fatal(err) t.Fatal(err)
} }
}() }()
for _ = range adder.Out { for range adder.Out {
} }
exp := 0 exp := 0

View File

@ -37,7 +37,6 @@ const (
// TODO: if a 'non-nice' strategy is implemented, consider increasing this value // TODO: if a 'non-nice' strategy is implemented, consider increasing this value
maxProvidersPerRequest = 3 maxProvidersPerRequest = 3
providerRequestTimeout = time.Second * 10 providerRequestTimeout = time.Second * 10
hasBlockTimeout = time.Second * 15
provideTimeout = time.Second * 15 provideTimeout = time.Second * 15
sizeBatchRequestChan = 32 sizeBatchRequestChan = 32
// kMaxPriority is the max priority as defined by the bitswap protocol // kMaxPriority is the max priority as defined by the bitswap protocol

View File

@ -199,7 +199,7 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
if err != nil { if err != nil {
errs <- err errs <- err
} }
for _ = range outch { for range outch {
} }
}(inst) }(inst)
} }
@ -226,16 +226,6 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
} }
} }
func getOrFail(bitswap Instance, b blocks.Block, t *testing.T, wg *sync.WaitGroup) {
if _, err := bitswap.Blockstore().Get(b.Cid()); err != nil {
_, err := bitswap.Exchange.GetBlock(context.Background(), b.Cid())
if err != nil {
t.Fatal(err)
}
}
wg.Done()
}
// TODO simplify this test. get to the _essence_! // TODO simplify this test. get to the _essence_!
func TestSendToWantingPeer(t *testing.T) { func TestSendToWantingPeer(t *testing.T) {
if testing.Short() { if testing.Short() {
@ -611,14 +601,14 @@ func TestBitswapLedgerTwoWay(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel() defer cancel()
blk, err := instances[1].Exchange.GetBlock(ctx, blocks[0].Cid()) _, err = instances[1].Exchange.GetBlock(ctx, blocks[0].Cid())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
ctx, cancel = context.WithTimeout(context.Background(), time.Second*5) ctx, cancel = context.WithTimeout(context.Background(), time.Second*5)
defer cancel() defer cancel()
blk, err = instances[0].Exchange.GetBlock(ctx, blocks[1].Cid()) blk, err := instances[0].Exchange.GetBlock(ctx, blocks[1].Cid())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -27,9 +27,6 @@ type ledger struct {
// Accounting tracks bytes sent and recieved. // Accounting tracks bytes sent and recieved.
Accounting debtRatio Accounting debtRatio
// firstExchnage is the time of the first data exchange.
firstExchange time.Time
// lastExchange is the time of the last data exchange. // lastExchange is the time of the last data exchange.
lastExchange time.Time lastExchange time.Time

View File

@ -220,19 +220,13 @@ func (m *impl) ToProtoV1() *pb.Message {
func (m *impl) ToNetV0(w io.Writer) error { func (m *impl) ToNetV0(w io.Writer) error {
pbw := ggio.NewDelimitedWriter(w) pbw := ggio.NewDelimitedWriter(w)
if err := pbw.WriteMsg(m.ToProtoV0()); err != nil { return pbw.WriteMsg(m.ToProtoV0())
return err
}
return nil
} }
func (m *impl) ToNetV1(w io.Writer) error { func (m *impl) ToNetV1(w io.Writer) error {
pbw := ggio.NewDelimitedWriter(w) pbw := ggio.NewDelimitedWriter(w)
if err := pbw.WriteMsg(m.ToProtoV1()); err != nil { return pbw.WriteMsg(m.ToProtoV1())
return err
}
return nil
} }
func (m *impl) Loggable() map[string]interface{} { func (m *impl) Loggable() map[string]interface{} {

View File

@ -88,8 +88,6 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
// just a much better idea. // just a much better idea.
func Session(ctx context.Context, net tn.Network, p testutil.Identity) Instance { func Session(ctx context.Context, net tn.Network, p testutil.Identity) Instance {
bsdelay := delay.Fixed(0) bsdelay := delay.Fixed(0)
const bloomSize = 512
const writeCacheElems = 100
adapter := net.Adapter(p) adapter := net.Adapter(p)
dstore := ds_sync.MutexWrap(datastore2.WithDelay(ds.NewMapDatastore(), bsdelay)) dstore := ds_sync.MutexWrap(datastore2.WithDelay(ds.NewMapDatastore(), bsdelay))

View File

@ -55,16 +55,6 @@ func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantMana
} }
} }
type msgPair struct {
to peer.ID
msg bsmsg.BitSwapMessage
}
type cancellation struct {
who peer.ID
blk *cid.Cid
}
type msgQueue struct { type msgQueue struct {
p peer.ID p peer.ID

View File

@ -42,7 +42,7 @@ func (_ *offlineExchange) Close() error {
} }
func (e *offlineExchange) GetBlocks(ctx context.Context, ks []*cid.Cid) (<-chan blocks.Block, error) { func (e *offlineExchange) GetBlocks(ctx context.Context, ks []*cid.Cid) (<-chan blocks.Block, error) {
out := make(chan blocks.Block, 0) out := make(chan blocks.Block)
go func() { go func() {
defer close(out) defer close(out)
var misses []*cid.Cid var misses []*cid.Cid

View File

@ -67,7 +67,7 @@ func TestGetBlocks(t *testing.T) {
} }
var count int var count int
for _ = range received { for range received {
count++ count++
} }
if len(expected) != count { if len(expected) != count {

View File

@ -162,7 +162,7 @@ func (f *FileManager) readDataObj(c *cid.Cid, d *pb.DataObj) ([]byte, error) {
} }
defer fi.Close() defer fi.Close()
_, err = fi.Seek(int64(d.GetOffset()), os.SEEK_SET) _, err = fi.Seek(int64(d.GetOffset()), io.SeekStart)
if err != nil { if err != nil {
return nil, &CorruptReferenceError{StatusFileError, err} return nil, &CorruptReferenceError{StatusFileError, err}
} }

View File

@ -33,9 +33,6 @@ func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
} }
pub := nsys.NewRoutingPublisher(n.Routing, n.Repo.Datastore()) pub := nsys.NewRoutingPublisher(n.Routing, n.Repo.Datastore())
if err := pub.Publish(ctx, key, path.FromCid(nodek)); err != nil {
return err
}
return nil return pub.Publish(ctx, key, path.FromCid(nodek))
} }

View File

@ -198,7 +198,7 @@ func TestFilePersistence(t *testing.T) {
mnt.Close() mnt.Close()
t.Log("Closed, opening new fs") t.Log("Closed, opening new fs")
node, mnt = setupIpnsTest(t, node) _, mnt = setupIpnsTest(t, node)
defer mnt.Close() defer mnt.Close()
rbuf, err := ioutil.ReadFile(mnt.Dir + fname) rbuf, err := ioutil.ReadFile(mnt.Dir + fname)

View File

@ -8,6 +8,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io"
"os" "os"
core "github.com/ipfs/go-ipfs/core" core "github.com/ipfs/go-ipfs/core"
@ -346,7 +347,7 @@ func (dir *Directory) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
} }
func (fi *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { func (fi *File) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
_, err := fi.fi.Seek(req.Offset, os.SEEK_SET) _, err := fi.fi.Seek(req.Offset, io.SeekStart)
if err != nil { if err != nil {
return err return err
} }
@ -473,7 +474,7 @@ func (fi *FileNode) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.
return nil, fuse.ENOTSUP return nil, fuse.ENOTSUP
} }
_, err := fd.Seek(0, os.SEEK_END) _, err := fd.Seek(0, io.SeekEnd)
if err != nil { if err != nil {
log.Error("seek reset failed: ", err) log.Error("seek reset failed: ", err)
return nil, err return nil, err

View File

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"time"
core "github.com/ipfs/go-ipfs/core" core "github.com/ipfs/go-ipfs/core"
ipns "github.com/ipfs/go-ipfs/fuse/ipns" ipns "github.com/ipfs/go-ipfs/fuse/ipns"
@ -18,10 +17,6 @@ import (
var log = logging.Logger("node") var log = logging.Logger("node")
// amount of time to wait for mount errors
// TODO is this non-deterministic?
const mountTimeout = time.Second
// fuseNoDirectory used to check the returning fuse error // fuseNoDirectory used to check the returning fuse error
const fuseNoDirectory = "fusermount: failed to access mountpoint" const fuseNoDirectory = "fusermount: failed to access mountpoint"
@ -49,12 +44,7 @@ func Mount(node *core.IpfsNode, fsdir, nsdir string) error {
return err return err
} }
var err error return doMount(node, fsdir, nsdir)
if err = doMount(node, fsdir, nsdir); err != nil {
return err
}
return nil
} }
func doMount(node *core.IpfsNode, fsdir, nsdir string) error { func doMount(node *core.IpfsNode, fsdir, nsdir string) error {

View File

@ -85,7 +85,6 @@ func (*Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
type Node struct { type Node struct {
Ipfs *core.IpfsNode Ipfs *core.IpfsNode
Nd *mdag.ProtoNode Nd *mdag.ProtoNode
fd *uio.DagReader
cached *ftpb.Data cached *ftpb.Data
} }
@ -190,7 +189,7 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
if err != nil { if err != nil {
return err return err
} }
o, err := r.Seek(req.Offset, os.SEEK_SET) o, err := r.Seek(req.Offset, io.SeekStart)
lm["res_offset"] = o lm["res_offset"] = o
if err != nil { if err != nil {
return err return err

View File

@ -6,14 +6,12 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
mrand "math/rand" mrand "math/rand"
"os"
"testing" "testing"
chunk "github.com/ipfs/go-ipfs/importer/chunk" chunk "github.com/ipfs/go-ipfs/importer/chunk"
h "github.com/ipfs/go-ipfs/importer/helpers" h "github.com/ipfs/go-ipfs/importer/helpers"
dag "github.com/ipfs/go-ipfs/merkledag" dag "github.com/ipfs/go-ipfs/merkledag"
mdtest "github.com/ipfs/go-ipfs/merkledag/test" mdtest "github.com/ipfs/go-ipfs/merkledag/test"
pin "github.com/ipfs/go-ipfs/pin"
uio "github.com/ipfs/go-ipfs/unixfs/io" uio "github.com/ipfs/go-ipfs/unixfs/io"
"context" "context"
@ -62,12 +60,6 @@ func TestSizeBasedSplit(t *testing.T) {
testFileConsistency(t, 31*4095, 4096) testFileConsistency(t, 31*4095, 4096)
} }
func dup(b []byte) []byte {
o := make([]byte, len(b))
copy(o, b)
return o
}
func testFileConsistency(t *testing.T, nbytes int64, blksize int64) { func testFileConsistency(t *testing.T, nbytes int64, blksize int64) {
ds := mdtest.Mock() ds := mdtest.Mock()
nd, should := getTestDag(t, ds, nbytes, blksize) nd, should := getTestDag(t, ds, nbytes, blksize)
@ -131,11 +123,6 @@ func dagrArrComp(t *testing.T, r io.Reader, should []byte) {
} }
} }
type dagservAndPinner struct {
ds dag.DAGService
mp pin.Pinner
}
func TestIndirectBlocks(t *testing.T) { func TestIndirectBlocks(t *testing.T) {
ds := mdtest.Mock() ds := mdtest.Mock()
dag, buf := getTestDag(t, ds, 1024*1024, 512) dag, buf := getTestDag(t, ds, 1024*1024, 512)
@ -166,7 +153,7 @@ func TestSeekingBasic(t *testing.T) {
} }
start := int64(4000) start := int64(4000)
n, err := rs.Seek(start, os.SEEK_SET) n, err := rs.Seek(start, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -194,7 +181,7 @@ func TestSeekToBegin(t *testing.T) {
t.Fatal("Copy didnt copy enough bytes") t.Fatal("Copy didnt copy enough bytes")
} }
seeked, err := rs.Seek(0, os.SEEK_SET) seeked, err := rs.Seek(0, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -222,7 +209,7 @@ func TestSeekToAlmostBegin(t *testing.T) {
t.Fatal("Copy didnt copy enough bytes") t.Fatal("Copy didnt copy enough bytes")
} }
seeked, err := rs.Seek(1, os.SEEK_SET) seeked, err := rs.Seek(1, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -243,7 +230,7 @@ func TestSeekEnd(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
seeked, err := rs.Seek(0, os.SEEK_END) seeked, err := rs.Seek(0, io.SeekEnd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -262,7 +249,7 @@ func TestSeekEndSingleBlockFile(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
seeked, err := rs.Seek(0, os.SEEK_END) seeked, err := rs.Seek(0, io.SeekEnd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -285,7 +272,7 @@ func TestSeekingStress(t *testing.T) {
for i := 0; i < 50; i++ { for i := 0; i < 50; i++ {
offset := mrand.Intn(int(nbytes)) offset := mrand.Intn(int(nbytes))
l := int(nbytes) - offset l := int(nbytes) - offset
n, err := rs.Seek(int64(offset), os.SEEK_SET) n, err := rs.Seek(int64(offset), io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -323,7 +310,7 @@ func TestSeekingConsistency(t *testing.T) {
for coff := nbytes - 4096; coff >= 0; coff -= 4096 { for coff := nbytes - 4096; coff >= 0; coff -= 4096 {
t.Log(coff) t.Log(coff)
n, err := rs.Seek(coff, os.SEEK_SET) n, err := rs.Seek(coff, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"os" "os"
chunk "github.com/ipfs/go-ipfs/importer/chunk"
dag "github.com/ipfs/go-ipfs/merkledag" dag "github.com/ipfs/go-ipfs/merkledag"
pi "github.com/ipfs/go-ipfs/thirdparty/posinfo" pi "github.com/ipfs/go-ipfs/thirdparty/posinfo"
ft "github.com/ipfs/go-ipfs/unixfs" ft "github.com/ipfs/go-ipfs/unixfs"
@ -18,7 +17,6 @@ import (
var BlockSizeLimit = 1048576 // 1 MB var BlockSizeLimit = 1048576 // 1 MB
// rough estimates on expected sizes // rough estimates on expected sizes
var roughDataBlockSize = chunk.DefaultBlockSize
var roughLinkBlockSize = 1 << 13 // 8KB var roughLinkBlockSize = 1 << 13 // 8KB
var roughLinkSize = 34 + 8 + 5 // sha256 multihash + size + no name + protobuf framing var roughLinkSize = 34 + 8 + 5 // sha256 multihash + size + no name + protobuf framing
@ -113,11 +111,8 @@ func (n *UnixfsNode) AddChild(child *UnixfsNode, db *DagBuilderHelper) error {
} }
_, err = db.batch.Add(childnode) _, err = db.batch.Add(childnode)
if err != nil {
return err
}
return nil return err
} }
// Removes the child node at the given index // Removes the child node at the given index

View File

@ -13,12 +13,9 @@ import (
trickle "github.com/ipfs/go-ipfs/importer/trickle" trickle "github.com/ipfs/go-ipfs/importer/trickle"
dag "github.com/ipfs/go-ipfs/merkledag" dag "github.com/ipfs/go-ipfs/merkledag"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format" node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
) )
var log = logging.Logger("importer")
// Builds a DAG from the given file, writing created blocks to disk as they are // Builds a DAG from the given file, writing created blocks to disk as they are
// created // created
func BuildDagFromFile(fpath string, ds dag.DAGService) (node.Node, error) { func BuildDagFromFile(fpath string, ds dag.DAGService) (node.Node, error) {

View File

@ -7,14 +7,12 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
mrand "math/rand" mrand "math/rand"
"os"
"testing" "testing"
chunk "github.com/ipfs/go-ipfs/importer/chunk" chunk "github.com/ipfs/go-ipfs/importer/chunk"
h "github.com/ipfs/go-ipfs/importer/helpers" h "github.com/ipfs/go-ipfs/importer/helpers"
merkledag "github.com/ipfs/go-ipfs/merkledag" merkledag "github.com/ipfs/go-ipfs/merkledag"
mdtest "github.com/ipfs/go-ipfs/merkledag/test" mdtest "github.com/ipfs/go-ipfs/merkledag/test"
pin "github.com/ipfs/go-ipfs/pin"
ft "github.com/ipfs/go-ipfs/unixfs" ft "github.com/ipfs/go-ipfs/unixfs"
uio "github.com/ipfs/go-ipfs/unixfs/io" uio "github.com/ipfs/go-ipfs/unixfs/io"
@ -126,11 +124,6 @@ func arrComp(a, b []byte) error {
return nil return nil
} }
type dagservAndPinner struct {
ds merkledag.DAGService
mp pin.Pinner
}
func TestIndirectBlocks(t *testing.T) { func TestIndirectBlocks(t *testing.T) {
splitter := chunk.SizeSplitterGen(512) splitter := chunk.SizeSplitterGen(512)
nbytes := 1024 * 1024 nbytes := 1024 * 1024
@ -178,7 +171,7 @@ func TestSeekingBasic(t *testing.T) {
} }
start := int64(4000) start := int64(4000)
n, err := rs.Seek(start, os.SEEK_SET) n, err := rs.Seek(start, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -222,7 +215,7 @@ func TestSeekToBegin(t *testing.T) {
t.Fatal("Copy didnt copy enough bytes") t.Fatal("Copy didnt copy enough bytes")
} }
seeked, err := rs.Seek(0, os.SEEK_SET) seeked, err := rs.Seek(0, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -266,7 +259,7 @@ func TestSeekToAlmostBegin(t *testing.T) {
t.Fatal("Copy didnt copy enough bytes") t.Fatal("Copy didnt copy enough bytes")
} }
seeked, err := rs.Seek(1, os.SEEK_SET) seeked, err := rs.Seek(1, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -302,7 +295,7 @@ func TestSeekEnd(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
seeked, err := rs.Seek(0, os.SEEK_END) seeked, err := rs.Seek(0, io.SeekEnd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -328,7 +321,7 @@ func TestSeekEndSingleBlockFile(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
seeked, err := rs.Seek(0, os.SEEK_END) seeked, err := rs.Seek(0, io.SeekEnd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -358,7 +351,7 @@ func TestSeekingStress(t *testing.T) {
for i := 0; i < 50; i++ { for i := 0; i < 50; i++ {
offset := mrand.Intn(int(nbytes)) offset := mrand.Intn(int(nbytes))
l := int(nbytes) - offset l := int(nbytes) - offset
n, err := rs.Seek(int64(offset), os.SEEK_SET) n, err := rs.Seek(int64(offset), io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -403,7 +396,7 @@ func TestSeekingConsistency(t *testing.T) {
for coff := nbytes - 4096; coff >= 0; coff -= 4096 { for coff := nbytes - 4096; coff >= 0; coff -= 4096 {
t.Log(coff) t.Log(coff)
n, err := rs.Seek(coff, os.SEEK_SET) n, err := rs.Seek(coff, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -566,31 +559,3 @@ func TestAppendSingleBytesToEmpty(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
} }
func printDag(nd *merkledag.ProtoNode, ds merkledag.DAGService, indent int) {
pbd, err := ft.FromBytes(nd.Data())
if err != nil {
panic(err)
}
for i := 0; i < indent; i++ {
fmt.Print(" ")
}
fmt.Printf("{size = %d, type = %s, nc = %d", pbd.GetFilesize(), pbd.GetType().String(), len(pbd.GetBlocksizes()))
if len(nd.Links()) > 0 {
fmt.Println()
}
for _, lnk := range nd.Links() {
child, err := lnk.GetNode(context.Background(), ds)
if err != nil {
panic(err)
}
printDag(child.(*merkledag.ProtoNode), ds, indent+1)
}
if len(nd.Links()) > 0 {
for i := 0; i < indent; i++ {
fmt.Print(" ")
}
}
fmt.Println("}")
}

View File

@ -104,11 +104,8 @@ func (ks *FSKeystore) Put(name string, k ci.PrivKey) error {
defer fi.Close() defer fi.Close()
_, err = fi.Write(b) _, err = fi.Write(b)
if err != nil {
return err
}
return nil return err
} }
// Get retrieve a key from the Keystore // Get retrieve a key from the Keystore

View File

@ -12,12 +12,10 @@ import (
offline "github.com/ipfs/go-ipfs/exchange/offline" offline "github.com/ipfs/go-ipfs/exchange/offline"
ipldcbor "gx/ipfs/QmNrbCt8j9DT5W9Pmjy2SdudT9k8GpaDr4sRuFix3BXhgR/go-ipld-cbor" ipldcbor "gx/ipfs/QmNrbCt8j9DT5W9Pmjy2SdudT9k8GpaDr4sRuFix3BXhgR/go-ipld-cbor"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid" cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format" node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
) )
var log = logging.Logger("merkledag")
var ErrNotFound = fmt.Errorf("merkledag: not found") var ErrNotFound = fmt.Errorf("merkledag: not found")
// DAGService is an IPFS Merkle DAG service. // DAGService is an IPFS Merkle DAG service.

View File

@ -209,12 +209,6 @@ func runBatchFetchTest(t *testing.T, read io.Reader) {
} }
} }
func assertCanGet(t *testing.T, ds DAGService, n node.Node) {
if _, err := ds.Get(context.Background(), n.Cid()); err != nil {
t.Fatal(err)
}
}
func TestCantGet(t *testing.T) { func TestCantGet(t *testing.T) {
ds := dstest.Mock() ds := dstest.Mock()
a := NodeWithData([]byte("A")) a := NodeWithData([]byte("A"))

View File

@ -215,9 +215,8 @@ func (n *ProtoNode) SetData(d []byte) {
// that. If a link of the same name existed, it is removed. // that. If a link of the same name existed, it is removed.
func (n *ProtoNode) UpdateNodeLink(name string, that *ProtoNode) (*ProtoNode, error) { func (n *ProtoNode) UpdateNodeLink(name string, that *ProtoNode) (*ProtoNode, error) {
newnode := n.Copy().(*ProtoNode) newnode := n.Copy().(*ProtoNode)
err := newnode.RemoveNodeLink(name) _ = newnode.RemoveNodeLink(name) // ignore error
err = nil // ignore error err := newnode.AddNodeLink(name, that)
err = newnode.AddNodeLink(name, that)
return newnode, err return newnode, err
} }

View File

@ -326,12 +326,7 @@ func (d *Directory) Unlink(name string) error {
delete(d.childDirs, name) delete(d.childDirs, name)
delete(d.files, name) delete(d.files, name)
err := d.dirbuilder.RemoveChild(d.ctx, name) return d.dirbuilder.RemoveChild(d.ctx, name)
if err != nil {
return err
}
return nil
} }
func (d *Directory) Flush() error { func (d *Directory) Flush() error {

View File

@ -396,6 +396,9 @@ func TestMfsFile(t *testing.T) {
// assert size is as expected // assert size is as expected
size, err := fi.Size() size, err := fi.Size()
if err != nil {
t.Fatal(err)
}
if size != int64(fisize) { if size != int64(fisize) {
t.Fatal("size isnt correct") t.Fatal("size isnt correct")
} }
@ -419,12 +422,15 @@ func TestMfsFile(t *testing.T) {
// make sure size hasnt changed // make sure size hasnt changed
size, err = wfd.Size() size, err = wfd.Size()
if err != nil {
t.Fatal(err)
}
if size != int64(fisize) { if size != int64(fisize) {
t.Fatal("size isnt correct") t.Fatal("size isnt correct")
} }
// seek back to beginning // seek back to beginning
ns, err := wfd.Seek(0, os.SEEK_SET) ns, err := wfd.Seek(0, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -561,13 +567,9 @@ func actorMakeFile(d *Directory) error {
return err return err
} }
err = wfd.Close() return wfd.Close()
if err != nil {
return err
}
return nil
} }
func actorMkdir(d *Directory) error { func actorMkdir(d *Directory) error {
d, err := randomWalk(d, rand.Intn(7)) d, err := randomWalk(d, rand.Intn(7))
if err != nil { if err != nil {
@ -575,31 +577,8 @@ func actorMkdir(d *Directory) error {
} }
_, err = d.Mkdir(randomName()) _, err = d.Mkdir(randomName())
if err != nil {
return err
}
return nil return err
}
func actorRemoveFile(d *Directory) error {
d, err := randomWalk(d, rand.Intn(7))
if err != nil {
return err
}
ents, err := d.List(context.Background())
if err != nil {
return err
}
if len(ents) == 0 {
return nil
}
re := ents[rand.Intn(len(ents))]
return d.Unlink(re.Name)
} }
func randomFile(d *Directory) (*File, error) { func randomFile(d *Directory) (*File, error) {
@ -895,7 +874,7 @@ func readFile(rt *Root, path string, offset int64, buf []byte) error {
return err return err
} }
_, err = fd.Seek(offset, os.SEEK_SET) _, err = fd.Seek(offset, io.SeekStart)
if err != nil { if err != nil {
return err return err
} }

View File

@ -65,12 +65,7 @@ func Mv(r *Root, src, dst string) error {
return err return err
} }
err = srcDirObj.Unlink(srcFname) return srcDirObj.Unlink(srcFname)
if err != nil {
return err
}
return nil
} }
func lookupDir(r *Root, path string) (*Directory, error) { func lookupDir(r *Root, path string) (*Directory, error) {

View File

@ -170,12 +170,6 @@ type Republisher struct {
lastpub *cid.Cid lastpub *cid.Cid
} }
func (rp *Republisher) getVal() *cid.Cid {
rp.lk.Lock()
defer rp.lk.Unlock()
return rp.val
}
// NewRepublisher creates a new Republisher object to republish the given root // NewRepublisher creates a new Republisher object to republish the given root
// using the given short and long time intervals // using the given short and long time intervals
func NewRepublisher(ctx context.Context, pf PubFunc, tshort, tlong time.Duration) *Republisher { func NewRepublisher(ctx context.Context, pf PubFunc, tshort, tlong time.Duration) *Republisher {
@ -197,13 +191,6 @@ func (p *Republisher) setVal(c *cid.Cid) {
p.val = c p.val = c
} }
func (p *Republisher) pubNow() {
select {
case p.pubnowch <- nil:
default:
}
}
func (p *Republisher) WaitPub() { func (p *Republisher) WaitPub() {
p.lk.Lock() p.lk.Lock()
consistent := p.lastpub == p.val consistent := p.lastpub == p.val

View File

@ -13,6 +13,7 @@ CHECK_GO :=
go-pkg-name=$(shell go list $(go-tags) github.com/ipfs/go-ipfs/$(1)) go-pkg-name=$(shell go list $(go-tags) github.com/ipfs/go-ipfs/$(1))
go-main-name=$(notdir $(call go-pkg-name,$(1)))$(?exe) go-main-name=$(notdir $(call go-pkg-name,$(1)))$(?exe)
go-curr-pkg-tgt=$(d)/$(call go-main-name,$(d)) go-curr-pkg-tgt=$(d)/$(call go-main-name,$(d))
go-pkgs-novendor=$(shell go list github.com/ipfs/go-ipfs/... | grep -v /Godeps/)
go-tags=$(if $(GOTAGS), -tags="$(call join-with,$(space),$(GOTAGS))") go-tags=$(if $(GOTAGS), -tags="$(call join-with,$(space),$(GOTAGS))")
go-flags-with-tags=$(GOFLAGS)$(go-tags) go-flags-with-tags=$(GOFLAGS)$(go-tags)
@ -39,6 +40,11 @@ test_go_fmt:
.PHONY: test_go_fmt .PHONY: test_go_fmt
TEST_GO += test_go_fmt TEST_GO += test_go_fmt
test_go_megacheck:
@go get honnef.co/go/tools/cmd/megacheck
@for pkg in $(go-pkgs-novendor); do megacheck "$$pkg"; done
.PHONY: megacheck
test_go: $(TEST_GO) test_go: $(TEST_GO)
check_go_version: check_go_version:

View File

@ -160,17 +160,11 @@ func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqn
errs <- PublishPublicKey(ctx, r, namekey, k.GetPublic()) errs <- PublishPublicKey(ctx, r, namekey, k.GetPublic())
}() }()
err = waitOnErrChan(ctx, errs) if err := waitOnErrChan(ctx, errs); err != nil {
if err != nil {
return err return err
} }
err = waitOnErrChan(ctx, errs) return waitOnErrChan(ctx, errs)
if err != nil {
return err
}
return nil
} }
func waitOnErrChan(ctx context.Context, errs chan error) error { func waitOnErrChan(ctx context.Context, errs chan error) error {
@ -192,12 +186,7 @@ func PublishPublicKey(ctx context.Context, r routing.ValueStore, k string, pubk
// Store associated public key // Store associated public key
timectx, cancel := context.WithTimeout(ctx, PublishPutValTimeout) timectx, cancel := context.WithTimeout(ctx, PublishPutValTimeout)
defer cancel() defer cancel()
err = r.PutValue(timectx, k, pkbytes) return r.PutValue(timectx, k, pkbytes)
if err != nil {
return err
}
return nil
} }
func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec *pb.IpnsEntry) error { func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec *pb.IpnsEntry) error {
@ -211,11 +200,7 @@ func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec
log.Debugf("Storing ipns entry at: %s", ipnskey) log.Debugf("Storing ipns entry at: %s", ipnskey)
// Store ipns entry at "/ipns/"+b58(h(pubkey)) // Store ipns entry at "/ipns/"+b58(h(pubkey))
if err := r.PutValue(timectx, ipnskey, data); err != nil { return r.PutValue(timectx, ipnskey, data)
return err
}
return nil
} }
func CreateRoutingEntryData(pk ci.PrivKey, val path.Path, seq uint64, eol time.Time) (*pb.IpnsEntry, error) { func CreateRoutingEntryData(pk ci.PrivKey, val path.Path, seq uint64, eol time.Time) (*pb.IpnsEntry, error) {
@ -349,12 +334,7 @@ func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, p
return err return err
} }
err = pub.Publish(ctx, key, path.FromCid(nodek)) return pub.Publish(ctx, key, path.FromCid(nodek))
if err != nil {
return err
}
return nil
} }
func IpnsKeysForID(id peer.ID) (name, ipns string) { func IpnsKeysForID(id peer.ID) (name, ipns string) {

View File

@ -9,13 +9,10 @@ import (
dag "github.com/ipfs/go-ipfs/merkledag" dag "github.com/ipfs/go-ipfs/merkledag"
pin "github.com/ipfs/go-ipfs/pin" pin "github.com/ipfs/go-ipfs/pin"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid" cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format" node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
) )
var log = logging.Logger("gc")
// Result represents an incremental output from a garbage collection // Result represents an incremental output from a garbage collection
// run. It contains either an error, or the cid of a removed object. // run. It contains either an error, or the cid of a removed object.
type Result struct { type Result struct {

View File

@ -528,9 +528,7 @@ func (p *pinner) InternalPins() []*cid.Cid {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()
var out []*cid.Cid var out []*cid.Cid
for _, c := range p.internalPin.Keys() { out = append(out, p.internalPin.Keys()...)
out = append(out, c)
}
return out return out
} }

View File

@ -183,8 +183,8 @@ func TestIsPinnedLookup(t *testing.T) {
// TODO does pinner need to share datastore with blockservice? // TODO does pinner need to share datastore with blockservice?
p := NewPinner(dstore, dserv, dserv) p := NewPinner(dstore, dserv, dserv)
aNodes := make([]*mdag.ProtoNode, aBranchLen, aBranchLen) aNodes := make([]*mdag.ProtoNode, aBranchLen)
aKeys := make([]*cid.Cid, aBranchLen, aBranchLen) aKeys := make([]*cid.Cid, aBranchLen)
for i := 0; i < aBranchLen; i++ { for i := 0; i < aBranchLen; i++ {
a, _ := randNode() a, _ := randNode()
if i >= 1 { if i >= 1 {

View File

@ -10,11 +10,8 @@ import (
"strings" "strings"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir" "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
) )
var log = logging.Logger("config")
// Config is used to load ipfs config files. // Config is used to load ipfs config files.
type Config struct { type Config struct {
Identity Identity // local node's peer identity Identity Identity // local node's peer identity

View File

@ -20,13 +20,6 @@ var DefaultSNRServers = []string{
"/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN", "/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN",
} }
func initSNRConfig() (*SupernodeClientConfig, error) {
// TODO perform validation
return &SupernodeClientConfig{
Servers: DefaultSNRServers,
}, nil
}
func (gcr *SupernodeClientConfig) ServerIPFSAddrs() ([]ipfsaddr.IPFSAddr, error) { func (gcr *SupernodeClientConfig) ServerIPFSAddrs() ([]ipfsaddr.IPFSAddr, error) {
var addrs []ipfsaddr.IPFSAddr var addrs []ipfsaddr.IPFSAddr
for _, server := range gcr.Servers { for _, server := range gcr.Servers {

View File

@ -41,16 +41,6 @@ func openDefaultDatastore(r *FSRepo) (repo.Datastore, error) {
return nil, fmt.Errorf("unable to open flatfs datastore: %v", err) return nil, fmt.Errorf("unable to open flatfs datastore: %v", err)
} }
// Add our PeerID to metrics paths to keep them unique
//
// As some tests just pass a zero-value Config to fsrepo.Init,
// cope with missing PeerID.
id := r.config.Identity.PeerID
if id == "" {
// the tests pass in a zero Config; cope with it
id = fmt.Sprintf("uninitialized_%p", r)
}
prefix := "ipfs.fsrepo.datastore." prefix := "ipfs.fsrepo.datastore."
metricsBlocks := measure.New(prefix+"blocks", blocksDS) metricsBlocks := measure.New(prefix+"blocks", blocksDS)
metricsLevelDB := measure.New(prefix+"leveldb", leveldbDS) metricsLevelDB := measure.New(prefix+"leveldb", leveldbDS)

View File

@ -37,11 +37,6 @@ var RepoVersion = 5
var migrationInstructions = `See https://github.com/ipfs/fs-repo-migrations/blob/master/run.md var migrationInstructions = `See https://github.com/ipfs/fs-repo-migrations/blob/master/run.md
Sorry for the inconvenience. In the future, these will run automatically.` Sorry for the inconvenience. In the future, these will run automatically.`
var errIncorrectRepoFmt = `Repo has incorrect version: %s
Program version is: %s
Please run the ipfs migration tool before continuing.
` + migrationInstructions
var programTooLowMessage = `Your programs version (%d) is lower than your repos (%d). var programTooLowMessage = `Your programs version (%d) is lower than your repos (%d).
Please update ipfs to a version that supports the existing repo, or run Please update ipfs to a version that supports the existing repo, or run
a migration in reverse. a migration in reverse.
@ -411,10 +406,7 @@ func (r *FSRepo) Close() error {
// logging.Configure(logging.Output(os.Stderr)) // logging.Configure(logging.Output(os.Stderr))
r.closed = true r.closed = true
if err := r.lockfile.Close(); err != nil { return r.lockfile.Close()
return err
}
return nil
} }
// Result when not Open is undefined. The method may panic if it pleases. // Result when not Open is undefined. The method may panic if it pleases.

View File

@ -100,7 +100,7 @@ func TestDatastorePersistsFromRepoToRepo(t *testing.T) {
actual, ok := v.([]byte) actual, ok := v.([]byte)
assert.True(ok, t, "value should be the []byte from r1's Put") assert.True(ok, t, "value should be the []byte from r1's Put")
assert.Nil(r2.Close(), t) assert.Nil(r2.Close(), t)
assert.True(bytes.Compare(expected, actual) == 0, t, "data should match") assert.True(bytes.Equal(expected, actual), t, "data should match")
} }
func TestOpenMoreThanOnceInSameProcess(t *testing.T) { func TestOpenMoreThanOnceInSameProcess(t *testing.T) {

View File

@ -70,11 +70,8 @@ func writeToPath(rc io.Reader, out string) error {
defer binfi.Close() defer binfi.Close()
_, err = io.Copy(binfi, rc) _, err = io.Copy(binfi, rc)
if err != nil {
return err
}
return nil return err
} }
func unpackZip(dist, binnom, path, out string) error { func unpackZip(dist, binnom, path, out string) error {

View File

@ -9,13 +9,10 @@ import (
"path/filepath" "path/filepath"
"github.com/ipfs/go-ipfs/repo/config" "github.com/ipfs/go-ipfs/repo/config"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
"gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util" "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
"gx/ipfs/QmdYwCmx8pZRkzdcd8MhmLJqYVoVTC1aGsy5Q4reMGLNLg/atomicfile" "gx/ipfs/QmdYwCmx8pZRkzdcd8MhmLJqYVoVTC1aGsy5Q4reMGLNLg/atomicfile"
) )
var log = logging.Logger("fsrepo")
// ReadConfigFile reads the config from `filename` into `cfg`. // ReadConfigFile reads the config from `filename` into `cfg`.
func ReadConfigFile(filename string, cfg interface{}) error { func ReadConfigFile(filename string, cfg interface{}) error {
f, err := os.Open(filename) f, err := os.Open(filename)

View File

@ -66,7 +66,7 @@ func (rs *s) Providers(c *cid.Cid) []pstore.PeerInfo {
return ret return ret
} }
for _, r := range records { for _, r := range records {
if time.Now().Sub(r.Created) > rs.delayConf.ValueVisibility.Get() { if time.Since(r.Created) > rs.delayConf.ValueVisibility.Get() {
ret = append(ret, r.Peer) ret = append(ret, r.Peer)
} }
} }

View File

@ -45,7 +45,7 @@ func TestClientFindProviders(t *testing.T) {
providersFromClient := client.FindProvidersAsync(context.Background(), k, max) providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
isInClient := false isInClient := false
for pi := range providersFromClient { for pi := range providersFromClient {
if pi.ID == pi.ID { if pi.ID == pi.ID { // <-- typo?
isInClient = true isInClient = true
} }
} }
@ -72,7 +72,7 @@ func TestClientOverMax(t *testing.T) {
providersFromClient := client.FindProvidersAsync(context.Background(), k, max) providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
i := 0 i := 0
for _ = range providersFromClient { for range providersFromClient {
i++ i++
} }
if i != max { if i != max {
@ -128,7 +128,7 @@ func TestCanceledContext(t *testing.T) {
providers := client.FindProvidersAsync(ctx, k, max) providers := client.FindProvidersAsync(ctx, k, max)
numProvidersReturned := 0 numProvidersReturned := 0
for _ = range providers { for range providers {
numProvidersReturned++ numProvidersReturned++
} }
t.Log(numProvidersReturned) t.Log(numProvidersReturned)

View File

@ -7,15 +7,12 @@ import (
repo "github.com/ipfs/go-ipfs/repo" repo "github.com/ipfs/go-ipfs/repo"
routing "gx/ipfs/QmNdaQ8itUU9jEZUwTsG4gHMaPmRfi6FEe89QjQAFbep3M/go-libp2p-routing" routing "gx/ipfs/QmNdaQ8itUU9jEZUwTsG4gHMaPmRfi6FEe89QjQAFbep3M/go-libp2p-routing"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
p2phost "gx/ipfs/QmUywuGNZoUKV8B9iyvup9bPkLiMrhTsyVMkeSXW5VxAfC/go-libp2p-host" p2phost "gx/ipfs/QmUywuGNZoUKV8B9iyvup9bPkLiMrhTsyVMkeSXW5VxAfC/go-libp2p-host"
pstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore" pstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid" cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
peer "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer" peer "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
) )
var log = logging.Logger("mockrouter")
type nilclient struct { type nilclient struct {
} }

View File

@ -10,7 +10,6 @@ import (
routing "gx/ipfs/QmNdaQ8itUU9jEZUwTsG4gHMaPmRfi6FEe89QjQAFbep3M/go-libp2p-routing" routing "gx/ipfs/QmNdaQ8itUU9jEZUwTsG4gHMaPmRfi6FEe89QjQAFbep3M/go-libp2p-routing"
ci "gx/ipfs/QmP1DfoUjiWH2ZBo1PBH6FupdBucbDepx3HpWmEY6JMUpY/go-libp2p-crypto" ci "gx/ipfs/QmP1DfoUjiWH2ZBo1PBH6FupdBucbDepx3HpWmEY6JMUpY/go-libp2p-crypto"
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore" ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
record "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record" record "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record"
pb "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record/pb" pb "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record/pb"
pstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore" pstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
@ -19,8 +18,6 @@ import (
"gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer" "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
) )
var log = logging.Logger("offlinerouting")
var ErrOffline = errors.New("routing system in offline mode") var ErrOffline = errors.New("routing system in offline mode")
func NewOfflineRouter(dstore ds.Datastore, privkey ci.PrivKey) routing.IpfsRouting { func NewOfflineRouter(dstore ds.Datastore, privkey ci.PrivKey) routing.IpfsRouting {

View File

@ -15,17 +15,19 @@ func TestOfflineRouterStorage(t *testing.T) {
privkey, _, _ := testutil.RandTestKeyPair(128) privkey, _, _ := testutil.RandTestKeyPair(128)
offline := NewOfflineRouter(nds, privkey) offline := NewOfflineRouter(nds, privkey)
err := offline.PutValue(ctx, "key", []byte("testing 1 2 3")) if err := offline.PutValue(ctx, "key", []byte("testing 1 2 3")); err != nil {
if err != nil {
t.Fatal(err) t.Fatal(err)
} }
val, err := offline.GetValue(ctx, "key") val, err := offline.GetValue(ctx, "key")
if err != nil {
t.Fatal(err)
}
if !bytes.Equal([]byte("testing 1 2 3"), val) { if !bytes.Equal([]byte("testing 1 2 3"), val) {
t.Fatal("OfflineRouter does not properly store") t.Fatal("OfflineRouter does not properly store")
} }
val, err = offline.GetValue(ctx, "notHere") _, err = offline.GetValue(ctx, "notHere")
if err == nil { if err == nil {
t.Fatal("Router should throw errors for unfound records") t.Fatal("Router should throw errors for unfound records")
} }

View File

@ -104,10 +104,7 @@ func (px *standard) sendMessage(ctx context.Context, m *dhtpb.Message, remote pe
} }
defer s.Close() defer s.Close()
pbw := ggio.NewDelimitedWriter(s) pbw := ggio.NewDelimitedWriter(s)
if err := pbw.WriteMsg(m); err != nil { return pbw.WriteMsg(m)
return err
}
return nil
} }
// SendRequest sends the request to each remote sequentially (randomized order), // SendRequest sends the request to each remote sequentially (randomized order),

View File

@ -10,7 +10,6 @@ import (
datastore "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore" datastore "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
dhtpb "gx/ipfs/QmRmroYSdievxnjiuy99C8BzShNstdEWcEF3LQHF7fUbez/go-libp2p-kad-dht/pb" dhtpb "gx/ipfs/QmRmroYSdievxnjiuy99C8BzShNstdEWcEF3LQHF7fUbez/go-libp2p-kad-dht/pb"
record "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record"
pb "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record/pb" pb "gx/ipfs/QmWYCqr6UDqqD1bfRybaAPtbAqcN3TSJpveaBXMwbQ3ePZ/go-libp2p-record/pb"
pstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore" pstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
@ -140,10 +139,7 @@ func putRoutingRecord(ds datastore.Datastore, k string, value *pb.Record) error
} }
dskey := dshelp.NewKeyFromBinary([]byte(k)) dskey := dshelp.NewKeyFromBinary([]byte(k))
// TODO namespace // TODO namespace
if err := ds.Put(dskey, data); err != nil { return ds.Put(dskey, data)
return err
}
return nil
} }
func putRoutingProviders(ds datastore.Datastore, k string, newRecords []*dhtpb.Message_Peer) error { func putRoutingProviders(ds datastore.Datastore, k string, newRecords []*dhtpb.Message_Peer) error {
@ -204,20 +200,3 @@ func getRoutingProviders(ds datastore.Datastore, k string) ([]*dhtpb.Message_Pee
func providerKey(k string) datastore.Key { func providerKey(k string) datastore.Key {
return datastore.KeyWithNamespaces([]string{"routing", "providers", k}) return datastore.KeyWithNamespaces([]string{"routing", "providers", k})
} }
func verify(ps pstore.Peerstore, r *pb.Record) error {
v := make(record.Validator)
v["pk"] = record.PublicKeyValidator
p := peer.ID(r.GetAuthor())
pk := ps.PubKey(p)
if pk == nil {
return fmt.Errorf("do not have public key for %s", p)
}
if err := record.CheckRecordSig(r, pk); err != nil {
return err
}
if err := v.VerifyRecord(r); err != nil {
return err
}
return nil
}

View File

@ -65,7 +65,6 @@ func TestThreeLeggedCat100MBMacbookCoastToCoast(t *testing.T) {
func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error { func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
const numPeers = 3
// create network // create network
mn := mocknet.New(ctx) mn := mocknet.New(ctx)

View File

@ -64,8 +64,8 @@ func run() error {
return err return err
} }
repoPath := gopath.Join(cwd, config.DefaultPathName) repoPath := gopath.Join(cwd, config.DefaultPathName)
if err := ensureRepoInitialized(repoPath); err != nil { _ = ensureRepoInitialized(repoPath)
}
repo, err := fsrepo.Open(repoPath) repo, err := fsrepo.Open(repoPath)
if err != nil { // owned by node if err != nil { // owned by node
return err return err
@ -233,26 +233,6 @@ func runFileCattingWorker(ctx context.Context, n *core.IpfsNode) error {
return nil return nil
} }
func toPeerInfos(bpeers []config.BootstrapPeer) ([]pstore.PeerInfo, error) {
var peers []pstore.PeerInfo
for _, bootstrap := range bpeers {
p, err := toPeerInfo(bootstrap)
if err != nil {
return nil, err
}
peers = append(peers, p)
}
return peers, nil
}
func toPeerInfo(bootstrap config.BootstrapPeer) (p pstore.PeerInfo, err error) {
p = pstore.PeerInfo{
ID: bootstrap.ID(),
Addrs: []ma.Multiaddr{bootstrap.Multiaddr()},
}
return p, nil
}
func cmdCtx(node *core.IpfsNode, repoPath string) commands.Context { func cmdCtx(node *core.IpfsNode, repoPath string) commands.Context {
return commands.Context{ return commands.Context{
Online: true, Online: true,

View File

@ -79,12 +79,7 @@ func (te *Extractor) extractDir(h *tar.Header, depth int) error {
te.Path = path te.Path = path
} }
err := os.MkdirAll(path, 0755) return os.MkdirAll(path, 0755)
if err != nil {
return err
}
return nil
} }
func (te *Extractor) extractSymlink(h *tar.Header) error { func (te *Extractor) extractSymlink(h *tar.Header) error {
@ -112,12 +107,7 @@ func (te *Extractor) extractFile(h *tar.Header, r *tar.Reader, depth int, rootEx
} }
defer file.Close() defer file.Close()
err = copyWithProgress(file, r, te.Progress) return copyWithProgress(file, r, te.Progress)
if err != nil {
return err
}
return nil
} }
func copyWithProgress(to io.Writer, from io.Reader, cb func(int64) int64) error { func copyWithProgress(to io.Writer, from io.Reader, cb func(int64) int64) error {

View File

@ -1,13 +1,10 @@
package hamt package hamt
import ( import (
"bufio"
"context" "context"
"fmt" "fmt"
"math/rand" "math/rand"
"os" "os"
"strconv"
"strings"
"testing" "testing"
"time" "time"
@ -191,7 +188,8 @@ func genOpSet(seed int64, keep, temp []string) []testOp {
} }
// executes the given op set with a repl to allow easier debugging // executes the given op set with a repl to allow easier debugging
func debugExecuteOpSet(ds dag.DAGService, width int, ops []testOp) (*HamtShard, error) { /*func debugExecuteOpSet(ds dag.DAGService, width int, ops []testOp) (*HamtShard, error) {
s, err := NewHamtShard(ds, width) s, err := NewHamtShard(ds, width)
if err != nil { if err != nil {
return nil, err return nil, err
@ -238,7 +236,7 @@ mainloop:
run = -1 run = -1
} }
case "lookop": case "lookop":
for k := 0; k < len(ops); k++ { for k = 0; k < len(ops); k++ {
if ops[k].Val == parts[1] { if ops[k].Val == parts[1] {
fmt.Printf(" Op %d: %s %s\n", k, opnames[ops[k].Op], parts[1]) fmt.Printf(" Op %d: %s %s\n", k, opnames[ops[k].Op], parts[1])
} }
@ -289,4 +287,4 @@ func readCommand() string {
scan := bufio.NewScanner(os.Stdin) scan := bufio.NewScanner(os.Stdin)
scan.Scan() scan.Scan()
return scan.Text() return scan.Text()
} }*/

View File

@ -6,7 +6,6 @@ import (
"math/rand" "math/rand"
"os" "os"
"sort" "sort"
"strings"
"testing" "testing"
"time" "time"
@ -138,7 +137,7 @@ func TestBasicSet(t *testing.T) {
func TestDirBuilding(t *testing.T) { func TestDirBuilding(t *testing.T) {
ds := mdtest.Mock() ds := mdtest.Mock()
s, _ := NewHamtShard(ds, 256) _, _ = NewHamtShard(ds, 256)
_, s, err := makeDir(ds, 200) _, s, err := makeDir(ds, 200)
if err != nil { if err != nil {
@ -161,7 +160,7 @@ func TestDirBuilding(t *testing.T) {
func TestShardReload(t *testing.T) { func TestShardReload(t *testing.T) {
ds := mdtest.Mock() ds := mdtest.Mock()
s, _ := NewHamtShard(ds, 256) _, _ = NewHamtShard(ds, 256)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
@ -494,21 +493,6 @@ func TestSetHamtChild(t *testing.T) {
} }
} }
func printDag(ds dag.DAGService, nd *dag.ProtoNode, depth int) {
padding := strings.Repeat(" ", depth)
fmt.Println("{")
for _, l := range nd.Links() {
fmt.Printf("%s%s: %s", padding, l.Name, l.Cid.String())
ch, err := ds.Get(context.Background(), l.Cid)
if err != nil {
panic(err)
}
printDag(ds, ch.(*dag.ProtoNode), depth+1)
}
fmt.Println(padding + "}")
}
func printDiff(ds dag.DAGService, a, b *dag.ProtoNode) { func printDiff(ds dag.DAGService, a, b *dag.ProtoNode) {
diff, err := dagutils.Diff(context.TODO(), ds, a, b) diff, err := dagutils.Diff(context.TODO(), ds, a, b)
if err != nil { if err != nil {

View File

@ -2,8 +2,8 @@ package io
import ( import (
"bytes" "bytes"
"io"
"io/ioutil" "io/ioutil"
"os"
"strings" "strings"
"testing" "testing"
@ -54,7 +54,7 @@ func TestSeekAndRead(t *testing.T) {
} }
for i := 255; i >= 0; i-- { for i := 255; i >= 0; i-- {
reader.Seek(int64(i), os.SEEK_SET) reader.Seek(int64(i), io.SeekStart)
if reader.Offset() != int64(i) { if reader.Offset() != int64(i) {
t.Fatal("expected offset to be increased by one after read") t.Fatal("expected offset to be increased by one after read")
@ -100,14 +100,14 @@ func TestRelativeSeek(t *testing.T) {
t.Fatalf("expected to read: %d at %d, read %d", i, reader.Offset()-1, out) t.Fatalf("expected to read: %d at %d, read %d", i, reader.Offset()-1, out)
} }
if i != 255 { if i != 255 {
_, err := reader.Seek(3, os.SEEK_CUR) _, err := reader.Seek(3, io.SeekCurrent)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
} }
_, err = reader.Seek(4, os.SEEK_END) _, err = reader.Seek(4, io.SeekEnd)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -120,7 +120,7 @@ func TestRelativeSeek(t *testing.T) {
if int(out) != 255-i { if int(out) != 255-i {
t.Fatalf("expected to read: %d at %d, read %d", 255-i, reader.Offset()-1, out) t.Fatalf("expected to read: %d at %d, read %d", 255-i, reader.Offset()-1, out)
} }
reader.Seek(-5, os.SEEK_CUR) // seek 4 bytes but we read one byte every time so 5 bytes reader.Seek(-5, io.SeekCurrent) // seek 4 bytes but we read one byte every time so 5 bytes
} }
} }

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"os"
mdag "github.com/ipfs/go-ipfs/merkledag" mdag "github.com/ipfs/go-ipfs/merkledag"
ft "github.com/ipfs/go-ipfs/unixfs" ft "github.com/ipfs/go-ipfs/unixfs"
@ -185,7 +184,7 @@ func (dr *pbDagReader) Offset() int64 {
// recreations that need to happen. // recreations that need to happen.
func (dr *pbDagReader) Seek(offset int64, whence int) (int64, error) { func (dr *pbDagReader) Seek(offset int64, whence int) (int64, error) {
switch whence { switch whence {
case os.SEEK_SET: case io.SeekStart:
if offset < 0 { if offset < 0 {
return -1, errors.New("Invalid offset") return -1, errors.New("Invalid offset")
} }
@ -226,7 +225,7 @@ func (dr *pbDagReader) Seek(offset int64, whence int) (int64, error) {
} }
// set proper offset within child readseeker // set proper offset within child readseeker
n, err := dr.buf.Seek(left, os.SEEK_SET) n, err := dr.buf.Seek(left, io.SeekStart)
if err != nil { if err != nil {
return -1, err return -1, err
} }
@ -238,13 +237,13 @@ func (dr *pbDagReader) Seek(offset int64, whence int) (int64, error) {
} }
dr.offset = offset dr.offset = offset
return offset, nil return offset, nil
case os.SEEK_CUR: case io.SeekCurrent:
// TODO: be smarter here // TODO: be smarter here
noffset := dr.offset + offset noffset := dr.offset + offset
return dr.Seek(noffset, os.SEEK_SET) return dr.Seek(noffset, io.SeekStart)
case os.SEEK_END: case io.SeekEnd:
noffset := int64(dr.pbdata.GetFilesize()) - offset noffset := int64(dr.pbdata.GetFilesize()) - offset
return dr.Seek(noffset, os.SEEK_SET) return dr.Seek(noffset, io.SeekStart)
default: default:
return 0, errors.New("invalid whence") return 0, errors.New("invalid whence")
} }

View File

@ -5,7 +5,6 @@ import (
"context" "context"
"errors" "errors"
"io" "io"
"os"
chunk "github.com/ipfs/go-ipfs/importer/chunk" chunk "github.com/ipfs/go-ipfs/importer/chunk"
help "github.com/ipfs/go-ipfs/importer/helpers" help "github.com/ipfs/go-ipfs/importer/helpers"
@ -14,7 +13,6 @@ import (
ft "github.com/ipfs/go-ipfs/unixfs" ft "github.com/ipfs/go-ipfs/unixfs"
uio "github.com/ipfs/go-ipfs/unixfs/io" uio "github.com/ipfs/go-ipfs/unixfs/io"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid" cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto" proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format" node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
@ -26,8 +24,6 @@ var ErrUnrecognizedWhence = errors.New("unrecognized whence")
// 2MB // 2MB
var writebufferSize = 1 << 21 var writebufferSize = 1 << 21
var log = logging.Logger("dagio")
// DagModifier is the only struct licensed and able to correctly // DagModifier is the only struct licensed and able to correctly
// perform surgery on a DAG 'file' // perform surgery on a DAG 'file'
// Dear god, please rename this to something more pleasant // Dear god, please rename this to something more pleasant
@ -340,7 +336,7 @@ func (dm *DagModifier) readPrep() error {
return err return err
} }
i, err := dr.Seek(int64(dm.curWrOff), os.SEEK_SET) i, err := dr.Seek(int64(dm.curWrOff), io.SeekStart)
if err != nil { if err != nil {
cancel() cancel()
return err return err
@ -397,11 +393,11 @@ func (dm *DagModifier) Seek(offset int64, whence int) (int64, error) {
var newoffset uint64 var newoffset uint64
switch whence { switch whence {
case os.SEEK_CUR: case io.SeekCurrent:
newoffset = dm.curWrOff + uint64(offset) newoffset = dm.curWrOff + uint64(offset)
case os.SEEK_SET: case io.SeekStart:
newoffset = uint64(offset) newoffset = uint64(offset)
case os.SEEK_END: case io.SeekEnd:
newoffset = uint64(fisize) - uint64(offset) newoffset = uint64(fisize) - uint64(offset)
default: default:
return 0, ErrUnrecognizedWhence return 0, ErrUnrecognizedWhence

View File

@ -1,36 +1,21 @@
package mod package mod
import ( import (
"context"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os"
"testing" "testing"
"github.com/ipfs/go-ipfs/blocks/blockstore"
bs "github.com/ipfs/go-ipfs/blockservice"
"github.com/ipfs/go-ipfs/exchange/offline"
h "github.com/ipfs/go-ipfs/importer/helpers" h "github.com/ipfs/go-ipfs/importer/helpers"
trickle "github.com/ipfs/go-ipfs/importer/trickle" trickle "github.com/ipfs/go-ipfs/importer/trickle"
mdag "github.com/ipfs/go-ipfs/merkledag"
ft "github.com/ipfs/go-ipfs/unixfs" ft "github.com/ipfs/go-ipfs/unixfs"
uio "github.com/ipfs/go-ipfs/unixfs/io" uio "github.com/ipfs/go-ipfs/unixfs/io"
testu "github.com/ipfs/go-ipfs/unixfs/test" testu "github.com/ipfs/go-ipfs/unixfs/test"
context "context"
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
"gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore/sync"
u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util" u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
) )
func getMockDagServAndBstore(t testing.TB) (mdag.DAGService, blockstore.Blockstore) {
dstore := ds.NewMapDatastore()
tsds := sync.MutexWrap(dstore)
bstore := blockstore.NewBlockstore(tsds)
bserv := bs.New(bstore, offline.Exchange(bstore))
dserv := mdag.NewDAGService(bserv)
return dserv, bstore
}
func testModWrite(t *testing.T, beg, size uint64, orig []byte, dm *DagModifier) []byte { func testModWrite(t *testing.T, beg, size uint64, orig []byte, dm *DagModifier) []byte {
newdata := make([]byte, size) newdata := make([]byte, size)
r := u.NewTimeSeededRand() r := u.NewTimeSeededRand()
@ -112,7 +97,7 @@ func TestDagModifierBasic(t *testing.T) {
beg = uint64(len(b)) beg = uint64(len(b))
length = 3000 length = 3000
t.Log("Testing pure append") t.Log("Testing pure append")
b = testModWrite(t, beg, length, b, dagmod) _ = testModWrite(t, beg, length, b, dagmod)
// Verify reported length // Verify reported length
node, err := dagmod.GetNode() node, err := dagmod.GetNode()
@ -384,7 +369,7 @@ func TestDagTruncate(t *testing.T) {
t.Fatal("size was incorrect!") t.Fatal("size was incorrect!")
} }
_, err = dagmod.Seek(0, os.SEEK_SET) _, err = dagmod.Seek(0, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -450,7 +435,7 @@ func TestSparseWrite(t *testing.T) {
t.Fatal("incorrect write amount") t.Fatal("incorrect write amount")
} }
_, err = dagmod.Seek(0, os.SEEK_SET) _, err = dagmod.Seek(0, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -479,7 +464,7 @@ func TestSeekPastEndWrite(t *testing.T) {
buf := make([]byte, 5000) buf := make([]byte, 5000)
u.NewTimeSeededRand().Read(buf[2500:]) u.NewTimeSeededRand().Read(buf[2500:])
nseek, err := dagmod.Seek(2500, os.SEEK_SET) nseek, err := dagmod.Seek(2500, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -497,7 +482,7 @@ func TestSeekPastEndWrite(t *testing.T) {
t.Fatal("incorrect write amount") t.Fatal("incorrect write amount")
} }
_, err = dagmod.Seek(0, os.SEEK_SET) _, err = dagmod.Seek(0, io.SeekStart)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -525,7 +510,7 @@ func TestRelativeSeek(t *testing.T) {
for i := 0; i < 64; i++ { for i := 0; i < 64; i++ {
dagmod.Write([]byte{byte(i)}) dagmod.Write([]byte{byte(i)})
if _, err := dagmod.Seek(1, os.SEEK_CUR); err != nil { if _, err := dagmod.Seek(1, io.SeekCurrent); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
@ -576,17 +561,26 @@ func TestEndSeek(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
offset, err := dagmod.Seek(0, os.SEEK_CUR) offset, err := dagmod.Seek(0, io.SeekCurrent)
if err != nil {
t.Fatal(err)
}
if offset != 100 { if offset != 100 {
t.Fatal("expected the relative seek 0 to return current location") t.Fatal("expected the relative seek 0 to return current location")
} }
offset, err = dagmod.Seek(0, os.SEEK_SET) offset, err = dagmod.Seek(0, io.SeekStart)
if err != nil {
t.Fatal(err)
}
if offset != 0 { if offset != 0 {
t.Fatal("expected the absolute seek to set offset at 0") t.Fatal("expected the absolute seek to set offset at 0")
} }
offset, err = dagmod.Seek(0, os.SEEK_END) offset, err = dagmod.Seek(0, io.SeekEnd)
if err != nil {
t.Fatal(err)
}
if offset != 100 { if offset != 100 {
t.Fatal("expected the end seek to set offset at end") t.Fatal("expected the end seek to set offset at end")
} }
@ -612,7 +606,7 @@ func TestReadAndSeek(t *testing.T) {
} }
readBuf := make([]byte, 4) readBuf := make([]byte, 4)
offset, err := dagmod.Seek(0, os.SEEK_SET) offset, err := dagmod.Seek(0, io.SeekStart)
if offset != 0 { if offset != 0 {
t.Fatal("expected offset to be 0") t.Fatal("expected offset to be 0")
} }
@ -636,7 +630,7 @@ func TestReadAndSeek(t *testing.T) {
} }
// skip 4 // skip 4
_, err = dagmod.Seek(1, os.SEEK_CUR) _, err = dagmod.Seek(1, io.SeekCurrent)
if err != nil { if err != nil {
t.Fatalf("error: %s, offset %d, reader offset %d", err, dagmod.curWrOff, dagmod.read.Offset()) t.Fatalf("error: %s, offset %d, reader offset %d", err, dagmod.curWrOff, dagmod.read.Offset())
} }
@ -676,7 +670,7 @@ func TestCtxRead(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
dagmod.Seek(0, os.SEEK_SET) dagmod.Seek(0, io.SeekStart)
readBuf := make([]byte, 4) readBuf := make([]byte, 4)
_, err = dagmod.CtxReadFull(ctx, readBuf) _, err = dagmod.CtxReadFull(ctx, readBuf)