Skip to content

Commit

Permalink
feat: add protobuf size
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Jun 20, 2023
1 parent 3299daf commit 737c660
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions core/commands/name/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type IpnsInspectEntry struct {

type IpnsInspectResult struct {
Entry IpnsInspectEntry
PbSize int
SignatureType string
HexDump string
Validation *IpnsInspectValidation
Expand Down Expand Up @@ -129,7 +130,7 @@ Passing --verify will verify signature against provided public key.
},
Options: []cmds.Option{
cmds.StringOption("verify", "CID of the public IPNS key to validate against."),
cmds.BoolOption("verbose", "Show a full hex dump of the raw Protobuf record."),
cmds.BoolOption("dump", "Include a full hex dump of the raw Protobuf record.").WithDefault(true),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
file, err := cmdenv.GetFileArg(req.Files.Entries())
Expand Down Expand Up @@ -188,6 +189,7 @@ Passing --verify will verify signature against provided public key.
} else {
result.SignatureType = "Unknown"
}
result.PbSize = proto.Size(&pbRecord)

if verify, ok := req.Options["verify"].(string); ok {
name, err := ipns.NameFromString(verify)
Expand All @@ -207,7 +209,7 @@ Passing --verify will verify signature against provided public key.
}
}

if verbose, ok := req.Options["verbose"].(bool); ok && verbose {
if dump, ok := req.Options["dump"].(bool); ok && dump {
result.HexDump = hex.Dump(b.Bytes())
}

Expand Down Expand Up @@ -239,9 +241,8 @@ Passing --verify will verify signature against provided public key.
fmt.Fprintf(tw, "TTL:\t%s\n", out.Entry.TTL.String())
}

if out.SignatureType != "" {
fmt.Fprintf(tw, "Signature Type:\t%s\n", out.SignatureType)
}
fmt.Fprintf(tw, "Protobuf Size:\t%d\n", out.PbSize)
fmt.Fprintf(tw, "Signature Type:\t%s\n", out.SignatureType)

if out.Validation == nil {
tw.Flush()
Expand Down
3 changes: 2 additions & 1 deletion test/cli/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func TestName(t *testing.T) {

res = node.IPFS("routing", "get", ipnsPath)
record := res.Stdout.Bytes()
t.Log(record)

res = node.PipeToIPFS(bytes.NewReader(record), "name", "inspect")
out := res.Stdout.String()
Expand All @@ -181,6 +180,7 @@ func TestName(t *testing.T) {
out = res.Stdout.String()
require.Contains(t, out, "Valid: true")
require.Contains(t, out, "Signature Type: V2")
require.Contains(t, out, fmt.Sprintf("Protobuf Size: %d", len(record)))
})

t.Run("Publish with TTL and inspect record", func(t *testing.T) {
Expand All @@ -202,6 +202,7 @@ func TestName(t *testing.T) {
require.Contains(t, out, publishPath)
require.Contains(t, out, "30m")
require.Contains(t, out, "Signature Type: V1+V2")
require.Contains(t, out, fmt.Sprintf("Protobuf Size: %d", len(record)))
})

t.Run("Inspect record shows valid with correct name", func(t *testing.T) {
Expand Down

0 comments on commit 737c660

Please sign in to comment.