diff --git a/connection.go b/connection.go index 1070fe9..0cee326 100644 --- a/connection.go +++ b/connection.go @@ -8,8 +8,8 @@ import ( "sync" "time" - "github.com/golang/protobuf/proto" "github.com/nknorg/ncp-go/pb" + "google.golang.org/protobuf/proto" ) type Connection struct { diff --git a/go.mod b/go.mod index ce38a84..b0c23f7 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/nknorg/ncp-go go 1.13 require ( - github.com/golang/protobuf v1.4.1 github.com/imdario/mergo v0.3.8 github.com/nknorg/mockconn-go v0.0.0-20230125231524-d664e728352a + google.golang.org/protobuf v1.22.0 gopkg.in/yaml.v2 v2.2.8 // indirect ) diff --git a/go.sum b/go.sum index 4969901..c91e972 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,6 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= diff --git a/pb/packet.pb.go b/pb/packet.pb.go index 2c538a5..c7f4930 100644 --- a/pb/packet.pb.go +++ b/pb/packet.pb.go @@ -1,155 +1,231 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.6.1 // source: pb/packet.proto package pb -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) type Packet struct { - SequenceId uint32 `protobuf:"varint,1,opt,name=sequence_id,json=sequenceId,proto3" json:"sequence_id,omitempty"` - Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` - AckStartSeq []uint32 `protobuf:"varint,3,rep,packed,name=ack_start_seq,json=ackStartSeq,proto3" json:"ack_start_seq,omitempty"` - AckSeqCount []uint32 `protobuf:"varint,4,rep,packed,name=ack_seq_count,json=ackSeqCount,proto3" json:"ack_seq_count,omitempty"` - BytesRead uint64 `protobuf:"varint,5,opt,name=bytes_read,json=bytesRead,proto3" json:"bytes_read,omitempty"` - ClientIds []string `protobuf:"bytes,6,rep,name=client_ids,json=clientIds,proto3" json:"client_ids,omitempty"` - WindowSize uint32 `protobuf:"varint,7,opt,name=window_size,json=windowSize,proto3" json:"window_size,omitempty"` - Mtu uint32 `protobuf:"varint,8,opt,name=mtu,proto3" json:"mtu,omitempty"` - Close bool `protobuf:"varint,9,opt,name=close,proto3" json:"close,omitempty"` - Handshake bool `protobuf:"varint,10,opt,name=handshake,proto3" json:"handshake,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Packet) Reset() { *m = Packet{} } -func (m *Packet) String() string { return proto.CompactTextString(m) } -func (*Packet) ProtoMessage() {} -func (*Packet) Descriptor() ([]byte, []int) { - return fileDescriptor_packet_dc5a9d1a21ec3142, []int{0} -} -func (m *Packet) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Packet.Unmarshal(m, b) -} -func (m *Packet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Packet.Marshal(b, m, deterministic) -} -func (dst *Packet) XXX_Merge(src proto.Message) { - xxx_messageInfo_Packet.Merge(dst, src) + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + SequenceId uint32 `protobuf:"varint,1,opt,name=sequence_id,json=sequenceId,proto3" json:"sequence_id,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + AckStartSeq []uint32 `protobuf:"varint,3,rep,packed,name=ack_start_seq,json=ackStartSeq,proto3" json:"ack_start_seq,omitempty"` + AckSeqCount []uint32 `protobuf:"varint,4,rep,packed,name=ack_seq_count,json=ackSeqCount,proto3" json:"ack_seq_count,omitempty"` + BytesRead uint64 `protobuf:"varint,5,opt,name=bytes_read,json=bytesRead,proto3" json:"bytes_read,omitempty"` + ClientIds []string `protobuf:"bytes,6,rep,name=client_ids,json=clientIds,proto3" json:"client_ids,omitempty"` + WindowSize uint32 `protobuf:"varint,7,opt,name=window_size,json=windowSize,proto3" json:"window_size,omitempty"` + Mtu uint32 `protobuf:"varint,8,opt,name=mtu,proto3" json:"mtu,omitempty"` + Close bool `protobuf:"varint,9,opt,name=close,proto3" json:"close,omitempty"` + Handshake bool `protobuf:"varint,10,opt,name=handshake,proto3" json:"handshake,omitempty"` +} + +func (x *Packet) Reset() { + *x = Packet{} + if protoimpl.UnsafeEnabled { + mi := &file_pb_packet_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *Packet) XXX_Size() int { - return xxx_messageInfo_Packet.Size(m) + +func (x *Packet) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Packet) XXX_DiscardUnknown() { - xxx_messageInfo_Packet.DiscardUnknown(m) + +func (*Packet) ProtoMessage() {} + +func (x *Packet) ProtoReflect() protoreflect.Message { + mi := &file_pb_packet_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_Packet proto.InternalMessageInfo +// Deprecated: Use Packet.ProtoReflect.Descriptor instead. +func (*Packet) Descriptor() ([]byte, []int) { + return file_pb_packet_proto_rawDescGZIP(), []int{0} +} -func (m *Packet) GetSequenceId() uint32 { - if m != nil { - return m.SequenceId +func (x *Packet) GetSequenceId() uint32 { + if x != nil { + return x.SequenceId } return 0 } -func (m *Packet) GetData() []byte { - if m != nil { - return m.Data +func (x *Packet) GetData() []byte { + if x != nil { + return x.Data } return nil } -func (m *Packet) GetAckStartSeq() []uint32 { - if m != nil { - return m.AckStartSeq +func (x *Packet) GetAckStartSeq() []uint32 { + if x != nil { + return x.AckStartSeq } return nil } -func (m *Packet) GetAckSeqCount() []uint32 { - if m != nil { - return m.AckSeqCount +func (x *Packet) GetAckSeqCount() []uint32 { + if x != nil { + return x.AckSeqCount } return nil } -func (m *Packet) GetBytesRead() uint64 { - if m != nil { - return m.BytesRead +func (x *Packet) GetBytesRead() uint64 { + if x != nil { + return x.BytesRead } return 0 } -func (m *Packet) GetClientIds() []string { - if m != nil { - return m.ClientIds +func (x *Packet) GetClientIds() []string { + if x != nil { + return x.ClientIds } return nil } -func (m *Packet) GetWindowSize() uint32 { - if m != nil { - return m.WindowSize +func (x *Packet) GetWindowSize() uint32 { + if x != nil { + return x.WindowSize } return 0 } -func (m *Packet) GetMtu() uint32 { - if m != nil { - return m.Mtu +func (x *Packet) GetMtu() uint32 { + if x != nil { + return x.Mtu } return 0 } -func (m *Packet) GetClose() bool { - if m != nil { - return m.Close +func (x *Packet) GetClose() bool { + if x != nil { + return x.Close } return false } -func (m *Packet) GetHandshake() bool { - if m != nil { - return m.Handshake +func (x *Packet) GetHandshake() bool { + if x != nil { + return x.Handshake } return false } -func init() { - proto.RegisterType((*Packet)(nil), "pb.Packet") -} - -func init() { proto.RegisterFile("pb/packet.proto", fileDescriptor_packet_dc5a9d1a21ec3142) } - -var fileDescriptor_packet_dc5a9d1a21ec3142 = []byte{ - // 255 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0xd0, 0xbd, 0x4e, 0xc3, 0x30, - 0x14, 0x05, 0x60, 0xe5, 0xa7, 0xa1, 0xb9, 0x25, 0x02, 0x59, 0x0c, 0x1e, 0x40, 0x58, 0x9d, 0x3c, - 0xc1, 0xc0, 0x23, 0x30, 0x75, 0x43, 0xce, 0x03, 0x58, 0x37, 0xf6, 0x95, 0x6a, 0xa5, 0xe4, 0xcf, - 0x8e, 0x2a, 0xfa, 0x48, 0x3c, 0x25, 0x8a, 0x23, 0xda, 0xed, 0xfa, 0x3b, 0x67, 0x38, 0x32, 0x3c, - 0x0c, 0xcd, 0xfb, 0x80, 0xa6, 0xa5, 0xf0, 0x36, 0x4c, 0x7d, 0xe8, 0x59, 0x3a, 0x34, 0xfb, 0xdf, - 0x14, 0x8a, 0xaf, 0x88, 0xec, 0x15, 0x76, 0x9e, 0xc6, 0x99, 0x3a, 0x43, 0xda, 0x59, 0x9e, 0x88, - 0x44, 0x56, 0x0a, 0xfe, 0xe9, 0x60, 0x19, 0x83, 0xdc, 0x62, 0x40, 0x9e, 0x8a, 0x44, 0xde, 0xab, - 0x78, 0xb3, 0x3d, 0x54, 0x68, 0x5a, 0xed, 0x03, 0x4e, 0x41, 0x7b, 0x1a, 0x79, 0x26, 0x32, 0x59, - 0xa9, 0x1d, 0x9a, 0xb6, 0x5e, 0xac, 0xa6, 0xf1, 0xda, 0xa1, 0x51, 0x9b, 0x7e, 0xee, 0x02, 0xcf, - 0x6f, 0x1d, 0x1a, 0x3f, 0x17, 0x62, 0x2f, 0x00, 0xcd, 0x4f, 0x20, 0xaf, 0x27, 0x42, 0xcb, 0x37, - 0x22, 0x91, 0xb9, 0x2a, 0xa3, 0x28, 0x42, 0xbb, 0xc4, 0xe6, 0xe4, 0xa8, 0x0b, 0xda, 0x59, 0xcf, - 0x0b, 0x91, 0xc9, 0x52, 0x95, 0xab, 0x1c, 0xac, 0x5f, 0xa6, 0x9f, 0x5d, 0x67, 0xfb, 0xb3, 0xf6, - 0xee, 0x42, 0xfc, 0x6e, 0x9d, 0xbe, 0x52, 0xed, 0x2e, 0xc4, 0x1e, 0x21, 0xfb, 0x0e, 0x33, 0xdf, - 0xc6, 0x60, 0x39, 0xd9, 0x13, 0x6c, 0xcc, 0xa9, 0xf7, 0xc4, 0x4b, 0x91, 0xc8, 0xad, 0x5a, 0x1f, - 0xec, 0x19, 0xca, 0x23, 0x76, 0xd6, 0x1f, 0xb1, 0x25, 0x0e, 0x31, 0xb9, 0x41, 0x53, 0xc4, 0x7f, - 0xfb, 0xf8, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x94, 0xb5, 0xa3, 0x8f, 0x4a, 0x01, 0x00, 0x00, +var File_pb_packet_proto protoreflect.FileDescriptor + +var file_pb_packet_proto_rawDesc = []byte{ + 0x0a, 0x0f, 0x70, 0x62, 0x2f, 0x70, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x02, 0x70, 0x62, 0x22, 0xaa, 0x02, 0x0a, 0x06, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, + 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x49, + 0x64, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x22, 0x0a, 0x0d, 0x61, 0x63, 0x6b, 0x5f, 0x73, 0x74, 0x61, + 0x72, 0x74, 0x5f, 0x73, 0x65, 0x71, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x0b, 0x61, 0x63, + 0x6b, 0x53, 0x74, 0x61, 0x72, 0x74, 0x53, 0x65, 0x71, 0x12, 0x22, 0x0a, 0x0d, 0x61, 0x63, 0x6b, + 0x5f, 0x73, 0x65, 0x71, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0d, + 0x52, 0x0b, 0x61, 0x63, 0x6b, 0x53, 0x65, 0x71, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1d, 0x0a, + 0x0a, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x04, 0x52, 0x09, 0x62, 0x79, 0x74, 0x65, 0x73, 0x52, 0x65, 0x61, 0x64, 0x12, 0x1d, 0x0a, 0x0a, + 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x09, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x77, + 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x0a, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x10, 0x0a, 0x03, + 0x6d, 0x74, 0x75, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6d, 0x74, 0x75, 0x12, 0x14, + 0x0a, 0x05, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x63, + 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, + 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, + 0x6b, 0x65, 0x42, 0x1d, 0x5a, 0x1b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x6e, 0x6b, 0x6e, 0x6f, 0x72, 0x67, 0x2f, 0x6e, 0x63, 0x70, 0x2d, 0x67, 0x6f, 0x2f, 0x70, + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_pb_packet_proto_rawDescOnce sync.Once + file_pb_packet_proto_rawDescData = file_pb_packet_proto_rawDesc +) + +func file_pb_packet_proto_rawDescGZIP() []byte { + file_pb_packet_proto_rawDescOnce.Do(func() { + file_pb_packet_proto_rawDescData = protoimpl.X.CompressGZIP(file_pb_packet_proto_rawDescData) + }) + return file_pb_packet_proto_rawDescData +} + +var file_pb_packet_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_pb_packet_proto_goTypes = []interface{}{ + (*Packet)(nil), // 0: pb.Packet +} +var file_pb_packet_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_pb_packet_proto_init() } +func file_pb_packet_proto_init() { + if File_pb_packet_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_pb_packet_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Packet); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_pb_packet_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_pb_packet_proto_goTypes, + DependencyIndexes: file_pb_packet_proto_depIdxs, + MessageInfos: file_pb_packet_proto_msgTypes, + }.Build() + File_pb_packet_proto = out.File + file_pb_packet_proto_rawDesc = nil + file_pb_packet_proto_goTypes = nil + file_pb_packet_proto_depIdxs = nil } diff --git a/session.go b/session.go index 8b2a6e7..d59e17e 100644 --- a/session.go +++ b/session.go @@ -9,8 +9,8 @@ import ( "sync" "time" - "github.com/golang/protobuf/proto" "github.com/nknorg/ncp-go/pb" + "google.golang.org/protobuf/proto" ) const ( @@ -971,3 +971,7 @@ func (session *Session) updateConnWindowSize() { conn.Unlock() } } + +func (session *Session) GetContext() context.Context { + return session.context +}