Skip to content

Commit

Permalink
PTP API: Rename Corenet to PTP
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Jun 2, 2017
1 parent eac7184 commit 4816a6c
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 131 deletions.
104 changes: 51 additions & 53 deletions core/commands/corenet.go → core/commands/ptp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -85,22 +85,22 @@ 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(),
})
}

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 {
Expand All @@ -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()
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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.
`,
Expand Down Expand Up @@ -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
}
Expand All @@ -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{
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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),
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions core/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions corenet/corenet.go

This file was deleted.

2 changes: 1 addition & 1 deletion corenet/apps.go → ptp/apps.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package corenet
package ptp

import (
"io"
Expand Down
12 changes: 12 additions & 0 deletions ptp/corenet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ptp

// PTP structure holds information on currently running streams/apps
type PTP struct {
Apps AppRegistry
Streams StreamRegistry
}

// NewPTP creates new PTP struct
func NewPTP() *PTP {
return &PTP{}
}
Loading

0 comments on commit 4816a6c

Please sign in to comment.