From 737c660133797954f9a77c3b71447d5b57d4b71e Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 20 Jun 2023 13:56:04 +0200 Subject: [PATCH] feat: add protobuf size --- core/commands/name/name.go | 11 ++++++----- test/cli/name_test.go | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/commands/name/name.go b/core/commands/name/name.go index 23ae21272e6..3bcb5c8e415 100644 --- a/core/commands/name/name.go +++ b/core/commands/name/name.go @@ -96,6 +96,7 @@ type IpnsInspectEntry struct { type IpnsInspectResult struct { Entry IpnsInspectEntry + PbSize int SignatureType string HexDump string Validation *IpnsInspectValidation @@ -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()) @@ -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) @@ -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()) } @@ -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() diff --git a/test/cli/name_test.go b/test/cli/name_test.go index a3f6a810661..e0f2f090962 100644 --- a/test/cli/name_test.go +++ b/test/cli/name_test.go @@ -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() @@ -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) { @@ -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) {