mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 02:47:48 +08:00
This commit adds a sequence number to the IpnsEntry protobuf that is used to determine which among a set of entries for the same key is the 'most correct'. GetValues has been added to the routing interface to retrieve a set of records from the dht, for the caller to select from. GetValue (singular) will call GetValues, select the 'best' record, and then update that record to peers we received outdated records from. This will help keep the dht consistent. License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
41 lines
981 B
Go
41 lines
981 B
Go
package record
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
key "github.com/ipfs/go-ipfs/blocks/key"
|
|
)
|
|
|
|
// A SelectorFunc selects the best value for the given key from
|
|
// a slice of possible values and returns the index of the chosen one
|
|
type SelectorFunc func(key.Key, [][]byte) (int, error)
|
|
|
|
type Selector map[string]SelectorFunc
|
|
|
|
func (s Selector) BestRecord(k key.Key, recs [][]byte) (int, error) {
|
|
if len(recs) == 0 {
|
|
return 0, errors.New("no records given!")
|
|
}
|
|
|
|
parts := strings.Split(string(k), "/")
|
|
if len(parts) < 3 {
|
|
log.Infof("Record key does not have selectorfunc: %s", k)
|
|
return 0, errors.New("record key does not have selectorfunc")
|
|
}
|
|
|
|
sel, ok := s[parts[1]]
|
|
if !ok {
|
|
log.Infof("Unrecognized key prefix: %s", parts[1])
|
|
return 0, ErrInvalidRecordType
|
|
}
|
|
|
|
return sel(k, recs)
|
|
}
|
|
|
|
// PublicKeySelector just selects the first entry.
|
|
// All valid public key records will be equivalent.
|
|
func PublicKeySelector(k key.Key, vals [][]byte) (int, error) {
|
|
return 0, nil
|
|
}
|