diff --git a/README.md b/README.md index 2457df2..85f057d 100644 --- a/README.md +++ b/README.md @@ -33,14 +33,19 @@ Email `contact@vaporsfot.xyz` if you have any questions. - [ ] Switch to [SQLX](https://github.com/jmoiron/sqlx) for extra sanity. - [ ] Write docs for all CLI commands / args AFTER completion. - [ ] Finish all the things below: + +# Protocol Changes? + - [ ] Rename `lipmaa` to `backlink` as Bamboo protocol has done? + - [ ] Don't enforce a structure on how blobs are packed into bundles- the client is forced to determine the SHA checksum regardless. Forced structure just complicates protocol design. + - [ ] Mandate usage of ZIP files so that bundles are always a single file? |Done?|Noun |Verb | Flag / arg 1 | Flag 2 | |-----|------------|-----------|---------------|-----------| | |bundle |ingest | | | - | |blob |remove | mhash | | | |message |show | message mhash | | | |message |find | --all | | + | |blob |remove | mhash | | | |message |find | --last | | | |draft |create | | | | |draft |publish | | | diff --git a/fixture.pgn b/fixtures/fixture.pgn similarity index 100% rename from fixture.pgn rename to fixtures/fixture.pgn diff --git a/fixtures/has_blobs/622PVGPG.blb b/fixtures/has_blobs/622PVGPG.blb new file mode 100644 index 0000000..38b1f66 Binary files /dev/null and b/fixtures/has_blobs/622PVGPG.blb differ diff --git a/fixtures/has_blobs/FV0FVMRG.blb b/fixtures/has_blobs/FV0FVMRG.blb new file mode 100644 index 0000000..ed902d4 Binary files /dev/null and b/fixtures/has_blobs/FV0FVMRG.blb differ diff --git a/fixtures/has_blobs/YPF1PCSG.blb b/fixtures/has_blobs/YPF1PCSG.blb new file mode 100644 index 0000000..a4cd0bd Binary files /dev/null and b/fixtures/has_blobs/YPF1PCSG.blb differ diff --git a/fixtures/has_blobs/messages.pgn b/fixtures/has_blobs/messages.pgn new file mode 100644 index 0000000..fdf1205 --- /dev/null +++ b/fixtures/has_blobs/messages.pgn @@ -0,0 +1,29 @@ +author USER.09XBQDDGZPEKFBFBY67XNR5QA0TRWAKYKYNEDNQTZJV0F1JB0DGG +depth 0 +kind example +lipmaa NONE +prev NONE + +file_name:FILE.FV0FJ0YZADY7C5JTTFYPKDBHTZJ5JVVP5TCKP0605WWXYJG4VMRG + +signature ZYSCKNFP8TW9DME9P9DK4Z4RV09APVEE762HK628K18NMS4DX084XKED71TCRXJNZBWY3TWDYVK1W3K496QF7Y55SCKEWP1D0SP5R30 + +author USER.09XBQDDGZPEKFBFBY67XNR5QA0TRWAKYKYNEDNQTZJV0F1JB0DGG +depth 1 +kind example +lipmaa NONE +prev TEXT.RGKRHC0APNN9FCJTVBN1NR1ZYQ9ZY34PYYASSMJ6016S30ZTWHR0 + +file_name:FILE.YPF11E5N9JFVB6KB1N1WDVVT9DXMCHE0XJWBZHT2CQ29S5SEPCSG + +signature GAZGWG8PWZSP4VSSNYD8J873CQ6KDM93SBMA9VGGC1YW66FER96HEGZQ4CJBH51YN22WMGYADNY2SCWS0JY6YPX4APFDQ60X751JJ1R + +author USER.09XBQDDGZPEKFBFBY67XNR5QA0TRWAKYKYNEDNQTZJV0F1JB0DGG +depth 2 +kind example +lipmaa NONE +prev TEXT.Z3QS1HPX756E22XWKXAXH7NTSTJGY0AHEM9KQNATTC6HHCACZGN0 + +file_name:FILE.622PRNJ7C0S05XR2AHDPKWMG051B1QW5SXMN2RQHF2AND6J8VGPG + +signature W94BVC4ED00Z4TJC0T3BEVC63RJYJC1J4DDS13BJTTGGXK40JSX276B9MV3GPS5JJHZW92YKAZNZ1Q4DCG0K58SCD9ZD0TVZVX7100G diff --git a/project/cli.go b/project/cli.go index 331d21c..a304acc 100644 --- a/project/cli.go +++ b/project/cli.go @@ -145,6 +145,21 @@ var blobFindCommand = &cobra.Command{ }, } +var bundleCommand = &cobra.Command{ + Use: "bundle", + Short: "Operations relating to 'bundles'- a package of information provided by peers", + Run: func(cmd *cobra.Command, args []string) { + }, +} + +var bundleIngestCommand = &cobra.Command{ + Use: "ingest", + Short: "consume a bundle into the local database", + Run: func(cmd *cobra.Command, args []string) { + panic("Work in progress.") + }, +} + // BootstrapCLI wires up all the relevant commands. func BootstrapCLI() { rootCmd.AddCommand(versionCmd) @@ -163,6 +178,9 @@ func BootstrapCLI() { blobRootCmd.AddCommand(blobAddCommand) blobRootCmd.AddCommand(blobFindCommand) + rootCmd.AddCommand(bundleCommand) + bundleCommand.AddCommand(bundleIngestCommand) + if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) diff --git a/project/import_bundle.go b/project/import_bundle.go new file mode 100644 index 0000000..cbc7d3f --- /dev/null +++ b/project/import_bundle.go @@ -0,0 +1,10 @@ +package main + +import "errors" + +func importBundle(path string) error { + // Get messages.pgn file + // Parse messages + // Map over messages + return errors.New("Not done yet") +} diff --git a/project/import_bundle_test.go b/project/import_bundle_test.go new file mode 100644 index 0000000..e4668ba --- /dev/null +++ b/project/import_bundle_test.go @@ -0,0 +1,10 @@ +package main + +import "testing" + +func TestImportBundle(t *testing.T) { + error := importBundle("../fixtures/has_blobs/messages.pgn") + if error != nil { + t.Fatalf("Error while importing: %s", error) + } +} diff --git a/project/parser_test.go b/project/parser_test.go index afa48f4..bd71ec4 100644 --- a/project/parser_test.go +++ b/project/parser_test.go @@ -7,7 +7,7 @@ import ( ) func TestParser(t *testing.T) { - content, err1 := ioutil.ReadFile("../fixture.pgn") + content, err1 := ioutil.ReadFile("../fixtures/fixture.pgn") if err1 != nil { log.Fatal(err1) } @@ -23,3 +23,33 @@ func TestParser(t *testing.T) { t.Fatalf("Expected %d items, got %d", fixtureSize, length) } } + +func TestParser2(t *testing.T) { + content, err1 := ioutil.ReadFile("../fixtures/has_blobs/messages.pgn") + if err1 != nil { + log.Fatal(err1) + } + output, err2 := parseMessage(string(content)) + + if err2 != nil { + log.Fatal(err2) + } + + fixtureSize := 3 + length := len(output) + if length != fixtureSize { + t.Fatalf("Expected %d items, got %d", fixtureSize, length) + } + sig0 := "ZYSCKNFP8TW9DME9P9DK4Z4RV09APVEE762HK628K18NMS4DX084XKED71TCRXJNZBWY3TWDYVK1W3K496QF7Y55SCKEWP1D0SP5R30" + if output[0].signature != sig0 { + t.Fatal("`sig0` is not correct") + } + sig1 := "GAZGWG8PWZSP4VSSNYD8J873CQ6KDM93SBMA9VGGC1YW66FER96HEGZQ4CJBH51YN22WMGYADNY2SCWS0JY6YPX4APFDQ60X751JJ1R" + if output[1].signature != sig1 { + t.Fatal("`sig1` is not correct") + } + sig2 := "W94BVC4ED00Z4TJC0T3BEVC63RJYJC1J4DDS13BJTTGGXK40JSX276B9MV3GPS5JJHZW92YKAZNZ1Q4DCG0K58SCD9ZD0TVZVX7100G" + if output[2].signature != sig2 { + t.Fatal("`sig2` is not correct") + } +}