@cryptotaxi247 / kubo / commits / 52da1e329

fix bootstrapping bug and add real test for bootstrapping

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jan 16, 2016 at 16:05 UTC 52da1e32932cd7b536383620848e044fe2533545
3 files changed +70 -18
core/bootstrap.go
+4 -17
@@ -15,7 +15,6 @@ import (
15 math2 "github.com/ipfs/go-ipfs/thirdparty/math2"
16 lgbl "github.com/ipfs/go-ipfs/util/eventlog/loggables"
17
18 - ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
18 goprocess "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess"
19 procctx "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/goprocess/context"
20 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)
201 return nil
202 }
203
205 -func toPeerInfos(bpeers []config.BootstrapPeer) []peer.PeerInfo {
204 +func toPeerInfos(bpeers []config.BootstrapPeer) ([]peer.PeerInfo, error) {
205 pinfos := make(map[peer.ID]*peer.PeerInfo)
206 for _, bootstrap := range bpeers {
207 pinfo, ok := pinfos[bootstrap.ID()]
@@ -211,7 +210,8 @@ func toPeerInfos(bpeers []config.BootstrapPeer) []peer.PeerInfo {
210 pinfos[bootstrap.ID()] = pinfo
211 pinfo.ID = bootstrap.ID()
212 }
214 - pinfo.Addrs = append(pinfo.Addrs, bootstrap.Multiaddr())
213 +
214 + pinfo.Addrs = append(pinfo.Addrs, bootstrap.Transport())
215 }
216
217 var peers []peer.PeerInfo
@@ -219,20 +219,7 @@ func toPeerInfos(bpeers []config.BootstrapPeer) []peer.PeerInfo {
219 peers = append(peers, *pinfo)
220 }
221
222 - return peers
223 -}
224 -
225 -func toPeerInfo(bp config.BootstrapPeer) peer.PeerInfo {
226 - // for now, we drop the "ipfs addr" part of the multiaddr. the rest
227 - // of the codebase currently uses addresses without the peerid part.
228 - m := bp.Multiaddr()
229 - s := ma.Split(m)
230 - m = ma.Join(s[:len(s)-1]...)
231 -
232 - return peer.PeerInfo{
233 - ID: bp.ID(),
234 - Addrs: []ma.Multiaddr{m},
235 - }
222 + return peers, nil
223 }
224
225 func randomSubsetOfPeers(in []peer.PeerInfo, max int) []peer.PeerInfo {
core/core.go
+1 -1
@@ -468,7 +468,7 @@ func (n *IpfsNode) loadBootstrapPeers() ([]peer.PeerInfo, error) {
468 if err != nil {
469 return nil, err
470 }
471 - return toPeerInfos(parsed), nil
471 + return toPeerInfos(parsed)
472 }
473
474 func (n *IpfsNode) loadFilesRoot() error {
test/sharness/t0121-bootstrap-iptb.sh new
+65
@@ -0,0 +1,65 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2016 Jeromy Johnson
4 +# MIT Licensed; see the LICENSE file in this repository.
5 +#
6 +
7 +# changing the bootstrap peers will require changing it in two places :)
8 +test_description="test node bootstrapping"
9 +
10 +. lib/test-lib.sh
11 +
12 +test_init_ipfs
13 +
14 +test_expect_success "disable mdns" '
15 + ipfs config Discovery.MDNS.Enabled false --json
16 +'
17 +
18 +test_launch_ipfs_daemon
19 +
20 +export IPTB_ROOT="`pwd`/.iptb"
21 +
22 +ipfsi() {
23 + dir="$1"
24 + shift
25 + IPFS_PATH="$IPTB_ROOT/$dir" ipfs $@
26 +}
27 +
28 +check_has_connection() {
29 + node=$1
30 + ipfsi $node swarm peers | grep ipfs > /dev/null
31 +}
32 +
33 +test_expect_success "setup iptb nodes" '
34 + iptb init -n 5 -f --bootstrap=none --port=0
35 +'
36 +
37 +test_expect_success "set bootstrap addrs" '
38 + bsn_peer_id=$(ipfs id -f "<id>") &&
39 + BADDR="/ip4/127.0.0.1/tcp/$PORT_SWARM/ipfs/$bsn_peer_id" &&
40 + ipfsi 0 bootstrap add $BADDR &&
41 + ipfsi 1 bootstrap add $BADDR &&
42 + ipfsi 2 bootstrap add $BADDR &&
43 + ipfsi 3 bootstrap add $BADDR &&
44 + ipfsi 4 bootstrap add $BADDR
45 +'
46 +
47 +test_expect_success "start up iptb nodes" '
48 + iptb start --wait
49 +'
50 +
51 +test_expect_success "check peers works" '
52 + ipfs swarm peers > peers_out
53 +'
54 +
55 +test_expect_success "correct number of peers" '
56 + test `cat peers_out | wc -l` == 5
57 +'
58 +
59 +test_kill_ipfs_daemon
60 +
61 +test_expect_success "bring down iptb nodes" '
62 + iptb stop
63 +'
64 +
65 +test_done