Beispiel #1
0
func (w *Worker) Stats(l *hkp.Lookup) {
	keyStatsLock.Lock()
	defer keyStatsLock.Unlock()
	resp := &StatsResponse{
		Lookup: l,
		Stats: &HkpStats{
			Version:        hockeypuck.Version,
			KeyStatsHourly: keyStatsHourly,
			KeyStatsDaily:  keyStatsDaily,
			TotalKeys:      keyStatsTotal,
		},
	}
	resp.Stats.fetchServerInfo(l)
	l.Response() <- resp
}
Beispiel #2
0
func (w *Worker) Stats(l *hkp.Lookup) {
	keyStatsLock.Lock()
	defer keyStatsLock.Unlock()
	resp := &StatsResponse{
		Lookup: l,
		Stats: &HkpStats{
			Version:        hockeypuck.Version,
			KeyStatsHourly: keyStatsHourly,
			KeyStatsDaily:  keyStatsDaily,
		},
	}
	resp.Stats.fetchServerInfo(l)
	err := w.db.Get(resp.Stats, `
SELECT CAST(reltuples AS INTEGER) AS total_keys FROM pg_class WHERE relname = 'openpgp_pubkey'`)
	if err != nil {
		l.Response() <- &ErrorResponse{err}
		return
	}
	l.Response() <- resp
}
Beispiel #3
0
func (w *Worker) Lookup(l *hkp.Lookup) {
	// Dispatch the lookup operation to the correct query
	if l.Op == hkp.Stats {
		w.Stats(l)
		return
	} else if l.Op == hkp.UnknownOperation {
		l.Response() <- &ErrorResponse{hkp.ErrorUnknownOperation("")}
		return
	}
	var keys []*Pubkey
	var limit int = LOOKUP_RESULT_LIMIT
	var err error
	if l.Op == hkp.HashGet {
		keys, err = w.LookupHash(l.Search)
	} else {
		keys, err = w.LookupKeys(l.Search, limit)
	}
	if err != nil {
		l.Response() <- &ErrorResponse{err}
		return
	}
	// Formulate a response
	var resp hkp.Response
	switch l.Op {
	case hkp.Get:
		resp = &KeyringResponse{keys}
	case hkp.HashGet:
		resp = &KeyringResponse{keys}
	case hkp.Index:
		resp = &IndexResponse{Lookup: l, Keys: keys}
	case hkp.Vindex:
		resp = &IndexResponse{Lookup: l, Keys: keys, Verbose: true}
	default:
		resp = &ErrorResponse{ErrUnsupportedOperation}
		return
	}
	l.Response() <- resp
}