diff --git a/core/commands/p2p.go b/core/commands/p2p.go index daa904e43..f5b8eab99 100644 --- a/core/commands/p2p.go +++ b/core/commands/p2p.go @@ -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 } diff --git a/test/sharness/t0180-p2p.sh b/test/sharness/t0180-p2p.sh index ce6399918..10207a384 100755 --- a/test/sharness/t0180-p2p.sh +++ b/test/sharness/t0180-p2p.sh @@ -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 '