mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-12-26 16:45:18 +00:00
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
|
package blossomsub
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/libp2p/go-libp2p/core/protocol"
|
||
|
)
|
||
|
|
||
|
// BlossomSubFeatureTest is a feature test function; it takes a feature and a protocol ID and
|
||
|
// should return true if the feature is supported by the protocol
|
||
|
type BlossomSubFeatureTest = func(BlossomSubFeature, protocol.ID) bool
|
||
|
|
||
|
// BlossomSubFeature is a feature discriminant enum
|
||
|
type BlossomSubFeature int
|
||
|
|
||
|
const (
|
||
|
// Protocol supports basic BlossomSub Mesh -- BlossomSub-v1.1 compatible
|
||
|
BlossomSubFeatureMesh = iota
|
||
|
// Protocol supports Peer eXchange on prune -- BlossomSub-v1.1 compatible
|
||
|
BlossomSubFeaturePX
|
||
|
)
|
||
|
|
||
|
// BlossomSubDefaultProtocols is the default BlossomSub router protocol list
|
||
|
var BlossomSubDefaultProtocols = []protocol.ID{BlossomSubID_v11, FloodSubID}
|
||
|
|
||
|
// BlossomSubDefaultFeatures is the feature test function for the default BlossomSub protocols
|
||
|
func BlossomSubDefaultFeatures(feat BlossomSubFeature, proto protocol.ID) bool {
|
||
|
switch feat {
|
||
|
case BlossomSubFeatureMesh:
|
||
|
return proto == BlossomSubID_v11
|
||
|
case BlossomSubFeaturePX:
|
||
|
return proto == BlossomSubID_v11
|
||
|
default:
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithBlossomSubProtocols is a BlossomSub router option that configures a custom protocol list
|
||
|
// and feature test function
|
||
|
func WithBlossomSubProtocols(protos []protocol.ID, feature BlossomSubFeatureTest) Option {
|
||
|
return func(ps *PubSub) error {
|
||
|
gs, ok := ps.rt.(*BlossomSubRouter)
|
||
|
if !ok {
|
||
|
return fmt.Errorf("pubsub router is not BlossomSub")
|
||
|
}
|
||
|
|
||
|
gs.protos = protos
|
||
|
gs.feature = feature
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
}
|