コード例 #1
0
func (gds googledriveservice) GetCommit(h objects.HKID) (c objects.Commit, err error) {
	if gds.driveService == nil {
		return objects.Commit{}, fmt.Errorf("Drive Service not initialized")
	}
	thisCommitFolderID, err := gds.getChildWithTitle(gds.commitsFolderID, h.Hex())
	r, err := gds.driveService.Children.List(thisCommitFolderID).Do()
	if err != nil {
		log.Printf("Error: %v\n", err)
		return
	}
	if len(r.Items) < 1 {
		return objects.Commit{}, fmt.Errorf("no file %s", h.Hex())
	}
	latestTitle := ""
	thisCommitfile := new(drive.File)
	for _, item := range r.Items {
		f, err := gds.driveService.Files.Get(item.Id).Do()
		if err != nil {
			return c, err
		}
		if f.Title > latestTitle && err == nil {
			latestTitle = f.Title
			thisCommitfile = f
		}
	}
	commitBytes, err := gds.DownloadFile(thisCommitfile)
	log.Printf("Commit %s:\n%q", h, commitBytes)
	c, err = objects.CommitFromBytes(commitBytes)
	return c, err
}
コード例 #2
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
}
コード例 #3
0
ファイル: directhttp.go プロジェクト: AaronGoldman/ccfs
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")
}
コード例 #4
0
func (a appsscriptservice) GetKey(h objects.HKID) (objects.Blob, error) {
	quarryurl := fmt.Sprintf(
		"%s%s%s%s%s",
		"https://",
		"script.google.com",
		"/macros/s/AKfycbzl2R7UR2FGGVdgl_WbKabbIoku66ELRSnQ4pbkmBgDdWWvgh8b/exec?",
		//"/macros/s/AKfycbxyU7ABEmq4HS_8nb7E5ZbtJKRwuVlLBwnhUJ4VjSH0/dev?",
		"type=key&hkid=",
		h.Hex(),
	)
	//log.Println(quarryurl)
	resp, err := http.Get(quarryurl)
	if err != nil {
		return objects.Blob{}, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return objects.Blob{}, err
	}
	data, err := base64.StdEncoding.DecodeString(string(body))
	if err != nil {
		log.Println("error:", err)
		return nil, err
	}
	return data, err
}
コード例 #5
0
ファイル: directhttp.go プロジェクト: AaronGoldman/ccfs
func (d directhttpservice) GetCommit(h objects.HKID) (objects.Commit, error) {
	for _, host := range hosts {
		urlVersions := fmt.Sprintf(
			"https://%s/c/%s/",
			host,
			h.Hex(),
		)
		bodyVersions, errVersions := urlReadAll(urlVersions)
		if errVersions != nil {
			return objects.Commit{}, errVersions
		}
		versionNumber := latestsVersion(bodyVersions)
		urlCommit := fmt.Sprintf(
			"https://%s/c/%s/%s",
			host,
			h.Hex(),
			versionNumber,
		)
		body, err := urlReadAll(urlCommit)
		if err != nil {
			return objects.Commit{}, err
		}
		commit, err := objects.CommitFromBytes(body)
		if err == nil {
			return commit, err
		}
	}
	return objects.Commit{}, fmt.Errorf("No Hosts")
}
コード例 #6
0
ファイル: localfileservice.go プロジェクト: AaronGoldman/ccfs
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
}
コード例 #7
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
}
コード例 #8
0
ファイル: ccfsWebService.go プロジェクト: AaronGoldman/ccfs
func composeQuery(typestring string, hash objects.HKID, namesegment string) (message string) {
	message = fmt.Sprintf("%s,%s", typestring, hash.String())
	if namesegment != "" {
		message = fmt.Sprintf("%s,%s", message, namesegment)
	}
	return message

}
コード例 #9
0
ファイル: localfileservice.go プロジェクト: AaronGoldman/ccfs
func (lfs localfileservice) GetKey(h objects.HKID) (objects.Blob, error) {
	filepath := fmt.Sprintf("bin/keys/%s", h.Hex())
	//log.Printf("Filepath: %v", filepath)
	filedata, err := ioutil.ReadFile(filepath)
	if err != nil {
		log.Println(err)
	}
	return filedata, err
}
コード例 #10
0
ファイル: kademliaservice.go プロジェクト: AaronGoldman/ccfs
func (k kademliaservice) GetKey(h objects.HKID) (b objects.Blob, err error) {
	values := url.Values{}
	values.Add("type", "key")
	values.Add("hkid", h.Hex())
	data, err := k.getobject(values)
	if err != nil {
		log.Println(err)
		return nil, err
	}
	return data, err
}
コード例 #11
0
ファイル: kademliaservice.go プロジェクト: AaronGoldman/ccfs
func (k kademliaservice) GetCommit(h objects.HKID) (c objects.Commit, err error) {
	values := url.Values{}
	values.Add("type", "commit")
	values.Add("hkid", h.Hex())
	data, err := k.getobject(values)
	if err != nil {
		log.Println(err)
		return c, err
	}
	c, err = objects.CommitFromBytes(data)
	return c, err
}
コード例 #12
0
ファイル: localfileservice.go プロジェクト: AaronGoldman/ccfs
func (lfs localfileservice) GetCommit(h objects.HKID) (c objects.Commit, err error) {
	//Validate input
	matches, err := filepath.Glob(fmt.Sprintf("bin/commits/%s/*", h.Hex()))
	filepath := lfs.latestVersion(matches)
	//log.Printf("Filepath: %v", filepath)
	data, err := ioutil.ReadFile(filepath)
	if err != nil {
		return
	}
	c, err = objects.CommitFromBytes(data)
	return c, err
}
コード例 #13
0
ファイル: kademliaservice.go プロジェクト: AaronGoldman/ccfs
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
}
コード例 #14
0
func (gds googledriveservice) GetKey(h objects.HKID) (b objects.Blob, err error) {
	if gds.driveService == nil {
		return nil, fmt.Errorf("Drive Service not initialized")
	}
	fileID, err := gds.getChildWithTitle(gds.keysFolderID, h.Hex())
	f, err := gds.driveService.Files.Get(fileID).Do()
	fileString, err := gds.DownloadFile(f)
	if err != nil {
		log.Printf("An error occurred: %v\n", err)
		return nil, err
	}
	log.Printf("Key %s:\n%q", h, fileString)
	return objects.Blob(fileString), err
}
コード例 #15
0
ファイル: multicastservice.go プロジェクト: AaronGoldman/ccfs
func (m multicastservice) GetKey(h objects.HKID) (b objects.Blob, err error) {
	message := fmt.Sprintf("{\"type\":\"key\",\"hkid\": \"%s\"}", h.Hex())
	m.sendmessage(message)
	keychannel := make(chan objects.Blob)
	m.waitingforkey[h.Hex()] = keychannel
	select {
	case b = <-keychannel:
		return b, err

	case <-time.After(12000 * time.Millisecond):
		//log.Printf("Timing out now")
		return b, fmt.Errorf("GetKey on Multicast service timed out")
	}

}
コード例 #16
0
ファイル: multicastservice.go プロジェクト: AaronGoldman/ccfs
func (m multicastservice) GetCommit(h objects.HKID) (c objects.Commit, err error) {
	message := fmt.Sprintf("{\"type\":\"commit\",\"hkid\": \"%s\"}", h.String())

	commitchannel := make(chan objects.Commit, 1)
	m.waitingforcommit[h.String()] = commitchannel
	m.sendmessage(message)
	select {
	case c = <-commitchannel:
		return c, err

	case <-time.After(150 * time.Millisecond):
		//log.Printf("Timing out now")
		return c, fmt.Errorf("GetCommit on Multicast service timed out")
	}

}
コード例 #17
0
ファイル: checkAvailable.go プロジェクト: AaronGoldman/ccfs
func buildResponse(hkid objects.HKID, hcid objects.HCID, typeString string, nameSegment string, version int64) (response string) {
	if typeString == "blob" {
		response = fmt.Sprintf("{\"type\": \"blob\", \"hcid\": \"%s\", \"URL\": \"%s\"}", hcid.Hex(),
			makeURL(hkid, hcid, typeString, nameSegment, version))
	} else if typeString == "commit" {
		response = fmt.Sprintf("{\"type\": \"commit\",\"hkid\": \"%s\", \"URL\": \"%s\"}", hkid.Hex(),
			makeURL(hkid, hcid, typeString, nameSegment, version))
	} else if typeString == "tag" {
		response = fmt.Sprintf("{\"type\": \"tag\", \"hkid\": \"%s\", \"namesegment\": \"%s\", \"URL\": \"%s\"}", hkid.Hex(), nameSegment,
			makeURL(hkid, hcid, typeString, nameSegment, version))
	} else if typeString == "key" {
		response = fmt.Sprintf("{\"type\": \"key\",\"hkid\": \"%s\", \"URL\": \"%s\"}", hkid.Hex(),
			makeURL(hkid, hcid, typeString, nameSegment, version))
	} else {
		return ""
	}
	return response

}
コード例 #18
0
ファイル: localfileservice.go プロジェクト: AaronGoldman/ccfs
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
}
コード例 #19
0
ファイル: multicastservice.go プロジェクト: AaronGoldman/ccfs
func (m multicastservice) GetTag(
	h objects.HKID,
	namesegment string,
) (t objects.Tag, err error) {
	message := fmt.Sprintf(
		"{\"type\":\"tag\", \"hkid\": \"%s\", \"namesegment\": \"%s\"}",
		h.Hex(),
		namesegment,
	)

	tagchannel := make(chan objects.Tag, 1)
	m.waitingfortag[h.Hex()+namesegment] = tagchannel
	m.sendmessage(message)
	select {
	case t = <-tagchannel:
		return t, err

	case <-time.After(150 * time.Millisecond):
		//log.Printf("Timing out now")
		return t, fmt.Errorf("GetTag on Multicast service timed out")
	}

}
コード例 #20
0
ファイル: checkAvailable.go プロジェクト: AaronGoldman/ccfs
func makeURL(hkid objects.HKID, hcid objects.HCID, typeString string, nameSegment string, version int64) (response string) {
	//Path
	if typeString == "blob" {
		response = fmt.Sprintf("/b/%s" /*host,*/, hcid.Hex())
	} else if typeString == "commit" {
		response = fmt.Sprintf("/c/%s/%d" /*host,*/, hkid.Hex(), version)
	} else if typeString == "tag" {
		response = fmt.Sprintf("/t/%s/%s/%d" /*host,*/, hkid.Hex(), nameSegment, version)
	} else if typeString == "key" {
		response = fmt.Sprintf("/k/%s" /*host,*/, hkid.Hex())
	} else {
		response = ""
	}
	return response
}
コード例 #21
0
ファイル: directhttp.go プロジェクト: AaronGoldman/ccfs
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
}