Example #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
}
Example #2
0
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")
}
Example #3
0
func (a appsscriptservice) GetCommit(h objects.HKID) (c objects.Commit, err error) {
	quarryurl := fmt.Sprintf(
		"%s%s%s%s%s%s",
		"https://",
		"script.google.com",
		"/macros/s/AKfycbzl2R7UR2FGGVdgl_WbKabbIoku66ELRSnQ4pbkmBgDdWWvgh8b/exec?",
		//"/macros/s/AKfycbxyU7ABEmq4HS_8nb7E5ZbtJKRwuVlLBwnhUJ4VjSH0/dev?",
		"type=commit",
		"&hkid=",
		h.Hex(),
	)
	//log.Println(quarryurl)
	resp, err := http.Get(quarryurl)
	if err != nil {
		return c, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return c, err
	}
	data, err := base64.StdEncoding.DecodeString(string(body))
	if err != nil {
		log.Println("error:", err)
		return c, err
	}
	c, err = objects.CommitFromBytes(data)
	return c, err
}
Example #4
0
//GetCommitForHcid retrieves a specific commit by its HCID
func GetCommitForHcid(hash objects.HCID) (commit objects.Commit, err error) {
	commitbytes, err := GetBlob(hash)
	if err != nil {
		return commit, err
	}
	commit, err = objects.CommitFromBytes(commitbytes)
	//if err != nil {
	//	return commit, err
	//}
	return commit, err
}
Example #5
0
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
}
Example #6
0
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
}
Example #7
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")
	}
}
Example #8
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
}