Exemplo n.º 1
0
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()
	}
}
Exemplo n.º 2
0
func BenchmarkLowLevelRemoveTag(b *testing.B) {

	//Generate HKID from Private Key String
	hkidT := objects.HkidFromDString("19161720602889299965155738268484539070322612877960367"+
		"6430690841377095800236259476217638708086844263509012365665750826156"+
		"6766981217762072709507121631102726282", 10)
	//2c0b96cd9cd53349b7733f6f3c1b0993c350fa29ae9c9e05706f616fbf66a98a

	for i := 0; i < b.N; i++ {

		//Create Blob Object
		testBlob := objects.Blob([]byte("BlobToBeDeletedFromTag"))

		//Create Tag Object
		postTag(testBlob.Hash(), hkidT)

		//Retrieve Tag Object
		testTag, err := services.GetTag(hkidT, "testBlob")
		if err != nil {
			b.Fatalf("Error: Could Not retrieve tag: %s", err)
		}

		//Remove Blob from Tag Object
		emptyTag := testTag.Delete()

		//Publish empty Tag
		services.PostTag(emptyTag)

		//Retrieve Empty Tag
		newEmptyTag, err := services.GetTag(hkidT, "testBlob")
		if err != nil {
			b.Fatalf("Error: Could not retrieve Tag: %s", err)
		}

		//Check Tag to ensure it is empty
		if newEmptyTag.TypeString != "nab" {
			b.Fatalf("Error: Incorrect Tag Retrieved%s", newEmptyTag.TypeString)

		}
	}
}
Exemplo n.º 3
0
func (d dir) LookupTag(name string, intr fs.Intr, nodeID fuse.NodeID) (fs.Node, fuse.Error) {
	select {
	case <-intr:
		return nil, fuse.EINTR
	default:
	}
	t, tagErr := services.GetTag(d.leaf.(objects.HKID), name) //leaf is HID
	// no blobs because blobs are for file structure

	if tagErr != nil {
		log.Printf("not a tag Err:%s", tagErr)
		return nil, fuse.ENOENT
	}
	//getKey to figure out permissions of the child
	_, keyErr := services.GetKey(t.Hkid)
	perm := os.FileMode(0555) //default read permissions
	if keyErr == nil {
		perm = os.FileMode(0755)
	} else {
		log.Printf("no private key %s:", keyErr)
	}
	if t.TypeString == "blob" {
		b, blobErr := services.GetBlob(t.HashBytes.(objects.HCID))
		sizeBlob := 0
		if blobErr == nil {
			sizeBlob = len(b)
		}
		return file{
			contentHash: t.HashBytes.(objects.HCID),
			permission:  perm,
			name:        name,
			parent:      &d,
			inode:       nodeID,
			size:        uint64(sizeBlob),
		}, nil
	}
	return dir{
		leaf:        t.HashBytes,
		permission:  perm,
		contentType: t.TypeString,
		parent:      &d,
		name:        name,
		openHandles: map[string]*openFileHandle{},
		inode:       generateInode(d.parent.inode, name),
	}, nil
}
Exemplo n.º 4
0
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()
		}
	}
}
Exemplo n.º 5
0
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
	}
}
Exemplo n.º 6
0
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
}