fix: do not send the requests to join and cancel in the protected topic

This commit is contained in:
Richard Ramos 2023-09-20 14:30:58 -04:00 committed by richΛrd
parent 350a952116
commit ace5b26137
5 changed files with 27 additions and 39 deletions

View File

@ -3,8 +3,13 @@ package common
import (
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/transport"
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
)
const MainStatusShardCluster = 16
const NonProtectedIndex = 128
const UndefinedShardValue = 0
type Shard struct {
Cluster uint16 `json:"cluster"`
Index uint16 `json:"index"`
@ -43,5 +48,15 @@ func (s *Shard) Protobuffer() *protobuf.Shard {
}
}
const MainStatusShard = 16
const UndefinedShardValue = 0
func DefaultNonProtectedPubsubTopic(shard *Shard) string {
// TODO: remove the condition once DefaultWakuTopic usage
// is removed
if shard != nil {
return transport.GetPubsubTopic(&transport.Shard{
Cluster: MainStatusShardCluster,
Index: NonProtectedIndex,
})
} else {
return relay.DefaultWakuTopic
}
}

View File

@ -1617,6 +1617,12 @@ func (m *Messenger) Init() error {
logger := m.logger.With(zap.String("site", "Init"))
// Community requests will arrive in this pubsub topic
err := m.SubscribeToPubsubTopic(common.DefaultNonProtectedPubsubTopic(nil), nil)
if err != nil {
return err
}
var (
filtersToInit []transport.FiltersToInitialize
publicKeys []*ecdsa.PublicKey

View File

@ -17,8 +17,6 @@ import (
"github.com/golang/protobuf/proto"
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
@ -1097,7 +1095,7 @@ func (m *Messenger) RequestToJoinCommunity(request *requests.RequestToJoinCommun
CommunityID: community.ID(),
SkipProtocolLayer: true,
MessageType: protobuf.ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN,
PubsubTopic: relay.DefaultWakuTopic, // TODO: this should be sent on a non protected pubsub topic.
PubsubTopic: common.DefaultNonProtectedPubsubTopic(community.Shard()),
}
_, err = m.sender.SendCommunityMessage(context.Background(), rawMessage)
@ -1415,7 +1413,7 @@ func (m *Messenger) CancelRequestToJoinCommunity(request *requests.CancelRequest
CommunityID: community.ID(),
SkipProtocolLayer: true,
MessageType: protobuf.ApplicationMetadataMessage_COMMUNITY_CANCEL_REQUEST_TO_JOIN,
PubsubTopic: relay.DefaultWakuTopic, // TODO: this should be sent on a non protected pubsub topic.
PubsubTopic: common.DefaultNonProtectedPubsubTopic(community.Shard()),
}
_, err = m.sender.SendCommunityMessage(context.Background(), rawMessage)
@ -1531,7 +1529,7 @@ func (m *Messenger) AcceptRequestToJoinCommunity(request *requests.AcceptRequest
Sender: community.PrivateKey(),
SkipProtocolLayer: true,
MessageType: protobuf.ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN_RESPONSE,
PubsubTopic: community.PubsubTopic(), // TODO: confirm if it should be sent in community pubsub topic
PubsubTopic: common.DefaultNonProtectedPubsubTopic(community.Shard()),
}
_, err = m.sender.SendPrivate(context.Background(), pk, rawMessage)

View File

@ -138,13 +138,6 @@ func (m *Messenger) prepareEncodedCommunityData(community *communities.Community
return "", "", err
}
shardCluster := int32(common.UndefinedShardValue)
shardIndex := int32(common.UndefinedShardValue)
if community.Shard() != nil {
shardCluster = int32(community.Shard().Cluster)
shardIndex = int32(community.Shard().Index)
}
urlDataProto := &protobuf.URLData{
Content: communityData,
Shard: community.Shard().Protobuffer(),
@ -209,14 +202,6 @@ func (m *Messenger) parseCommunityURLWithData(data string, chatKey string) (*URL
return nil, err
}
var shard *common.Shard
if urlDataProto.ShardCluster != common.UndefinedShardValue && urlDataProto.ShardIndex != common.UndefinedShardValue {
shard = &common.Shard{
Cluster: uint16(urlDataProto.ShardCluster),
Index: uint16(urlDataProto.ShardIndex),
}
}
return &URLDataResponse{
Community: CommunityURLData{
DisplayName: communityProto.DisplayName,
@ -320,14 +305,6 @@ func (m *Messenger) prepareEncodedCommunityChannelData(community *communities.Co
return "", "", err
}
shardCluster := int32(common.UndefinedShardValue)
shardIndex := int32(common.UndefinedShardValue)
if community.Shard() != nil {
shardCluster = int32(community.Shard().Cluster)
shardIndex = int32(community.Shard().Index)
}
urlDataProto := &protobuf.URLData{
Content: channelData,
Shard: community.Shard().Protobuffer(),
@ -405,14 +382,6 @@ func (m *Messenger) parseCommunityChannelURLWithData(data string, chatKey string
return nil, err
}
var shard *common.Shard
if urlDataProto.ShardCluster != common.UndefinedShardValue && urlDataProto.ShardIndex != common.UndefinedShardValue {
shard = &common.Shard{
Cluster: uint16(urlDataProto.ShardCluster),
Index: uint16(urlDataProto.ShardIndex),
}
}
return &URLDataResponse{
Community: CommunityURLData{
DisplayName: channelProto.Community.DisplayName,

View File

@ -19,7 +19,7 @@ func (s *SetCommunityShard) Validate() error {
}
if s.Shard != nil {
// TODO: for now only MainStatusShard(16) is accepted
if s.Shard.Cluster != common.MainStatusShard {
if s.Shard.Cluster != common.MainStatusShardCluster {
return errors.New("invalid shard cluster")
}
if s.Shard.Index > 1023 {