예제 #1
0
func (d directhttpservice) GetTag(h objects.HKID, namesegment string) (
	objects.Tag, error) {
	for _, host := range hosts {
		quarryurl := fmt.Sprintf(
			"https://%s/t/%s/%s",
			host,
			h.Hex(),
			namesegment,
		)
		bodyVersions, err := urlReadAll(quarryurl)
		if err != nil {
			return objects.Tag{}, err
		}
		versionNumber := latestsVersion(bodyVersions)
		tagurl := fmt.Sprintf(
			"https://%s/t/%s/%s/%s",
			host,
			h.Hex(),
			namesegment,
			versionNumber,
		)
		body, err := urlReadAll(tagurl)
		tag, err := objects.TagFromBytes(body)
		if err == nil {
			return tag, err
		}
	}
	return objects.Tag{}, fmt.Errorf("No Hosts")
}
예제 #2
0
func (lfs localfileservice) GetTags(h objects.HKID) (tags []objects.Tag, err error) {
	//ToDo Validate input
	directoryEntries, err := ioutil.ReadDir(fmt.Sprintf("bin/tags/%s", h.Hex()))
	if err != nil {
		log.Println(err)
	}
	//log.Println(h)
	namesegment := ""
	for _, directoryEntry := range directoryEntries {
		if directoryEntry.IsDir() {
			namesegment = directoryEntry.Name()
		} else {
			continue
		}
		matches, err := filepath.Glob(fmt.Sprintf("bin/tags/%s/%s/*",
			h.Hex(), namesegment))
		filepath := lfs.latestVersion(matches)
		//log.Printf("Filepath: %v", filepath)
		data, err := ioutil.ReadFile(filepath)
		if err == nil {
			tag, err := objects.TagFromBytes(data)
			if err == nil {
				tags = append(tags, tag)
			} else {
				log.Println(err)
			}
		} else {
			log.Panicln(err)
		}
	}
	//log.Println(tags)
	return tags, err
}
예제 #3
0
func (gds googledriveservice) GetTag(h objects.HKID, namesegment string) (t objects.Tag, err error) {
	if gds.driveService == nil {
		return objects.Tag{}, fmt.Errorf("Drive Service not initialized")
	}
	hkidTagFolderID, err := gds.getChildWithTitle(gds.tagsFolderID, h.Hex())
	nameSegmentTagFolderID, err := gds.getChildWithTitle(hkidTagFolderID, namesegment)
	r, err := gds.driveService.Children.List(nameSegmentTagFolderID).Do()
	if err != nil {
		log.Printf("Error: %v\n", err)
		return objects.Tag{}, err
	}
	if len(r.Items) < 1 {
		return objects.Tag{}, fmt.Errorf("no file %s ,%s", h.Hex(), namesegment)
	}
	latestTitle := ""
	thisTagfile := new(drive.File)
	for _, item := range r.Items {
		f, err := gds.driveService.Files.Get(item.Id).Do()
		if err != nil {
			return t, err
		} //log.Println(f.Title)
		if f.Title > latestTitle && err == nil {
			latestTitle = f.Title
			thisTagfile = f
		}

	}
	tagBytes, err := gds.DownloadFile(thisTagfile)
	log.Printf("Tag %s:\n%q", h, tagBytes)
	t, err = objects.TagFromBytes(tagBytes)
	return t, nil
}
예제 #4
0
func (a appsscriptservice) GetTag(h objects.HKID, namesegment string) (t objects.Tag, err error) {
	quarryurl := fmt.Sprintf(
		"%s%s%s%s%s%s%s",
		"https://",
		"script.google.com",
		"/macros/s/AKfycbzl2R7UR2FGGVdgl_WbKabbIoku66ELRSnQ4pbkmBgDdWWvgh8b/exec?",
		//"/macros/s/AKfycbxyU7ABEmq4HS_8nb7E5ZbtJKRwuVlLBwnhUJ4VjSH0/dev?",
		"type=tag&hkid=",
		h.Hex(),
		"&namesegment=",
		namesegment,
	)
	//log.Println(quarryurl)
	resp, err := http.Get(quarryurl)
	if err != nil {
		return t, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return t, err
	}
	data, err := base64.StdEncoding.DecodeString(string(body))
	if err != nil {
		log.Println("error:", err)
		return t, err
	}
	t, err = objects.TagFromBytes(data)
	return t, err
}
예제 #5
0
파일: get.go 프로젝트: AaronGoldman/ccfs
//GetTagForHcid retrieves a specific tag by its HCID
func GetTagForHcid(hash objects.HCID) (tag objects.Tag, err error) {
	tagbytes, err := GetBlob(hash)
	if err != nil {
		return tag, err
	}
	tag, err = objects.TagFromBytes(tagbytes)
	//if err != nil {
	//	return tag, err
	//}
	return tag, err
}
예제 #6
0
func (k kademliaservice) GetTag(h objects.HKID, namesegment string) (t objects.Tag, err error) {
	values := url.Values{}
	values.Add("type", "tag")
	values.Add("hkid", h.Hex())
	values.Add("namesegment", namesegment)
	data, err := k.getobject(values)
	if err != nil {
		log.Println(err)
		return t, err
	}
	t, err = objects.TagFromBytes(data)
	return t, err
}
예제 #7
0
func (lfs localfileservice) GetTag(h objects.HKID, namesegment string) (t objects.Tag, err error) {
	//ToDo Validate input
	matches, err := filepath.Glob(fmt.Sprintf("bin/tags/%s/%s/*",
		h.Hex(), namesegment))
	if err != nil {
		log.Println(err)
	}
	if len(matches) == 0 {
		log.Println("No tags found in folder")
	}
	filepath := lfs.latestVersion(matches)
	//log.Printf("Filepath: %v", filepath)
	data, err := ioutil.ReadFile(filepath)
	if err != nil {
		return
	}
	t, err = objects.TagFromBytes(data)
	return t, err
}
예제 #8
0
func Testbadfrombytes(t *testing.T) {
	var err error
	_, err = objects.ListFromBytes([]byte{})
	if err.Error() != "Could not parse list bytes" {
		t.Errorf("[] should not parse")
	}
	_, err = objects.CommitFromBytes([]byte{})
	if err.Error() != "Could not parse commit bytes" {
		t.Errorf("[] should not parse")
	}
	_, err = objects.TagFromBytes([]byte{})
	if err.Error() != "Could not parse tag bytes" {
		t.Errorf("[] should not parse")
	}
	_, err = objects.PrivateKeyFromBytes([]byte{})
	if err.Error() != "Could not parse commit bytes" {
		t.Errorf("[] should not parse")
	}
}
예제 #9
0
func (d directhttpservice) GetTags(h objects.HKID) (
	tags []objects.Tag, err error) {
	if len(hosts) == 0 {
		return []objects.Tag{}, fmt.Errorf("No Hosts")
	}

	var maxTags map[string]objects.Tag
	for _, host := range hosts {
		quarryurl := fmt.Sprintf(
			"http://%s/t/%s/",
			host,
			h.Hex(),
		)
		bodyNameSegments, err := urlReadAll(quarryurl)
		if err != nil {
			continue
			//return []objects.Tag{}, err
		}
		//ToDo find and get latests version of all labels
		namesegments := allNameSegments(bodyNameSegments)
		for _, namesegment := range namesegments {
			versionurl := fmt.Sprintf(
				"https://%s/t/%s/%s",
				host,
				h.Hex(),
				namesegment,
			)
			versionBody, err := urlReadAll(versionurl)
			if err != nil {
				continue
			}
			versionNumber := latestsVersion(versionBody)

			tagurl := fmt.Sprintf(
				"https://%s/t/%s/%s/%s",
				host,
				h.Hex(),
				namesegment,
				versionNumber,
			)

			body, err := urlReadAll(tagurl)
			if err != nil {
				continue
			}

			tag, err := objects.TagFromBytes(body)
			if err != nil {
				continue
				//return []objects.Tag{tag}, err
			}
			maxTag, present := maxTags[string(namesegment)]
			if !present || maxTag.Version < tag.Version {
				maxTags[string(namesegment)] = tag
			}
		}
	}
	for _, maxTag := range maxTags {
		tags = append(tags, maxTag)
	}
	if len(tags) == 0 {
		return []objects.Tag{}, fmt.Errorf("No Tags found")
	}
	return tags, nil
}
예제 #10
0
func (m multicastservice) receivemessage(
	message string,
	addr net.Addr,
) (err error) {
	//log.Printf("Received message, %s,\n", message)
	hkid, hcid, typestring, namesegment, url := parseMessage(message)
	if url == "" {
		checkAndRespond(hkid, hcid, typestring, namesegment)
		return nil
	}
	host, _, err := net.SplitHostPort(addr.String())
	if err != nil {
		return err
	}
	url = fmt.Sprintf("http://%s:%d%s", host, 8080, url)

	if typestring == "blob" {
		blobchannel, present := m.waitingforblob[hcid.String()]
		//log.Printf("url is %s", url)
		data, err := m.geturl(url)

		if err == nil {
			if present {
				blobchannel <- data
				//log.Printf("Data: %s\nHCID: %s", data, hcid)
			} else {
				log.Printf(
					"%s \nis not present in waiting map, \n%v",
					hcid.String(),
					m.waitingforblob,
				)
			}
			if objects.Blob(data).Hash().Hex() == hcid.Hex() {

				localfile.Instance.PostBlob(data)
			}
		} else {
			log.Printf("error: %s", err)
		}
	}

	if typestring == "tag" {
		tagchannel, present := m.waitingfortag[hkid.Hex()+namesegment]
		data, err := m.geturl(url)
		if err != nil {
			log.Printf("Error from geturl in tag, %s", err)
		}
		t, err := objects.TagFromBytes(data)
		if err == nil {
			if present {
				//log.Printf("Tag is present")
				tagchannel <- t
			} else {
				//log.Printf(
				//	"%s \n is not present in map \n %s",
				//	hkid.Hex()+namesegment,
				//	m.waitingfortag,
				//)
			}
			if t.Verify() {
				localfile.Instance.PostTag(t)
			}
		} else {
			log.Printf("error, %s", err)
			log.Printf("Data, %s", data)
		}
	}

	if typestring == "commit" {
		commitchannel, present := m.waitingforcommit[hkid.String()]
		data, err := m.geturl(url)
		if err != nil {
			log.Printf("Error for geturl in commitchannel is, %s", err)
		} else {
			c, err := objects.CommitFromBytes(data)

			if err == nil {
				if present {
					//log.Printf("commit is present")
					commitchannel <- c
				} else {
					//log.Printf(
					//	"commit %s\n is not present, \n%v",
					//	hkid.String(),
					//	m.waitingforcommit,
					//)
				}
				if c.Verify() {
					localfile.Instance.PostCommit(c)
				}
			}
		}
	}
	if typestring == "key" {
		keychannel, present := m.waitingforkey[hkid.String()]
		data, err := m.geturl(url)
		if err == nil {
			if present {
				log.Printf("key is present")
				keychannel <- data
			} else {
				log.Printf("key is not present, %v", m.waitingforkey)
			}
			p, err := objects.PrivateKeyFromBytes(data)

			if err != nil && p.Verify() && p.Hkid().Hex() == hkid.Hex() {
				localfile.Instance.PostKey(p)
			}

		}
	}

	return err
}