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())
	}
}
Example #2
0
func postCommit(hcid objects.HCID, hkidC objects.HKID) (testCommit objects.Commit) {
	testCommitPointingToTestList := objects.NewCommit(hcid,
		hkidC) //gen test commit
	err := services.PostCommit(testCommitPointingToTestList) //post test commit
	if err != nil {
		log.Println(err)
	}

	return testCommitPointingToTestList
}
Example #3
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()
	}
}
Example #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)
	}
}
Example #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")
		}
	}
}
Example #6
0
func commitHelper(h objects.HKID, path string, postBytes objects.Byteser, postType string) (objects.HID, error) {
	c, geterr := GetCommit(h)
	posterr := error(nil)
	if geterr == nil {
		//A existing vertion was found
		nextTypeString := "list"
		nextHash := c.ListHash
		nextPath := path
		var hashOfPosted objects.HID
		hashOfPosted, posterr = post(nextHash, nextPath,
			nextTypeString, postBytes, postType)
		if posterr != nil {
			return nil, posterr
		}
		c = c.Update(hashOfPosted.Bytes())
	} else {
		//A existing vertion was NOT found
		_, err := GetPrivateKeyForHkid(h)
		if err == nil {
			nextHash := objects.HID(nil)
			nextPath := path
			nextTypeString := "list"
			var hashOfPosted objects.HID
			hashOfPosted, posterr = post(nextHash, nextPath,
				nextTypeString, postBytes, postType)
			c = objects.NewCommit(hashOfPosted.Bytes(), h)
		} else {
			log.Printf("You don't seem to own this repo\n\th=%v\n\terr=%v\n", h, err)
			return objects.HKID{}, fmt.Errorf("You don't seem to own this repo")
		}
	}
	if posterr != nil {
		return nil, posterr
	}
	//log.Print(c)
	err := PostCommit(c)
	if err == nil {
		return c.Hkid, nil
	}
	return nil, err
}
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)
	}
}