@cryptotaxi247 / kubo / commits / eb4543651

p2p: allow-custom-protocol option

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Jun 18, 2018 at 02:05 UTC eb45436512be3524fa3ae61519c2f970bcf62d42
2 files changed +21 -2
core/commands/p2p.go
+12 -2
@@ -19,6 +19,7 @@ import (
19 "gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
20 )
21
22 +// P2PProtoPrefix is the default required prefix for protocol names
23 const P2PProtoPrefix = "/x/"
24
25 // P2PListenerInfoOutput is output type of ls command
@@ -91,6 +92,9 @@ Examples:
92 cmdkit.StringArg("listen-address", true, false, "Listening endpoint."),
93 cmdkit.StringArg("target-address", true, false, "Target endpoint."),
94 },
95 + Options: []cmdkit.Option{
96 + cmdkit.BoolOption("allow-custom-protocol", "Don't require /x/ prefix"),
97 + },
98 Run: func(req cmds.Request, res cmds.Response) {
99 n, err := p2pGetNode(req)
100 if err != nil {
@@ -102,8 +106,14 @@ Examples:
106 listen := req.Arguments()[1]
107 target := req.Arguments()[2]
108
105 - if !strings.HasPrefix(proto, P2PProtoPrefix) {
106 - res.SetError(errors.New("protocol name must be within '" + P2PProtoPrefix + "' namespace"), cmdkit.ErrNormal)
109 + allowCustom, _, err := req.Option("allow-custom-protocol").Bool()
110 + if err != nil {
111 + res.SetError(err, cmdkit.ErrNormal)
112 + return
113 + }
114 +
115 + if !allowCustom && !strings.HasPrefix(proto, P2PProtoPrefix) {
116 + res.SetError(errors.New("protocol name must be within '"+P2PProtoPrefix+"' namespace"), cmdkit.ErrNormal)
117 return
118 }
119
test/sharness/t0180-p2p.sh
+9
@@ -239,6 +239,15 @@ test_expect_success "non /x/ scoped protocols are not allowed" '
239
240 check_test_ports
241
242 +test_expect_success 'start p2p listener on custom proto' '
243 + ipfsi 0 p2p forward --allow-custom-protocol /p2p-test /ipfs /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
244 + test_must_be_empty listener-stdouterr.log
245 +'
246 +
247 +test_expect_success 'C->S Close local listener' '
248 + ipfsi 0 p2p close -p /p2p-test
249 +'
250 +
251 test_expect_success 'stop iptb' '
252 iptb stop
253 '