From 52da1e32932cd7b536383620848e044fe2533545 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 16 Jan 2016 16:05:46 -0800 Subject: [PATCH] fix bootstrapping bug and add real test for bootstrapping License: MIT Signed-off-by: Jeromy --- core/bootstrap.go | 21 ++------- core/core.go | 2 +- test/sharness/t0121-bootstrap-iptb.sh | 65 +++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 18 deletions(-) create mode 100755 test/sharness/t0121-bootstrap-iptb.sh diff --git a/core/bootstrap.go b/core/bootstrap.go index 35d316332..f40585ff8 100644 --- a/core/bootstrap.go +++ b/core/bootstrap.go @@ -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" @@ -202,7 +201,7 @@ func bootstrapConnect(ctx context.Context, ph host.Host, peers []peer.PeerInfo) return nil } -func toPeerInfos(bpeers []config.BootstrapPeer) []peer.PeerInfo { +func toPeerInfos(bpeers []config.BootstrapPeer) ([]peer.PeerInfo, error) { pinfos := make(map[peer.ID]*peer.PeerInfo) for _, bootstrap := range bpeers { pinfo, ok := pinfos[bootstrap.ID()] @@ -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 @@ -219,20 +219,7 @@ func toPeerInfos(bpeers []config.BootstrapPeer) []peer.PeerInfo { peers = append(peers, *pinfo) } - 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}, - } + return peers, nil } func randomSubsetOfPeers(in []peer.PeerInfo, max int) []peer.PeerInfo { diff --git a/core/core.go b/core/core.go index fa01d4a69..7e2773d6f 100644 --- a/core/core.go +++ b/core/core.go @@ -468,7 +468,7 @@ func (n *IpfsNode) loadBootstrapPeers() ([]peer.PeerInfo, error) { if err != nil { return nil, err } - return toPeerInfos(parsed), nil + return toPeerInfos(parsed) } func (n *IpfsNode) loadFilesRoot() error { diff --git a/test/sharness/t0121-bootstrap-iptb.sh b/test/sharness/t0121-bootstrap-iptb.sh new file mode 100755 index 000000000..ffb60f9c1 --- /dev/null +++ b/test/sharness/t0121-bootstrap-iptb.sh @@ -0,0 +1,65 @@ +#!/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 "set bootstrap addrs" ' + bsn_peer_id=$(ipfs id -f "") && + 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