Example #1
0
func (w *Worker) Stats(l *hkp.Lookup) {
	resp := &StatsResponse{Lookup: l, Stats: &HkpStats{Worker: w}}
	resp.Stats.fetchServerInfo(l)
	err := resp.Stats.fetchKeyStats()
	if err != nil {
		l.Response() <- &ErrorResponse{err}
		return
	}
	err = resp.Stats.fetchTotalKeys()
	if err != nil {
		l.Response() <- &ErrorResponse{err}
		return
	}
	l.Response() <- resp
}
Example #2
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
	}
	//PRC Start
	delegated := false
	//PRC End

	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 || len(keys) < 1 {
			//PRC Start
			errLocal := err
			//Delegate to SKS
			//if len(keys) < 1
			//Do a Query with 0x
			if Config().GetBool("authority.delegateToPKS") {
				sksServer := Config().GetStringDefault("authority.delegateAddress", "pool.sks-keyservers.net:11371")
				keys, err = DelegateToSKS(l.Search, sksServer)
				if len(keys) < 1 || err != nil {
					keys, err = DelegateToSKS("0x"+l.Search, sksServer)
				}
				if len(keys) > 0 && err == nil {
					delegated = true
				}
				if err != nil {
					err = errLocal
				}

			}
		}
		//PRC End
	}
	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:
		//PRC Original in HP
		//resp = &IndexResponse{Lookup: l, Keys: keys}
		resp = &IndexResponse{Lookup: l, Keys: keys, Delegated: delegated}
	case hkp.Vindex:
		//PRC Original in HP
		//resp = &IndexResponse{Lookup: l, Keys: keys, Verbose: true}
		resp = &IndexResponse{Lookup: l, Keys: keys, Verbose: true, Delegated: delegated}
	default:
		resp = &ErrorResponse{ErrUnsupportedOperation}
		return
	}
	l.Response() <- resp
}