提交 aeaae901 作者: Jeromy Johnson

Merge pull request #2210 from ipfs/fix/bootstrapping

fix bootstrapping bug and add real test for bootstrapping
......@@ -15,7 +15,6 @@ import (
math2 "github.com/ipfs/go-ipfs/thirdparty/math2"
lgbl "github.com/ipfs/go-ipfs/util/eventlog/loggables"
ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
goprocess "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
procctx "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
periodicproc "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/periodic"
......@@ -211,7 +210,8 @@ func toPeerInfos(bpeers []config.BootstrapPeer) []peer.PeerInfo {
pinfos[bootstrap.ID()] = pinfo
pinfo.ID = bootstrap.ID()
}
pinfo.Addrs = append(pinfo.Addrs, bootstrap.Multiaddr())
pinfo.Addrs = append(pinfo.Addrs, bootstrap.Transport())
}
var peers []peer.PeerInfo
......@@ -222,19 +222,6 @@ func toPeerInfos(bpeers []config.BootstrapPeer) []peer.PeerInfo {
return peers
}
func toPeerInfo(bp config.BootstrapPeer) peer.PeerInfo {
// for now, we drop the "ipfs addr" part of the multiaddr. the rest
// of the codebase currently uses addresses without the peerid part.
m := bp.Multiaddr()
s := ma.Split(m)
m = ma.Join(s[:len(s)-1]...)
return peer.PeerInfo{
ID: bp.ID(),
Addrs: []ma.Multiaddr{m},
}
}
func randomSubsetOfPeers(in []peer.PeerInfo, max int) []peer.PeerInfo {
n := math2.IntMin(max, len(in))
var out []peer.PeerInfo
......
#!/bin/sh
#
# Copyright (c) 2016 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#
# changing the bootstrap peers will require changing it in two places :)
test_description="test node bootstrapping"
. lib/test-lib.sh
test_init_ipfs
test_expect_success "disable mdns" '
ipfs config Discovery.MDNS.Enabled false --json
'
test_launch_ipfs_daemon
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
}
test_expect_success "setup iptb nodes" '
iptb init -n 5 -f --bootstrap=none --port=0
'
test_expect_success "start up iptb nodes" '
iptb start
'
test_expect_success "check peers works" '
ipfs swarm peers >peers_out
'
test_expect_success "correct number of peers" '
test -z "`cat peers_out`"
'
betterwait() {
while kill -0 $1; do true; done
}
test_expect_success "bring down iptb nodes" '
PID0=$(cat "$IPTB_ROOT/0/daemon.pid") &&
PID1=$(cat "$IPTB_ROOT/1/daemon.pid") &&
PID2=$(cat "$IPTB_ROOT/2/daemon.pid") &&
PID3=$(cat "$IPTB_ROOT/3/daemon.pid") &&
PID4=$(cat "$IPTB_ROOT/4/daemon.pid") &&
iptb stop && # TODO: add --wait flag to iptb stop
betterwait $PID0
betterwait $PID1
betterwait $PID2
betterwait $PID3
betterwait $PID4
'
test_expect_success "reset iptb nodes" '
# the api doesnt seem to get cleaned up in sharness tests for some reason
iptb init -n 5 -f --bootstrap=none --port=0
'
test_expect_success "set bootstrap addrs" '
bsn_peer_id=$(ipfs id -f "<id>") &&
BADDR="/ip4/127.0.0.1/tcp/$PORT_SWARM/ipfs/$bsn_peer_id" &&
ipfsi 0 bootstrap add $BADDR &&
ipfsi 1 bootstrap add $BADDR &&
ipfsi 2 bootstrap add $BADDR &&
ipfsi 3 bootstrap add $BADDR &&
ipfsi 4 bootstrap add $BADDR
'
test_expect_success "start up iptb nodes" '
iptb start --wait
'
test_expect_success "check peers works" '
ipfs swarm peers > peers_out
'
test_expect_success "correct number of peers" '
test `cat peers_out | wc -l` = 5
'
test_kill_ipfs_daemon
test_expect_success "bring down iptb nodes" '
iptb stop
'
test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论