Skip to content

Commit 55e656a

Browse files
committed
PTP API: Rename Corenet to PTP
License: MIT Signed-off-by: Łukasz Magiera <[email protected]>
1 parent eac7184 commit 55e656a

File tree

13 files changed

+239
-241
lines changed

13 files changed

+239
-241
lines changed

core/commands/corenet.go renamed to core/commands/ptp.go

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ import (
99
"text/tabwriter"
1010

1111
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"
1414

1515
ma "gx/ipfs/QmcyqRMCAXVtYPS4DiBrA7sezL9rRGfW8Ctx7cywL4TXJj/go-multiaddr"
1616
)
1717

18-
// CorenetAppInfoOutput is output type of ls command
19-
type CorenetAppInfoOutput struct {
18+
// PTPAppInfoOutput is output type of ls command
19+
type PTPAppInfoOutput struct {
2020
Protocol string
2121
Address string
2222
}
2323

24-
// CorenetStreamInfoOutput is output type of streams command
25-
type CorenetStreamInfoOutput struct {
24+
// PTPStreamInfoOutput is output type of streams command
25+
type PTPStreamInfoOutput struct {
2626
HandlerID string
2727
Protocol string
2828
LocalPeer string
@@ -31,38 +31,38 @@ type CorenetStreamInfoOutput struct {
3131
RemoteAddress string
3232
}
3333

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
3737
}
3838

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
4242
}
4343

44-
// CorenetCmd is the 'ipfs corenet' command
45-
var CorenetCmd = &cmds.Command{
44+
// PTPCmd is the 'ipfs ptp' command
45+
var PTPCmd = &cmds.Command{
4646
Helptext: cmds.HelpText{
4747
Tagline: "Libp2p stream mounting.",
4848
ShortDescription: `
49-
Expose a local application to remote peers over libp2p
49+
Create and use tunnels to remote peers over libp2p
5050
5151
Note: this command is experimental and subject to change as usecases and APIs are refined`,
5252
},
5353

5454
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,
6060
},
6161
}
6262

63-
var corenetLsCmd = &cmds.Command{
63+
var ptpLsCmd = &cmds.Command{
6464
Helptext: cmds.HelpText{
65-
Tagline: "List active application protocol listeners.",
65+
Tagline: "List active p2p listeners.",
6666
},
6767
Options: []cmds.Option{
6868
cmds.BoolOption("headers", "v", "Print table headers (HandlerID, Protocol, Local, Remote).").Default(false),
@@ -85,22 +85,22 @@ var corenetLsCmd = &cmds.Command{
8585
return
8686
}
8787

88-
output := &CorenetLsOutput{}
88+
output := &PTPLsOutput{}
8989

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{
9292
Protocol: app.Protocol,
9393
Address: app.Address.String(),
9494
})
9595
}
9696

9797
res.SetOutput(output)
9898
},
99-
Type: CorenetLsOutput{},
99+
Type: PTPLsOutput{},
100100
Marshalers: cmds.MarshalerMap{
101101
cmds.Text: func(res cmds.Response) (io.Reader, error) {
102102
headers, _, _ := res.Request().Option("headers").Bool()
103-
list, _ := res.Output().(*CorenetLsOutput)
103+
list, _ := res.Output().(*PTPLsOutput)
104104
buf := new(bytes.Buffer)
105105
w := tabwriter.NewWriter(buf, 1, 2, 1, ' ', 0)
106106
for _, app := range list.Apps {
@@ -117,12 +117,12 @@ var corenetLsCmd = &cmds.Command{
117117
},
118118
}
119119

120-
var corenetStreamsCmd = &cmds.Command{
120+
var ptpStreamsCmd = &cmds.Command{
121121
Helptext: cmds.HelpText{
122-
Tagline: "List active application protocol streams.",
122+
Tagline: "List active p2p streams.",
123123
},
124124
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),
126126
},
127127
Run: func(req cmds.Request, res cmds.Response) {
128128
n, err := req.InvocContext().GetNode()
@@ -142,10 +142,10 @@ var corenetStreamsCmd = &cmds.Command{
142142
return
143143
}
144144

145-
output := &CorenetStreamsOutput{}
145+
output := &PTPStreamsOutput{}
146146

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{
149149
HandlerID: strconv.FormatUint(s.HandlerID, 10),
150150

151151
Protocol: s.Protocol,
@@ -160,11 +160,11 @@ var corenetStreamsCmd = &cmds.Command{
160160

161161
res.SetOutput(output)
162162
},
163-
Type: CorenetStreamsOutput{},
163+
Type: PTPStreamsOutput{},
164164
Marshalers: cmds.MarshalerMap{
165165
cmds.Text: func(res cmds.Response) (io.Reader, error) {
166166
headers, _, _ := res.Request().Option("headers").Bool()
167-
list, _ := res.Output().(*CorenetStreamsOutput)
167+
list, _ := res.Output().(*PTPStreamsOutput)
168168
buf := new(bytes.Buffer)
169169
w := tabwriter.NewWriter(buf, 1, 2, 1, ' ', 0)
170170
for _, stream := range list.Streams {
@@ -181,12 +181,11 @@ var corenetStreamsCmd = &cmds.Command{
181181
},
182182
}
183183

184-
var corenetListenCmd = &cmds.Command{
184+
var ptpListenCmd = &cmds.Command{
185185
Helptext: cmds.HelpText{
186186
Tagline: "Create application protocol listener and proxy to network multiaddr.",
187187
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.
190189
191190
Note that the connections originate from the ipfs daemon process.
192191
`,
@@ -214,7 +213,7 @@ Note that the connections originate from the ipfs daemon process.
214213
}
215214

216215
proto := "/app/" + req.Arguments()[0]
217-
if cnet.CheckProtoExists(n, proto) {
216+
if ptpnet.CheckProtoExists(n, proto) {
218217
res.SetError(errors.New("protocol handler already registered"), cmds.ErrNormal)
219218
return
220219
}
@@ -225,30 +224,30 @@ Note that the connections originate from the ipfs daemon process.
225224
return
226225
}
227226

228-
_, err = cnet.NewListener(n, proto, addr)
227+
_, err = ptpnet.NewListener(n, proto, addr)
229228
if err != nil {
230229
res.SetError(err, cmds.ErrNormal)
231230
return
232231
}
233232

234233
// Successful response.
235-
res.SetOutput(&CorenetAppInfoOutput{
234+
res.SetOutput(&PTPAppInfoOutput{
236235
Protocol: proto,
237236
Address: addr.String(),
238237
})
239238
},
240239
}
241240

242-
var corenetDialCmd = &cmds.Command{
241+
var ptpDialCmd = &cmds.Command{
243242
Helptext: cmds.HelpText{
244-
Tagline: "Dial to an application service.",
243+
Tagline: "Dial to a p2p listener.",
245244

246245
ShortDescription: `
247246
Establish a new connection to a peer service.
248247
249248
When a connection is made to a peer service the ipfs daemon will setup one time
250249
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.
252251
`,
253252
},
254253
Arguments: []cmds.Argument{
@@ -291,13 +290,13 @@ transparently connect to a corenet service.
291290
}
292291
}
293292

294-
app, err := cnet.Dial(n, addr, peer, proto, bindAddr)
293+
app, err := ptpnet.Dial(n, addr, peer, proto, bindAddr)
295294
if err != nil {
296295
res.SetError(err, cmds.ErrNormal)
297296
return
298297
}
299298

300-
output := CorenetAppInfoOutput{
299+
output := PTPAppInfoOutput{
301300
Protocol: app.Protocol,
302301
Address: app.Address.String(),
303302
}
@@ -306,13 +305,12 @@ transparently connect to a corenet service.
306305
},
307306
}
308307

309-
var corenetCloseCmd = &cmds.Command{
308+
var ptpCloseCmd = &cmds.Command{
310309
Helptext: cmds.HelpText{
311-
Tagline: "Closes an active stream listener or client.",
310+
Tagline: "Closes an active p2p stream or listener.",
312311
},
313312
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"),
316314
},
317315
Options: []cmds.Option{
318316
cmds.BoolOption("all", "a", "Close all streams and listeners.").Default(false),
@@ -344,7 +342,7 @@ var corenetCloseCmd = &cmds.Command{
344342

345343
if !closeAll {
346344
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)
348346
return
349347
}
350348

@@ -357,7 +355,7 @@ var corenetCloseCmd = &cmds.Command{
357355
}
358356

359357
if closeAll || useHandlerID {
360-
for _, stream := range n.Corenet.Streams.Streams {
358+
for _, stream := range n.PTP.Streams.Streams {
361359
if !closeAll && handlerID != stream.HandlerID {
362360
continue
363361
}
@@ -369,7 +367,7 @@ var corenetCloseCmd = &cmds.Command{
369367
}
370368

371369
if closeAll || !useHandlerID {
372-
for _, app := range n.Corenet.Apps.Apps {
370+
for _, app := range n.PTP.Apps.Apps {
373371
if !closeAll && app.Protocol != proto {
374372
continue
375373
}

core/commands/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ADVANCED COMMANDS
4747
pin Pin objects to local storage
4848
repo Manipulate the IPFS repository
4949
stats Various operational stats
50-
corenet Libp2p stream mounting
50+
ptp Libp2p stream mounting
5151
filestore Manage the filestore (experimental)
5252
5353
NETWORK COMMANDS
@@ -99,7 +99,6 @@ var rootSubcommands = map[string]*cmds.Command{
9999
"cat": CatCmd,
100100
"commands": CommandsDaemonCmd,
101101
"config": ConfigCmd,
102-
"corenet": CorenetCmd,
103102
"dag": dag.DagCmd,
104103
"dht": DhtCmd,
105104
"diag": DiagCmd,
@@ -115,6 +114,7 @@ var rootSubcommands = map[string]*cmds.Command{
115114
"object": ocmd.ObjectCmd,
116115
"pin": PinCmd,
117116
"ping": PingCmd,
117+
"ptp": PTPCmd,
118118
"pubsub": PubsubCmd,
119119
"refs": RefsCmd,
120120
"repo": RepoCmd,

core/core.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
bstore "github.com/ipfs/go-ipfs/blocks/blockstore"
2525
bserv "github.com/ipfs/go-ipfs/blockservice"
26-
corenet "github.com/ipfs/go-ipfs/corenet"
26+
ptp "github.com/ipfs/go-ipfs/ptp"
2727
exchange "github.com/ipfs/go-ipfs/exchange"
2828
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
2929
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
@@ -132,7 +132,7 @@ type IpfsNode struct {
132132
IpnsRepub *ipnsrp.Republisher
133133

134134
Floodsub *floodsub.PubSub
135-
Corenet *corenet.Corenet
135+
PTP *ptp.PTP
136136

137137
proc goprocess.Process
138138
ctx context.Context
@@ -248,7 +248,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
248248
n.Floodsub = floodsub.NewFloodSub(ctx, peerhost)
249249
}
250250

251-
n.Corenet = corenet.NewCorenet()
251+
n.PTP = ptp.NewPTP()
252252

253253
// setup local discovery
254254
if do != nil {

corenet/corenet.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

corenet/apps.go renamed to ptp/apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package corenet
1+
package ptp
22

33
import (
44
"io"

ptp/corenet.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ptp
2+
3+
// PTP structure holds information on currently running streams/apps
4+
type PTP struct {
5+
Apps AppRegistry
6+
Streams StreamRegistry
7+
}
8+
9+
// NewPTP creates new PTP struct
10+
func NewPTP() *PTP {
11+
return &PTP{}
12+
}

0 commit comments

Comments
 (0)