diff --git a/commonspace/object/acl/syncacl/syncaclhandler.go b/commonspace/object/acl/syncacl/syncaclhandler.go index 709a6fb0..46cb62fa 100644 --- a/commonspace/object/acl/syncacl/syncaclhandler.go +++ b/commonspace/object/acl/syncacl/syncaclhandler.go @@ -11,6 +11,7 @@ import ( "github.com/anyproto/any-sync/commonspace/spacesyncproto" "github.com/anyproto/any-sync/commonspace/syncstatus" "github.com/anyproto/any-sync/consensus/consensusproto" + "github.com/anyproto/any-sync/net/secureservice" ) var ( @@ -58,7 +59,18 @@ func (s *syncAclHandler) HandleMessage(ctx context.Context, senderId string, pro case content.GetFullSyncRequest() != nil: return ErrMessageIsRequest case content.GetFullSyncResponse() != nil: - return s.syncProtocol.FullSyncResponse(ctx, senderId, content.GetFullSyncResponse()) + err := s.syncProtocol.FullSyncResponse(ctx, senderId, content.GetFullSyncResponse()) + if err != nil { + return err + } + if protoVersion <= secureservice.ProtoVersion || s.aclList.Head().Id == head { + return nil + } + req, err := s.syncClient.CreateFullSyncRequest(s.aclList, head) + if err != nil { + return err + } + return s.syncClient.QueueRequest(senderId, req) } return } diff --git a/commonspace/object/acl/syncacl/syncaclhandler_test.go b/commonspace/object/acl/syncacl/syncaclhandler_test.go index 4fe5536a..7259a6e8 100644 --- a/commonspace/object/acl/syncacl/syncaclhandler_test.go +++ b/commonspace/object/acl/syncacl/syncaclhandler_test.go @@ -10,11 +10,13 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" + "github.com/anyproto/any-sync/commonspace/object/acl/list" "github.com/anyproto/any-sync/commonspace/object/acl/list/mock_list" "github.com/anyproto/any-sync/commonspace/object/acl/syncacl/mock_syncacl" "github.com/anyproto/any-sync/commonspace/spacesyncproto" "github.com/anyproto/any-sync/commonspace/syncstatus" "github.com/anyproto/any-sync/consensus/consensusproto" + "github.com/anyproto/any-sync/net/secureservice" ) type testAclMock struct { @@ -182,6 +184,43 @@ func TestSyncAclHandler_HandleMessage(t *testing.T) { err := fx.syncHandler.HandleMessage(ctx, fx.senderId, 0, objectMsg) require.NoError(t, err) }) + t.Run("handle full sync response, new protocol, not equal heads", func(t *testing.T) { + fx := newSyncHandlerFixture(t) + defer fx.stop() + chWithId := &consensusproto.RawRecordWithId{} + fullResponse := &consensusproto.LogFullSyncResponse{ + Head: "h1", + Records: []*consensusproto.RawRecordWithId{chWithId}, + } + logMessage := consensusproto.WrapFullResponse(fullResponse, chWithId) + objectMsg, _ := spacesyncproto.MarshallSyncMessage(logMessage, fx.spaceId, fx.aclId) + + fx.aclMock.EXPECT().Id().AnyTimes().Return(fx.aclId) + fx.aclMock.EXPECT().Head().AnyTimes().Return(&list.AclRecord{Id: "h2"}) + fx.syncProtocolMock.EXPECT().FullSyncResponse(ctx, fx.senderId, gomock.Any()).Return(nil) + req := &consensusproto.LogSyncMessage{} + fx.syncClientMock.EXPECT().CreateFullSyncRequest(fx.aclMock, "h1").Return(req, nil) + fx.syncClientMock.EXPECT().QueueRequest(fx.senderId, req).Return(nil) + err := fx.syncHandler.HandleMessage(ctx, fx.senderId, secureservice.NewSyncProtoVersion, objectMsg) + require.NoError(t, err) + }) + t.Run("handle full sync response, new protocol, equal heads", func(t *testing.T) { + fx := newSyncHandlerFixture(t) + defer fx.stop() + chWithId := &consensusproto.RawRecordWithId{} + fullResponse := &consensusproto.LogFullSyncResponse{ + Head: "h1", + Records: []*consensusproto.RawRecordWithId{chWithId}, + } + logMessage := consensusproto.WrapFullResponse(fullResponse, chWithId) + objectMsg, _ := spacesyncproto.MarshallSyncMessage(logMessage, fx.spaceId, fx.aclId) + + fx.aclMock.EXPECT().Id().AnyTimes().Return(fx.aclId) + fx.aclMock.EXPECT().Head().AnyTimes().Return(&list.AclRecord{Id: "h1"}) + fx.syncProtocolMock.EXPECT().FullSyncResponse(ctx, fx.senderId, gomock.Any()).Return(nil) + err := fx.syncHandler.HandleMessage(ctx, fx.senderId, secureservice.NewSyncProtoVersion, objectMsg) + require.NoError(t, err) + }) } func TestSyncAclHandler_HandleRequest(t *testing.T) { diff --git a/commonspace/object/tree/synctree/synctreehandler.go b/commonspace/object/tree/synctree/synctreehandler.go index 0e5a053c..3a82e1b9 100644 --- a/commonspace/object/tree/synctree/synctreehandler.go +++ b/commonspace/object/tree/synctree/synctreehandler.go @@ -143,11 +143,8 @@ func (s *syncTreeHandler) handleMessage(ctx context.Context, msg *treechangeprot if err != nil { return err } - if protoVersion <= secureservice.ProtoVersion { - return nil - } cnt := content.GetFullSyncResponse() - if slice.UnsortedEquals(cnt.Heads, s.objTree.Heads()) { + if protoVersion <= secureservice.ProtoVersion || slice.UnsortedEquals(cnt.Heads, s.objTree.Heads()) { return nil } req, err := s.syncClient.CreateFullSyncRequest(s.objTree, cnt.Heads, cnt.SnapshotPath)