diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index dfa72ff2f..fd90899ec 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -108,7 +108,6 @@ type bitswap struct { // GetBlock attempts to retrieve a particular block from peers within the // deadline enforced by the context. func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, error) { - log := log.Prefix("bitswap(%s).GetBlock(%s)", bs.self, k) // Any async work initiated by this function must end when this function // returns. To ensure this, derive a new context. Note that it is okay to @@ -121,11 +120,9 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err ctx = eventlog.ContextWithLoggable(ctx, eventlog.Uuid("GetBlockRequest")) defer log.EventBegin(ctx, "GetBlockRequest", &k).Done() - log.Debugf("GetBlockRequestBegin") defer func() { cancelFunc() - log.Debugf("GetBlockRequestEnd") }() promise, err := bs.GetBlocks(ctx, []u.Key{k}) @@ -150,7 +147,6 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err // resources, provide a context with a reasonably short deadline (ie. not one // that lasts throughout the lifetime of the server) func (bs *bitswap) GetBlocks(ctx context.Context, keys []u.Key) (<-chan *blocks.Block, error) { - // TODO log the request promise := bs.notifications.Subscribe(ctx, keys...) select { @@ -172,18 +168,6 @@ func (bs *bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error { return bs.network.Provide(ctx, blk.Key()) } -func (bs *bitswap) sendWantlistMsgToPeer(ctx context.Context, m bsmsg.BitSwapMessage, p peer.ID) error { - log := log.Prefix("bitswap(%s).bitswap.sendWantlistMsgToPeer(%d, %s)", bs.self, len(m.Wantlist()), p) - - log.Debug("sending wantlist") - if err := bs.send(ctx, p, m); err != nil { - log.Errorf("send wantlist error: %s", err) - return err - } - log.Debugf("send wantlist success") - return nil -} - func (bs *bitswap) sendWantlistMsgToPeers(ctx context.Context, m bsmsg.BitSwapMessage, peers <-chan peer.ID) error { if peers == nil { panic("Cant send wantlist to nil peerchan") @@ -207,7 +191,9 @@ func (bs *bitswap) sendWantlistMsgToPeers(ctx context.Context, m bsmsg.BitSwapMe wg.Add(1) go func(p peer.ID) { defer wg.Done() - bs.sendWantlistMsgToPeer(ctx, m, p) + if err := bs.send(ctx, p, m); err != nil { + log.Error(err) // TODO remove if too verbose + } }(peerToQuery) } wg.Wait() @@ -304,23 +290,19 @@ func (bs *bitswap) clientWorker(parent context.Context) { case <-broadcastSignal: // resend unfulfilled wantlist keys bs.sendWantlistToProviders(ctx) broadcastSignal = time.After(rebroadcastDelay.Get()) - case ks := <-bs.batchRequests: - if len(ks) == 0 { + case keys := <-bs.batchRequests: + if len(keys) == 0 { log.Warning("Received batch request for zero blocks") continue } - for i, k := range ks { + for i, k := range keys { bs.wantlist.Add(k, kMaxPriority-i) } - // NB: send want list to providers for the first peer in this list. - // the assumption is made that the providers of the first key in - // the set are likely to have others as well. - // This currently holds true in most every situation, since when - // pinning a file, you store and provide all blocks associated with - // it. Later, this assumption may not hold as true if we implement - // newer bitswap strategies. + // NB: Optimization. Assumes that providers of key[0] are likely to + // be able to provide for all keys. This currently holds true in most + // every situation. Later, this assumption may not hold as true. child, _ := context.WithTimeout(ctx, providerRequestTimeout) - providers := bs.network.FindProvidersAsync(child, ks[0], maxProvidersPerRequest) + providers := bs.network.FindProvidersAsync(child, keys[0], maxProvidersPerRequest) err := bs.sendWantlistToPeers(ctx, providers) if err != nil { log.Errorf("error sending wantlist: %s", err) diff --git a/exchange/bitswap/decision/engine.go b/exchange/bitswap/decision/engine.go index 05687b312..99c66d0ba 100644 --- a/exchange/bitswap/decision/engine.go +++ b/exchange/bitswap/decision/engine.go @@ -160,6 +160,9 @@ func (e *Engine) Peers() []peer.ID { // MessageReceived performs book-keeping. Returns error if passed invalid // arguments. func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error { + e.lock.Lock() + defer e.lock.Unlock() + log := log.Prefix("bitswap.Engine.MessageReceived(%s)", p) log.Debugf("enter. %d entries %d blocks", len(m.Wantlist()), len(m.Blocks())) defer log.Debugf("exit") @@ -175,9 +178,6 @@ func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error { } }() - e.lock.Lock() - defer e.lock.Unlock() - l := e.findOrCreate(p) if m.Full() { l.wantList = wl.New() diff --git a/repo/config/config.go b/repo/config/config.go index 4c1086e8b..16b6a7896 100644 --- a/repo/config/config.go +++ b/repo/config/config.go @@ -32,7 +32,7 @@ const ( // DefaultConfigFile is the filename of the configuration file DefaultConfigFile = "config" // EnvDir is the environment variable used to change the path root. - EnvDir = "IPFS_DIR" + EnvDir = "IPFS_PATH" ) // PathRoot returns the default configuration root directory diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index 43bd1397d..f19f4fdde 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -67,7 +67,7 @@ test_wait_output_n_lines_60_sec() { test_init_ipfs() { test_expect_success "ipfs init succeeds" ' - export IPFS_DIR="$(pwd)/.go-ipfs" && + export IPFS_PATH="$(pwd)/.go-ipfs" && ipfs init -b=1024 > /dev/null ' diff --git a/test/sharness/t0020-init.sh b/test/sharness/t0020-init.sh index 9b97c6905..5e6995b83 100755 --- a/test/sharness/t0020-init.sh +++ b/test/sharness/t0020-init.sh @@ -9,7 +9,7 @@ test_description="Test init command" . lib/test-lib.sh test_expect_success "ipfs init succeeds" ' - export IPFS_DIR="$(pwd)/.go-ipfs" && + export IPFS_PATH="$(pwd)/.go-ipfs" && ipfs init >actual_init ' @@ -35,7 +35,7 @@ test_expect_success "ipfs peer id looks good" ' test_expect_success "ipfs init output looks good" ' STARTHASH="QmYpv2VEsxzTTXRYX3PjDg961cnJE3kY1YDXLycHGQ3zZB" && - echo "initializing ipfs node at $IPFS_DIR" >expected && + echo "initializing ipfs node at $IPFS_PATH" >expected && echo "generating key pair...done" >>expected && echo "peer identity: $PEERID" >>expected && printf "\\n%s\\n" "to get started, enter: ipfs cat $STARTHASH" >>expected && diff --git a/test/sharness/t0060-daemon.sh b/test/sharness/t0060-daemon.sh index e2a5b6173..32a6b2aad 100755 --- a/test/sharness/t0060-daemon.sh +++ b/test/sharness/t0060-daemon.sh @@ -13,7 +13,7 @@ test_description="Test daemon command" # NOTE: this should remove bootstrap peers (needs a flag) test_expect_success "ipfs daemon --init launches" ' - export IPFS_DIR="$(pwd)/.go-ipfs" && + export IPFS_PATH="$(pwd)/.go-ipfs" && ipfs daemon --init 2>&1 >actual_init & ' @@ -35,7 +35,7 @@ test_expect_success "ipfs peer id looks good" ' # note this is almost the same as t0020-init.sh "ipfs init output looks good" test_expect_success "ipfs daemon output looks good" ' STARTHASH="QmYpv2VEsxzTTXRYX3PjDg961cnJE3kY1YDXLycHGQ3zZB" && - echo "initializing ipfs node at $IPFS_DIR" >expected && + echo "initializing ipfs node at $IPFS_PATH" >expected && echo "generating key pair...done" >>expected && echo "peer identity: $PEERID" >>expected && echo "\nto get started, enter: ipfs cat $STARTHASH" >>expected &&