2023-11-15 15:58:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
wakuproto "github.com/waku-org/go-waku/waku/v2/protocol"
|
2023-11-25 23:24:20 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2023-11-15 15:58:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Shard struct {
|
|
|
|
Cluster uint16 `json:"cluster"`
|
|
|
|
Index uint16 `json:"index"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func FromProtobuff(p *protobuf.Shard) *Shard {
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Shard{
|
|
|
|
Cluster: uint16(p.Cluster),
|
|
|
|
Index: uint16(p.Index),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) Protobuffer() *protobuf.Shard {
|
|
|
|
if s == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &protobuf.Shard{
|
|
|
|
Cluster: int32(s.Cluster),
|
|
|
|
Index: int32(s.Index),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (s *Shard) PubsubTopic() string {
|
|
|
|
if s != nil {
|
|
|
|
return wakuproto.NewStaticShardingPubsubTopic(s.Cluster, s.Index).String()
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
const MainStatusShardCluster = 16
|
|
|
|
const DefaultShardIndex = 32
|
|
|
|
const NonProtectedShardIndex = 64
|
|
|
|
|
|
|
|
func DefaultShardPubsubTopic() string {
|
|
|
|
return wakuproto.NewStaticShardingPubsubTopic(MainStatusShardCluster, DefaultShardIndex).String()
|
|
|
|
}
|
2023-12-22 12:37:37 +00:00
|
|
|
|
2024-06-06 13:52:51 +00:00
|
|
|
func DefaultNonProtectedShard() *Shard {
|
2023-12-22 12:37:37 +00:00
|
|
|
return &Shard{
|
|
|
|
Cluster: MainStatusShardCluster,
|
|
|
|
Index: NonProtectedShardIndex,
|
|
|
|
}
|
|
|
|
}
|
2024-06-06 13:52:51 +00:00
|
|
|
|
|
|
|
func DefaultNonProtectedPubsubTopic() string {
|
|
|
|
return DefaultNonProtectedShard().PubsubTopic()
|
|
|
|
}
|