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
597bf2a4
Commit
597bf2a4
authored
Oct 25, 2018
by
Overbool
Committed by
Steven Allen
Mar 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(swarm): collect maddr by channel
License: MIT Signed-off-by:
Overbool
<
overbool.xu@gmail.com
>
parent
309cf705
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
4 deletions
+21
-4
core/commands/swarm.go
core/commands/swarm.go
+21
-4
No files found.
core/commands/swarm.go
View file @
597bf2a4
...
...
@@ -7,7 +7,6 @@ import (
"io"
"path"
"sort"
"strings"
"sync"
"time"
...
...
@@ -25,6 +24,7 @@ import (
pstore
"github.com/libp2p/go-libp2p-peerstore"
swarm
"github.com/libp2p/go-libp2p-swarm"
ma
"github.com/multiformats/go-multiaddr"
madns
"github.com/multiformats/go-multiaddr-dns"
mafilter
"github.com/whyrusleeping/multiaddr-filter"
)
...
...
@@ -505,13 +505,27 @@ func resolveAddresses(addrs []string) ([]ma.Multiaddr, error) {
var
wg
sync
.
WaitGroup
resolveErrC
:=
make
(
chan
error
,
len
(
addrs
))
maddrC
:=
make
(
chan
ma
.
Multiaddr
)
go
func
()
{
for
{
select
{
case
maddr
,
ok
:=
<-
maddrC
:
if
!
ok
{
return
}
maddrs
=
append
(
maddrs
,
maddr
)
}
}
}()
for
_
,
addr
:=
range
addrs
{
maddr
,
err
:=
ma
.
NewMultiaddr
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
// check whether address ends in `ipfs/Qm...`
if
_
,
err
:=
ma
ddr
.
ValueForProtocol
(
ma
.
P_IPFS
);
err
!=
ma
.
ErrProtocolNotFound
{
if
_
,
last
:=
ma
.
SplitLast
(
maddr
);
last
.
Protocol
()
.
Code
==
ma
.
P_IPFS
{
maddrs
=
append
(
maddrs
,
maddr
)
continue
}
...
...
@@ -531,14 +545,17 @@ func resolveAddresses(addrs []string) ([]ma.Multiaddr, error) {
}
// filter out addresses that still doesn't end in `ipfs/Qm...`
for
_
,
raddr
:=
range
raddrs
{
if
_
,
err
:=
raddr
.
ValueForProtocol
(
ma
.
P_IPFS
);
err
!=
ma
.
ErrProtocolNotFound
{
maddrs
=
append
(
maddrs
,
raddr
)
if
_
,
last
:=
ma
.
SplitLast
(
raddr
);
last
.
Protocol
()
.
Code
==
ma
.
P_IPFS
{
maddrC
<-
raddr
continue
}
}
}(
maddr
)
}
// wait for address resolving
wg
.
Wait
()
// close the channel of collecting multiaddr
close
(
maddrC
)
select
{
case
err
:=
<-
resolveErrC
:
...
...
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