Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
1649b44a
Commit
1649b44a
authored
Jan 14, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
combine multiple bootstrap addrs into single peer info
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
3c6a40a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
2 deletions
+45
-2
core/bootstrap.go
core/bootstrap.go
+14
-2
core/bootstrap_test.go
core/bootstrap_test.go
+31
-0
No files found.
core/bootstrap.go
View file @
1649b44a
...
...
@@ -203,10 +203,22 @@ func bootstrapConnect(ctx context.Context, ph host.Host, peers []peer.PeerInfo)
}
func
toPeerInfos
(
bpeers
[]
config
.
BootstrapPeer
)
[]
peer
.
PeerInfo
{
var
peers
[]
peer
.
PeerInfo
pinfos
:=
make
(
map
[
peer
.
ID
]
*
peer
.
PeerInfo
)
for
_
,
bootstrap
:=
range
bpeers
{
peers
=
append
(
peers
,
toPeerInfo
(
bootstrap
))
pinfo
,
ok
:=
pinfos
[
bootstrap
.
ID
()]
if
!
ok
{
pinfo
=
new
(
peer
.
PeerInfo
)
pinfos
[
bootstrap
.
ID
()]
=
pinfo
pinfo
.
ID
=
bootstrap
.
ID
()
}
pinfo
.
Addrs
=
append
(
pinfo
.
Addrs
,
bootstrap
.
Multiaddr
())
}
var
peers
[]
peer
.
PeerInfo
for
_
,
pinfo
:=
range
pinfos
{
peers
=
append
(
peers
,
*
pinfo
)
}
return
peers
}
...
...
core/bootstrap_test.go
View file @
1649b44a
package
core
import
(
"fmt"
"testing"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
config
"github.com/ipfs/go-ipfs/repo/config"
testutil
"github.com/ipfs/go-ipfs/util/testutil"
)
...
...
@@ -23,3 +25,32 @@ func TestSubsetWhenMaxIsGreaterThanLengthOfSlice(t *testing.T) {
t
.
Fail
()
}
}
func
TestMultipleAddrsPerPeer
(
t
*
testing
.
T
)
{
var
bsps
[]
config
.
BootstrapPeer
for
i
:=
0
;
i
<
10
;
i
++
{
pid
,
err
:=
testutil
.
RandPeerID
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
addr
:=
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/5001/ipfs/%s"
,
pid
.
Pretty
())
bsp1
,
err
:=
config
.
ParseBootstrapPeer
(
addr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
addr
=
fmt
.
Sprintf
(
"/ip4/127.0.0.1/udp/5002/utp/ipfs/%s"
,
pid
.
Pretty
())
bsp2
,
err
:=
config
.
ParseBootstrapPeer
(
addr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
bsps
=
append
(
bsps
,
bsp1
,
bsp2
)
}
pinfos
:=
toPeerInfos
(
bsps
)
if
len
(
pinfos
)
!=
len
(
bsps
)
/
2
{
t
.
Fatal
(
"expected fewer peers"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment