1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-24 14:08:13 +08:00

p2p: allow-custom-protocol option

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera
2018-06-18 02:05:10 +02:00
parent c19102816f
commit eb45436512
2 changed files with 21 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import (
"gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
)
// P2PProtoPrefix is the default required prefix for protocol names
const P2PProtoPrefix = "/x/"
// P2PListenerInfoOutput is output type of ls command
@ -91,6 +92,9 @@ Examples:
cmdkit.StringArg("listen-address", true, false, "Listening endpoint."),
cmdkit.StringArg("target-address", true, false, "Target endpoint."),
},
Options: []cmdkit.Option{
cmdkit.BoolOption("allow-custom-protocol", "Don't require /x/ prefix"),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := p2pGetNode(req)
if err != nil {
@ -102,8 +106,14 @@ Examples:
listen := req.Arguments()[1]
target := req.Arguments()[2]
if !strings.HasPrefix(proto, P2PProtoPrefix) {
res.SetError(errors.New("protocol name must be within '" + P2PProtoPrefix + "' namespace"), cmdkit.ErrNormal)
allowCustom, _, err := req.Option("allow-custom-protocol").Bool()
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}
if !allowCustom && !strings.HasPrefix(proto, P2PProtoPrefix) {
res.SetError(errors.New("protocol name must be within '"+P2PProtoPrefix+"' namespace"), cmdkit.ErrNormal)
return
}

View File

@ -239,6 +239,15 @@ test_expect_success "non /x/ scoped protocols are not allowed" '
check_test_ports
test_expect_success 'start p2p listener on custom proto' '
ipfsi 0 p2p forward --allow-custom-protocol /p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
test_must_be_empty listener-stdouterr.log
'
test_expect_success 'C->S Close local listener' '
ipfsi 0 p2p close -p /p2p-test
'
test_expect_success 'stop iptb' '
iptb stop
'