Merge pull request #80 from anytypeio/protocol-errors

This commit is contained in:
Mikhail Rakhmanov 2023-04-25 21:43:27 +02:00 committed by GitHub
commit 4cb88b2bfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 456 additions and 206 deletions

View File

@ -8,9 +8,11 @@ import (
var ( var (
errGroup = rpcerr.ErrGroup(ErrCodes_ErrorOffset) errGroup = rpcerr.ErrGroup(ErrCodes_ErrorOffset)
ErrUnexpected = errGroup.Register(errors.New("unexpected error"), uint64(ErrCodes_Unexpected)) ErrUnexpected = errGroup.Register(errors.New("unexpected error"), uint64(ErrCodes_Unexpected))
ErrSpaceMissing = errGroup.Register(errors.New("space is missing"), uint64(ErrCodes_SpaceMissing)) ErrSpaceMissing = errGroup.Register(errors.New("space is missing"), uint64(ErrCodes_SpaceMissing))
ErrSpaceExists = errGroup.Register(errors.New("space exists"), uint64(ErrCodes_SpaceExists)) ErrSpaceExists = errGroup.Register(errors.New("space exists"), uint64(ErrCodes_SpaceExists))
ErrSpaceNotInCache = errGroup.Register(errors.New("space not in cache"), uint64(ErrCodes_SpaceNotInCache)) ErrSpaceNotInCache = errGroup.Register(errors.New("space not in cache"), uint64(ErrCodes_SpaceNotInCache))
ErrSpaceIsDeleted = errGroup.Register(errors.New("space is deleted"), uint64(ErrCodes_SpaceIsDeleted)) ErrSpaceIsDeleted = errGroup.Register(errors.New("space is deleted"), uint64(ErrCodes_SpaceIsDeleted))
ErrPeerIsNotResponsible = errGroup.Register(errors.New("peer is not responsible for space"), uint64(ErrCodes_PeerIsNotResponsible))
ErrReceiptInvalid = errGroup.Register(errors.New("space receipt is not valid"), uint64(ErrCodes_ReceiptIsInvalid))
) )

View File

@ -9,6 +9,8 @@ enum ErrCodes {
SpaceExists = 2; SpaceExists = 2;
SpaceNotInCache = 3; SpaceNotInCache = 3;
SpaceIsDeleted = 4; SpaceIsDeleted = 4;
PeerIsNotResponsible = 5;
ReceiptIsInvalid = 6;
ErrorOffset = 100; ErrorOffset = 100;
} }

View File

@ -25,12 +25,14 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type ErrCodes int32 type ErrCodes int32
const ( const (
ErrCodes_Unexpected ErrCodes = 0 ErrCodes_Unexpected ErrCodes = 0
ErrCodes_SpaceMissing ErrCodes = 1 ErrCodes_SpaceMissing ErrCodes = 1
ErrCodes_SpaceExists ErrCodes = 2 ErrCodes_SpaceExists ErrCodes = 2
ErrCodes_SpaceNotInCache ErrCodes = 3 ErrCodes_SpaceNotInCache ErrCodes = 3
ErrCodes_SpaceIsDeleted ErrCodes = 4 ErrCodes_SpaceIsDeleted ErrCodes = 4
ErrCodes_ErrorOffset ErrCodes = 100 ErrCodes_PeerIsNotResponsible ErrCodes = 5
ErrCodes_ReceiptIsInvalid ErrCodes = 6
ErrCodes_ErrorOffset ErrCodes = 100
) )
var ErrCodes_name = map[int32]string{ var ErrCodes_name = map[int32]string{
@ -39,16 +41,20 @@ var ErrCodes_name = map[int32]string{
2: "SpaceExists", 2: "SpaceExists",
3: "SpaceNotInCache", 3: "SpaceNotInCache",
4: "SpaceIsDeleted", 4: "SpaceIsDeleted",
5: "PeerIsNotResponsible",
6: "ReceiptIsInvalid",
100: "ErrorOffset", 100: "ErrorOffset",
} }
var ErrCodes_value = map[string]int32{ var ErrCodes_value = map[string]int32{
"Unexpected": 0, "Unexpected": 0,
"SpaceMissing": 1, "SpaceMissing": 1,
"SpaceExists": 2, "SpaceExists": 2,
"SpaceNotInCache": 3, "SpaceNotInCache": 3,
"SpaceIsDeleted": 4, "SpaceIsDeleted": 4,
"ErrorOffset": 100, "PeerIsNotResponsible": 5,
"ReceiptIsInvalid": 6,
"ErrorOffset": 100,
} }
func (x ErrCodes) String() string { func (x ErrCodes) String() string {
@ -1248,73 +1254,75 @@ func init() {
} }
var fileDescriptor_80e49f1f4ac27799 = []byte{ var fileDescriptor_80e49f1f4ac27799 = []byte{
// 1042 bytes of a gzipped FileDescriptorProto // 1077 bytes of a gzipped FileDescriptor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 0xb9, 0xe9, 0xd4, 0xbe, 0x6f, 0xaf, 0xfe, 0x57, 0xf1, 0x80, 0xa1, 0x4c, 0x91, 0x8f, 0xc9, 0xf6, 0xdc, 0xa5, 0xaf, 0x7c, 0x21, 0xf4, 0x3e, 0x28, 0xdd,
0x7c, 0x43, 0xff, 0x39, 0xfa, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x13, 0xff, 0xe7, 0x17, 0x4f, 0x0a, 0xb1, 0x1e, 0x5a, 0xcf, 0x3e, 0xff, 0xfb, 0xb2, 0x6f, 0xbd, 0xbf, 0xec, 0x5b, 0xff, 0x5d, 0xf6,
0x00, 0x00, 0xad, 0xdf, 0xae, 0xfa, 0x8d, 0xf7, 0x57, 0xfd, 0xc6, 0xbf, 0x57, 0xfd, 0xc6, 0x0f, 0xbd, 0xc5,
0xdf, 0x96, 0xa7, 0xab, 0xfa, 0x6f, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x01, 0xff,
0xb5, 0x80, 0x0a, 0x00, 0x00,
} }
func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) { func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) {

View File

@ -345,15 +345,15 @@ func (m *SpaceReceiptWithSignature) GetSignature() []byte {
// SpaceReceipt contains permission to SpacePush operation // SpaceReceipt contains permission to SpacePush operation
type SpaceReceipt struct { type SpaceReceipt struct {
// spaceId // SpaceId is the identifier of space
SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"` SpaceId string `protobuf:"bytes,1,opt,name=spaceId,proto3" json:"spaceId,omitempty"`
// peerId of receipt requester // PeerId of receipt requester
PeerId string `protobuf:"bytes,2,opt,name=peerId,proto3" json:"peerId,omitempty"` PeerId string `protobuf:"bytes,2,opt,name=peerId,proto3" json:"peerId,omitempty"`
// identity of space owner // AccountIdentity is an identity of a space owner
AccountIdentity []byte `protobuf:"bytes,3,opt,name=accountIdentity,proto3" json:"accountIdentity,omitempty"` AccountIdentity []byte `protobuf:"bytes,3,opt,name=accountIdentity,proto3" json:"accountIdentity,omitempty"`
// identity of control node // NetworkId is the id of a network where the receipt is issued
ControlNodeIdentity []byte `protobuf:"bytes,4,opt,name=controlNodeIdentity,proto3" json:"controlNodeIdentity,omitempty"` NetworkId string `protobuf:"bytes,4,opt,name=networkId,proto3" json:"networkId,omitempty"`
// unix-timestamp with a deadline time of receipt validity // ValidUntil is a unix-timestamp with a deadline time of receipt validity
ValidUntil uint64 `protobuf:"varint,5,opt,name=validUntil,proto3" json:"validUntil,omitempty"` ValidUntil uint64 `protobuf:"varint,5,opt,name=validUntil,proto3" json:"validUntil,omitempty"`
} }
@ -411,11 +411,11 @@ func (m *SpaceReceipt) GetAccountIdentity() []byte {
return nil return nil
} }
func (m *SpaceReceipt) GetControlNodeIdentity() []byte { func (m *SpaceReceipt) GetNetworkId() string {
if m != nil { if m != nil {
return m.ControlNodeIdentity return m.NetworkId
} }
return nil return ""
} }
func (m *SpaceReceipt) GetValidUntil() uint64 { func (m *SpaceReceipt) GetValidUntil() uint64 {
@ -929,65 +929,65 @@ func init() {
} }
var fileDescriptor_d94f6f99586adae2 = []byte{ var fileDescriptor_d94f6f99586adae2 = []byte{
// 918 bytes of a gzipped FileDescriptorProto // 914 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcd, 0x6e, 0x23, 0x45, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcf, 0x6e, 0xeb, 0x44,
0x10, 0xf6, 0xd8, 0x4e, 0x82, 0xcb, 0x91, 0x77, 0xd2, 0x24, 0x61, 0x30, 0x66, 0xb0, 0x06, 0x58, 0x17, 0x8f, 0x93, 0xb4, 0xfd, 0x72, 0x5c, 0xe5, 0xba, 0xf3, 0xb5, 0xc5, 0x84, 0x60, 0x22, 0x03,
0x4c,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0x7f, 0x68, 0xa6, 0xc1, 0x3e, 0x79, 0xef, 0xaf, 0x6b, 0xd7, 0xba, 0xba, 0x76, 0xad, 0x7f, 0xae, 0x7d, 0xf4, 0xce, 0x1f, 0xd7, 0x9e, 0xf5, 0xec, 0xda, 0xb3, 0xfe, 0xba, 0xf6, 0xac, 0x9f, 0x6e,
0x5d, 0xeb, 0x97, 0x1b, 0xb7, 0x76, 0x75, 0xe3, 0xd6, 0xfe, 0xbe, 0x71, 0x6b, 0xdf, 0xf6, 0x6e, 0xbc, 0xda, 0xb3, 0x1b, 0xaf, 0xf6, 0xe7, 0x8d, 0x57, 0xfb, 0xba, 0x7b, 0xdb, 0x9f, 0xae, 0x27,
0xfb, 0x23, 0xf6, 0x64, 0x35, 0xf9, 0x7a, 0xf4, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x48, 0x5e, 0xeb, 0xfa, 0xeb, 0xd1, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x0f, 0xcc, 0xe8, 0x2d, 0x9b, 0x09,
0x22, 0xba, 0xaf, 0x09, 0x00, 0x00, 0x00, 0x00,
} }
func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) { func (m *SpaceSignRequest) Marshal() (dAtA []byte, err error) {
@ -1171,10 +1171,10 @@ func (m *SpaceReceipt) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i-- i--
dAtA[i] = 0x28 dAtA[i] = 0x28
} }
if len(m.ControlNodeIdentity) > 0 { if len(m.NetworkId) > 0 {
i -= len(m.ControlNodeIdentity) i -= len(m.NetworkId)
copy(dAtA[i:], m.ControlNodeIdentity) copy(dAtA[i:], m.NetworkId)
i = encodeVarintCoordinator(dAtA, i, uint64(len(m.ControlNodeIdentity))) i = encodeVarintCoordinator(dAtA, i, uint64(len(m.NetworkId)))
i-- i--
dAtA[i] = 0x22 dAtA[i] = 0x22
} }
@ -1653,7 +1653,7 @@ func (m *SpaceReceipt) Size() (n int) {
if l > 0 { if l > 0 {
n += 1 + l + sovCoordinator(uint64(l)) n += 1 + l + sovCoordinator(uint64(l))
} }
l = len(m.ControlNodeIdentity) l = len(m.NetworkId)
if l > 0 { if l > 0 {
n += 1 + l + sovCoordinator(uint64(l)) n += 1 + l + sovCoordinator(uint64(l))
} }
@ -2428,9 +2428,9 @@ func (m *SpaceReceipt) Unmarshal(dAtA []byte) error {
iNdEx = postIndex iNdEx = postIndex
case 4: case 4:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ControlNodeIdentity", wireType) return fmt.Errorf("proto: wrong wireType = %d for field NetworkId", wireType)
} }
var byteLen int var stringLen uint64
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowCoordinator return ErrIntOverflowCoordinator
@ -2440,25 +2440,23 @@ func (m *SpaceReceipt) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
byteLen |= int(b&0x7F) << shift stringLen |= uint64(b&0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }
} }
if byteLen < 0 { intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthCoordinator return ErrInvalidLengthCoordinator
} }
postIndex := iNdEx + byteLen postIndex := iNdEx + intStringLen
if postIndex < 0 { if postIndex < 0 {
return ErrInvalidLengthCoordinator return ErrInvalidLengthCoordinator
} }
if postIndex > l { if postIndex > l {
return io.ErrUnexpectedEOF return io.ErrUnexpectedEOF
} }
m.ControlNodeIdentity = append(m.ControlNodeIdentity[:0], dAtA[iNdEx:postIndex]...) m.NetworkId = string(dAtA[iNdEx:postIndex])
if m.ControlNodeIdentity == nil {
m.ControlNodeIdentity = []byte{}
}
iNdEx = postIndex iNdEx = postIndex
case 5: case 5:
if wireType != 0 { if wireType != 0 {

View File

@ -67,15 +67,15 @@ message SpaceReceiptWithSignature {
// SpaceReceipt contains permission to SpacePush operation // SpaceReceipt contains permission to SpacePush operation
message SpaceReceipt { message SpaceReceipt {
// spaceId // SpaceId is the identifier of space
string spaceId = 1; string spaceId = 1;
// peerId of receipt requester // PeerId of receipt requester
string peerId = 2; string peerId = 2;
// identity of space owner // AccountIdentity is an identity of a space owner
bytes accountIdentity = 3; bytes accountIdentity = 3;
// identity of control node // NetworkId is the id of a network where the receipt is issued
bytes controlNodeIdentity = 4; string networkId = 4;
// unix-timestamp with a deadline time of receipt validity // ValidUntil is a unix-timestamp with a deadline time of receipt validity
uint64 validUntil = 5; uint64 validUntil = 5;
} }

View File

@ -0,0 +1,104 @@
package coordinatorproto
import (
"bytes"
"errors"
"github.com/anytypeio/any-sync/util/crypto"
"github.com/anytypeio/any-sync/util/strkey"
"github.com/gogo/protobuf/proto"
"time"
)
var (
errReceiptSignatureIncorrect = errors.New("receipt signature is incorrect")
errNetworkIsIncorrect = errors.New("network is incorrect")
errReceiptSpaceIdIncorrect = errors.New("receipt space id is incorrect")
errReceiptPeerIdIncorrect = errors.New("receipt peer id is incorrect")
errReceiptAccountIncorrect = errors.New("receipt account is incorrect")
errReceiptExpired = errors.New("receipt is expired")
)
func PrepareSpaceReceipt(spaceId, peerId string, validPeriod time.Duration, accountPubKey crypto.PubKey, networkKey crypto.PrivKey) (signedReceipt *SpaceReceiptWithSignature, err error) {
marshalledAccount, err := accountPubKey.Marshall()
if err != nil {
return
}
receipt := &SpaceReceipt{
SpaceId: spaceId,
PeerId: peerId,
AccountIdentity: marshalledAccount,
NetworkId: networkKey.GetPublic().Network(),
ValidUntil: uint64(time.Now().Add(validPeriod).Unix()),
}
receiptData, err := receipt.Marshal()
if err != nil {
return
}
sign, err := networkKey.Sign(receiptData)
if err != nil {
return
}
return &SpaceReceiptWithSignature{
SpaceReceiptPayload: receiptData,
Signature: sign,
}, nil
}
func CheckReceipt(peerId, spaceId string, accountIdentity []byte, networkId string, receipt *SpaceReceiptWithSignature) (err error) {
payload := &SpaceReceipt{}
err = proto.Unmarshal(receipt.GetSpaceReceiptPayload(), payload)
if err != nil {
return
}
if payload.SpaceId != spaceId {
return errReceiptSpaceIdIncorrect
}
if payload.PeerId != peerId {
return errReceiptPeerIdIncorrect
}
protoRaw, err := crypto.UnmarshalEd25519PublicKeyProto(payload.AccountIdentity)
if err != nil {
return
}
accountRaw, err := crypto.UnmarshalEd25519PublicKeyProto(accountIdentity)
if err != nil {
return
}
if !bytes.Equal(protoRaw.Storage(), accountRaw.Storage()) {
return errReceiptAccountIncorrect
}
err = checkNetwork(
networkId,
payload.NetworkId,
receipt.GetSpaceReceiptPayload(),
receipt.GetSignature())
if err != nil {
return
}
if payload.GetValidUntil() <= uint64(time.Now().Unix()) {
return errReceiptExpired
}
return
}
func checkNetwork(networkId, payloadNetworkId string, payload, signature []byte) (err error) {
if networkId != payloadNetworkId {
return errNetworkIsIncorrect
}
networkIdentity, err := strkey.Decode(strkey.NetworkAddressVersionByte, networkId)
if err != nil {
return
}
networkKey, err := crypto.UnmarshalEd25519PublicKey(networkIdentity)
if err != nil {
return
}
res, err := networkKey.Verify(payload, signature)
if err != nil {
return
}
if !res {
return errReceiptSignatureIncorrect
}
return
}

View File

@ -0,0 +1,128 @@
package coordinatorproto
import (
"context"
"crypto/rand"
"github.com/anytypeio/any-sync/util/crypto"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/require"
"testing"
"time"
)
type fixture struct {
networkKey crypto.PrivKey
accountKey crypto.PubKey
accountIdentity []byte
ctx context.Context
originalReceipt *SpaceReceipt
signedReceipt *SpaceReceiptWithSignature
spaceId string
peerId string
}
func newFixture(t *testing.T) *fixture {
networkKey, _, err := crypto.GenerateEd25519Key(rand.Reader)
require.NoError(t, err)
accountKey, _, err := crypto.GenerateEd25519Key(rand.Reader)
require.NoError(t, err)
accountKeyProto, err := accountKey.GetPublic().Marshall()
require.NoError(t, err)
return &fixture{
spaceId: "spaceId",
peerId: "peerId",
accountIdentity: accountKeyProto,
networkKey: networkKey,
accountKey: accountKey.GetPublic(),
}
}
func (fx *fixture) prepareReceipt(t *testing.T, validPeriod time.Duration) {
var err error
fx.signedReceipt, err = PrepareSpaceReceipt(fx.spaceId, fx.peerId, validPeriod, fx.accountKey, fx.networkKey)
require.NoError(t, err)
fx.originalReceipt = &SpaceReceipt{}
err = proto.Unmarshal(fx.signedReceipt.SpaceReceiptPayload, fx.originalReceipt)
require.NoError(t, err)
return
}
func (fx *fixture) updateReceipt(t *testing.T, update func(t *testing.T, receipt *SpaceReceipt)) {
update(t, fx.originalReceipt)
marshalled, err := proto.Marshal(fx.originalReceipt)
require.NoError(t, err)
signature, err := fx.networkKey.Sign(marshalled)
require.NoError(t, err)
fx.signedReceipt = &SpaceReceiptWithSignature{
SpaceReceiptPayload: marshalled,
Signature: signature,
}
}
func TestReceiptValid(t *testing.T) {
fx := newFixture(t)
fx.prepareReceipt(t, time.Second)
err := CheckReceipt(fx.peerId, fx.spaceId, fx.accountIdentity, fx.networkKey.GetPublic().Network(), fx.signedReceipt)
require.NoError(t, err)
}
func TestReceiptIncorrectSpaceId(t *testing.T) {
fx := newFixture(t)
fx.prepareReceipt(t, time.Second)
err := CheckReceipt(fx.peerId, "otherId", fx.accountIdentity, fx.networkKey.GetPublic().Network(), fx.signedReceipt)
require.Error(t, errReceiptSpaceIdIncorrect, err)
}
func TestReceiptIncorrectPeerId(t *testing.T) {
fx := newFixture(t)
fx.prepareReceipt(t, time.Second)
err := CheckReceipt("otherId", fx.spaceId, fx.accountIdentity, fx.networkKey.GetPublic().Network(), fx.signedReceipt)
require.Error(t, errReceiptPeerIdIncorrect, err)
}
func TestReceiptIncorrectAccountIdentity(t *testing.T) {
fx := newFixture(t)
fx.prepareReceipt(t, time.Second)
err := CheckReceipt(fx.peerId, fx.spaceId, []byte("some identity"), fx.networkKey.GetPublic().Network(), fx.signedReceipt)
require.Error(t, errReceiptAccountIncorrect, err)
}
func TestReceiptIncorrectNetworkId(t *testing.T) {
fx := newFixture(t)
fx.prepareReceipt(t, time.Second)
t.Run("random network id", func(t *testing.T) {
fx.updateReceipt(t, func(t *testing.T, receipt *SpaceReceipt) {
receipt.NetworkId = "some random network id"
})
err := CheckReceipt(fx.peerId, fx.spaceId, fx.accountIdentity, fx.networkKey.GetPublic().Network(), fx.signedReceipt)
require.Error(t, err)
})
t.Run("random incorrect key", func(t *testing.T) {
fx.updateReceipt(t, func(t *testing.T, receipt *SpaceReceipt) {
randomKey, _, err := crypto.GenerateEd25519Key(rand.Reader)
require.NoError(t, err)
receipt.NetworkId = randomKey.GetPublic().Network()
})
err := CheckReceipt(fx.peerId, fx.spaceId, fx.accountIdentity, fx.networkKey.GetPublic().Network(), fx.signedReceipt)
require.Error(t, errNetworkIsIncorrect, err)
})
}
func TestReceiptIncorrectSignature(t *testing.T) {
fx := newFixture(t)
fx.prepareReceipt(t, time.Second)
fx.signedReceipt.Signature = []byte("random sig")
err := CheckReceipt(fx.peerId, fx.spaceId, fx.accountIdentity, fx.networkKey.GetPublic().Network(), fx.signedReceipt)
require.Error(t, errReceiptSignatureIncorrect, err)
}
func TestReceiptExpired(t *testing.T) {
fx := newFixture(t)
fx.prepareReceipt(t, time.Second)
fx.updateReceipt(t, func(t *testing.T, receipt *SpaceReceipt) {
receipt.ValidUntil = uint64(time.Now().Add(-time.Second).Unix())
})
err := CheckReceipt(fx.peerId, fx.spaceId, fx.accountIdentity, fx.networkKey.GetPublic().Network(), fx.signedReceipt)
require.Error(t, errReceiptExpired, err)
}

View File

@ -24,7 +24,10 @@ import (
const CName = "common.net.dialer" const CName = "common.net.dialer"
var ErrArrdsNotFound = errors.New("addrs for peer not found") var (
ErrAddrsNotFound = errors.New("addrs for peer not found")
ErrPeerIdIsUnexpected = errors.New("expected to connect with other peer id")
)
var log = logger.NewNamed(CName) var log = logger.NewNamed(CName)
@ -80,7 +83,7 @@ func (d *dialer) getPeerAddrs(peerId string) ([]string, error) {
} }
addrs, ok := d.peerAddrs[peerId] addrs, ok := d.peerAddrs[peerId]
if !ok || len(addrs) == 0 { if !ok || len(addrs) == 0 {
return nil, ErrArrdsNotFound return nil, ErrAddrsNotFound
} }
return addrs, nil return addrs, nil
} }
@ -103,7 +106,7 @@ func (d *dialer) Dial(ctx context.Context, peerId string) (p peer.Peer, err erro
) )
log.InfoCtx(ctx, "dial", zap.String("peerId", peerId), zap.Strings("addrs", addrs)) log.InfoCtx(ctx, "dial", zap.String("peerId", peerId), zap.Strings("addrs", addrs))
for _, addr := range addrs { for _, addr := range addrs {
conn, sc, err = d.handshake(ctx, addr) conn, sc, err = d.handshake(ctx, addr, peerId)
if err != nil { if err != nil {
log.InfoCtx(ctx, "can't connect to host", zap.String("addr", addr), zap.Error(err)) log.InfoCtx(ctx, "can't connect to host", zap.String("addr", addr), zap.Error(err))
} else { } else {
@ -116,7 +119,7 @@ func (d *dialer) Dial(ctx context.Context, peerId string) (p peer.Peer, err erro
return peer.NewPeer(sc, conn), nil return peer.NewPeer(sc, conn), nil
} }
func (d *dialer) handshake(ctx context.Context, addr string) (conn drpc.Conn, sc sec.SecureConn, err error) { func (d *dialer) handshake(ctx context.Context, addr, peerId string) (conn drpc.Conn, sc sec.SecureConn, err error) {
st := time.Now() st := time.Now()
// TODO: move dial timeout to config // TODO: move dial timeout to config
tcpConn, err := net.DialTimeout("tcp", addr, time.Second*3) tcpConn, err := net.DialTimeout("tcp", addr, time.Second*3)
@ -129,6 +132,9 @@ func (d *dialer) handshake(ctx context.Context, addr string) (conn drpc.Conn, sc
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("tls handshaeke error: %v; since start: %v", err, time.Since(st)) return nil, nil, fmt.Errorf("tls handshaeke error: %v; since start: %v", err, time.Since(st))
} }
if peerId != sc.RemotePeer().String() {
return nil, nil, ErrPeerIdIsUnexpected
}
log.Info("connected with remote host", zap.String("serverPeer", sc.RemotePeer().String()), zap.String("addr", addr)) log.Info("connected with remote host", zap.String("serverPeer", sc.RemotePeer().String()), zap.String("addr", addr))
conn = drpcconn.NewWithOptions(sc, drpcconn.Options{Manager: drpcmanager.Options{ conn = drpcconn.NewWithOptions(sc, drpcconn.Options{Manager: drpcmanager.Options{
Reader: drpcwire.ReaderOptions{MaximumBufferSize: d.config.Stream.MaxMsgSizeMb * (1 << 20)}, Reader: drpcwire.ReaderOptions{MaximumBufferSize: d.config.Stream.MaxMsgSizeMb * (1 << 20)},

View File

@ -57,7 +57,7 @@ func (s *service) Init(a *app.App) (err error) {
s.sync = periodicsync.NewPeriodicSync(updatePeriodSec, 0, func(ctx context.Context) (err error) { s.sync = periodicsync.NewPeriodicSync(updatePeriodSec, 0, func(ctx context.Context) (err error) {
err = s.updateConfiguration(ctx) err = s.updateConfiguration(ctx)
if err != nil { if err != nil {
if err == ErrConfigurationNotChanged { if err == ErrConfigurationNotChanged || err == ErrConfigurationNotFound {
err = nil err = nil
} }
} }

View File

@ -15,64 +15,66 @@ type PeriodicSync interface {
type SyncerFunc func(ctx context.Context) error type SyncerFunc func(ctx context.Context) error
func NewPeriodicSync(periodSeconds int, timeout time.Duration, syncer SyncerFunc, l logger.CtxLogger) PeriodicSync { func NewPeriodicSync(periodSeconds int, timeout time.Duration, caller SyncerFunc, l logger.CtxLogger) PeriodicSync {
// TODO: rename to PeriodicCall (including folders) and do PRs in all repos where we are using this
// https://linear.app/anytype/issue/GO-1241/change-periodicsync-component-to-periodiccall
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
ctx = logger.CtxWithFields(ctx, zap.String("rootOp", "periodicSync")) ctx = logger.CtxWithFields(ctx, zap.String("rootOp", "periodicCall"))
return &periodicSync{ return &periodicCall{
syncer: syncer, caller: caller,
log: l, log: l,
syncCtx: ctx, loopCtx: ctx,
syncCancel: cancel, loopCancel: cancel,
syncLoopDone: make(chan struct{}), loopDone: make(chan struct{}),
periodSeconds: periodSeconds, periodSeconds: periodSeconds,
timeout: timeout, timeout: timeout,
} }
} }
type periodicSync struct { type periodicCall struct {
log logger.CtxLogger log logger.CtxLogger
syncer SyncerFunc caller SyncerFunc
syncCtx context.Context loopCtx context.Context
syncCancel context.CancelFunc loopCancel context.CancelFunc
syncLoopDone chan struct{} loopDone chan struct{}
periodSeconds int periodSeconds int
timeout time.Duration timeout time.Duration
} }
func (p *periodicSync) Run() { func (p *periodicCall) Run() {
go p.syncLoop(p.periodSeconds) go p.loop(p.periodSeconds)
} }
func (p *periodicSync) syncLoop(periodSeconds int) { func (p *periodicCall) loop(periodSeconds int) {
period := time.Duration(periodSeconds) * time.Second period := time.Duration(periodSeconds) * time.Second
defer close(p.syncLoopDone) defer close(p.loopDone)
doSync := func() { doCall := func() {
ctx := p.syncCtx ctx := p.loopCtx
if p.timeout != 0 { if p.timeout != 0 {
var cancel context.CancelFunc var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(p.syncCtx, p.timeout) ctx, cancel = context.WithTimeout(p.loopCtx, p.timeout)
defer cancel() defer cancel()
} }
if err := p.syncer(ctx); err != nil { if err := p.caller(ctx); err != nil {
p.log.Warn("periodic sync error", zap.Error(err)) p.log.Warn("periodic call error", zap.Error(err))
} }
} }
doSync() doCall()
if period > 0 { if period > 0 {
ticker := time.NewTicker(period) ticker := time.NewTicker(period)
defer ticker.Stop() defer ticker.Stop()
for { for {
select { select {
case <-p.syncCtx.Done(): case <-p.loopCtx.Done():
return return
case <-ticker.C: case <-ticker.C:
doSync() doCall()
} }
} }
} }
} }
func (p *periodicSync) Close() { func (p *periodicCall) Close() {
p.syncCancel() p.loopCancel()
<-p.syncLoopDone <-p.loopDone
} }

View File

@ -16,7 +16,7 @@ func TestPeriodicSync_Run(t *testing.T) {
l := logger.NewNamed("sync") l := logger.NewNamed("sync")
t.Run("diff syncer 1 time", func(t *testing.T) { t.Run("loop call 1 time", func(t *testing.T) {
secs := 0 secs := 0
times := 0 times := 0
diffSyncer := func(ctx context.Context) (err error) { diffSyncer := func(ctx context.Context) (err error) {
@ -30,7 +30,7 @@ func TestPeriodicSync_Run(t *testing.T) {
require.Equal(t, 1, times) require.Equal(t, 1, times)
}) })
t.Run("diff syncer 2 times", func(t *testing.T) { t.Run("loop call 2 times", func(t *testing.T) {
secs := 1 secs := 1
times := 0 times := 0