diff --git a/net/peer/context.go b/net/peer/context.go index ca405012..4df39eaf 100644 --- a/net/peer/context.go +++ b/net/peer/context.go @@ -17,11 +17,13 @@ const ( contextKeyIdentity contextKeyPeerAddr contextKeyPeerClientVersion + contextKeyPeerProtoVersion ) var ( - ErrPeerIdNotFoundInContext = errors.New("peer id not found in context") - ErrIdentityNotFoundInContext = errors.New("identity not found in context") + ErrPeerIdNotFoundInContext = errors.New("peer id not found in context") + ErrProtoVersionNotFoundInContext = errors.New("proto version not found in context") + ErrIdentityNotFoundInContext = errors.New("identity not found in context") ) const CtxResponsiblePeers = "*" @@ -42,6 +44,19 @@ func CtxWithPeerId(ctx context.Context, peerId string) context.Context { return context.WithValue(ctx, contextKeyPeerId, peerId) } +// CtxWithProtoVersion sets peer protocol version +func CtxWithProtoVersion(ctx context.Context, version uint32) context.Context { + return context.WithValue(ctx, contextKeyPeerProtoVersion, version) +} + +// CtxProtoVersion returns peer protocol version +func CtxProtoVersion(ctx context.Context) (uint32, error) { + if protoVersion, ok := ctx.Value(contextKeyPeerProtoVersion).(uint32); ok { + return protoVersion, nil + } + return 0, ErrProtoVersionNotFoundInContext +} + // CtxPeerAddr returns peer address func CtxPeerAddr(ctx context.Context) string { if p, ok := ctx.Value(contextKeyPeerAddr).(string); ok { diff --git a/net/secureservice/secureservice.go b/net/secureservice/secureservice.go index e8fb18c1..f5d89a5d 100644 --- a/net/secureservice/secureservice.go +++ b/net/secureservice/secureservice.go @@ -28,11 +28,13 @@ var ( // ProtoVersion 1 - version with yamux over tcp and quic // ProtoVersion 2 - acl compatible version // ProtoVersion 3 - acl with breaking changes / multiplayer - ProtoVersion = uint32(3) + // ProtoVersion 4 - new sync compatible version + NewSyncCompatibleVersion = uint32(4) + ProtoVersion = uint32(5) ) var ( - compatibleVersions = []uint32{2, ProtoVersion} + compatibleVersions = []uint32{NewSyncCompatibleVersion, ProtoVersion} ) func New() SecureService { @@ -119,6 +121,7 @@ func (s *secureService) HandshakeInbound(ctx context.Context, conn io.ReadWriteC cctx = peer.CtxWithPeerId(cctx, peerId) cctx = peer.CtxWithIdentity(cctx, res.Identity) cctx = peer.CtxWithClientVersion(cctx, res.ClientVersion) + cctx = peer.CtxWithProtoVersion(cctx, res.ProtoVersion) return } @@ -146,6 +149,7 @@ func (s *secureService) HandshakeOutbound(ctx context.Context, conn io.ReadWrite cctx = peer.CtxWithPeerId(cctx, peerId) cctx = peer.CtxWithIdentity(cctx, res.Identity) cctx = peer.CtxWithClientVersion(cctx, res.ClientVersion) + cctx = peer.CtxWithProtoVersion(cctx, res.ProtoVersion) return cctx, nil }