Skip to content

GO-5401: Add object type to message for ignore purposes #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions commonspace/object/acl/syncacl/headupdate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package syncacl

import (
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
"github.com/anyproto/any-sync/commonspace/sync/objectsync/objectmessages"
"github.com/anyproto/any-sync/consensus/consensusproto"
)
Expand All @@ -24,6 +25,10 @@ func (h *InnerHeadUpdate) MsgSize() uint64 {
return size + uint64(len(h.head)) + uint64(len(h.root.Id)) + uint64(len(h.root.Payload))
}

func (h *InnerHeadUpdate) ObjectType() spacesyncproto.ObjectType {
return spacesyncproto.ObjectType_Acl
}

func (h *InnerHeadUpdate) Prepare() error {
logMsg := consensusproto.WrapHeadUpdate(&consensusproto.LogHeadUpdate{
Head: h.head,
Expand Down
5 changes: 5 additions & 0 deletions commonspace/object/tree/synctree/headupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"slices"

"github.com/anyproto/any-sync/commonspace/object/tree/treechangeproto"
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
"github.com/anyproto/any-sync/commonspace/sync/objectsync/objectmessages"
)

Expand All @@ -21,6 +22,10 @@ func (h *InnerHeadUpdate) MsgSize() (size uint64) {
return uint64(len(h.prepared))
}

func (h *InnerHeadUpdate) ObjectType() spacesyncproto.ObjectType {
return spacesyncproto.ObjectType_Tree
}

func (h *InnerHeadUpdate) Prepare() error {
treeMsg := treechangeproto.WrapHeadUpdate(&treechangeproto.TreeHeadUpdate{
Heads: h.heads,
Expand Down
10 changes: 9 additions & 1 deletion commonspace/spacesyncproto/protos/spacesync.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ message ObjectSyncMessage {
string replyId = 3;
bytes payload = 4;
string objectId = 5;
ObjectType objectType = 6;
}

// SpacePushRequest is a request to add space on a node containing only one acl record
Expand Down Expand Up @@ -201,4 +202,11 @@ enum DiffType {
Initial = 0;
V1 = 1;
V2 = 2;
}
}

// ObjectType is a type of object
enum ObjectType {
Tree = 0;
Acl = 1;
KeyValue = 2;
}
242 changes: 155 additions & 87 deletions commonspace/spacesyncproto/spacesync.pb.go

Large diffs are not rendered by default.

31 changes: 20 additions & 11 deletions commonspace/sync/objectsync/objectmessages/headupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type InnerHeadUpdate interface {
Prepare() error
Heads() []string
MsgSize() uint64
ObjectType() spacesyncproto.ObjectType
}

type ObjectMeta struct {
Expand All @@ -48,10 +49,11 @@ type ObjectMeta struct {
}

type HeadUpdate struct {
Meta ObjectMeta
Bytes []byte
Update InnerHeadUpdate
msg *spacesyncproto.ObjectSyncMessage
Meta ObjectMeta
Bytes []byte
Update InnerHeadUpdate
objectType spacesyncproto.ObjectType
msg *spacesyncproto.ObjectSyncMessage
}

func (h *HeadUpdate) MsgSize() uint64 {
Expand Down Expand Up @@ -84,6 +86,7 @@ func (h *HeadUpdate) SetProtoMessage(message proto.Message) error {
h.Bytes = msg.GetPayload()
h.Meta.SpaceId = msg.SpaceId
h.Meta.ObjectId = msg.ObjectId
h.objectType = msg.GetObjectType()
return nil
}

Expand All @@ -94,14 +97,19 @@ func (h *HeadUpdate) ProtoMessage() (proto.Message, error) {
return nil, err
}
return &spacesyncproto.ObjectSyncMessage{
SpaceId: h.Meta.SpaceId,
Payload: payload,
ObjectId: h.Meta.ObjectId,
SpaceId: h.Meta.SpaceId,
Payload: payload,
ObjectId: h.Meta.ObjectId,
ObjectType: h.Update.ObjectType(),
}, nil
}
return NewMessage(), nil
}

func (h *HeadUpdate) ObjectType() spacesyncproto.ObjectType {
return h.objectType
}

func (h *HeadUpdate) SpaceId() string {
return h.Meta.SpaceId
}
Expand All @@ -116,9 +124,10 @@ func (h *HeadUpdate) ObjectId() string {

func (h *HeadUpdate) Copy() drpc.Message {
return &HeadUpdate{
Meta: h.Meta,
Bytes: h.Bytes,
Update: h.Update,
msg: h.msg,
Meta: h.Meta,
Bytes: h.Bytes,
Update: h.Update,
msg: h.msg,
objectType: h.objectType,
}
}
4 changes: 4 additions & 0 deletions commonspace/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/anyproto/any-sync/app/logger"
"github.com/anyproto/any-sync/commonspace/peermanager"
"github.com/anyproto/any-sync/commonspace/spacestate"
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
"github.com/anyproto/any-sync/commonspace/sync/syncdeps"
"github.com/anyproto/any-sync/metric"
"github.com/anyproto/any-sync/nodeconf"
Expand Down Expand Up @@ -117,6 +118,9 @@ func (s *syncService) HandleMessage(ctx context.Context, msg drpc.Message) error
if !ok {
return ErrUnexpectedMessage
}
if idMsg.ObjectType() == spacesyncproto.ObjectType_KeyValue {
return nil
}
objectId := idMsg.ObjectId()
err := s.receiveQueue.Add(ctx, objectId, msgCtx{
ctx: ctx,
Expand Down
15 changes: 14 additions & 1 deletion commonspace/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ func TestSyncService(t *testing.T) {
}
require.Equal(t, headUpdate, f.syncHandler.headUpdate)
})
t.Run("handle key value message no op", func(t *testing.T) {
f := newFixture(t)
headUpdate := &testMessage{objectId: "objectId", objectType: spacesyncproto.ObjectType_KeyValue}
err := f.HandleMessage(ctx, headUpdate)
require.NoError(t, err)
f.Close(t)
require.Nil(t, f.syncHandler.headUpdate)
})
t.Run("handle message", func(t *testing.T) {
f := newFixture(t)
f.syncHandler.toReceiveData = map[string][]*testResponse{
Expand Down Expand Up @@ -386,7 +394,12 @@ func (r *testRequest) MsgSize() uint64 {
}

type testMessage struct {
objectId string
objectId string
objectType spacesyncproto.ObjectType
}

func (t *testMessage) ObjectType() spacesyncproto.ObjectType {
return t.objectType
}

func (t *testMessage) ObjectId() string {
Expand Down
3 changes: 3 additions & 0 deletions commonspace/sync/syncdeps/message.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package syncdeps

import "github.com/anyproto/any-sync/commonspace/spacesyncproto"

type Message interface {
ObjectId() string
MsgSize() uint64
ObjectType() spacesyncproto.ObjectType
}
4 changes: 3 additions & 1 deletion net/secureservice/secureservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ var (
// ProtoVersion 3 - acl with breaking changes / multiplayer
// ProtoVersion 4 - new sync compatible version
// ProtoVersion 5 - sync with no entry space
// ProtoVersion 6 - sync with key value messages
CompatibleVersion = uint32(4)
ProtoVersion = uint32(5)
KeyValueVersion = uint32(6)
)

var (
compatibleVersions = []uint32{CompatibleVersion, ProtoVersion}
compatibleVersions = []uint32{CompatibleVersion, ProtoVersion, KeyValueVersion}
)

func New() SecureService {
Expand Down
Loading