go-libp2p-pubsub-router
go-libp2p-pubsub-router copied to clipboard
PubsubValueStore should handle arbitrary merge functions
Currently the PubsubValueStore
assumes Pubsub is distributing a single Key-Value pair which is updating by utilizing a best
function that is passed in via the Validator
interface.
This looks like:
bestVal, updated := best(currentVal, receivedVal)
if updated {
data[key]=bestVal
Publish(bestVal)
}
Instead it would be better to use an interface that allows for:
updatedState, delta := merge(currentState, receivedState)
if delta != nil {
data[key]=updatedState
Publish(delta)
}
Given that the PubsubValueStore
assumes Get
and Put
of full data records (as opposed to deltas) it's probably fine to assume that the types of the state
and delta
s are the same. However, if we wanted we could also add a diff
function that takes the states and computes a delta.
Some example merge
functions:
- Best (as we have now)
- Union (if the record type is a set take the union of the set)
- BestN (do a union, but only keep the best N records)
Having this (and landing #33) would make an implementation of the suggestion at https://github.com/libp2p/go-libp2p/issues/694#issuecomment-517339808 fairly straightforward.