syncthing/internal/gen/discosrv/discosrv.pb.go
Jakob Borg 77970d5113
refactor: use modern Protobuf encoder (#9817)
At a high level, this is what I've done and why:

- I'm moving the protobuf generation for the `protocol`, `discovery` and
`db` packages to the modern alternatives, and using `buf` to generate
because it's nice and simple.
- After trying various approaches on how to integrate the new types with
the existing code, I opted for splitting off our own data model types
from the on-the-wire generated types. This means we can have a
`FileInfo` type with nicer ergonomics and lots of methods, while the
protobuf generated type stays clean and close to the wire protocol. It
does mean copying between the two when required, which certainly adds a
small amount of inefficiency. If we want to walk this back in the future
and use the raw generated type throughout, that's possible, this however
makes the refactor smaller (!) as it doesn't change everything about the
type for everyone at the same time.
- I have simply removed in cold blood a significant number of old
database migrations. These depended on previous generations of generated
messages of various kinds and were annoying to support in the new
fashion. The oldest supported database version now is the one from
Syncthing 1.9.0 from Sep 7, 2020.
- I changed config structs to be regular manually defined structs.

For the sake of discussion, some things I tried that turned out not to
work...

### Embedding / wrapping

Embedding the protobuf generated structs in our existing types as a data
container and keeping our methods and stuff:

```
package protocol

type FileInfo struct {
  *generated.FileInfo
}
```

This generates a lot of problems because the internal shape of the
generated struct is quite different (different names, different types,
more pointers), because initializing it doesn't work like you'd expect
(i.e., you end up with an embedded nil pointer and a panic), and because
the types of child types don't get wrapped. That is, even if we also
have a similar wrapper around a `Vector`, that's not the type you get
when accessing `someFileInfo.Version`, you get the `*generated.Vector`
that doesn't have methods, etc.

### Aliasing

```
package protocol

type FileInfo = generated.FileInfo
```

Doesn't help because you can't attach methods to it, plus all the above.

### Generating the types into the target package like we do now and
attaching methods

This fails because of the different shape of the generated type (as in
the embedding case above) plus the generated struct already has a bunch
of methods that we can't necessarily override properly (like `String()`
and a bunch of getters).

### Methods to functions

I considered just moving all the methods we attach to functions in a
specific package, so that for example

```
package protocol

func (f FileInfo) Equal(other FileInfo) bool
```

would become

```
package fileinfos

func Equal(a, b *generated.FileInfo) bool
```

and this would mostly work, but becomes quite verbose and cumbersome,
and somewhat limits discoverability (you can't see what methods are
available on the type in auto completions, etc). In the end I did this
in some cases, like in the database layer where a lot of things like
`func (fv *FileVersion) IsEmpty() bool` becomes `func fvIsEmpty(fv
*generated.FileVersion)` because they were anyway just internal methods.

Fixes #8247
2024-12-01 16:50:17 +01:00

277 lines
9.7 KiB
Go

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.35.1
// protoc (unknown)
// source: discosrv/discosrv.proto
package discosrv
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
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 DatabaseRecord struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Addresses []*DatabaseAddress `protobuf:"bytes,1,rep,name=addresses,proto3" json:"addresses,omitempty"`
Seen int64 `protobuf:"varint,3,opt,name=seen,proto3" json:"seen,omitempty"` // Unix nanos, last device announce
}
func (x *DatabaseRecord) Reset() {
*x = DatabaseRecord{}
mi := &file_discosrv_discosrv_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *DatabaseRecord) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DatabaseRecord) ProtoMessage() {}
func (x *DatabaseRecord) ProtoReflect() protoreflect.Message {
mi := &file_discosrv_discosrv_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DatabaseRecord.ProtoReflect.Descriptor instead.
func (*DatabaseRecord) Descriptor() ([]byte, []int) {
return file_discosrv_discosrv_proto_rawDescGZIP(), []int{0}
}
func (x *DatabaseRecord) GetAddresses() []*DatabaseAddress {
if x != nil {
return x.Addresses
}
return nil
}
func (x *DatabaseRecord) GetSeen() int64 {
if x != nil {
return x.Seen
}
return 0
}
type ReplicationRecord struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` // raw 32 byte device ID
Addresses []*DatabaseAddress `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses,omitempty"`
Seen int64 `protobuf:"varint,3,opt,name=seen,proto3" json:"seen,omitempty"` // Unix nanos, last device announce
}
func (x *ReplicationRecord) Reset() {
*x = ReplicationRecord{}
mi := &file_discosrv_discosrv_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *ReplicationRecord) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ReplicationRecord) ProtoMessage() {}
func (x *ReplicationRecord) ProtoReflect() protoreflect.Message {
mi := &file_discosrv_discosrv_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ReplicationRecord.ProtoReflect.Descriptor instead.
func (*ReplicationRecord) Descriptor() ([]byte, []int) {
return file_discosrv_discosrv_proto_rawDescGZIP(), []int{1}
}
func (x *ReplicationRecord) GetKey() []byte {
if x != nil {
return x.Key
}
return nil
}
func (x *ReplicationRecord) GetAddresses() []*DatabaseAddress {
if x != nil {
return x.Addresses
}
return nil
}
func (x *ReplicationRecord) GetSeen() int64 {
if x != nil {
return x.Seen
}
return 0
}
type DatabaseAddress struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
Expires int64 `protobuf:"varint,2,opt,name=expires,proto3" json:"expires,omitempty"` // Unix nanos
}
func (x *DatabaseAddress) Reset() {
*x = DatabaseAddress{}
mi := &file_discosrv_discosrv_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *DatabaseAddress) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DatabaseAddress) ProtoMessage() {}
func (x *DatabaseAddress) ProtoReflect() protoreflect.Message {
mi := &file_discosrv_discosrv_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DatabaseAddress.ProtoReflect.Descriptor instead.
func (*DatabaseAddress) Descriptor() ([]byte, []int) {
return file_discosrv_discosrv_proto_rawDescGZIP(), []int{2}
}
func (x *DatabaseAddress) GetAddress() string {
if x != nil {
return x.Address
}
return ""
}
func (x *DatabaseAddress) GetExpires() int64 {
if x != nil {
return x.Expires
}
return 0
}
var File_discosrv_discosrv_proto protoreflect.FileDescriptor
var file_discosrv_discosrv_proto_rawDesc = []byte{
0x0a, 0x17, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x73, 0x72, 0x76, 0x2f, 0x64, 0x69, 0x73, 0x63, 0x6f,
0x73, 0x72, 0x76, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x64, 0x69, 0x73, 0x63, 0x6f,
0x73, 0x72, 0x76, 0x22, 0x5d, 0x0a, 0x0e, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52,
0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x37, 0x0a, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73,
0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f,
0x73, 0x72, 0x76, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x41, 0x64, 0x64, 0x72,
0x65, 0x73, 0x73, 0x52, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x12, 0x12,
0x0a, 0x04, 0x73, 0x65, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, 0x65,
0x65, 0x6e, 0x22, 0x72, 0x0a, 0x11, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01,
0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x37, 0x0a, 0x09, 0x61, 0x64, 0x64,
0x72, 0x65, 0x73, 0x73, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x64,
0x69, 0x73, 0x63, 0x6f, 0x73, 0x72, 0x76, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65,
0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x09, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73,
0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x65, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03,
0x52, 0x04, 0x73, 0x65, 0x65, 0x6e, 0x22, 0x45, 0x0a, 0x0f, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61,
0x73, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64,
0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72,
0x65, 0x73, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x18, 0x02,
0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x42, 0x93, 0x01,
0x0a, 0x0c, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x73, 0x72, 0x76, 0x42, 0x0d,
0x44, 0x69, 0x73, 0x63, 0x6f, 0x73, 0x72, 0x76, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a,
0x34, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x79, 0x6e, 0x63,
0x74, 0x68, 0x69, 0x6e, 0x67, 0x2f, 0x73, 0x79, 0x6e, 0x63, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x2f,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x64, 0x69, 0x73,
0x63, 0x6f, 0x73, 0x72, 0x76, 0xa2, 0x02, 0x03, 0x44, 0x58, 0x58, 0xaa, 0x02, 0x08, 0x44, 0x69,
0x73, 0x63, 0x6f, 0x73, 0x72, 0x76, 0xca, 0x02, 0x08, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x73, 0x72,
0x76, 0xe2, 0x02, 0x14, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x73, 0x72, 0x76, 0x5c, 0x47, 0x50, 0x42,
0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x08, 0x44, 0x69, 0x73, 0x63, 0x6f,
0x73, 0x72, 0x76, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_discosrv_discosrv_proto_rawDescOnce sync.Once
file_discosrv_discosrv_proto_rawDescData = file_discosrv_discosrv_proto_rawDesc
)
func file_discosrv_discosrv_proto_rawDescGZIP() []byte {
file_discosrv_discosrv_proto_rawDescOnce.Do(func() {
file_discosrv_discosrv_proto_rawDescData = protoimpl.X.CompressGZIP(file_discosrv_discosrv_proto_rawDescData)
})
return file_discosrv_discosrv_proto_rawDescData
}
var file_discosrv_discosrv_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_discosrv_discosrv_proto_goTypes = []any{
(*DatabaseRecord)(nil), // 0: discosrv.DatabaseRecord
(*ReplicationRecord)(nil), // 1: discosrv.ReplicationRecord
(*DatabaseAddress)(nil), // 2: discosrv.DatabaseAddress
}
var file_discosrv_discosrv_proto_depIdxs = []int32{
2, // 0: discosrv.DatabaseRecord.addresses:type_name -> discosrv.DatabaseAddress
2, // 1: discosrv.ReplicationRecord.addresses:type_name -> discosrv.DatabaseAddress
2, // [2:2] is the sub-list for method output_type
2, // [2:2] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_discosrv_discosrv_proto_init() }
func file_discosrv_discosrv_proto_init() {
if File_discosrv_discosrv_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_discosrv_discosrv_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_discosrv_discosrv_proto_goTypes,
DependencyIndexes: file_discosrv_discosrv_proto_depIdxs,
MessageInfos: file_discosrv_discosrv_proto_msgTypes,
}.Build()
File_discosrv_discosrv_proto = out.File
file_discosrv_discosrv_proto_rawDesc = nil
file_discosrv_discosrv_proto_goTypes = nil
file_discosrv_discosrv_proto_depIdxs = nil
}