mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +08:00
fix random bitswap hangs
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -56,6 +56,8 @@ type msgQueue struct {
|
|||||||
out bsmsg.BitSwapMessage
|
out bsmsg.BitSwapMessage
|
||||||
network bsnet.BitSwapNetwork
|
network bsnet.BitSwapNetwork
|
||||||
|
|
||||||
|
refcnt int
|
||||||
|
|
||||||
work chan struct{}
|
work chan struct{}
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
}
|
}
|
||||||
@ -101,13 +103,13 @@ func (pm *WantManager) SendBlock(ctx context.Context, env *engine.Envelope) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pm *WantManager) startPeerHandler(p peer.ID) *msgQueue {
|
func (pm *WantManager) startPeerHandler(p peer.ID) *msgQueue {
|
||||||
_, ok := pm.peers[p]
|
mq, ok := pm.peers[p]
|
||||||
if ok {
|
if ok {
|
||||||
// TODO: log an error?
|
mq.refcnt++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mq := pm.newMsgQueue(p)
|
mq = pm.newMsgQueue(p)
|
||||||
|
|
||||||
// new peer, we will want to give them our full wantlist
|
// new peer, we will want to give them our full wantlist
|
||||||
fullwantlist := bsmsg.New(true)
|
fullwantlist := bsmsg.New(true)
|
||||||
@ -129,6 +131,11 @@ func (pm *WantManager) stopPeerHandler(p peer.ID) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pq.refcnt--
|
||||||
|
if pq.refcnt > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
close(pq.done)
|
close(pq.done)
|
||||||
delete(pm.peers, p)
|
delete(pm.peers, p)
|
||||||
}
|
}
|
||||||
@ -247,6 +254,7 @@ func (wm *WantManager) newMsgQueue(p peer.ID) *msgQueue {
|
|||||||
mq.work = make(chan struct{}, 1)
|
mq.work = make(chan struct{}, 1)
|
||||||
mq.network = wm.network
|
mq.network = wm.network
|
||||||
mq.p = p
|
mq.p = p
|
||||||
|
mq.refcnt = 1
|
||||||
|
|
||||||
return mq
|
return mq
|
||||||
}
|
}
|
||||||
|
81
test/sharness/t0130-multinode.sh
Executable file
81
test/sharness/t0130-multinode.sh
Executable file
@ -0,0 +1,81 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2015 Jeromy Johnson
|
||||||
|
# MIT Licensed; see the LICENSE file in this repository.
|
||||||
|
#
|
||||||
|
|
||||||
|
test_description="Test multiple ipfs nodes"
|
||||||
|
|
||||||
|
. lib/test-lib.sh
|
||||||
|
|
||||||
|
export IPTB_ROOT="`pwd`/.iptb"
|
||||||
|
|
||||||
|
ipfsi() {
|
||||||
|
dir="$1"
|
||||||
|
shift
|
||||||
|
IPFS_PATH="$IPTB_ROOT/$dir" ipfs $@
|
||||||
|
}
|
||||||
|
|
||||||
|
check_has_connection() {
|
||||||
|
node=$1
|
||||||
|
ipfsi $node swarm peers | grep ipfs > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
startup_cluster() {
|
||||||
|
test_expect_success "start up nodes" '
|
||||||
|
iptb start
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "connect nodes to eachother" '
|
||||||
|
iptb connect [1-4] 0
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "nodes are connected" '
|
||||||
|
check_has_connection 0 &&
|
||||||
|
check_has_connection 1 &&
|
||||||
|
check_has_connection 2 &&
|
||||||
|
check_has_connection 3 &&
|
||||||
|
check_has_connection 4
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
check_file_fetch() {
|
||||||
|
node=$1
|
||||||
|
fhash=$2
|
||||||
|
fname=$3
|
||||||
|
|
||||||
|
test_expect_success "can fetch file" '
|
||||||
|
ipfsi $node cat $fhash > fetch_out
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "file looks good" '
|
||||||
|
test_cmp $fname fetch_out
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
run_basic_test() {
|
||||||
|
startup_cluster
|
||||||
|
|
||||||
|
test_expect_success "add a file on node1" '
|
||||||
|
random 1000000 > filea &&
|
||||||
|
FILEA_HASH=$(ipfsi 1 add -q filea)
|
||||||
|
'
|
||||||
|
|
||||||
|
check_file_fetch 4 $FILEA_HASH filea
|
||||||
|
check_file_fetch 3 $FILEA_HASH filea
|
||||||
|
check_file_fetch 2 $FILEA_HASH filea
|
||||||
|
check_file_fetch 1 $FILEA_HASH filea
|
||||||
|
check_file_fetch 0 $FILEA_HASH filea
|
||||||
|
|
||||||
|
test_expect_success "shut down nodes" '
|
||||||
|
iptb stop
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
test_expect_success "set up tcp testbed" '
|
||||||
|
iptb init -n 5 -p 0 -f --bootstrap=none
|
||||||
|
'
|
||||||
|
|
||||||
|
run_basic_test
|
||||||
|
|
||||||
|
test_done
|
Reference in New Issue
Block a user