Пример #1
0
// RTTResolver returns a Sliver from a Site with lowest RTT given a client's IP.
func RTTResolver(c appengine.Context, toolID string, ip net.IP) (net.IP, error) {
	cgIP := rtt.GetClientGroup(ip).IP
	rttKey := datastore.NewKey(c, "string", "rtt", 0, nil)
	key := datastore.NewKey(c, "ClientGroup", cgIP.String(), 0, rttKey)

	// Get ClientGroup from datastore.
	var cg rtt.ClientGroup
	err := data.GetData(c, MCKey_ClientGroup(cgIP), key, &cg)
	if err != nil {
		if err == datastore.ErrNoSuchEntity {
			return nil, ErrNotEnoughData
		}
		return nil, err
	}

	// Get first error-less Site and a random SliverTool from selected Site.
	var siteID string
	var sliverTool *data.SliverTool
	for _, sr := range cg.SiteRTTs {
		siteID = sr.SiteID
		sliverTool, err = data.GetRandomSliverFromSite(c, toolID, siteID)
		if err == nil {
			return net.ParseIP(sliverTool.SliverIPv4), nil
		}
	}
	// No valid Site found.
	return nil, ErrNotEnoughData
}
Пример #2
0
// GetLastSuccesfulImportDate returns the last recorded time of a successful
// bigquery import.
func GetLastSuccesfulImportDate(c appengine.Context) (time.Time, error) {
	key := datastore.NewKey(c, "Stats", DSKeyStats, 0, DatastoreParentKey(c))
	var s Stats
	err := data.GetData(c, DSKeyStats, key, &s)
	if err == datastore.ErrNoSuchEntity {
		return EarliestTimewithRTTData, nil
	} else if err != nil {
		return s.LastSuccessfulImportDate, err
	}
	return s.LastSuccessfulImportDate, nil
}
Пример #3
0
// SetLastSuccesfulImportDate sets a time as the last recorded time of a
// successful bigquery import.
func SetLastSuccessfulImportDate(c appengine.Context, t time.Time) error {
	key := datastore.NewKey(c, "Stats", DSKeyStats, 0, DatastoreParentKey(c))
	var s Stats
	if err := data.GetData(c, DSKeyStats, key, &s); err != datastore.ErrNoSuchEntity && err != nil {
		return err
	}
	s.LastSuccessfulImportDate = t
	if err := data.SetData(c, DSKeyStats, key, &s); err != nil {
		return err
	}
	return nil
}