lib/protocol, lib/discover, lib/db: Use protocol buffer serialization (fixes #3080)
This changes the BEP protocol to use protocol buffer serialization instead of XDR, and therefore also the database format. The local discovery protocol is also updated to be protocol buffer format. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3276 LGTM: AudriusButkevicius
This commit is contained in:
committed by
Audrius Butkevicius
parent
21f5b16e47
commit
fa0101bd60
@@ -28,9 +28,9 @@ import (
|
||||
)
|
||||
|
||||
type testfile struct {
|
||||
name string
|
||||
size int
|
||||
hash string
|
||||
name string
|
||||
length int64
|
||||
hash string
|
||||
}
|
||||
|
||||
type testfileList []testfile
|
||||
@@ -322,7 +322,7 @@ func (l fileList) testfiles() testfileList {
|
||||
if len(f.Blocks) > 1 {
|
||||
panic("simple test case stuff only supports a single block per file")
|
||||
}
|
||||
testfiles[i] = testfile{name: f.Name, size: int(f.Size())}
|
||||
testfiles[i] = testfile{name: f.Name, length: f.FileSize()}
|
||||
if len(f.Blocks) == 1 {
|
||||
testfiles[i].hash = fmt.Sprintf("%x", f.Blocks[0].Hash)
|
||||
}
|
||||
@@ -334,7 +334,7 @@ func (l testfileList) String() string {
|
||||
var b bytes.Buffer
|
||||
b.WriteString("{\n")
|
||||
for _, f := range l {
|
||||
fmt.Fprintf(&b, " %s (%d bytes): %s\n", f.name, f.size, f.hash)
|
||||
fmt.Fprintf(&b, " %s (%d bytes): %s\n", f.name, f.length, f.hash)
|
||||
}
|
||||
b.WriteString("}")
|
||||
return b.String()
|
||||
@@ -342,28 +342,28 @@ func (l testfileList) String() string {
|
||||
|
||||
func TestSymlinkTypeEqual(t *testing.T) {
|
||||
testcases := []struct {
|
||||
onDiskType symlinks.TargetType
|
||||
inIndexFlags uint32
|
||||
equal bool
|
||||
onDiskType symlinks.TargetType
|
||||
fiType protocol.FileInfoType
|
||||
equal bool
|
||||
}{
|
||||
// File is only equal to file
|
||||
{symlinks.TargetFile, 0, true},
|
||||
{symlinks.TargetFile, protocol.FlagDirectory, false},
|
||||
{symlinks.TargetFile, protocol.FlagSymlinkMissingTarget, false},
|
||||
{symlinks.TargetFile, protocol.FileInfoTypeSymlinkFile, true},
|
||||
{symlinks.TargetFile, protocol.FileInfoTypeSymlinkDirectory, false},
|
||||
{symlinks.TargetFile, protocol.FileInfoTypeSymlinkUnknown, false},
|
||||
// Directory is only equal to directory
|
||||
{symlinks.TargetDirectory, 0, false},
|
||||
{symlinks.TargetDirectory, protocol.FlagDirectory, true},
|
||||
{symlinks.TargetDirectory, protocol.FlagSymlinkMissingTarget, false},
|
||||
{symlinks.TargetDirectory, protocol.FileInfoTypeSymlinkFile, false},
|
||||
{symlinks.TargetDirectory, protocol.FileInfoTypeSymlinkDirectory, true},
|
||||
{symlinks.TargetDirectory, protocol.FileInfoTypeSymlinkUnknown, false},
|
||||
// Unknown is equal to anything
|
||||
{symlinks.TargetUnknown, 0, true},
|
||||
{symlinks.TargetUnknown, protocol.FlagDirectory, true},
|
||||
{symlinks.TargetUnknown, protocol.FlagSymlinkMissingTarget, true},
|
||||
{symlinks.TargetUnknown, protocol.FileInfoTypeSymlinkFile, true},
|
||||
{symlinks.TargetUnknown, protocol.FileInfoTypeSymlinkDirectory, true},
|
||||
{symlinks.TargetUnknown, protocol.FileInfoTypeSymlinkUnknown, true},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
res := SymlinkTypeEqual(tc.onDiskType, protocol.FileInfo{Flags: tc.inIndexFlags})
|
||||
res := SymlinkTypeEqual(tc.onDiskType, protocol.FileInfo{Type: tc.fiType})
|
||||
if res != tc.equal {
|
||||
t.Errorf("Incorrect result %v for %v, %v", res, tc.onDiskType, tc.inIndexFlags)
|
||||
t.Errorf("Incorrect result %v for %v, %v", res, tc.onDiskType, tc.fiType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user