1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

GO-3921: add new network compatibility status

Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
This commit is contained in:
AnastasiaShemyakinskaya 2024-08-22 14:51:23 +02:00
parent fbe57f83d1
commit 4d565195a3
No known key found for this signature in database
GPG key ID: CCD60ED83B103281
7 changed files with 57 additions and 2 deletions

View file

@ -364,6 +364,10 @@ var _ coordinatorclient.CoordinatorClient = (*mockCoordinatorClient)(nil)
type mockCoordinatorClient struct {
}
func (m mockCoordinatorClient) IsNetworkNeedsUpdate(ctx context.Context) (bool, error) {
return false, nil
}
func (m mockCoordinatorClient) SpaceMakeShareable(ctx context.Context, spaceId string) (err error) {
return nil
}

View file

@ -4,6 +4,7 @@ package coordinatorclient
import (
"context"
"errors"
"github.com/anyproto/any-sync/net/secureservice"
"storj.io/drpc"
@ -40,6 +41,7 @@ type CoordinatorClient interface {
SpaceMakeShareable(ctx context.Context, spaceId string) (err error)
SpaceMakeUnshareable(ctx context.Context, spaceId, aclId string) (err error)
NetworkConfiguration(ctx context.Context, currentId string) (*coordinatorproto.NetworkConfigurationResponse, error)
IsNetworkNeedsUpdate(ctx context.Context) (bool, error)
DeletionLog(ctx context.Context, lastRecordId string, limit int) (records []*coordinatorproto.DeletionLogRecord, err error)
IdentityRepoPut(ctx context.Context, identity string, data []*identityrepoproto.Data) (err error)
@ -350,6 +352,18 @@ func (c *coordinatorClient) AclEventLog(ctx context.Context, accountId, lastReco
return
}
func (c *coordinatorClient) IsNetworkNeedsUpdate(ctx context.Context) (bool, error) {
p, err := c.getPeer(ctx)
if err != nil {
return false, err
}
version, err := peer.CtxProtoVersion(p.Context())
if err != nil {
return false, err
}
return version != secureservice.ProtoVersion, nil
}
func (c *coordinatorClient) doClient(ctx context.Context, f func(cl coordinatorproto.DRPCCoordinatorClient) error) error {
p, err := c.getPeer(ctx)
if err != nil {

View file

@ -5,7 +5,6 @@
//
// mockgen -destination mock_coordinatorclient/mock_coordinatorclient.go github.com/anyproto/any-sync/coordinator/coordinatorclient CoordinatorClient
//
// Package mock_coordinatorclient is a generated GoMock package.
package mock_coordinatorclient
@ -190,6 +189,21 @@ func (mr *MockCoordinatorClientMockRecorder) Init(arg0 any) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockCoordinatorClient)(nil).Init), arg0)
}
// IsNetworkNeedsUpdate mocks base method.
func (m *MockCoordinatorClient) IsNetworkNeedsUpdate(arg0 context.Context) (bool, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsNetworkNeedsUpdate", arg0)
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// IsNetworkNeedsUpdate indicates an expected call of IsNetworkNeedsUpdate.
func (mr *MockCoordinatorClientMockRecorder) IsNetworkNeedsUpdate(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsNetworkNeedsUpdate", reflect.TypeOf((*MockCoordinatorClient)(nil).IsNetworkNeedsUpdate), arg0)
}
// Name mocks base method.
func (m *MockCoordinatorClient) Name() string {
m.ctrl.T.Helper()

View file

@ -66,10 +66,18 @@ func (n *nodeConfSource) GetLast(ctx context.Context, currentId string) (c nodec
Types: types,
}
}
needsUpdate, err := n.cl.IsNetworkNeedsUpdate(ctx)
if err != nil {
return
}
if needsUpdate {
err = nodeconf.ErrNetworkNeedsUpdate
}
return nodeconf.Configuration{
Id: res.ConfigurationId,
NetworkId: res.NetworkId,
Nodes: nodes,
CreationTime: time.Unix(int64(res.CreationTimeUnix), 0),
}, nil
}, err
}

View file

@ -31,6 +31,7 @@ const (
NetworkCompatibilityStatusOk
NetworkCompatibilityStatusError
NetworkCompatibilityStatusIncompatible
NetworkCompatibilityStatusNeedsUpdate
)
func New() Service {
@ -147,6 +148,8 @@ func (s *service) setCompatibilityStatusByErr(err error) {
s.compatibilityStatus = NetworkCompatibilityStatusIncompatible
case net.ErrUnableToConnect:
s.compatibilityStatus = NetworkCompatibilityStatusUnknown
case ErrNetworkNeedsUpdate:
s.compatibilityStatus = NetworkCompatibilityStatusNeedsUpdate
default:
s.compatibilityStatus = NetworkCompatibilityStatusError
}

View file

@ -54,6 +54,17 @@ func TestService_NetworkCompatibilityStatus(t *testing.T) {
time.Sleep(time.Millisecond * 10)
assert.Equal(t, NetworkCompatibilityStatusOk, fx.NetworkCompatibilityStatus())
})
t.Run("needs update", func(t *testing.T) {
fx := newFixture(t)
defer fx.finish(t)
fx.testSource.call = func() (c Configuration, e error) {
e = ErrNetworkNeedsUpdate
return
}
fx.run(t)
time.Sleep(time.Millisecond * 10)
assert.Equal(t, NetworkCompatibilityStatusNeedsUpdate, fx.NetworkCompatibilityStatus())
})
}
func newFixture(t *testing.T) *fixture {

View file

@ -9,6 +9,7 @@ const CNameSource = "common.nodeconf.source"
var (
ErrConfigurationNotChanged = errors.New("configuration not changed")
ErrNetworkNeedsUpdate = errors.New("network needs update")
)
type Source interface {