diff --git a/project/blob.go b/project/blob.go index e7ff5a0..ef21b15 100644 --- a/project/blob.go +++ b/project/blob.go @@ -53,13 +53,7 @@ func fileExists(filename string) bool { func blobExists(mhash string) bool { p1, fname := pathAndFilename(mhash) p2 := path.Join(p1, fname) - result := fileExists(p2) - if result { - fmt.Printf("$$$$$ GOT IT %s\n", p2) - } else { - fmt.Printf("$$$$$ NOPE %s\n", p2) - } - return result + return fileExists(p2) } func addBlob(mhash string, data []byte) string { diff --git a/project/encoders.go b/project/encoders.go index 43f5a5a..7e16eef 100644 --- a/project/encoders.go +++ b/project/encoders.go @@ -19,3 +19,9 @@ func encodePeerMhash(pubKey []byte) string { func encodeBlobMhash(sha256 []byte) string { return BlobSigil + B32Encode(sha256[:]) } + +func encodeMessageMhash(b32signature string) string { + sigData := B32Decode(b32signature) + shaData := getSha256(sigData) + return MessageSigil + B32Encode(shaData) +} diff --git a/project/import_bundle.go b/project/import_bundle.go index ad1a38f..1fc5263 100644 --- a/project/import_bundle.go +++ b/project/import_bundle.go @@ -7,15 +7,23 @@ import ( "path/filepath" ) -const insertMessageQuery = "INSERT INTO messages(author, depth, kind, lipmaa, prev, signature) VALUES(?1, ?2, ?3, ?4, ?5, ?6)" +const insertMessageQuery = "INSERT INTO messages(author, depth, kind, lipmaa, prev, signature, mhash) VALUES(?1, ?2, ?3, ?4, ?5, ?6, $7)" const insertBodyItemQuery = "INSERT INTO body_items(parent, key, value, rank) VALUES(?1, ?2, ?3, ?4)" func ingestOneMessage(msg pigeonMessage, blobIndex map[string]bool) { if getPeerStatus(msg.author) == following { tx, err1 := getDB().Begin() check(err1, "ingestOneMessage: Can't open DB: %s", err1) - results, err2 := tx.Exec(insertMessageQuery, msg.author, msg.depth, msg.kind, msg.lipmaa, msg.prev, msg.signature) - rollbackCheck(tx, err2, "Failed to save message %s", msg.signature) + mhash := encodeMessageMhash(msg.signature) + results, err2 := tx.Exec(insertMessageQuery, + msg.author, + msg.depth, + msg.kind, + msg.lipmaa, + msg.prev, + msg.signature, + mhash) + rollbackCheck(tx, err2, "Failed to save message %s. %s", msg.signature, err2) parent, err3 := results.LastInsertId() rollbackCheck(tx, err3, "Failed to get last ID for message %s", msg.signature) @@ -50,7 +58,6 @@ func ingestBlobs(p string, blobIndex map[string]bool) { mhash, data := getMhashForFile(blobPath) if blobIndex[mhash] { - fmt.Printf("Ingesting %s\n", mhash) addBlob(mhash, data) blobIndex[mhash] = false } else { diff --git a/project/import_bundle_test.go b/project/import_bundle_test.go index 33c4941..84f7e13 100644 --- a/project/import_bundle_test.go +++ b/project/import_bundle_test.go @@ -25,15 +25,14 @@ func TestImportBundle(t *testing.T) { } } - t.Fatal("Next step: uncomment code below") - // messages := []string{ - // "TEXT.RGKRHC0APNN9FCJTVBN1NR1ZYQ9ZY34PYYASSMJ6016S30ZTWHR0", - // "TEXT.V52B1GH1XS8K1QKJG3AK127XYA23E82J0A2ZQTJ08TF8NZN2A1Y0", - // "TEXT.Z3QS1HPX756E22XWKXAXH7NTSTJGY0AHEM9KQNATTC6HHCACZGN0", - // } - // for _, mhash := range messages { - // if !messageExists(mhash) { - // t.Fatalf("Can't find message: %s", mhash) - // } - // } + messages := []string{ + "TEXT.RGKRHC0APNN9FCJTVBN1NR1ZYQ9ZY34PYYASSMJ6016S30ZTWHR0", + "TEXT.V52B1GH1XS8K1QKJG3AK127XYA23E82J0A2ZQTJ08TF8NZN2A1Y0", + "TEXT.Z3QS1HPX756E22XWKXAXH7NTSTJGY0AHEM9KQNATTC6HHCACZGN0", + } + for _, mhash := range messages { + if !messageExists(mhash) { + t.Fatalf("Can't find message: %s", mhash) + } + } } diff --git a/project/message.go b/project/message.go new file mode 100644 index 0000000..8960920 --- /dev/null +++ b/project/message.go @@ -0,0 +1,5 @@ +package main + +func messageExists(mhash string) bool { + return false +} diff --git a/project/migrations.go b/project/migrations.go index 6dda62d..88eb640 100644 --- a/project/migrations.go +++ b/project/migrations.go @@ -36,7 +36,8 @@ var migrations = []migration{ kind string NOT NULL, lipmaa string NOT NULL, prev string NOT NULL, - signature string NOT NULL + signature string NOT NULL, + mhash string NOT NULL ); `, down: `DROP TABLE IF EXISTS messages`,