Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
c67b87ce
Unverified
Commit
c67b87ce
authored
Aug 21, 2018
by
Steven Allen
Committed by
GitHub
Aug 21, 2018
Browse files
Merge pull request #400 from rargulati/add-secure-tpt-to-set
Ensure duplicate transports are filtered
parents
7d6f9521
6e72e884
Changes
3
Show whitespace changes
Inline
Side-by-side
config/muxer.go
View file @
c67b87ce
...
@@ -50,6 +50,7 @@ func makeMuxer(h host.Host, tpts []MsMuxC) (mux.Transport, error) {
...
@@ -50,6 +50,7 @@ func makeMuxer(h host.Host, tpts []MsMuxC) (mux.Transport, error) {
if
_
,
ok
:=
transportSet
[
tptC
.
ID
];
ok
{
if
_
,
ok
:=
transportSet
[
tptC
.
ID
];
ok
{
return
nil
,
fmt
.
Errorf
(
"duplicate muxer transport: %s"
,
tptC
.
ID
)
return
nil
,
fmt
.
Errorf
(
"duplicate muxer transport: %s"
,
tptC
.
ID
)
}
}
transportSet
[
tptC
.
ID
]
=
struct
{}{}
}
}
for
_
,
tptC
:=
range
tpts
{
for
_
,
tptC
:=
range
tpts
{
tpt
,
err
:=
tptC
.
MuxC
(
h
)
tpt
,
err
:=
tptC
.
MuxC
(
h
)
...
...
config/muxer_test.go
View file @
c67b87ce
package
config
package
config
import
(
import
(
"context"
"testing"
"testing"
host
"github.com/libp2p/go-libp2p-host"
peer
"github.com/libp2p/go-libp2p-peer"
peer
"github.com/libp2p/go-libp2p-peer"
swarmt
"github.com/libp2p/go-libp2p-swarm/testing"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
mux
"github.com/libp2p/go-stream-muxer"
mux
"github.com/libp2p/go-stream-muxer"
yamux
"github.com/whyrusleeping/go-smux-yamux"
yamux
"github.com/whyrusleeping/go-smux-yamux"
)
)
...
@@ -52,3 +56,46 @@ func TestMuxerBadTypes(t *testing.T) {
...
@@ -52,3 +56,46 @@ func TestMuxerBadTypes(t *testing.T) {
}
}
}
}
}
}
func
TestCatchDuplicateTransportsMuxer
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
h
:=
bhost
.
New
(
swarmt
.
GenSwarm
(
t
,
ctx
))
yamuxMuxer
,
err
:=
MuxerConstructor
(
yamux
.
DefaultTransport
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
var
tests
=
map
[
string
]
struct
{
h
host
.
Host
transports
[]
MsMuxC
expectedError
string
}{
"no duplicate transports"
:
{
h
:
h
,
transports
:
[]
MsMuxC
{
MsMuxC
{
yamuxMuxer
,
"yamux"
}},
expectedError
:
""
,
},
"duplicate transports"
:
{
h
:
h
,
transports
:
[]
MsMuxC
{
MsMuxC
{
yamuxMuxer
,
"yamux"
},
MsMuxC
{
yamuxMuxer
,
"yamux"
},
},
expectedError
:
"duplicate muxer transport: yamux"
,
},
}
for
testName
,
test
:=
range
tests
{
t
.
Run
(
testName
,
func
(
t
*
testing
.
T
)
{
_
,
err
=
makeMuxer
(
test
.
h
,
test
.
transports
)
if
err
!=
nil
{
if
err
.
Error
()
!=
test
.
expectedError
{
t
.
Errorf
(
"
\n
expected: [%v]
\n
actual: [%v]
\n
"
,
test
.
expectedError
,
err
,
)
}
}
})
}
}
config/security.go
View file @
c67b87ce
...
@@ -61,6 +61,7 @@ func makeSecurityTransport(h host.Host, tpts []MsSecC) (security.Transport, erro
...
@@ -61,6 +61,7 @@ func makeSecurityTransport(h host.Host, tpts []MsSecC) (security.Transport, erro
if
_
,
ok
:=
transportSet
[
tptC
.
ID
];
ok
{
if
_
,
ok
:=
transportSet
[
tptC
.
ID
];
ok
{
return
nil
,
fmt
.
Errorf
(
"duplicate security transport: %s"
,
tptC
.
ID
)
return
nil
,
fmt
.
Errorf
(
"duplicate security transport: %s"
,
tptC
.
ID
)
}
}
transportSet
[
tptC
.
ID
]
=
struct
{}{}
}
}
for
_
,
tptC
:=
range
tpts
{
for
_
,
tptC
:=
range
tpts
{
tpt
,
err
:=
tptC
.
SecC
(
h
)
tpt
,
err
:=
tptC
.
SecC
(
h
)
...
...
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