提交 ad9ae350 作者: Łukasz Magiera

PTP API: Rename Corenet to PTP

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 eac71847
......@@ -9,20 +9,20 @@ import (
"text/tabwriter"
cmds "github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/core"
cnet "github.com/ipfs/go-ipfs/corenet/net"
core "github.com/ipfs/go-ipfs/core"
ptpnet "github.com/ipfs/go-ipfs/ptp/net"
ma "gx/ipfs/QmcyqRMCAXVtYPS4DiBrA7sezL9rRGfW8Ctx7cywL4TXJj/go-multiaddr"
)
// CorenetAppInfoOutput is output type of ls command
type CorenetAppInfoOutput struct {
// PTPAppInfoOutput is output type of ls command
type PTPAppInfoOutput struct {
Protocol string
Address string
}
// CorenetStreamInfoOutput is output type of streams command
type CorenetStreamInfoOutput struct {
// PTPStreamInfoOutput is output type of streams command
type PTPStreamInfoOutput struct {
HandlerID string
Protocol string
LocalPeer string
......@@ -31,38 +31,38 @@ type CorenetStreamInfoOutput struct {
RemoteAddress string
}
// CorenetLsOutput is output type of ls command
type CorenetLsOutput struct {
Apps []CorenetAppInfoOutput
// PTPLsOutput is output type of ls command
type PTPLsOutput struct {
Apps []PTPAppInfoOutput
}
// CorenetStreamsOutput is output type of streams command
type CorenetStreamsOutput struct {
Streams []CorenetStreamInfoOutput
// PTPStreamsOutput is output type of streams command
type PTPStreamsOutput struct {
Streams []PTPStreamInfoOutput
}
// CorenetCmd is the 'ipfs corenet' command
var CorenetCmd = &cmds.Command{
// PTPCmd is the 'ipfs ptp' command
var PTPCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Libp2p stream mounting.",
ShortDescription: `
Expose a local application to remote peers over libp2p
Create and use tunnels to remote peers over libp2p
Note: this command is experimental and subject to change as usecases and APIs are refined`,
},
Subcommands: map[string]*cmds.Command{
"ls": corenetLsCmd,
"streams": corenetStreamsCmd,
"dial": corenetDialCmd,
"listen": corenetListenCmd,
"close": corenetCloseCmd,
"ls": ptpLsCmd,
"streams": ptpStreamsCmd,
"dial": ptpDialCmd,
"listen": ptpListenCmd,
"close": ptpCloseCmd,
},
}
var corenetLsCmd = &cmds.Command{
var ptpLsCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List active application protocol listeners.",
Tagline: "List active p2p listeners.",
},
Options: []cmds.Option{
cmds.BoolOption("headers", "v", "Print table headers (HandlerID, Protocol, Local, Remote).").Default(false),
......@@ -85,10 +85,10 @@ var corenetLsCmd = &cmds.Command{
return
}
output := &CorenetLsOutput{}
output := &PTPLsOutput{}
for _, app := range n.Corenet.Apps.Apps {
output.Apps = append(output.Apps, CorenetAppInfoOutput{
for _, app := range n.PTP.Apps.Apps {
output.Apps = append(output.Apps, PTPAppInfoOutput{
Protocol: app.Protocol,
Address: app.Address.String(),
})
......@@ -96,11 +96,11 @@ var corenetLsCmd = &cmds.Command{
res.SetOutput(output)
},
Type: CorenetLsOutput{},
Type: PTPLsOutput{},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
headers, _, _ := res.Request().Option("headers").Bool()
list, _ := res.Output().(*CorenetLsOutput)
list, _ := res.Output().(*PTPLsOutput)
buf := new(bytes.Buffer)
w := tabwriter.NewWriter(buf, 1, 2, 1, ' ', 0)
for _, app := range list.Apps {
......@@ -117,12 +117,12 @@ var corenetLsCmd = &cmds.Command{
},
}
var corenetStreamsCmd = &cmds.Command{
var ptpStreamsCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "List active application protocol streams.",
Tagline: "List active p2p streams.",
},
Options: []cmds.Option{
cmds.BoolOption("headers", "v", "Print table headers (HandlerID, Protocol, Local, Remote).").Default(false),
cmds.BoolOption("headers", "v", "Print table headers (HagndlerID, Protocol, Local, Remote).").Default(false),
},
Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode()
......@@ -142,10 +142,10 @@ var corenetStreamsCmd = &cmds.Command{
return
}
output := &CorenetStreamsOutput{}
output := &PTPStreamsOutput{}
for _, s := range n.Corenet.Streams.Streams {
output.Streams = append(output.Streams, CorenetStreamInfoOutput{
for _, s := range n.PTP.Streams.Streams {
output.Streams = append(output.Streams, PTPStreamInfoOutput{
HandlerID: strconv.FormatUint(s.HandlerID, 10),
Protocol: s.Protocol,
......@@ -160,11 +160,11 @@ var corenetStreamsCmd = &cmds.Command{
res.SetOutput(output)
},
Type: CorenetStreamsOutput{},
Type: PTPStreamsOutput{},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
headers, _, _ := res.Request().Option("headers").Bool()
list, _ := res.Output().(*CorenetStreamsOutput)
list, _ := res.Output().(*PTPStreamsOutput)
buf := new(bytes.Buffer)
w := tabwriter.NewWriter(buf, 1, 2, 1, ' ', 0)
for _, stream := range list.Streams {
......@@ -181,12 +181,11 @@ var corenetStreamsCmd = &cmds.Command{
},
}
var corenetListenCmd = &cmds.Command{
var ptpListenCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Create application protocol listener and proxy to network multiaddr.",
ShortDescription: `
Register a p2p connection handler and proxies the connections to a specified
address.
Register a p2p connection handler and proxies the connections to a specified address.
Note that the connections originate from the ipfs daemon process.
`,
......@@ -214,7 +213,7 @@ Note that the connections originate from the ipfs daemon process.
}
proto := "/app/" + req.Arguments()[0]
if cnet.CheckProtoExists(n, proto) {
if ptpnet.CheckProtoExists(n, proto) {
res.SetError(errors.New("protocol handler already registered"), cmds.ErrNormal)
return
}
......@@ -225,30 +224,30 @@ Note that the connections originate from the ipfs daemon process.
return
}
_, err = cnet.NewListener(n, proto, addr)
_, err = ptpnet.NewListener(n, proto, addr)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
// Successful response.
res.SetOutput(&CorenetAppInfoOutput{
res.SetOutput(&PTPAppInfoOutput{
Protocol: proto,
Address: addr.String(),
})
},
}
var corenetDialCmd = &cmds.Command{
var ptpDialCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Dial to an application service.",
Tagline: "Dial to a p2p listener.",
ShortDescription: `
Establish a new connection to a peer service.
When a connection is made to a peer service the ipfs daemon will setup one time
TCP listener and return it's bind port, this way a dialing application can
transparently connect to a corenet service.
transparently connect to a p2p service.
`,
},
Arguments: []cmds.Argument{
......@@ -291,13 +290,13 @@ transparently connect to a corenet service.
}
}
app, err := cnet.Dial(n, addr, peer, proto, bindAddr)
app, err := ptpnet.Dial(n, addr, peer, proto, bindAddr)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
output := CorenetAppInfoOutput{
output := PTPAppInfoOutput{
Protocol: app.Protocol,
Address: app.Address.String(),
}
......@@ -306,13 +305,12 @@ transparently connect to a corenet service.
},
}
var corenetCloseCmd = &cmds.Command{
var ptpCloseCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Closes an active stream listener or client.",
Tagline: "Closes an active p2p stream or listener.",
},
Arguments: []cmds.Argument{
cmds.StringArg("HandlerID", false, false, "Application listener or client HandlerID"),
cmds.StringArg("Protocol", false, false, "Application listener or client HandlerID"),
cmds.StringArg("Identifier", false, false, "Stream HandlerID or p2p listener protocol"),
},
Options: []cmds.Option{
cmds.BoolOption("all", "a", "Close all streams and listeners.").Default(false),
......@@ -344,7 +342,7 @@ var corenetCloseCmd = &cmds.Command{
if !closeAll {
if len(req.Arguments()) == 0 {
res.SetError(errors.New("no handlerID nor stream protocol specified"), cmds.ErrNormal)
res.SetError(errors.New("no handlerID nor listener protocol specified"), cmds.ErrNormal)
return
}
......@@ -357,7 +355,7 @@ var corenetCloseCmd = &cmds.Command{
}
if closeAll || useHandlerID {
for _, stream := range n.Corenet.Streams.Streams {
for _, stream := range n.PTP.Streams.Streams {
if !closeAll && handlerID != stream.HandlerID {
continue
}
......@@ -369,7 +367,7 @@ var corenetCloseCmd = &cmds.Command{
}
if closeAll || !useHandlerID {
for _, app := range n.Corenet.Apps.Apps {
for _, app := range n.PTP.Apps.Apps {
if !closeAll && app.Protocol != proto {
continue
}
......
......@@ -47,7 +47,7 @@ ADVANCED COMMANDS
pin Pin objects to local storage
repo Manipulate the IPFS repository
stats Various operational stats
corenet Libp2p stream mounting
ptp Libp2p stream mounting
filestore Manage the filestore (experimental)
NETWORK COMMANDS
......@@ -99,7 +99,6 @@ var rootSubcommands = map[string]*cmds.Command{
"cat": CatCmd,
"commands": CommandsDaemonCmd,
"config": ConfigCmd,
"corenet": CorenetCmd,
"dag": dag.DagCmd,
"dht": DhtCmd,
"diag": DiagCmd,
......@@ -115,6 +114,7 @@ var rootSubcommands = map[string]*cmds.Command{
"object": ocmd.ObjectCmd,
"pin": PinCmd,
"ping": PingCmd,
"ptp": PTPCmd,
"pubsub": PubsubCmd,
"refs": RefsCmd,
"repo": RepoCmd,
......
......@@ -23,7 +23,7 @@ import (
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
bserv "github.com/ipfs/go-ipfs/blockservice"
corenet "github.com/ipfs/go-ipfs/corenet"
ptp "github.com/ipfs/go-ipfs/ptp"
exchange "github.com/ipfs/go-ipfs/exchange"
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
......@@ -132,7 +132,7 @@ type IpfsNode struct {
IpnsRepub *ipnsrp.Republisher
Floodsub *floodsub.PubSub
Corenet *corenet.Corenet
PTP *ptp.PTP
proc goprocess.Process
ctx context.Context
......@@ -248,7 +248,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
n.Floodsub = floodsub.NewFloodSub(ctx, peerhost)
}
n.Corenet = corenet.NewCorenet()
n.PTP = ptp.NewPTP()
// setup local discovery
if do != nil {
......
package corenet
// Corenet structure holds information on currently running streams/apps
type Corenet struct {
Apps AppRegistry
Streams StreamRegistry
}
// NewCorenet creates new Corenet struct
func NewCorenet() *Corenet {
return &Corenet{}
}
package corenet
package ptp
import (
"io"
......@@ -8,8 +8,8 @@ import (
"fmt"
)
// AppInfo holds information on a local application protocol listener service.
type AppInfo struct {
// ListenerInfo holds information on a p2p listener.
type ListenerInfo struct {
// Application protocol identifier.
Protocol string
......@@ -26,30 +26,30 @@ type AppInfo struct {
// whether this application listener has been shutdown.
Running bool
Registry *AppRegistry
Registry *ListenerRegistry
}
// Close closes the listener. Does not affect child streams
func (c *AppInfo) Close() error {
func (c *ListenerInfo) Close() error {
c.Closer.Close()
err := c.Registry.Deregister(c.Protocol)
return err
}
// AppRegistry is a collection of local application protocol listeners.
type AppRegistry struct {
Apps []*AppInfo
// ListenerRegistry is a collection of local application protocol listeners.
type ListenerRegistry struct {
Listeners []*ListenerInfo
}
// Register registers appInfo in this registry
func (c *AppRegistry) Register(appInfo *AppInfo) {
c.Apps = append(c.Apps, appInfo)
// Register registers listenerInfo in this registry
func (c *ListenerRegistry) Register(listenerInfo *ListenerInfo) {
c.Listeners = append(c.Listeners, listenerInfo)
}
// Deregister deregisters protocol handler from this registry
func (c *AppRegistry) Deregister(proto string) error {
// Deregister removes p2p listener from this registry
func (c *ListenerRegistry) Deregister(proto string) error {
foundAt := -1
for i, a := range c.Apps {
for i, a := range c.Listeners {
if a.Protocol == proto {
foundAt = i
break
......@@ -57,7 +57,7 @@ func (c *AppRegistry) Deregister(proto string) error {
}
if foundAt != -1 {
c.Apps = append(c.Apps[:foundAt], c.Apps[foundAt+1:]...)
c.Listeners = append(c.Listeners[:foundAt], c.Listeners[foundAt+1:]...)
return nil
}
......
......@@ -4,7 +4,7 @@ import (
"errors"
core "github.com/ipfs/go-ipfs/core"
corenet "github.com/ipfs/go-ipfs/corenet"
ptp "github.com/ipfs/go-ipfs/ptp"
net "gx/ipfs/QmRscs8KxrSmSv4iuevHv8JfuUzHBMoqiaHzxfDRiksd6e/go-libp2p-net"
peerstore "gx/ipfs/QmXZSd1qR5BxZkPyuwfT5jpqQFScZccoZvDneXsKzCNHWX/go-libp2p-peerstore"
......@@ -13,13 +13,13 @@ import (
manet "gx/ipfs/Qmf1Gq7N45Rpuw7ev47uWgH6dLPtdnvcMRNPkVBwqjLJg2/go-multiaddr-net"
)
func Dial(n *core.IpfsNode, addr ma.Multiaddr, peer peer.ID, proto string, bindAddr ma.Multiaddr) (*corenet.AppInfo, error) {
func Dial(n *core.IpfsNode, addr ma.Multiaddr, peer peer.ID, proto string, bindAddr ma.Multiaddr) (*ptp.ListenerInfo, error) {
lnet, _, err := manet.DialArgs(bindAddr)
if err != nil {
return nil, err
}
app := corenet.AppInfo{
app := ptp.ListenerInfo{
Identity: n.Identity,
Protocol: proto,
}
......@@ -54,7 +54,7 @@ func Dial(n *core.IpfsNode, addr ma.Multiaddr, peer peer.ID, proto string, bindA
return &app, nil
}
func doAccept(n *core.IpfsNode, app *corenet.AppInfo, remote net.Stream, listener manet.Listener) {
func doAccept(n *core.IpfsNode, app *ptp.ListenerInfo, remote net.Stream, listener manet.Listener) {
defer listener.Close()
local, err := listener.Accept()
......@@ -62,7 +62,7 @@ func doAccept(n *core.IpfsNode, app *corenet.AppInfo, remote net.Stream, listene
return
}
stream := corenet.StreamInfo{
stream := ptp.StreamInfo{
Protocol: app.Protocol,
LocalPeer: app.Identity,
......@@ -74,9 +74,9 @@ func doAccept(n *core.IpfsNode, app *corenet.AppInfo, remote net.Stream, listene
Local: local,
Remote: remote,
Registry: &n.Corenet.Streams,
Registry: &n.PTP.Streams,
}
n.Corenet.Streams.Register(&stream)
n.PTP.Streams.Register(&stream)
startStreaming(&stream)
}
......@@ -2,54 +2,54 @@ package net
import (
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/corenet"
"github.com/ipfs/go-ipfs/ptp"
ma "gx/ipfs/QmcyqRMCAXVtYPS4DiBrA7sezL9rRGfW8Ctx7cywL4TXJj/go-multiaddr"
manet "gx/ipfs/Qmf1Gq7N45Rpuw7ev47uWgH6dLPtdnvcMRNPkVBwqjLJg2/go-multiaddr-net"
)
// NewListener creates new corenet listener
func NewListener(n *core.IpfsNode, proto string, addr ma.Multiaddr) (*corenet.AppInfo, error) {
// NewListener creates new ptp listener
func NewListener(n *core.IpfsNode, proto string, addr ma.Multiaddr) (*ptp.ListenerInfo, error) {
listener, err := Listen(n, proto)
if err != nil {
return nil, err
}
app := corenet.AppInfo{
listenerInfo := ptp.ListenerInfo{
Identity: n.Identity,
Protocol: proto,
Address: addr,
Closer: listener,
Running: true,
Registry: &n.Corenet.Apps,
Registry: &n.PTP.Listeners,
}
go acceptStreams(n, &app, listener)
go acceptStreams(n, &listenerInfo, listener)
n.Corenet.Apps.Register(&app)
n.PTP.Listeners.Register(&listenerInfo)
return &app, nil
return &listenerInfo, nil
}
func acceptStreams(n *core.IpfsNode, app *corenet.AppInfo, listener Listener) {
for app.Running {
func acceptStreams(n *core.IpfsNode, listenerInfo *ptp.ListenerInfo, listener Listener) {
for listenerInfo.Running {
remote, err := listener.Accept()
if err != nil {
listener.Close()
break
}
local, err := manet.Dial(app.Address)
local, err := manet.Dial(listenerInfo.Address)
if err != nil {
remote.Close()
continue
}
stream := corenet.StreamInfo{
Protocol: app.Protocol,
stream := ptp.StreamInfo{
Protocol: listenerInfo.Protocol,
LocalPeer: app.Identity,
LocalAddr: app.Address,
LocalPeer: listenerInfo.Identity,
LocalAddr: listenerInfo.Address,
RemotePeer: remote.Conn().RemotePeer(),
RemoteAddr: remote.Conn().RemoteMultiaddr(),
......@@ -57,11 +57,11 @@ func acceptStreams(n *core.IpfsNode, app *corenet.AppInfo, listener Listener) {
Local: local,
Remote: remote,
Registry: &n.Corenet.Streams,
Registry: &n.PTP.Streams,
}
n.Corenet.Streams.Register(&stream)
n.PTP.Streams.Register(&stream)
startStreaming(&stream)
}
n.Corenet.Apps.Deregister(app.Protocol)
n.PTP.Listeners.Deregister(listenerInfo.Protocol)
}
......@@ -3,10 +3,10 @@ package net
import (
"io"
corenet "github.com/ipfs/go-ipfs/corenet"
ptp "github.com/ipfs/go-ipfs/ptp"
)
func startStreaming(stream *corenet.StreamInfo) {
func startStreaming(stream *ptp.StreamInfo) {
go func() {
io.Copy(stream.Local, stream.Remote)
stream.Close()
......
package ptp
// PTP structure holds information on currently running streams/apps
type PTP struct {
Listeners ListenerRegistry
Streams StreamRegistry
}
// NewPTP creates new PTP struct
func NewPTP() *PTP {
return &PTP{}
}
package corenet
package ptp
import (
"io"
......@@ -7,7 +7,7 @@ import (
peer "gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
)
// StreamInfo holds information on active incoming and outgoing protocol app streams.
// StreamInfo holds information on active incoming and outgoing p2p streams.
type StreamInfo struct {
HandlerID uint64
......
#!/bin/sh
test_description="Test experimental corenet commands"
test_description="Test experimental ptp commands"
. lib/test-lib.sh
......@@ -10,8 +10,8 @@ test_expect_success 'init iptb' '
'
test_expect_success 'generate test data' '
echo "ABCDEF" > corenet0.bin &&
echo "012345" > corenet1.bin
echo "ABCDEF" > test0.bin &&
echo "012345" > test1.bin
'
startup_cluster 2
......@@ -27,7 +27,7 @@ test_expect_success "test ports are closed" '
'
test_must_fail 'fail without config option being enabled' '
ipfsi 0 corenet ls
ipfsi 0 ptp ls
'
test_expect_success "enable filestore config setting" '
......@@ -35,15 +35,15 @@ test_expect_success "enable filestore config setting" '
ipfsi 1 config --json Experimental.Libp2pStreamMounting true
'
test_expect_success 'start corenet listener' '
ipfsi 0 corenet listen corenet-test /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
test_expect_success 'start ptp listener' '
ipfsi 0 ptp listen ptp-test /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
'
test_expect_success 'Test server to client communications' '
ma-pipe-unidir --listen send /ip4/127.0.0.1/tcp/10101 < corenet0.bin &
ma-pipe-unidir --listen send /ip4/127.0.0.1/tcp/10101 < test0.bin &
SERVER_PID=$!
ipfsi 1 corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ipfsi 1 ptp dial $PEERID_0 ptp-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ma-pipe-unidir recv /ip4/127.0.0.1/tcp/10102 > client.out &&
wait $SERVER_PID
'
......@@ -52,92 +52,92 @@ test_expect_success 'Test client to server communications' '
ma-pipe-unidir --listen recv /ip4/127.0.0.1/tcp/10101 > server.out &
SERVER_PID=$!
ipfsi 1 corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ma-pipe-unidir send /ip4/127.0.0.1/tcp/10102 < corenet1.bin
ipfsi 1 ptp dial $PEERID_0 ptp-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ma-pipe-unidir send /ip4/127.0.0.1/tcp/10102 < test1.bin
wait $SERVER_PID
'
test_expect_success 'server to client output looks good' '
test_cmp client.out corenet0.bin
test_cmp client.out test0.bin
'
test_expect_success 'client to server output looks good' '
test_cmp server.out corenet1.bin
test_cmp server.out test1.bin
'
test_expect_success "'ipfs corenet ls' succeeds" '
echo "/ip4/127.0.0.1/tcp/10101 /app/corenet-test" > expected &&
ipfsi 0 corenet ls > actual
test_expect_success "'ipfs ptp ls' succeeds" '
echo "/ip4/127.0.0.1/tcp/10101 /app/ptp-test" > expected &&
ipfsi 0 ptp ls > actual
'
test_expect_success "'ipfs corenet ls' output looks good" '
test_expect_success "'ipfs ptp ls' output looks good" '
test_cmp expected actual
'
test_expect_success "Cannot re-register app handler" '
(! ipfsi 0 corenet listen corenet-test /ip4/127.0.0.1/tcp/10101)
(! ipfsi 0 ptp listen ptp-test /ip4/127.0.0.1/tcp/10101)
'
test_expect_success "'ipfs corenet streams' output is empty" '
ipfsi 0 corenet streams > actual &&
test_expect_success "'ipfs ptp streams' output is empty" '
ipfsi 0 ptp streams > actual &&
test_must_be_empty actual
'
test_expect_success "Setup: Idle stream" '
ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
ipfsi 1 corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ipfsi 1 ptp dial $PEERID_0 ptp-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
go-sleep 500ms &&
kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
'
test_expect_success "'ipfs corenet streams' succeeds" '
echo "2 /app/corenet-test /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
ipfsi 0 corenet streams > actual
test_expect_success "'ipfs ptp streams' succeeds" '
echo "2 /app/ptp-test /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
ipfsi 0 ptp streams > actual
'
test_expect_success "'ipfs corenet streams' output looks good" '
test_expect_success "'ipfs ptp streams' output looks good" '
test_cmp expected actual
'
test_expect_success "'ipfs corenet close' closes stream" '
ipfsi 0 corenet close 2 &&
ipfsi 0 corenet streams > actual &&
test_expect_success "'ipfs ptp close' closes stream" '
ipfsi 0 ptp close 2 &&
ipfsi 0 ptp streams > actual &&
[ ! -f listener.pid ] && [ ! -f client.pid ] &&
test_must_be_empty actual
'
test_expect_success "'ipfs corenet close' closes app handler" '
ipfsi 0 corenet close corenet-test &&
ipfsi 0 corenet ls > actual &&
test_expect_success "'ipfs ptp close' closes app handler" '
ipfsi 0 ptp close ptp-test &&
ipfsi 0 ptp ls > actual &&
test_must_be_empty actual
'
test_expect_success "Setup: Idle stream(2)" '
ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
ipfsi 0 corenet listen corenet-test2 /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
ipfsi 1 corenet dial $PEERID_0 corenet-test2 /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ipfsi 0 ptp listen ptp-test2 /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
ipfsi 1 ptp dial $PEERID_0 ptp-test2 /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
go-sleep 500ms &&
kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
'
test_expect_success "'ipfs corenet streams' succeeds(2)" '
echo "3 /app/corenet-test2 /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
ipfsi 0 corenet streams > actual
test_expect_success "'ipfs ptp streams' succeeds(2)" '
echo "3 /app/ptp-test2 /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
ipfsi 0 ptp streams > actual
test_cmp expected actual
'
test_expect_success "'ipfs corenet close -a' closes streams and app handlers" '
ipfsi 0 corenet close -a &&
ipfsi 0 corenet streams > actual &&
test_expect_success "'ipfs ptp close -a' closes streams and app handlers" '
ipfsi 0 ptp close -a &&
ipfsi 0 ptp streams > actual &&
[ ! -f listener.pid ] && [ ! -f client.pid ] &&
test_must_be_empty actual &&
ipfsi 0 corenet ls > actual &&
ipfsi 0 ptp ls > actual &&
test_must_be_empty actual
'
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论