提交 eb454365 作者: Łukasz Magiera

p2p: allow-custom-protocol option

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 c1910281
......@@ -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
}
......
......@@ -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
'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论