From 1b53d04ccf781263e94dabe0b91fd70b8d50b560 Mon Sep 17 00:00:00 2001 From: kaichao Date: Thu, 5 Sep 2024 18:53:09 +0800 Subject: [PATCH] feat_: accept community join request with mvds (#5787) * feat_: accept community join request with mvds * chore_: no sender when use mvds in comm join response * fix_: only use mvds for tokenized communities * chore_: add comment for this. --- protocol/common/raw_message.go | 1 + protocol/communities/manager.go | 1 + protocol/messenger_communities.go | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/protocol/common/raw_message.go b/protocol/common/raw_message.go index 608d959b8..687d3b78a 100644 --- a/protocol/common/raw_message.go +++ b/protocol/common/raw_message.go @@ -65,6 +65,7 @@ type RawMessage struct { // don't wrap message into ProtocolMessage. // when this is true, the message will not be resent via ResendTypeDataSync, but it's possible to // resend it via ResendTypeRawMessage specified in ResendType + // MVDS only supports sending encrypted message. SkipEncryptionLayer bool SendPushNotification bool MessageType protobuf.ApplicationMetadataMessage_Type diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 86f2bc6fb..2133d1c25 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -3520,6 +3520,7 @@ func (m *Manager) HandleCommunityRequestToJoinResponse(signer *ecdsa.PublicKey, isControlNodeSigner := common.IsPubKeyEqual(community.ControlNode(), signer) if !isControlNodeSigner { + m.logger.Debug("signer is not control node", zap.String("signer", common.PubkeyToHex(signer)), zap.String("controlNode", common.PubkeyToHex(community.ControlNode()))) return nil, ErrNotAuthorized } diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 7be473684..8049f24ed 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -1953,6 +1953,10 @@ func (m *Messenger) CancelRequestToJoinCommunity(ctx context.Context, request *r } func (m *Messenger) acceptRequestToJoinCommunity(requestToJoin *communities.RequestToJoin) (*MessengerResponse, error) { + m.logger.Debug("accept request to join community", + zap.String("community", requestToJoin.CommunityID.String()), + zap.String("pubkey", requestToJoin.PublicKey)) + community, err := m.communitiesManager.AcceptRequestToJoin(requestToJoin) if err != nil { return nil, err @@ -2021,6 +2025,16 @@ func (m *Messenger) acceptRequestToJoinCommunity(requestToJoin *communities.Requ Priority: &common.HighPriority, } + // Non-tokenized community treat community public key as the control node, + // tokenized community set control node to the public key of token owner. + // MVDS doesn't support custom sender, and use the identity key for signing messages, + // receiver will verify the message of community join response is signed by control node. + if !community.PublicKey().Equal(community.ControlNode()) { + rawMessage.ResendType = common.ResendTypeDataSync + rawMessage.SkipEncryptionLayer = false + rawMessage.Sender = nil + } + if community.Encrypted() { rawMessage.HashRatchetGroupID = community.ID() rawMessage.CommunityKeyExMsgType = common.KeyExMsgReuse @@ -2031,8 +2045,10 @@ func (m *Messenger) acceptRequestToJoinCommunity(requestToJoin *communities.Requ return nil, err } - if _, err = m.AddRawMessageToWatch(rawMessage); err != nil { - return nil, err + if rawMessage.ResendType == common.ResendTypeRawMessage { + if _, err = m.AddRawMessageToWatch(rawMessage); err != nil { + return nil, err + } } }