mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-03 23:38:07 +08:00
fix bootstrapping bug and add real test for bootstrapping
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
parent
f89a915ca0
commit
52da1e3293
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
65
test/sharness/t0121-bootstrap-iptb.sh
Executable file
65
test/sharness/t0121-bootstrap-iptb.sh
Executable file
@ -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 "<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
|
||||
Loading…
Reference in New Issue
Block a user