Remove old main code

This commit is contained in:
Oskar Thoren 2019-04-18 11:28:10 +08:00
parent 3c2933f081
commit 8dada4b41e
No known key found for this signature in database
GPG Key ID: 33AAFB33580C538E
1 changed files with 1 additions and 82 deletions

View File

@ -97,86 +97,5 @@ func pull(location string, mr string, haves []string) []string {
}
func main() {
fmt.Printf("Hello Merkleslash\n")
var list []merkletree.Content
list = append(list, TestContent{x: "Hello"})
list = append(list, TestContent{x: "Hi"})
list = append(list, TestContent{x: "Hey"})
// XXX: Let's assume we don't have this part of the tree
//list = append(list, TestContent{x: "Hola"})
t, err := merkletree.NewTree(list)
if err != nil {
log.Fatal(err)
}
mr := t.MerkleRoot()
mrHex := hex.EncodeToString(mr)
log.Println("Merkle Root:" , mrHex)
// mr2, err := hex.DecodeString(mrHex)
// if err != nil {
// log.Fatal(err)
// }
// log.Println("Merkle Root" , mr2)
vt, err := t.VerifyTree()
if err != nil {
log.Fatal(err)
}
log.Println("Verify Tree:", vt)
vc, err := t.VerifyContent(list[0])
if err != nil {
log.Fatal(err)
}
log.Println("Verify Content:", vc)
//log.Println(t)
// 1. Get trusted root
newMR := getTrustedRoot("", "")
log.Println("Trusted root:", newMR)
// 2. Sync difference
var emptyList []string
// NOTE: Byzantine case
location := "byzantine"
payloads := pull(location, newMR, emptyList)
//log.Println("Pulled payloads:", payloads)
content := TestContent{x: payloads[0]}
contents := list
contents = append(contents, content)
// Build up untrusted tree and compare it with contents
untrusted := t
// XXX: is there no way to append to tree?
err = untrusted.RebuildTreeWith(contents)
untrustedRoot := hex.EncodeToString(untrusted.MerkleRoot())
log.Println("Untrusted root [Byzantine case]:", untrustedRoot)
log.Println("Good data [Good case]?", untrustedRoot == newMR)
// NOTE: Good case
// TODO: partial case
location2 := "good"
payloads2 := pull(location2, newMR, emptyList)
//log.Println("Pulled payloads:", payloads)
content2 := TestContent{x: payloads2[0]}
contents2 := list
contents2 = append(contents2, content2)
// Build up untrusted tree and compare it with contents
untrusted2 := t
// XXX: is there no way to append to tree?
err = untrusted.RebuildTreeWith(contents)
untrustedRoot2 := hex.EncodeToString(untrusted2.MerkleRoot())
log.Println("Untrusted root [Good case]:", untrustedRoot2)
log.Println("Good data [Good case]?", untrustedRoot2 == newMR)
// Some more cases, let's tease them out
// 1) No data, only trusted root, good feedback (enhancement: partial list of other childs)
// 2) Some data
fmt.Printf("Hello Merkleslash, see tests\n")
}