Пример #1
0
func TestMulticastservice_GetCommit(t *testing.T) {
	//t.Skipf("Come back to this test")
	hkid := objects.HkidFromDString("5198719439877464148627795433286736285873678110640040333794349799294848737858561643942881983506066042818105864129178593001327423646717446545633525002218361750", 10)

	b := objects.Blob([]byte("blob found"))
	l := objects.NewList(b.Hash(), "blob", "Blobinlist")
	c := objects.NewCommit(l.Hash(), hkid)
	localfile.Instance.PostCommit(c)
	go func() {
		time.Sleep(1 * time.Millisecond)
		mcaddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:8000")
		Instance.receivemessage(fmt.Sprintf("{\"type\":\"commit\", \"hkid\": \"9bd1b3c9aeda7025068319c0a4af1d2b7b644066c9820d247b19f1b9bf40840c\", \"URL\": \"/c/9bd1b3c9aeda7025068319c0a4af1d2b7b644066c9820d247b19f1b9bf40840c/%d\"}", c.Version), mcaddr)
	}()

	output, err := Instance.GetCommit(c.Hkid())

	if err != nil {
		t.Errorf("Get Commit Failed \nError:%s", err)
	} else if !output.Verify() {
		//else if !bytes.Equal(output.Hash(), c.Hash()) {
		t.Errorf("Get Commit Failed \nExpected:%s \nGot: %s", c, output)
	}
	if output.Version() != c.Version() {
		log.Printf("Commit is stale %d", c.Version()-output.Version())
	}
}
Пример #2
0
func postList(target objects.HKID) (testTagHash objects.HCID) {
	testListPointingToTestTag := objects.NewList(target,
		"tag",
		"testTag") //gen test list
	err := services.PostList(testListPointingToTestTag) //store test list
	if err != nil {
		log.Println(err)
	}
	return testListPointingToTestTag.Hash()
}
Пример #3
0
func listHelper(h objects.HID, nextPathSegment string, restOfPath string,
	postBytes objects.Byteser, postType string) (objects.HID, error) {
	geterr := fmt.Errorf("h in nil")
	l := objects.List(nil)
	if h != nil {
		l, geterr = GetList(h.(objects.HCID))
	}
	posterr := error(nil)
	if geterr == nil {
		//update and publish old list
		nextTypeString, nextHash := l.HashForNamesegment(nextPathSegment)

		nextPath := restOfPath
		if nextTypeString == "" {
			nextTypeString = "list"
		}
		if restOfPath == "" {
			nextTypeString = postType
		}
		var hashOfPosted objects.HID
		if restOfPath == "" && postType != "blob" {
			hashOfPosted = postBytes.(objects.HKID) //insrt reference by HKID
			//log.Printf("insrt reference by HKID\n\tnext_path_segment:%s\n\trest_of_path:%s\n", next_path_segment, rest_of_path)
		} else {
			hashOfPosted, posterr = post(nextHash, nextPath,
				nextTypeString, postBytes, postType) //post Data
		}
		l.Add(nextPathSegment, hashOfPosted, nextTypeString)
	} else {
		//build and publish new list
		nextHash := objects.HID(nil)
		nextPath := restOfPath
		nextTypeString := "list"
		if restOfPath == "" {
			nextTypeString = postType
		}
		var hashOfPosted objects.HID
		if restOfPath == "" && postType != "blob" {
			hashOfPosted = postBytes.(objects.HKID) //insrt reference by HKID
			//log.Printf("insrt reference by HKID\n\tnext_path_segment:%s\n\trest_of_path:%s\n\t", next_path_segment, rest_of_path)
		} else {
			hashOfPosted, posterr = post(nextHash, nextPath,
				nextTypeString, postBytes, postType)
		}
		l = objects.NewList(hashOfPosted, nextTypeString, nextPathSegment)
	}
	if posterr != nil {
		return nil, posterr
	}
	err := PostList(l)
	if err == nil {
		return l.Hash(), nil
	}
	return nil, err
}
Пример #4
0
func setupForGets() {
	hkidT := objects.HkidFromDString("39968110670682397993178679825250942322686997267223"+
		"4437068973021071131498376777586055610149840018574420844767320660902612889"+
		"4016152514163591905578729891874833", 10)

	//key for commit
	hkidC := objects.HkidFromDString("4629814823893296480016411334808793836186124559723200"+
		"9799621767537249764640887064630013835561124248209118706504211519889067517"+
		"10824965155500230480521264034469", 10)

	//Post blob
	testBlob := objects.Blob([]byte("testing")) //gen test blob
	err := services.PostBlob(testBlob)          //store test blob
	if err != nil {
		log.Println(err)
	}

	//post tag
	testTagPointingToTestBlob := objects.NewTag(
		objects.HID(testBlob.Hash()),
		"blob",
		"testBlob",
		nil,
		hkidT,
	) //gen test tag
	err = services.PostTag(testTagPointingToTestBlob) //post test tag
	if err != nil {
		log.Println(err)
	}

	//post list
	testListPiontingToTestTag := objects.NewList(testTagPointingToTestBlob.Hkid,
		"tag",
		"testTag") //gen test list
	err = services.PostBlob(testListPiontingToTestTag.Bytes()) //store test list
	if err != nil {
		log.Println(err)
	}

	// post commit
	testCommitPointingToTestList := objects.NewCommit(testListPiontingToTestTag.Hash(),
		hkidC) //gen test commit
	err = services.PostCommit(testCommitPointingToTestList) //post test commit
	if err != nil {
		log.Println(err)
	}
}
Пример #5
0
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")
		}
	}
}
Пример #6
0
func TestKademliaserviceCommit(t *testing.T) {
	b := objects.Blob("TestPostData")
	l := objects.NewList(
		b.Hash(),
		"blob",
		"TestPostBlob",
	)
	repoHkid := objects.HkidFromDString("64171129167204289916774847858432"+
		"1039643124642934014944704416438487015947986633802511102841255411"+
		"2620702113155684804978643917650455537680636225253952875765474", 10)
	incommit := objects.NewCommit(l.Hash(), repoHkid)
	Instance.PostCommit(incommit)
	outcommit, err := Instance.GetCommit(repoHkid)

	if err != nil {
		t.Fatalf("\nGet Commit Err:%s\n", err)
	}
	if !outcommit.Verify() {
		t.Fatalf("\nVerify:%t", outcommit.Verify())
	}
	if !bytes.Equal(incommit.Bytes(), outcommit.Bytes()) {
		t.Fatalf("\nExpected:%v\nGot:%v", incommit, outcommit)
	}
}