func crawlCommit(targHash objects.HKID) (err error) { firstCommit, commitErr := services.GetCommit(targHash) if commitErr != nil { return commitErr } handleCommit(firstCommit) return nil }
func BenchmarkLowLevelRemoveBlob(b *testing.B) { //Generate HKID from Private Key String commitHkid := objects.HkidFromDString("25237284271696152257500017172738061121437774519248"+ "4973944393756241918592441392745192478415977843322020140748800825891925253"+ "1173359792875255431921541368062567", 10) for i := 0; i < b.N; i++ { //Create Blob and add it to Commit List testBlob := objects.Blob([]byte("BlobToBeDeleted")) _ = services.PostBlob(testBlob) testList := objects.NewList(testBlob.Hash(), "blob", "blobToBeDeleted") services.PostList(testList) testCommit := objects.NewCommit(testList.Hash(), commitHkid) services.PostCommit(testCommit) //Check to make sure Blob was added to Commit List commitFromHkid, err := services.GetCommit(commitHkid) _, err = services.GetList(commitFromHkid.ListHash) listEntry, found := testList["blobToBeDeleted"] if !found { b.Fatalf("Error: Blob could not be found in list") } _, err = services.GetBlob(listEntry.Hash.(objects.HCID)) if err != nil { b.Fatalf("Error: Blob could not be retrieved using HID from list") } //Remove Blob from Commit List testListDelete := testList.Remove("blobToBeDeleted") testCommitDelete := testCommit.Update(testListDelete.Hash()) services.PostCommit(testCommitDelete) //Check to make sure blob Does Not Exist in Commit List dneCommit, _ := services.GetCommit(commitHkid) dneList, _ := services.GetList(dneCommit.ListHash) _, found = dneList["blobToBeDeleted"] if found { b.Fatalf("Error: Blob incorrectly found in list") } } }
func TestLowLevel(t *testing.T) { indata := objects.Blob([]byte("TestPostData")) services.PostBlob(indata) blobhcid, err := objects.HcidFromHex( "ca4c4244cee2bd8b8a35feddcd0ba36d775d68637b7f0b4d2558728d0752a2a2", ) b, err := services.GetBlob(blobhcid) if !bytes.Equal(b.Hash(), blobhcid) { t.Fatalf("GetBlob Fail\nExpected: %s\nGot: %s\n", blobhcid, b.Hash()) //Changed } //6dedf7e580671bd90bc9d1f735c75a4f3692b697f8979a147e8edd64fab56e85 testhkid := objects.HkidFromDString( "6523237356270560228617783789728329416595512649112249373497830592"+ "0722414168936112160694238047304378604753005642729767620850685191"+ "88612732562106886379081213385", 10) testCommit := objects.NewCommit(b.Hash(), testhkid) services.PostCommit(testCommit) c, err := services.GetCommit(testhkid) if err != nil { t.Fatalf("Get Commit Fail: %s", err) } else if !bytes.Equal(c.Hkid, testhkid) { t.Fatalf("Expected: %s Got: %s", testhkid, c.Hkid) } else if !c.Verify() { t.Fatalf("Commit Signature Invalid.") } //ede7bec713c93929751f18b1db46d4be3c95286bd5f2d92b9759ff02115dc312 taghkid := objects.HkidFromDString( "4813315537186321970719165779488475377688633084782731170482174374"+ "7256947679650787426167575073363006751150073195493002048627629373"+ "76227751462258339344895829332", 10) lowlvlTag := objects.NewTag( objects.HID(b.Hash()), "blob", "testBlob", nil, taghkid, ) //gen test tag services.PostTag(lowlvlTag) testtag, err := services.GetTag(taghkid, lowlvlTag.NameSegment) if err != nil { t.Fatalf("GetTag Fail. error: %s", err) } else if !bytes.Equal(testtag.Hkid, taghkid) { t.Fatalf("GetTag Fail.\n\t expected: %v\n\t got: %v", taghkid, testtag.Hkid) } else if !testtag.Verify() { t.Fatalf("GetTag Verify Fail") } prikey, err := services.GetKey(taghkid) if err != nil || !bytes.Equal(prikey.Hkid(), taghkid) || !prikey.Verify() { t.Logf("GetKey Fail") t.Fail() } }
func BenchmarkLowLevelPath(b *testing.B) { //key for tag hkidT := objects.HkidFromDString("39968110670682397993178679825250942322686997267223"+ "4437068973021071131498376777586055610149840018574420844767320660902612889"+ "4016152514163591905578729891874833", 10) //key for commit hkidC := objects.HkidFromDString("4629814823893296480016411334808793836186124559723200"+ "9799621767537249764640887064630013835561124248209118706504211519889067517"+ "10824965155500230480521264034469", 10) for i := 0; i < b.N; i++ { blobHcid := postBlob("testing") postTag(blobHcid, hkidT) tagHcid := postList(hkidT) postCommit(tagHcid, hkidC) //get commit hkid, _ := hex.DecodeString( "1312ac161875b270da2ae4e1471ba94a9883419250caa4c2f1fd80a91b37907e", ) testcommit, err := services.GetCommit(hkid) if err != nil { log.Panic(err) } //log.Printf("authentic commit:%v\n", testcommit.Verify()) if !testcommit.Verify() { b.FailNow() } //get list listbytes, err := services.GetBlob(testcommit.ListHash) if err != nil { log.Panic(err) } testlist, err := objects.ListFromBytes(listbytes) //log.Printf("authentic list:%v\n", ) if !bytes.Equal(testcommit.ListHash, testlist.Hash()) { b.FailNow() } //get tag _, testTagHash := testlist.HashForNamesegment("testTag") testTag, err := services.GetTag(testTagHash.Bytes(), "testBlob") //log.Printf("authentic tag:%v\n", testTag.Verify()) if !testTag.Verify() { b.FailNow() } //get blob testBlob, err := services.GetBlob(testTag.HashBytes.(objects.HCID)) //log.Printf("authentic blob:%v\n", bytes.Equal(testTag.HashBytes, // testBlob.Hash())) if err != nil { b.Fatalf("Get Blob Error: %s\n", err) } if !bytes.Equal(testTag.HashBytes.(objects.HCID), testBlob.Hash()) { b.FailNow() } } }
func (d dir) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) { //log.Printf("ReadDir requested:\n\tName:%s", d.name) select { case <-intr: return nil, fuse.EINTR default: } var l objects.List var listErr error var dirDirs = []fuse.Dirent{} switch d.contentType { case "tag": //if d.content_type == "tag" { tags, tagErr := services.GetTags(d.leaf.(objects.HKID)) if tagErr != nil { log.Printf("tag %s:", tagErr) return nil, fuse.ENOENT } for _, tag := range tags { name := tag.NameSegment enttype := fuse.DT_Dir switch tag.TypeString { case "blob": enttype = fuse.DT_File fallthrough case "list", "commit", "tag": dirDirs = append(dirDirs, fuse.Dirent{ Inode: fs.GenerateDynamicInode(uint64(d.inode), name), Name: name, Type: enttype, }) default: } } return dirDirs, nil case "commit": //} else if d.content_type == "commit" { c, CommitErr := services.GetCommit(d.leaf.(objects.HKID)) if CommitErr != nil { log.Printf("commit %s:", CommitErr) return nil, fuse.ENOENT } l, listErr = services.GetList(c.ListHash) if listErr != nil { log.Printf("commit list %s:", listErr) return nil, fuse.ENOENT } case "list": l, listErr = services.GetList(d.leaf.(objects.HCID)) if listErr != nil { log.Printf("list %s:", listErr) return nil, fuse.ENOENT } default: return nil, fuse.ENOENT } for name, entry := range l { if entry.TypeString == "blob" { appendToList := fuse.Dirent{ Inode: fs.GenerateDynamicInode(uint64(d.inode), name), Name: name, Type: fuse.DT_File, } dirDirs = append(dirDirs, appendToList) } else { appendToList := fuse.Dirent{ Inode: fs.GenerateDynamicInode(uint64(d.inode), name), Name: name, Type: fuse.DT_Dir} dirDirs = append(dirDirs, appendToList) } } //loop through openHandles for openHandle := range d.openHandles { inList := false for _, dirEntry := range dirDirs { if openHandle == dirEntry.Name { inList = true break } } if !inList { dirDirs = append( dirDirs, fuse.Dirent{ Inode: fs.GenerateDynamicInode(uint64(d.inode), openHandle), Name: openHandle, Type: fuse.DT_Dir, }) } } return dirDirs, nil }
func (d dir) LookupCommit(name string, intr fs.Intr, nodeID fuse.NodeID) (fs.Node, fuse.Error) { select { case <-intr: return nil, fuse.EINTR default: } ino := fuse.NodeID(1) if d.parent != nil { ino = generateInode(d.parent.inode, name) } c, CommitErr := services.GetCommit(d.leaf.(objects.HKID)) if CommitErr != nil { return nil, fuse.EIO /* log.Printf("commit %s:", CommitErr) _, err := services.GetKey(d.leaf.(objects.HKID)) perm := os.FileMode(0555) if err == nil { perm = 0777 } return dir{ permission: perm, contentType: "commit", leaf: d.leaf.(objects.HKID), parent: &d, name: name, openHandles: map[string]bool{}, inode: ino, }, nil */ } //get list hash l, listErr := services.GetList(c.ListHash) //l is the list object if listErr != nil { log.Printf("commit list retrieval error %s:", listErr) return nil, nil } listEntry, present := l[name] //go through list entries and is it maps to the string you passed in present == 1 if !present { return nil, fuse.ENOENT } //getKey to figure out permissions of the child _, keyErr := services.GetKey(c.Hkid) //perm := fuse.Attr{Mode: 0555}//default read permissions perm := os.FileMode(0777) if keyErr != nil { log.Printf("error not nil; change file Mode %s:", keyErr) //perm = fuse.Attr{Mode: 0755} perm = os.FileMode(0555) } if listEntry.TypeString == "blob" { b, blobErr := services.GetBlob(listEntry.Hash.(objects.HCID)) sizeBlob := 0 if blobErr == nil { sizeBlob = len(b) } return file{ contentHash: listEntry.Hash.(objects.HCID), permission: perm, name: name, parent: &d, inode: nodeID, size: uint64(sizeBlob), }, nil } ino = fuse.NodeID(1) if d.parent != nil { ino = generateInode(d.parent.inode, name) } return dir{ leaf: listEntry.Hash, permission: perm, contentType: listEntry.TypeString, parent: &d, name: name, openHandles: map[string]*openFileHandle{}, inode: ino, }, nil }
func (d dir) Publish(h objects.HCID, name string, typeString string) (err error) { switch d.contentType { default: log.Printf("unknown type: %s", d.contentType) return fmt.Errorf("unknown type: %s", d.contentType) case "commit": c, CommitErr := services.GetCommit(d.leaf.(objects.HKID)) if CommitErr != nil { return CommitErr } l, listErr := services.GetList(c.ListHash) if listErr != nil { return listErr } newList := l.Add(name, h, typeString) newCommit := c.Update(newList.Hash()) //========================================================================= //if verbosity == 1 { log.Printf( "Posting list %s\n-----BEGIN LIST-------\n%s\n-------END LIST-------", newList.Hash(), newList, ) //} //========================================================================= el := services.PostList(newList) if el != nil { return listErr } //========================================================================= //if verbosity == 1 { log.Printf( "Posting commit %s\n-----BEGIN COMMIT-----\n%s\n-------END COMMIT-----", newCommit.Hash(), newCommit, ) //} //========================================================================= ec := services.PostCommit(newCommit) if ec != nil { return listErr } return nil case "tag": t, tagErr := services.GetTag(d.leaf.(objects.HKID), name) var newTag objects.Tag if tagErr == nil { newTag = t.Update(h, typeString) } else { log.Printf("Tag %s\\%s Not Found", d.leaf, name) newTag = objects.NewTag(h, typeString, name, nil, d.leaf.(objects.HKID)) } //========================================================================= if verbosity == 1 { log.Printf( "Posting tag %s\n-----BEGIN TAG--------\n%s\n-------END TAG--------", newTag.Hash(), newTag, ) } //========================================================================= et := services.PostTag(newTag) if et != nil { return tagErr } return nil case "list": l, listErr := services.GetList(d.leaf.(objects.HCID)) if listErr != nil { return listErr } newList := l.Add(name, h, typeString) //========================================================================= if verbosity == 1 { log.Printf( "Posting list %s\n-----BEGIN LIST-------\n%s\n-------END LIST-------", newList.Hash(), newList, ) } //========================================================================= el := services.PostList(newList) if el != nil { return listErr } d.parent.Publish(newList.Hash(), d.name, "list") return nil } }
func (d dir) Rename( r *fuse.RenameRequest, newDir fs.Node, intr fs.Intr, ) fuse.Error { log.Printf("request: %+v\nobject: %+v", r, d) select { case <-intr: return fuse.EINTR default: } //find content_type if r.OldName != r.NewName { d.name = r.NewName } d.name = r.OldName switch d.contentType { case "list": l, listErr := services.GetList(d.leaf.(objects.HCID)) if listErr != nil { return listErr } newList := l.Add(r.NewName, l[r.OldName].Hash, l[r.OldName].TypeString) newList = l.Remove(r.OldName) //========================================================================= if verbosity == 1 { log.Printf( "Posting list %s\n-----BEGIN LIST-------\n%s\n-------END LIST-------", newList.Hash(), newList, ) } //========================================================================= el := services.PostList(newList) if el != nil { return listErr } d.Publish(d.leaf.(objects.HCID), d.name, d.contentType) case "commit": c, CommitErr := services.GetCommit(d.leaf.(objects.HKID)) if CommitErr != nil { return CommitErr } l, ListErr := services.GetList(c.ListHash) if ListErr != nil { return ListErr } newList := l.Add(r.NewName, l[r.OldName].Hash, l[r.OldName].TypeString) newList = l.Remove(r.OldName) newCommit := c.Update(newList.Hash()) //========================================================================= if verbosity == 1 { log.Printf( "Posting list %s\n-----BEGIN LIST-------\n%s\n-------END LIST-------", newList.Hash(), newList, ) } //========================================================================= el := services.PostList(newList) if el != nil { return ListErr } //========================================================================= if verbosity == 1 { log.Printf( "Posting commit %s\n-----BEGIN COMMIT-----\n%s\n-------END COMMIT-----", newCommit.Hash(), newCommit, ) } //========================================================================= ec := services.PostCommit(newCommit) if ec != nil { return ListErr } case "tag": oldTag, tagErr := services.GetTag(d.leaf.(objects.HKID), r.OldName) var newTag objects.Tag if tagErr == nil { newTag = objects.NewTag( oldTag.HashBytes, oldTag.TypeString, r.NewName, []objects.HCID{oldTag.Hash()}, d.leaf.(objects.HKID), ) } else { log.Printf("Tag %s\\%s Not Found", d.leaf, d.name) return fuse.ENOENT } //========================================================================= if verbosity == 1 { log.Printf( "Posting tag %s\n-----BEGIN TAG--------\n%s\n-------END TAG--------", newTag.Hash(), newTag, ) } //========================================================================= et := services.PostTag(newTag) if et != nil { return tagErr } } //end switch return nil }