TODO: Finish messageExists(mhash) helper
This commit is contained in:
parent
df61290c12
commit
f3580b8c8c
|
@ -53,13 +53,7 @@ func fileExists(filename string) bool {
|
||||||
func blobExists(mhash string) bool {
|
func blobExists(mhash string) bool {
|
||||||
p1, fname := pathAndFilename(mhash)
|
p1, fname := pathAndFilename(mhash)
|
||||||
p2 := path.Join(p1, fname)
|
p2 := path.Join(p1, fname)
|
||||||
result := fileExists(p2)
|
return fileExists(p2)
|
||||||
if result {
|
|
||||||
fmt.Printf("$$$$$ GOT IT %s\n", p2)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("$$$$$ NOPE %s\n", p2)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addBlob(mhash string, data []byte) string {
|
func addBlob(mhash string, data []byte) string {
|
||||||
|
|
|
@ -19,3 +19,9 @@ func encodePeerMhash(pubKey []byte) string {
|
||||||
func encodeBlobMhash(sha256 []byte) string {
|
func encodeBlobMhash(sha256 []byte) string {
|
||||||
return BlobSigil + B32Encode(sha256[:])
|
return BlobSigil + B32Encode(sha256[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func encodeMessageMhash(b32signature string) string {
|
||||||
|
sigData := B32Decode(b32signature)
|
||||||
|
shaData := getSha256(sigData)
|
||||||
|
return MessageSigil + B32Encode(shaData)
|
||||||
|
}
|
||||||
|
|
|
@ -7,15 +7,23 @@ import (
|
||||||
"path/filepath"
|
"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)"
|
const insertBodyItemQuery = "INSERT INTO body_items(parent, key, value, rank) VALUES(?1, ?2, ?3, ?4)"
|
||||||
|
|
||||||
func ingestOneMessage(msg pigeonMessage, blobIndex map[string]bool) {
|
func ingestOneMessage(msg pigeonMessage, blobIndex map[string]bool) {
|
||||||
if getPeerStatus(msg.author) == following {
|
if getPeerStatus(msg.author) == following {
|
||||||
tx, err1 := getDB().Begin()
|
tx, err1 := getDB().Begin()
|
||||||
check(err1, "ingestOneMessage: Can't open DB: %s", err1)
|
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)
|
mhash := encodeMessageMhash(msg.signature)
|
||||||
rollbackCheck(tx, err2, "Failed to save message %s", 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()
|
parent, err3 := results.LastInsertId()
|
||||||
rollbackCheck(tx, err3, "Failed to get last ID for message %s", msg.signature)
|
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)
|
mhash, data := getMhashForFile(blobPath)
|
||||||
|
|
||||||
if blobIndex[mhash] {
|
if blobIndex[mhash] {
|
||||||
fmt.Printf("Ingesting %s\n", mhash)
|
|
||||||
addBlob(mhash, data)
|
addBlob(mhash, data)
|
||||||
blobIndex[mhash] = false
|
blobIndex[mhash] = false
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -25,15 +25,14 @@ func TestImportBundle(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Fatal("Next step: uncomment code below")
|
messages := []string{
|
||||||
// messages := []string{
|
"TEXT.RGKRHC0APNN9FCJTVBN1NR1ZYQ9ZY34PYYASSMJ6016S30ZTWHR0",
|
||||||
// "TEXT.RGKRHC0APNN9FCJTVBN1NR1ZYQ9ZY34PYYASSMJ6016S30ZTWHR0",
|
"TEXT.V52B1GH1XS8K1QKJG3AK127XYA23E82J0A2ZQTJ08TF8NZN2A1Y0",
|
||||||
// "TEXT.V52B1GH1XS8K1QKJG3AK127XYA23E82J0A2ZQTJ08TF8NZN2A1Y0",
|
"TEXT.Z3QS1HPX756E22XWKXAXH7NTSTJGY0AHEM9KQNATTC6HHCACZGN0",
|
||||||
// "TEXT.Z3QS1HPX756E22XWKXAXH7NTSTJGY0AHEM9KQNATTC6HHCACZGN0",
|
}
|
||||||
// }
|
for _, mhash := range messages {
|
||||||
// for _, mhash := range messages {
|
if !messageExists(mhash) {
|
||||||
// if !messageExists(mhash) {
|
t.Fatalf("Can't find message: %s", mhash)
|
||||||
// t.Fatalf("Can't find message: %s", mhash)
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
func messageExists(mhash string) bool {
|
||||||
|
return false
|
||||||
|
}
|
|
@ -36,7 +36,8 @@ var migrations = []migration{
|
||||||
kind string NOT NULL,
|
kind string NOT NULL,
|
||||||
lipmaa string NOT NULL,
|
lipmaa string NOT NULL,
|
||||||
prev 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`,
|
down: `DROP TABLE IF EXISTS messages`,
|
||||||
|
|
Loading…
Reference in New Issue