Beispiel #1
0
func (ks *Keyserver) findRatificationsForEpoch(epoch uint64, desiredVerifiers map[uint64]struct{}) (
	ratifications []*proto.SignedEpochHead, haveVerifiers map[uint64]struct{}, err error,
) {
	ratifications = []*proto.SignedEpochHead{}
	haveVerifiers = make(map[uint64]struct{})
	for verifier := range desiredVerifiers {
		sehBytes, err := ks.db.Get(tableRatifications(epoch, verifier))
		switch err {
		case nil:
		case ks.db.ErrNotFound():
			continue
		default:
			log.Printf("ERROR: ks.db.Get(tableRatifications(%d, %d): %s", epoch, verifier, err)
			return nil, nil, fmt.Errorf("internal error")
		}
		seh := new(proto.SignedEpochHead)
		err = seh.Unmarshal(sehBytes)
		if err != nil {
			log.Printf("ERROR: tableRatifications(%d, %d) = %x is invalid: %s", epoch, verifier, sehBytes, err)
			return nil, nil, fmt.Errorf("internal error")
		}
		ratifications = append(ratifications, seh)
		haveVerifiers[verifier] = struct{}{}
	}
	return
}
Beispiel #2
0
func (ks *Keyserver) allRatificationsForEpoch(epoch uint64) (map[uint64]*proto.SignedEpochHead, error) {
	iter := ks.db.NewIterator(&kv.Range{Start: tableRatifications(epoch, 0), Limit: tableRatifications(epoch+1, 0)})
	defer iter.Release()
	sehs := make(map[uint64]*proto.SignedEpochHead)
	for iter.Next() {
		id := binary.BigEndian.Uint64(iter.Key()[1+8 : 1+8+8])
		seh := new(proto.SignedEpochHead)
		err := seh.Unmarshal(iter.Value())
		if err != nil {
			log.Panicf("tableRatifications(%d, %d) invalid: %s", epoch, id, err)
		}
		sehs[id] = seh
	}
	if err := iter.Error(); err != nil {
		return nil, err
	}
	return sehs, nil
}