github.com/status-im/status-go@v1.1.0/protocol/common/shard/shard.go (about) 1 package shard 2 3 import ( 4 wakuproto "github.com/waku-org/go-waku/waku/v2/protocol" 5 6 "github.com/status-im/status-go/protocol/protobuf" 7 ) 8 9 type Shard struct { 10 Cluster uint16 `json:"cluster"` 11 Index uint16 `json:"index"` 12 } 13 14 func FromProtobuff(p *protobuf.Shard) *Shard { 15 if p == nil { 16 return nil 17 } 18 19 return &Shard{ 20 Cluster: uint16(p.Cluster), 21 Index: uint16(p.Index), 22 } 23 } 24 25 func (s *Shard) Protobuffer() *protobuf.Shard { 26 if s == nil { 27 return nil 28 } 29 30 return &protobuf.Shard{ 31 Cluster: int32(s.Cluster), 32 Index: int32(s.Index), 33 } 34 } 35 func (s *Shard) PubsubTopic() string { 36 if s != nil { 37 return wakuproto.NewStaticShardingPubsubTopic(s.Cluster, s.Index).String() 38 } 39 return "" 40 } 41 42 const MainStatusShardCluster = 16 43 const DefaultShardIndex = 32 44 const NonProtectedShardIndex = 64 45 46 func DefaultShardPubsubTopic() string { 47 return wakuproto.NewStaticShardingPubsubTopic(MainStatusShardCluster, DefaultShardIndex).String() 48 } 49 50 func DefaultNonProtectedShard() *Shard { 51 return &Shard{ 52 Cluster: MainStatusShardCluster, 53 Index: NonProtectedShardIndex, 54 } 55 } 56 57 func DefaultNonProtectedPubsubTopic() string { 58 return DefaultNonProtectedShard().PubsubTopic() 59 }