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 }
// This function seeds the queue from a web request func seedQueue(hkidhex string) (err error) { h, hexerr := objects.HcidFromHex(hkidhex) if hexerr == nil { err = crawlList(objects.HCID(h.Bytes())) if err != nil { log.Println("seed was not a List") } err = crawlBlob(objects.HCID(h.Bytes())) if err != nil { log.Println("seed was not a Blob") } err = crawlCommit(objects.HKID(h.Bytes())) if err != nil { log.Println("seed was not a Commit") } err = crawlhcidCommit(objects.HCID(h.Bytes())) if err != nil { log.Println("seed was not a Commit's hcid") } err = crawlhcidTag(objects.HCID(h.Bytes())) if err != nil { log.Println("seed was not a Tag's hcid") } } else { log.Println(hexerr) } return hexerr }
func TestGetBlob(t *testing.T) { //hkidFromDString("4629814823893296480016411334808793836186124559723200"+ // "9799621767537249764640887064630013835561124248209118706504211519889067517"+ // "10824965155500230480521264034469", 10) //store the key setupForGets() dabytes, err := hex.DecodeString("1312ac161875b270da2ae4e1471ba94a" + "9883419250caa4c2f1fd80a91b37907e") hkid := objects.HKID(dabytes) path := "testTag/testBlob" b := []byte(":(") if err == nil { //log.Println(hkid.Hex()) b, err = services.Get(hkid, path) } if !bytes.Equal([]byte("testing"), b) || err != nil { t.Fail() } }