From df9e6ce640fa4713640585f7a29a31d38691073a Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Mon, 19 Jan 2015 00:02:43 -0800 Subject: [PATCH 1/6] refactor: rename IPFS_DIR -> IPFS_PATH closes #394 https://github.com/jbenet/go-ipfs/issues/394 --- repo/config/config.go | 2 +- test/sharness/lib/test-lib.sh | 2 +- test/sharness/t0020-init.sh | 4 ++-- test/sharness/t0060-daemon.sh | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) 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 && From aa4c0d1b9043bdb62caedb6da36e1dbf05622f7c Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Sun, 18 Jan 2015 23:40:23 -0800 Subject: [PATCH 2/6] fix(bitswap): release the lock last The area above the lock was getting big. Moving this up to avoid mistakes down the road. --- exchange/bitswap/decision/engine.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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() From 3d3ac08fcf1498ce4ec974e961a99f7b80013163 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Sun, 18 Jan 2015 20:30:23 -0800 Subject: [PATCH 3/6] chore(bitswap): rm debug log (covered by eventlog) --- exchange/bitswap/bitswap.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index dfa72ff2f..b80b13f98 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}) From 129d413f0ee8771a65581f21d93a6f86683c6367 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Sun, 18 Jan 2015 20:30:50 -0800 Subject: [PATCH 4/6] chore(bitswap): rm todo --- exchange/bitswap/bitswap.go | 1 - 1 file changed, 1 deletion(-) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index b80b13f98..d313713c1 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -147,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 { From 2f247f33557df663b85370c8c742c4f1df6ee2d4 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Sun, 18 Jan 2015 20:34:06 -0800 Subject: [PATCH 5/6] rm logging statements and inline `send` --- exchange/bitswap/bitswap.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index d313713c1..8019fab6e 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -168,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") @@ -203,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() From bb89e0d8d739cbd7a65d9a488b0f6bc9576c7f2c Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Sun, 18 Jan 2015 20:39:09 -0800 Subject: [PATCH 6/6] misc(bitswap): shorten comment and rename var --- exchange/bitswap/bitswap.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index 8019fab6e..fd90899ec 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -290,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)