func TestMulticastservice_GetTag(t *testing.T) {
	//t.Skipf("Come back to this test")
	//log.Printf("The key generated is, %d", KeyGen().D)
	//hkid := HKID{}
	hkid := objects.HkidFromDString("6450698573071574057685373503239926609554390924514830851922442833127942726436428023022500281659846836919706975681006884631876585143520956760217923400876937896", 10)
	b := objects.Blob([]byte("blob found"))
	tagT := objects.NewTag(b.Hash(), "blob", "BlobinTag", hkid)
	localfile.Instance.PostTag(tagT)
	go func() {
		time.Sleep(1 * time.Millisecond)
		mcaddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:8000")
		Instance.receivemessage(fmt.Sprintf("{\"type\":\"tag\", \"hkid\": \"%s\", \"namesegment\": \"%s\", \"URL\": \"/t/%s/%s/%d\"}", hkid, tagT.NameSegment, hkid, tagT.NameSegment, tagT.Version), mcaddr)
	}()

	output, err := Instance.GetTag(tagT.Hkid(), tagT.NameSegment)

	if err != nil {
		t.Errorf("Get Tag Failed \nError:%s", err)
	} else if !output.Verify() {
		//!bytes.Equal(output.Hash(), tag_t.Hash()) {
		t.Errorf("Get Tag Failed \nExpected:%s \nGot: %s", tagT, output)
	}
	if output.Version != tagT.Version {
		log.Printf("Tag is stale %d", tagT.Version-output.Version)
	}
}
Exemple #2
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()
	}
}
Exemple #3
0
func tagHelper(h objects.HID, nextPathSegment string, restOfPath string,
	postBytes objects.Byteser, postType string) (objects.HID, error) {
	t, geterr := GetTag(h.Bytes(), nextPathSegment)
	posterr := error(nil)
	if geterr == nil {
		//the tag exists with that nameSegment
		nextTypeString := t.TypeString
		nextHash := t.HashBytes
		nextPath := restOfPath
		var hashOfPosted objects.HID
		if restOfPath == "" && postType != "blob" {
			hashOfPosted = objects.HKID(postBytes.Bytes()) //insrt reference by HKID
		} else {
			hashOfPosted, posterr = post(nextHash, nextPath,
				nextTypeString, postBytes, postType)
		}
		t = t.Update(hashOfPosted, t.TypeString)
	} else {
		//no tag exists with that nameSegment
		_, err := GetPrivateKeyForHkid(h.(objects.HKID))
		if err == nil {
			//you own the Domain

			nextHash := objects.HID(nil)
			nextPath := restOfPath
			nextTypeString := "list"
			if restOfPath == "" {
				nextTypeString = postType
			}
			log.Printf("tag pointing to a %s named %s", nextTypeString, nextPathSegment)
			var hashOfPosted objects.HID
			if restOfPath == "" && postType != "blob" {
				hashOfPosted = objects.HKID(postBytes.Bytes()) //insert reference by HKID
			} else {
				hashOfPosted, posterr = post(nextHash, nextPath,
					nextTypeString, postBytes, postType)
			}
			t = objects.NewTag(hashOfPosted, nextTypeString, nextPathSegment, nil, h.Bytes())
		} else {
			log.Printf("You don't seem to own this Domain")
			return nil, fmt.Errorf("You dont own the Domain, meanie")
		}
	}
	if posterr != nil {
		return nil, posterr
	}
	//log.Print(t)
	err := PostTag(t)
	if err == nil {
		return t.Hkid, nil
	}
	return nil, err
}
Exemple #4
0
func postTag(objHash objects.HCID, tagHkid objects.HKID) {
	testTagPointingToTestBlob := objects.NewTag(
		objects.HID(objHash),
		"blob",
		"testBlob",
		nil,
		tagHkid,
	) //gen test tag
	err := services.PostTag(testTagPointingToTestBlob) //post test tag
	if err != nil {
		log.Println(err)
	}
}
Exemple #5
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)
	}
}
func TestKademliaserviceTag(t *testing.T) {
	b := objects.Blob("TestPostData")
	domainHkid := objects.HkidFromDString("36353776900433612923412235249557"+
		"5547801975514185453610009798109590341135752484880821676711220739"+
		"4029990114056594565164287698180880449563881968956877896844137", 10)
	intag := objects.NewTag(
		b.Hash(),
		"blob",
		"TestPostBlob",
		[]objects.HCID{},
		domainHkid,
	)
	Instance.PostTag(intag)
	outtag, err := Instance.GetTag(
		domainHkid,
		"TestPostBlob",
	)
	if err != nil {
		t.Errorf("Get Tag Err: %s", err)
	}

	if !outtag.Verify() /*|| !bytes.Equal(outtag.Hkid(), domainHkid)*/ {
		t.Errorf(
			"\nVerify:%v",
			outtag.Verify(),
		)
	}

	if !bytes.Equal(intag.Bytes(), outtag.Bytes()) {
		t.Errorf(
			"\nExpected:%s\nGot:%s",
			intag,
			outtag,
		)
	}
}
Exemple #7
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
	}
}
Exemple #8
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
}