PTP API: Rename Corenet to PTP
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Jun 2, 2017 at 22:00 UTC
ad9ae350bf2069644a3125c85a16ed15f68570ff
13 files changed
+261
-263
core/commands/ptp.go
renamed
+51
-53
@@ -9,20 +9,20 @@ import (
9
"text/tabwriter"
10
11
cmds "github.com/ipfs/go-ipfs/commands"
12
- "github.com/ipfs/go-ipfs/core"
13
- cnet "github.com/ipfs/go-ipfs/corenet/net"
12
+ core "github.com/ipfs/go-ipfs/core"
13
+ ptpnet "github.com/ipfs/go-ipfs/ptp/net"
14
15
ma "gx/ipfs/QmcyqRMCAXVtYPS4DiBrA7sezL9rRGfW8Ctx7cywL4TXJj/go-multiaddr"
16
)
17
18
-// CorenetAppInfoOutput is output type of ls command
19
-type CorenetAppInfoOutput struct {
18
+// PTPAppInfoOutput is output type of ls command
19
+type PTPAppInfoOutput struct {
20
Protocol string
21
Address string
22
}
23
24
-// CorenetStreamInfoOutput is output type of streams command
25
-type CorenetStreamInfoOutput struct {
24
+// PTPStreamInfoOutput is output type of streams command
25
+type PTPStreamInfoOutput struct {
26
HandlerID string
27
Protocol string
28
LocalPeer string
@@ -31,38 +31,38 @@ type CorenetStreamInfoOutput struct {
31
RemoteAddress string
32
}
33
34
-// CorenetLsOutput is output type of ls command
35
-type CorenetLsOutput struct {
36
- Apps []CorenetAppInfoOutput
34
+// PTPLsOutput is output type of ls command
35
+type PTPLsOutput struct {
36
+ Apps []PTPAppInfoOutput
37
}
38
39
-// CorenetStreamsOutput is output type of streams command
40
-type CorenetStreamsOutput struct {
41
- Streams []CorenetStreamInfoOutput
39
+// PTPStreamsOutput is output type of streams command
40
+type PTPStreamsOutput struct {
41
+ Streams []PTPStreamInfoOutput
42
}
43
44
-// CorenetCmd is the 'ipfs corenet' command
45
-var CorenetCmd = &cmds.Command{
44
+// PTPCmd is the 'ipfs ptp' command
45
+var PTPCmd = &cmds.Command{
46
Helptext: cmds.HelpText{
47
Tagline: "Libp2p stream mounting.",
48
ShortDescription: `
49
-Expose a local application to remote peers over libp2p
49
+Create and use tunnels to remote peers over libp2p
50
51
Note: this command is experimental and subject to change as usecases and APIs are refined`,
52
},
53
54
Subcommands: map[string]*cmds.Command{
55
- "ls": corenetLsCmd,
56
- "streams": corenetStreamsCmd,
57
- "dial": corenetDialCmd,
58
- "listen": corenetListenCmd,
59
- "close": corenetCloseCmd,
55
+ "ls": ptpLsCmd,
56
+ "streams": ptpStreamsCmd,
57
+ "dial": ptpDialCmd,
58
+ "listen": ptpListenCmd,
59
+ "close": ptpCloseCmd,
60
},
61
}
62
63
-var corenetLsCmd = &cmds.Command{
63
+var ptpLsCmd = &cmds.Command{
64
Helptext: cmds.HelpText{
65
- Tagline: "List active application protocol listeners.",
65
+ Tagline: "List active p2p listeners.",
66
},
67
Options: []cmds.Option{
68
cmds.BoolOption("headers", "v", "Print table headers (HandlerID, Protocol, Local, Remote).").Default(false),
@@ -85,10 +85,10 @@ var corenetLsCmd = &cmds.Command{
85
return
86
}
87
88
- output := &CorenetLsOutput{}
88
+ output := &PTPLsOutput{}
89
90
- for _, app := range n.Corenet.Apps.Apps {
91
- output.Apps = append(output.Apps, CorenetAppInfoOutput{
90
+ for _, app := range n.PTP.Apps.Apps {
91
+ output.Apps = append(output.Apps, PTPAppInfoOutput{
92
Protocol: app.Protocol,
93
Address: app.Address.String(),
94
})
@@ -96,11 +96,11 @@ var corenetLsCmd = &cmds.Command{
96
97
res.SetOutput(output)
98
},
99
- Type: CorenetLsOutput{},
99
+ Type: PTPLsOutput{},
100
Marshalers: cmds.MarshalerMap{
101
cmds.Text: func(res cmds.Response) (io.Reader, error) {
102
headers, _, _ := res.Request().Option("headers").Bool()
103
- list, _ := res.Output().(*CorenetLsOutput)
103
+ list, _ := res.Output().(*PTPLsOutput)
104
buf := new(bytes.Buffer)
105
w := tabwriter.NewWriter(buf, 1, 2, 1, ' ', 0)
106
for _, app := range list.Apps {
@@ -117,12 +117,12 @@ var corenetLsCmd = &cmds.Command{
117
},
118
}
119
120
-var corenetStreamsCmd = &cmds.Command{
120
+var ptpStreamsCmd = &cmds.Command{
121
Helptext: cmds.HelpText{
122
- Tagline: "List active application protocol streams.",
122
+ Tagline: "List active p2p streams.",
123
},
124
Options: []cmds.Option{
125
- cmds.BoolOption("headers", "v", "Print table headers (HandlerID, Protocol, Local, Remote).").Default(false),
125
+ cmds.BoolOption("headers", "v", "Print table headers (HagndlerID, Protocol, Local, Remote).").Default(false),
126
},
127
Run: func(req cmds.Request, res cmds.Response) {
128
n, err := req.InvocContext().GetNode()
@@ -142,10 +142,10 @@ var corenetStreamsCmd = &cmds.Command{
142
return
143
}
144
145
- output := &CorenetStreamsOutput{}
145
+ output := &PTPStreamsOutput{}
146
147
- for _, s := range n.Corenet.Streams.Streams {
148
- output.Streams = append(output.Streams, CorenetStreamInfoOutput{
147
+ for _, s := range n.PTP.Streams.Streams {
148
+ output.Streams = append(output.Streams, PTPStreamInfoOutput{
149
HandlerID: strconv.FormatUint(s.HandlerID, 10),
150
151
Protocol: s.Protocol,
@@ -160,11 +160,11 @@ var corenetStreamsCmd = &cmds.Command{
160
161
res.SetOutput(output)
162
},
163
- Type: CorenetStreamsOutput{},
163
+ Type: PTPStreamsOutput{},
164
Marshalers: cmds.MarshalerMap{
165
cmds.Text: func(res cmds.Response) (io.Reader, error) {
166
headers, _, _ := res.Request().Option("headers").Bool()
167
- list, _ := res.Output().(*CorenetStreamsOutput)
167
+ list, _ := res.Output().(*PTPStreamsOutput)
168
buf := new(bytes.Buffer)
169
w := tabwriter.NewWriter(buf, 1, 2, 1, ' ', 0)
170
for _, stream := range list.Streams {
@@ -181,12 +181,11 @@ var corenetStreamsCmd = &cmds.Command{
181
},
182
}
183
184
-var corenetListenCmd = &cmds.Command{
184
+var ptpListenCmd = &cmds.Command{
185
Helptext: cmds.HelpText{
186
Tagline: "Create application protocol listener and proxy to network multiaddr.",
187
ShortDescription: `
188
-Register a p2p connection handler and proxies the connections to a specified
189
-address.
188
+Register a p2p connection handler and proxies the connections to a specified address.
189
190
Note that the connections originate from the ipfs daemon process.
191
`,
@@ -214,7 +213,7 @@ Note that the connections originate from the ipfs daemon process.
213
}
214
215
proto := "/app/" + req.Arguments()[0]
217
- if cnet.CheckProtoExists(n, proto) {
216
+ if ptpnet.CheckProtoExists(n, proto) {
217
res.SetError(errors.New("protocol handler already registered"), cmds.ErrNormal)
218
return
219
}
@@ -225,30 +224,30 @@ Note that the connections originate from the ipfs daemon process.
224
return
225
}
226
228
- _, err = cnet.NewListener(n, proto, addr)
227
+ _, err = ptpnet.NewListener(n, proto, addr)
228
if err != nil {
229
res.SetError(err, cmds.ErrNormal)
230
return
231
}
232
233
// Successful response.
235
- res.SetOutput(&CorenetAppInfoOutput{
234
+ res.SetOutput(&PTPAppInfoOutput{
235
Protocol: proto,
236
Address: addr.String(),
237
})
238
},
239
}
240
242
-var corenetDialCmd = &cmds.Command{
241
+var ptpDialCmd = &cmds.Command{
242
Helptext: cmds.HelpText{
244
- Tagline: "Dial to an application service.",
243
+ Tagline: "Dial to a p2p listener.",
244
245
ShortDescription: `
246
Establish a new connection to a peer service.
247
248
When a connection is made to a peer service the ipfs daemon will setup one time
249
TCP listener and return it's bind port, this way a dialing application can
251
-transparently connect to a corenet service.
250
+transparently connect to a p2p service.
251
`,
252
},
253
Arguments: []cmds.Argument{
@@ -291,13 +290,13 @@ transparently connect to a corenet service.
290
}
291
}
292
294
- app, err := cnet.Dial(n, addr, peer, proto, bindAddr)
293
+ app, err := ptpnet.Dial(n, addr, peer, proto, bindAddr)
294
if err != nil {
295
res.SetError(err, cmds.ErrNormal)
296
return
297
}
298
300
- output := CorenetAppInfoOutput{
299
+ output := PTPAppInfoOutput{
300
Protocol: app.Protocol,
301
Address: app.Address.String(),
302
}
@@ -306,13 +305,12 @@ transparently connect to a corenet service.
305
},
306
}
307
309
-var corenetCloseCmd = &cmds.Command{
308
+var ptpCloseCmd = &cmds.Command{
309
Helptext: cmds.HelpText{
311
- Tagline: "Closes an active stream listener or client.",
310
+ Tagline: "Closes an active p2p stream or listener.",
311
},
312
Arguments: []cmds.Argument{
314
- cmds.StringArg("HandlerID", false, false, "Application listener or client HandlerID"),
315
- cmds.StringArg("Protocol", false, false, "Application listener or client HandlerID"),
313
+ cmds.StringArg("Identifier", false, false, "Stream HandlerID or p2p listener protocol"),
314
},
315
Options: []cmds.Option{
316
cmds.BoolOption("all", "a", "Close all streams and listeners.").Default(false),
@@ -344,7 +342,7 @@ var corenetCloseCmd = &cmds.Command{
342
343
if !closeAll {
344
if len(req.Arguments()) == 0 {
347
- res.SetError(errors.New("no handlerID nor stream protocol specified"), cmds.ErrNormal)
345
+ res.SetError(errors.New("no handlerID nor listener protocol specified"), cmds.ErrNormal)
346
return
347
}
348
@@ -357,7 +355,7 @@ var corenetCloseCmd = &cmds.Command{
355
}
356
357
if closeAll || useHandlerID {
360
- for _, stream := range n.Corenet.Streams.Streams {
358
+ for _, stream := range n.PTP.Streams.Streams {
359
if !closeAll && handlerID != stream.HandlerID {
360
continue
361
}
@@ -369,7 +367,7 @@ var corenetCloseCmd = &cmds.Command{
367
}
368
369
if closeAll || !useHandlerID {
372
- for _, app := range n.Corenet.Apps.Apps {
370
+ for _, app := range n.PTP.Apps.Apps {
371
if !closeAll && app.Protocol != proto {
372
continue
373
}
core/commands/root.go
+2
-2
@@ -47,7 +47,7 @@ ADVANCED COMMANDS
47
pin Pin objects to local storage
48
repo Manipulate the IPFS repository
49
stats Various operational stats
50
- corenet Libp2p stream mounting
50
+ ptp Libp2p stream mounting
51
filestore Manage the filestore (experimental)
52
53
NETWORK COMMANDS
@@ -99,7 +99,6 @@ var rootSubcommands = map[string]*cmds.Command{
99
"cat": CatCmd,
100
"commands": CommandsDaemonCmd,
101
"config": ConfigCmd,
102
- "corenet": CorenetCmd,
102
"dag": dag.DagCmd,
103
"dht": DhtCmd,
104
"diag": DiagCmd,
@@ -115,6 +114,7 @@ var rootSubcommands = map[string]*cmds.Command{
114
"object": ocmd.ObjectCmd,
115
"pin": PinCmd,
116
"ping": PingCmd,
117
+ "ptp": PTPCmd,
118
"pubsub": PubsubCmd,
119
"refs": RefsCmd,
120
"repo": RepoCmd,
core/core.go
+3
-3
@@ -23,7 +23,7 @@ import (
23
24
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
25
bserv "github.com/ipfs/go-ipfs/blockservice"
26
- corenet "github.com/ipfs/go-ipfs/corenet"
26
+ ptp "github.com/ipfs/go-ipfs/ptp"
27
exchange "github.com/ipfs/go-ipfs/exchange"
28
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
29
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
@@ -132,7 +132,7 @@ type IpfsNode struct {
132
IpnsRepub *ipnsrp.Republisher
133
134
Floodsub *floodsub.PubSub
135
- Corenet *corenet.Corenet
135
+ PTP *ptp.PTP
136
137
proc goprocess.Process
138
ctx context.Context
@@ -248,7 +248,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
248
n.Floodsub = floodsub.NewFloodSub(ctx, peerhost)
249
}
250
251
- n.Corenet = corenet.NewCorenet()
251
+ n.PTP = ptp.NewPTP()
252
253
// setup local discovery
254
if do != nil {
corenet/corenet.go
deleted
-12
@@ -1,12 +0,0 @@
1
-package corenet
2
-
3
-// Corenet structure holds information on currently running streams/apps
4
-type Corenet struct {
5
- Apps AppRegistry
6
- Streams StreamRegistry
7
-}
8
-
9
-// NewCorenet creates new Corenet struct
10
-func NewCorenet() *Corenet {
11
- return &Corenet{}
12
-}
ptp/listeners.go
renamed
+15
-15
@@ -1,4 +1,4 @@
1
-package corenet
1
+package ptp
2
3
import (
4
"io"
@@ -8,8 +8,8 @@ import (
8
"fmt"
9
)
10
11
-// AppInfo holds information on a local application protocol listener service.
12
-type AppInfo struct {
11
+// ListenerInfo holds information on a p2p listener.
12
+type ListenerInfo struct {
13
// Application protocol identifier.
14
Protocol string
15
@@ -26,30 +26,30 @@ type AppInfo struct {
26
// whether this application listener has been shutdown.
27
Running bool
28
29
- Registry *AppRegistry
29
+ Registry *ListenerRegistry
30
}
31
32
// Close closes the listener. Does not affect child streams
33
-func (c *AppInfo) Close() error {
33
+func (c *ListenerInfo) Close() error {
34
c.Closer.Close()
35
err := c.Registry.Deregister(c.Protocol)
36
return err
37
}
38
39
-// AppRegistry is a collection of local application protocol listeners.
40
-type AppRegistry struct {
41
- Apps []*AppInfo
39
+// ListenerRegistry is a collection of local application protocol listeners.
40
+type ListenerRegistry struct {
41
+ Listeners []*ListenerInfo
42
}
43
44
-// Register registers appInfo in this registry
45
-func (c *AppRegistry) Register(appInfo *AppInfo) {
46
- c.Apps = append(c.Apps, appInfo)
44
+// Register registers listenerInfo in this registry
45
+func (c *ListenerRegistry) Register(listenerInfo *ListenerInfo) {
46
+ c.Listeners = append(c.Listeners, listenerInfo)
47
}
48
49
-// Deregister deregisters protocol handler from this registry
50
-func (c *AppRegistry) Deregister(proto string) error {
49
+// Deregister removes p2p listener from this registry
50
+func (c *ListenerRegistry) Deregister(proto string) error {
51
foundAt := -1
52
- for i, a := range c.Apps {
52
+ for i, a := range c.Listeners {
53
if a.Protocol == proto {
54
foundAt = i
55
break
@@ -57,7 +57,7 @@ func (c *AppRegistry) Deregister(proto string) error {
57
}
58
59
if foundAt != -1 {
60
- c.Apps = append(c.Apps[:foundAt], c.Apps[foundAt+1:]...)
60
+ c.Listeners = append(c.Listeners[:foundAt], c.Listeners[foundAt+1:]...)
61
return nil
62
}
63
ptp/net/dial.go
renamed
+7
-7
@@ -4,7 +4,7 @@ import (
4
"errors"
5
6
core "github.com/ipfs/go-ipfs/core"
7
- corenet "github.com/ipfs/go-ipfs/corenet"
7
+ ptp "github.com/ipfs/go-ipfs/ptp"
8
9
net "gx/ipfs/QmRscs8KxrSmSv4iuevHv8JfuUzHBMoqiaHzxfDRiksd6e/go-libp2p-net"
10
peerstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
@@ -13,13 +13,13 @@ import (
13
manet "gx/ipfs/Qmf1Gq7N45Rpuw7ev47uWgH6dLPtdnvcMRNPkVBwqjLJg2/go-multiaddr-net"
14
)
15
16
-func Dial(n *core.IpfsNode, addr ma.Multiaddr, peer peer.ID, proto string, bindAddr ma.Multiaddr) (*corenet.AppInfo, error) {
16
+func Dial(n *core.IpfsNode, addr ma.Multiaddr, peer peer.ID, proto string, bindAddr ma.Multiaddr) (*ptp.ListenerInfo, error) {
17
lnet, _, err := manet.DialArgs(bindAddr)
18
if err != nil {
19
return nil, err
20
}
21
22
- app := corenet.AppInfo{
22
+ app := ptp.ListenerInfo{
23
Identity: n.Identity,
24
Protocol: proto,
25
}
@@ -54,7 +54,7 @@ func Dial(n *core.IpfsNode, addr ma.Multiaddr, peer peer.ID, proto string, bindA
54
return &app, nil
55
}
56
57
-func doAccept(n *core.IpfsNode, app *corenet.AppInfo, remote net.Stream, listener manet.Listener) {
57
+func doAccept(n *core.IpfsNode, app *ptp.ListenerInfo, remote net.Stream, listener manet.Listener) {
58
defer listener.Close()
59
60
local, err := listener.Accept()
@@ -62,7 +62,7 @@ func doAccept(n *core.IpfsNode, app *corenet.AppInfo, remote net.Stream, listene
62
return
63
}
64
65
- stream := corenet.StreamInfo{
65
+ stream := ptp.StreamInfo{
66
Protocol: app.Protocol,
67
68
LocalPeer: app.Identity,
@@ -74,9 +74,9 @@ func doAccept(n *core.IpfsNode, app *corenet.AppInfo, remote net.Stream, listene
74
Local: local,
75
Remote: remote,
76
77
- Registry: &n.Corenet.Streams,
77
+ Registry: &n.PTP.Streams,
78
}
79
80
- n.Corenet.Streams.Register(&stream)
80
+ n.PTP.Streams.Register(&stream)
81
startStreaming(&stream)
82
}
ptp/net/listen.go
renamed
+18
-18
@@ -2,54 +2,54 @@ package net
2
3
import (
4
"github.com/ipfs/go-ipfs/core"
5
- "github.com/ipfs/go-ipfs/corenet"
5
+ "github.com/ipfs/go-ipfs/ptp"
6
7
ma "gx/ipfs/QmcyqRMCAXVtYPS4DiBrA7sezL9rRGfW8Ctx7cywL4TXJj/go-multiaddr"
8
manet "gx/ipfs/Qmf1Gq7N45Rpuw7ev47uWgH6dLPtdnvcMRNPkVBwqjLJg2/go-multiaddr-net"
9
)
10
11
-// NewListener creates new corenet listener
12
-func NewListener(n *core.IpfsNode, proto string, addr ma.Multiaddr) (*corenet.AppInfo, error) {
11
+// NewListener creates new ptp listener
12
+func NewListener(n *core.IpfsNode, proto string, addr ma.Multiaddr) (*ptp.ListenerInfo, error) {
13
listener, err := Listen(n, proto)
14
if err != nil {
15
return nil, err
16
}
17
18
- app := corenet.AppInfo{
18
+ listenerInfo := ptp.ListenerInfo{
19
Identity: n.Identity,
20
Protocol: proto,
21
Address: addr,
22
Closer: listener,
23
Running: true,
24
- Registry: &n.Corenet.Apps,
24
+ Registry: &n.PTP.Listeners,
25
}
26
27
- go acceptStreams(n, &app, listener)
27
+ go acceptStreams(n, &listenerInfo, listener)
28
29
- n.Corenet.Apps.Register(&app)
29
+ n.PTP.Listeners.Register(&listenerInfo)
30
31
- return &app, nil
31
+ return &listenerInfo, nil
32
}
33
34
-func acceptStreams(n *core.IpfsNode, app *corenet.AppInfo, listener Listener) {
35
- for app.Running {
34
+func acceptStreams(n *core.IpfsNode, listenerInfo *ptp.ListenerInfo, listener Listener) {
35
+ for listenerInfo.Running {
36
remote, err := listener.Accept()
37
if err != nil {
38
listener.Close()
39
break
40
}
41
42
- local, err := manet.Dial(app.Address)
42
+ local, err := manet.Dial(listenerInfo.Address)
43
if err != nil {
44
remote.Close()
45
continue
46
}
47
48
- stream := corenet.StreamInfo{
49
- Protocol: app.Protocol,
48
+ stream := ptp.StreamInfo{
49
+ Protocol: listenerInfo.Protocol,
50
51
- LocalPeer: app.Identity,
52
- LocalAddr: app.Address,
51
+ LocalPeer: listenerInfo.Identity,
52
+ LocalAddr: listenerInfo.Address,
53
54
RemotePeer: remote.Conn().RemotePeer(),
55
RemoteAddr: remote.Conn().RemoteMultiaddr(),
@@ -57,11 +57,11 @@ func acceptStreams(n *core.IpfsNode, app *corenet.AppInfo, listener Listener) {
57
Local: local,
58
Remote: remote,
59
60
- Registry: &n.Corenet.Streams,
60
+ Registry: &n.PTP.Streams,
61
}
62
63
- n.Corenet.Streams.Register(&stream)
63
+ n.PTP.Streams.Register(&stream)
64
startStreaming(&stream)
65
}
66
- n.Corenet.Apps.Deregister(app.Protocol)
66
+ n.PTP.Listeners.Deregister(listenerInfo.Protocol)
67
}
ptp/net/net.go
renamed
ptp/net/util.go
renamed
+2
-2
@@ -3,10 +3,10 @@ package net
3
import (
4
"io"
5
6
- corenet "github.com/ipfs/go-ipfs/corenet"
6
+ ptp "github.com/ipfs/go-ipfs/ptp"
7
)
8
9
-func startStreaming(stream *corenet.StreamInfo) {
9
+func startStreaming(stream *ptp.StreamInfo) {
10
go func() {
11
io.Copy(stream.Local, stream.Remote)
12
stream.Close()
ptp/ptp.go
new
+12
@@ -0,0 +1,12 @@
1
+package ptp
2
+
3
+// PTP structure holds information on currently running streams/apps
4
+type PTP struct {
5
+ Listeners ListenerRegistry
6
+ Streams StreamRegistry
7
+}
8
+
9
+// NewPTP creates new PTP struct
10
+func NewPTP() *PTP {
11
+ return &PTP{}
12
+}
ptp/streams.go
renamed
+2
-2
@@ -1,4 +1,4 @@
1
-package corenet
1
+package ptp
2
3
import (
4
"io"
@@ -7,7 +7,7 @@ import (
7
peer "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
8
)
9
10
-// StreamInfo holds information on active incoming and outgoing protocol app streams.
10
+// StreamInfo holds information on active incoming and outgoing p2p streams.
11
type StreamInfo struct {
12
HandlerID uint64
13
test/sharness/t0180-corenet.sh
deleted
-149
@@ -1,149 +0,0 @@
1
-#!/bin/sh
2
-
3
-test_description="Test experimental corenet commands"
4
-
5
-. lib/test-lib.sh
6
-
7
-# start iptb + wait for peering
8
-test_expect_success 'init iptb' '
9
- iptb init -n 2 --bootstrap=none --port=0
10
-'
11
-
12
-test_expect_success 'generate test data' '
13
- echo "ABCDEF" > corenet0.bin &&
14
- echo "012345" > corenet1.bin
15
-'
16
-
17
-startup_cluster 2
18
-
19
-test_expect_success 'peer ids' '
20
- PEERID_0=$(iptb get id 0) &&
21
- PEERID_1=$(iptb get id 1)
22
-'
23
-
24
-test_expect_success "test ports are closed" '
25
- (! (netstat -ln | grep "LISTEN" | grep ":10101 ")) &&
26
- (! (netstat -ln | grep "LISTEN" | grep ":10102 "))
27
-'
28
-
29
-test_must_fail 'fail without config option being enabled' '
30
- ipfsi 0 corenet ls
31
-'
32
-
33
-test_expect_success "enable filestore config setting" '
34
- ipfsi 0 config --json Experimental.Libp2pStreamMounting true
35
- ipfsi 1 config --json Experimental.Libp2pStreamMounting true
36
-'
37
-
38
-test_expect_success 'start corenet listener' '
39
- ipfsi 0 corenet listen corenet-test /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
40
-'
41
-
42
-test_expect_success 'Test server to client communications' '
43
- ma-pipe-unidir --listen send /ip4/127.0.0.1/tcp/10101 < corenet0.bin &
44
- SERVER_PID=$!
45
-
46
- ipfsi 1 corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
47
- ma-pipe-unidir recv /ip4/127.0.0.1/tcp/10102 > client.out &&
48
- wait $SERVER_PID
49
-'
50
-
51
-test_expect_success 'Test client to server communications' '
52
- ma-pipe-unidir --listen recv /ip4/127.0.0.1/tcp/10101 > server.out &
53
- SERVER_PID=$!
54
-
55
- ipfsi 1 corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
56
- ma-pipe-unidir send /ip4/127.0.0.1/tcp/10102 < corenet1.bin
57
- wait $SERVER_PID
58
-'
59
-
60
-test_expect_success 'server to client output looks good' '
61
- test_cmp client.out corenet0.bin
62
-'
63
-
64
-test_expect_success 'client to server output looks good' '
65
- test_cmp server.out corenet1.bin
66
-'
67
-
68
-test_expect_success "'ipfs corenet ls' succeeds" '
69
- echo "/ip4/127.0.0.1/tcp/10101 /app/corenet-test" > expected &&
70
- ipfsi 0 corenet ls > actual
71
-'
72
-
73
-test_expect_success "'ipfs corenet ls' output looks good" '
74
- test_cmp expected actual
75
-'
76
-
77
-test_expect_success "Cannot re-register app handler" '
78
- (! ipfsi 0 corenet listen corenet-test /ip4/127.0.0.1/tcp/10101)
79
-'
80
-
81
-test_expect_success "'ipfs corenet streams' output is empty" '
82
- ipfsi 0 corenet streams > actual &&
83
- test_must_be_empty actual
84
-'
85
-
86
-test_expect_success "Setup: Idle stream" '
87
- ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
88
-
89
- ipfsi 1 corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
90
- ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
91
-
92
- go-sleep 500ms &&
93
- kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
94
-'
95
-
96
-test_expect_success "'ipfs corenet streams' succeeds" '
97
- echo "2 /app/corenet-test /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
98
- ipfsi 0 corenet streams > actual
99
-'
100
-
101
-test_expect_success "'ipfs corenet streams' output looks good" '
102
- test_cmp expected actual
103
-'
104
-
105
-test_expect_success "'ipfs corenet close' closes stream" '
106
- ipfsi 0 corenet close 2 &&
107
- ipfsi 0 corenet streams > actual &&
108
- [ ! -f listener.pid ] && [ ! -f client.pid ] &&
109
- test_must_be_empty actual
110
-'
111
-
112
-test_expect_success "'ipfs corenet close' closes app handler" '
113
- ipfsi 0 corenet close corenet-test &&
114
- ipfsi 0 corenet ls > actual &&
115
- test_must_be_empty actual
116
-'
117
-
118
-test_expect_success "Setup: Idle stream(2)" '
119
- ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
120
-
121
- ipfsi 0 corenet listen corenet-test2 /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
122
- ipfsi 1 corenet dial $PEERID_0 corenet-test2 /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
123
- ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
124
-
125
- go-sleep 500ms &&
126
- kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
127
-'
128
-
129
-test_expect_success "'ipfs corenet streams' succeeds(2)" '
130
- echo "3 /app/corenet-test2 /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
131
- ipfsi 0 corenet streams > actual
132
- test_cmp expected actual
133
-'
134
-
135
-test_expect_success "'ipfs corenet close -a' closes streams and app handlers" '
136
- ipfsi 0 corenet close -a &&
137
- ipfsi 0 corenet streams > actual &&
138
- [ ! -f listener.pid ] && [ ! -f client.pid ] &&
139
- test_must_be_empty actual &&
140
- ipfsi 0 corenet ls > actual &&
141
- test_must_be_empty actual
142
-'
143
-
144
-test_expect_success 'stop iptb' '
145
- iptb stop
146
-'
147
-
148
-test_done
149
-
test/sharness/t0180-ptp.sh
new
+149
@@ -0,0 +1,149 @@
1
+#!/bin/sh
2
+
3
+test_description="Test experimental ptp commands"
4
+
5
+. lib/test-lib.sh
6
+
7
+# start iptb + wait for peering
8
+test_expect_success 'init iptb' '
9
+ iptb init -n 2 --bootstrap=none --port=0
10
+'
11
+
12
+test_expect_success 'generate test data' '
13
+ echo "ABCDEF" > test0.bin &&
14
+ echo "012345" > test1.bin
15
+'
16
+
17
+startup_cluster 2
18
+
19
+test_expect_success 'peer ids' '
20
+ PEERID_0=$(iptb get id 0) &&
21
+ PEERID_1=$(iptb get id 1)
22
+'
23
+
24
+test_expect_success "test ports are closed" '
25
+ (! (netstat -ln | grep "LISTEN" | grep ":10101 ")) &&
26
+ (! (netstat -ln | grep "LISTEN" | grep ":10102 "))
27
+'
28
+
29
+test_must_fail 'fail without config option being enabled' '
30
+ ipfsi 0 ptp ls
31
+'
32
+
33
+test_expect_success "enable filestore config setting" '
34
+ ipfsi 0 config --json Experimental.Libp2pStreamMounting true
35
+ ipfsi 1 config --json Experimental.Libp2pStreamMounting true
36
+'
37
+
38
+test_expect_success 'start ptp listener' '
39
+ ipfsi 0 ptp listen ptp-test /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
40
+'
41
+
42
+test_expect_success 'Test server to client communications' '
43
+ ma-pipe-unidir --listen send /ip4/127.0.0.1/tcp/10101 < test0.bin &
44
+ SERVER_PID=$!
45
+
46
+ ipfsi 1 ptp dial $PEERID_0 ptp-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
47
+ ma-pipe-unidir recv /ip4/127.0.0.1/tcp/10102 > client.out &&
48
+ wait $SERVER_PID
49
+'
50
+
51
+test_expect_success 'Test client to server communications' '
52
+ ma-pipe-unidir --listen recv /ip4/127.0.0.1/tcp/10101 > server.out &
53
+ SERVER_PID=$!
54
+
55
+ ipfsi 1 ptp dial $PEERID_0 ptp-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
56
+ ma-pipe-unidir send /ip4/127.0.0.1/tcp/10102 < test1.bin
57
+ wait $SERVER_PID
58
+'
59
+
60
+test_expect_success 'server to client output looks good' '
61
+ test_cmp client.out test0.bin
62
+'
63
+
64
+test_expect_success 'client to server output looks good' '
65
+ test_cmp server.out test1.bin
66
+'
67
+
68
+test_expect_success "'ipfs ptp ls' succeeds" '
69
+ echo "/ip4/127.0.0.1/tcp/10101 /app/ptp-test" > expected &&
70
+ ipfsi 0 ptp ls > actual
71
+'
72
+
73
+test_expect_success "'ipfs ptp ls' output looks good" '
74
+ test_cmp expected actual
75
+'
76
+
77
+test_expect_success "Cannot re-register app handler" '
78
+ (! ipfsi 0 ptp listen ptp-test /ip4/127.0.0.1/tcp/10101)
79
+'
80
+
81
+test_expect_success "'ipfs ptp streams' output is empty" '
82
+ ipfsi 0 ptp streams > actual &&
83
+ test_must_be_empty actual
84
+'
85
+
86
+test_expect_success "Setup: Idle stream" '
87
+ ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
88
+
89
+ ipfsi 1 ptp dial $PEERID_0 ptp-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
90
+ ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
91
+
92
+ go-sleep 500ms &&
93
+ kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
94
+'
95
+
96
+test_expect_success "'ipfs ptp streams' succeeds" '
97
+ echo "2 /app/ptp-test /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
98
+ ipfsi 0 ptp streams > actual
99
+'
100
+
101
+test_expect_success "'ipfs ptp streams' output looks good" '
102
+ test_cmp expected actual
103
+'
104
+
105
+test_expect_success "'ipfs ptp close' closes stream" '
106
+ ipfsi 0 ptp close 2 &&
107
+ ipfsi 0 ptp streams > actual &&
108
+ [ ! -f listener.pid ] && [ ! -f client.pid ] &&
109
+ test_must_be_empty actual
110
+'
111
+
112
+test_expect_success "'ipfs ptp close' closes app handler" '
113
+ ipfsi 0 ptp close ptp-test &&
114
+ ipfsi 0 ptp ls > actual &&
115
+ test_must_be_empty actual
116
+'
117
+
118
+test_expect_success "Setup: Idle stream(2)" '
119
+ ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
120
+
121
+ ipfsi 0 ptp listen ptp-test2 /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
122
+ ipfsi 1 ptp dial $PEERID_0 ptp-test2 /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
123
+ ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
124
+
125
+ go-sleep 500ms &&
126
+ kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
127
+'
128
+
129
+test_expect_success "'ipfs ptp streams' succeeds(2)" '
130
+ echo "3 /app/ptp-test2 /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
131
+ ipfsi 0 ptp streams > actual
132
+ test_cmp expected actual
133
+'
134
+
135
+test_expect_success "'ipfs ptp close -a' closes streams and app handlers" '
136
+ ipfsi 0 ptp close -a &&
137
+ ipfsi 0 ptp streams > actual &&
138
+ [ ! -f listener.pid ] && [ ! -f client.pid ] &&
139
+ test_must_be_empty actual &&
140
+ ipfsi 0 ptp ls > actual &&
141
+ test_must_be_empty actual
142
+'
143
+
144
+test_expect_success 'stop iptb' '
145
+ iptb stop
146
+'
147
+
148
+test_done
149
+