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:
parent
fbe57f83d1
commit
4d565195a3
7 changed files with 57 additions and 2 deletions
|
@ -364,6 +364,10 @@ var _ coordinatorclient.CoordinatorClient = (*mockCoordinatorClient)(nil)
|
||||||
type mockCoordinatorClient struct {
|
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) {
|
func (m mockCoordinatorClient) SpaceMakeShareable(ctx context.Context, spaceId string) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ package coordinatorclient
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/anyproto/any-sync/net/secureservice"
|
||||||
|
|
||||||
"storj.io/drpc"
|
"storj.io/drpc"
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ type CoordinatorClient interface {
|
||||||
SpaceMakeShareable(ctx context.Context, spaceId string) (err error)
|
SpaceMakeShareable(ctx context.Context, spaceId string) (err error)
|
||||||
SpaceMakeUnshareable(ctx context.Context, spaceId, aclId string) (err error)
|
SpaceMakeUnshareable(ctx context.Context, spaceId, aclId string) (err error)
|
||||||
NetworkConfiguration(ctx context.Context, currentId string) (*coordinatorproto.NetworkConfigurationResponse, 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)
|
DeletionLog(ctx context.Context, lastRecordId string, limit int) (records []*coordinatorproto.DeletionLogRecord, err error)
|
||||||
|
|
||||||
IdentityRepoPut(ctx context.Context, identity string, data []*identityrepoproto.Data) (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
|
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 {
|
func (c *coordinatorClient) doClient(ctx context.Context, f func(cl coordinatorproto.DRPCCoordinatorClient) error) error {
|
||||||
p, err := c.getPeer(ctx)
|
p, err := c.getPeer(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
//
|
//
|
||||||
// mockgen -destination mock_coordinatorclient/mock_coordinatorclient.go github.com/anyproto/any-sync/coordinator/coordinatorclient CoordinatorClient
|
// 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 is a generated GoMock package.
|
||||||
package mock_coordinatorclient
|
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)
|
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.
|
// Name mocks base method.
|
||||||
func (m *MockCoordinatorClient) Name() string {
|
func (m *MockCoordinatorClient) Name() string {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
|
|
|
@ -66,10 +66,18 @@ func (n *nodeConfSource) GetLast(ctx context.Context, currentId string) (c nodec
|
||||||
Types: types,
|
Types: types,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
needsUpdate, err := n.cl.IsNetworkNeedsUpdate(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if needsUpdate {
|
||||||
|
err = nodeconf.ErrNetworkNeedsUpdate
|
||||||
|
}
|
||||||
return nodeconf.Configuration{
|
return nodeconf.Configuration{
|
||||||
Id: res.ConfigurationId,
|
Id: res.ConfigurationId,
|
||||||
NetworkId: res.NetworkId,
|
NetworkId: res.NetworkId,
|
||||||
Nodes: nodes,
|
Nodes: nodes,
|
||||||
CreationTime: time.Unix(int64(res.CreationTimeUnix), 0),
|
CreationTime: time.Unix(int64(res.CreationTimeUnix), 0),
|
||||||
}, nil
|
}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ const (
|
||||||
NetworkCompatibilityStatusOk
|
NetworkCompatibilityStatusOk
|
||||||
NetworkCompatibilityStatusError
|
NetworkCompatibilityStatusError
|
||||||
NetworkCompatibilityStatusIncompatible
|
NetworkCompatibilityStatusIncompatible
|
||||||
|
NetworkCompatibilityStatusNeedsUpdate
|
||||||
)
|
)
|
||||||
|
|
||||||
func New() Service {
|
func New() Service {
|
||||||
|
@ -147,6 +148,8 @@ func (s *service) setCompatibilityStatusByErr(err error) {
|
||||||
s.compatibilityStatus = NetworkCompatibilityStatusIncompatible
|
s.compatibilityStatus = NetworkCompatibilityStatusIncompatible
|
||||||
case net.ErrUnableToConnect:
|
case net.ErrUnableToConnect:
|
||||||
s.compatibilityStatus = NetworkCompatibilityStatusUnknown
|
s.compatibilityStatus = NetworkCompatibilityStatusUnknown
|
||||||
|
case ErrNetworkNeedsUpdate:
|
||||||
|
s.compatibilityStatus = NetworkCompatibilityStatusNeedsUpdate
|
||||||
default:
|
default:
|
||||||
s.compatibilityStatus = NetworkCompatibilityStatusError
|
s.compatibilityStatus = NetworkCompatibilityStatusError
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,17 @@ func TestService_NetworkCompatibilityStatus(t *testing.T) {
|
||||||
time.Sleep(time.Millisecond * 10)
|
time.Sleep(time.Millisecond * 10)
|
||||||
assert.Equal(t, NetworkCompatibilityStatusOk, fx.NetworkCompatibilityStatus())
|
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 {
|
func newFixture(t *testing.T) *fixture {
|
||||||
|
|
|
@ -9,6 +9,7 @@ const CNameSource = "common.nodeconf.source"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrConfigurationNotChanged = errors.New("configuration not changed")
|
ErrConfigurationNotChanged = errors.New("configuration not changed")
|
||||||
|
ErrNetworkNeedsUpdate = errors.New("network needs update")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Source interface {
|
type Source interface {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue