2023-10-12 19:21:49 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2023-10-18 06:17:49 +00:00
|
|
|
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
|
|
|
|
|
2023-10-12 19:21:49 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
"github.com/status-im/status-go/protocol/transport"
|
|
|
|
)
|
|
|
|
|
2023-09-20 18:30:58 +00:00
|
|
|
const MainStatusShardCluster = 16
|
2023-10-03 20:22:20 +00:00
|
|
|
const NonProtectedShardIndex = 64
|
2023-09-20 18:30:58 +00:00
|
|
|
const UndefinedShardValue = 0
|
|
|
|
|
2023-10-12 19:21:49 +00:00
|
|
|
type Shard struct {
|
|
|
|
Cluster uint16 `json:"cluster"`
|
|
|
|
Index uint16 `json:"index"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func ShardFromProtobuff(p *protobuf.Shard) *Shard {
|
|
|
|
if p == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Shard{
|
|
|
|
Cluster: uint16(p.Cluster),
|
|
|
|
Index: uint16(p.Index),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) TransportShard() *transport.Shard {
|
|
|
|
if s == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &transport.Shard{
|
|
|
|
Cluster: s.Cluster,
|
|
|
|
Index: s.Index,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Shard) Protobuffer() *protobuf.Shard {
|
|
|
|
if s == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &protobuf.Shard{
|
|
|
|
Cluster: int32(s.Cluster),
|
|
|
|
Index: int32(s.Index),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-20 18:30:58 +00:00
|
|
|
func DefaultNonProtectedPubsubTopic(shard *Shard) string {
|
|
|
|
// TODO: remove the condition once DefaultWakuTopic usage
|
|
|
|
// is removed
|
|
|
|
if shard != nil {
|
|
|
|
return transport.GetPubsubTopic(&transport.Shard{
|
|
|
|
Cluster: MainStatusShardCluster,
|
2023-10-03 20:22:20 +00:00
|
|
|
Index: NonProtectedShardIndex,
|
2023-09-20 18:30:58 +00:00
|
|
|
})
|
|
|
|
}
|
2023-10-03 20:22:20 +00:00
|
|
|
|
|
|
|
return relay.DefaultWakuTopic
|
2023-09-20 18:30:58 +00:00
|
|
|
}
|