-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
namesys/pubsub: --enable-namesys-pubsub option and management
Commits: package.json: update go-libp2p-blankhost namesys: fix stale package imports update go-testutil namesys/pubsub: reduce bootstrap provide period to 8hr namesys/pubsub: try to extract the key from id first option to enable ipns pubsub: --enable-namesys-pubsub ipfs name pubsub management subcommands corehttp/gateway_test: mockNamesys needs to implement GetResolver pacify code climate License: MIT Signed-off-by: vyzo <[email protected]>
- Loading branch information
Showing
11 changed files
with
207 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package commands | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
cmds "github.com/ipfs/go-ipfs/commands" | ||
ns "github.com/ipfs/go-ipfs/namesys" | ||
|
||
u "gx/ipfs/QmSU6eubNdhXjFBJBSksTp8kv8YRub8mGAPv8tVJHmL2EU/go-ipfs-util" | ||
) | ||
|
||
type ipnsPubsubState struct { | ||
Enabled bool | ||
} | ||
|
||
// IpnsPubsubCmd is the subcommand that allows us to manage the IPNS pubsub system | ||
var IpnsPubsubCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "IPNS pubsub management", | ||
ShortDescription: ` | ||
Manage and inspect the state of the IPNS pubsub resolver. | ||
Note: this command is experimental and subject to change as the system is refined | ||
`, | ||
}, | ||
Subcommands: map[string]*cmds.Command{ | ||
"state": ipnspsStateCmd, | ||
"subs": ipnspsSubsCmd, | ||
"cancel": ipnspsCancelCmd, | ||
}, | ||
} | ||
|
||
var ipnspsStateCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "Query the state of IPNS pubsub", | ||
}, | ||
Run: func(req cmds.Request, res cmds.Response) { | ||
n, err := req.InvocContext().GetNode() | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
_, ok := n.Namesys.GetResolver("pubsub") | ||
res.SetOutput(&ipnsPubsubState{ok}) | ||
}, | ||
Type: ipnsPubsubState{}, | ||
Marshalers: cmds.MarshalerMap{ | ||
cmds.Text: func(res cmds.Response) (io.Reader, error) { | ||
output, ok := res.Output().(*ipnsPubsubState) | ||
if !ok { | ||
return nil, u.ErrCast() | ||
} | ||
|
||
var state string | ||
if output.Enabled { | ||
state = "enabled" | ||
} else { | ||
state = "disabled" | ||
} | ||
|
||
return strings.NewReader(state + "\n"), nil | ||
}, | ||
}, | ||
} | ||
|
||
var ipnspsSubsCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "Show current name subscriptions", | ||
}, | ||
Run: func(req cmds.Request, res cmds.Response) { | ||
n, err := req.InvocContext().GetNode() | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
r, ok := n.Namesys.GetResolver("pubsub") | ||
if !ok { | ||
res.SetError(errors.New("IPNS pubsub subsystem is not enabled"), cmds.ErrClient) | ||
return | ||
} | ||
|
||
psr, ok := r.(*ns.PubsubResolver) | ||
if !ok { | ||
res.SetError(fmt.Errorf("unexpected resolver type: %v", r), cmds.ErrNormal) | ||
return | ||
} | ||
|
||
res.SetOutput(&stringList{psr.GetSubscriptions()}) | ||
}, | ||
Type: stringList{}, | ||
Marshalers: cmds.MarshalerMap{ | ||
cmds.Text: stringListMarshaler, | ||
}, | ||
} | ||
|
||
var ipnspsCancelCmd = &cmds.Command{ | ||
Helptext: cmds.HelpText{ | ||
Tagline: "Cancel a name subscription", | ||
}, | ||
Run: func(req cmds.Request, res cmds.Response) { | ||
n, err := req.InvocContext().GetNode() | ||
if err != nil { | ||
res.SetError(err, cmds.ErrNormal) | ||
return | ||
} | ||
|
||
r, ok := n.Namesys.GetResolver("pubsub") | ||
if !ok { | ||
res.SetError(errors.New("IPNS pubsub subsystem is not enabled"), cmds.ErrClient) | ||
return | ||
} | ||
|
||
psr, ok := r.(*ns.PubsubResolver) | ||
if !ok { | ||
res.SetError(fmt.Errorf("unexpected resolver type: %v", r), cmds.ErrNormal) | ||
return | ||
} | ||
|
||
psr.Cancel(req.Arguments()[0]) | ||
}, | ||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("name", true, false, "Name to cancel the subscription for."), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters