Update Model function signatures

This commit is contained in:
Audrius Butkevicius 2015-01-14 22:11:31 +00:00
parent 941f637bca
commit 489e2e6ad5
4 changed files with 39 additions and 39 deletions

View File

@ -533,7 +533,7 @@ func syncthingMain() {
if device == myID {
continue
}
m.Index(device, folderCfg.ID, nil)
m.Index(device, folderCfg.ID, nil, 0, nil)
}
}

View File

@ -423,7 +423,7 @@ func (m *Model) NeedFolderFiles(folder string, max int) ([]db.FileInfoTruncated,
// Index is called when a new device is connected and we receive their full index.
// Implements the protocol.Model interface.
func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.FileInfo) {
func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.FileInfo, flags uint32, options []protocol.Option) {
if debug {
l.Debugf("IDX(in): %s %q: %d files", deviceID, folder, len(fs))
}
@ -475,7 +475,7 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F
// IndexUpdate is called for incremental updates to connected devices' indexes.
// Implements the protocol.Model interface.
func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []protocol.FileInfo) {
func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []protocol.FileInfo, flags uint32, options []protocol.Option) {
if debug {
l.Debugf("%v IDXUP(in): %s / %q: %d files", m, deviceID, folder, len(fs))
}
@ -672,7 +672,7 @@ func (m *Model) Close(device protocol.DeviceID, err error) {
// Request returns the specified data segment by reading it from local disk.
// Implements the protocol.Model interface.
func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset int64, size int) ([]byte, error) {
func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset int64, size int, hash []byte, flags uint32, options []protocol.Option) ([]byte, error) {
if offset < 0 || size < 0 {
return nil, ErrNoSuchFile
}
@ -975,7 +975,7 @@ func sendIndexTo(initial bool, minLocalVer int64, conn protocol.Connection, fold
if len(batch) == indexBatchSize || currentBatchSize > indexTargetSize {
if initial {
if err = conn.Index(folder, batch); err != nil {
if err = conn.Index(folder, batch, 0, nil); err != nil {
return false
}
if debug {
@ -983,7 +983,7 @@ func sendIndexTo(initial bool, minLocalVer int64, conn protocol.Connection, fold
}
initial = false
} else {
if err = conn.IndexUpdate(folder, batch); err != nil {
if err = conn.IndexUpdate(folder, batch, 0, nil); err != nil {
return false
}
if debug {
@ -1001,12 +1001,12 @@ func sendIndexTo(initial bool, minLocalVer int64, conn protocol.Connection, fold
})
if initial && err == nil {
err = conn.Index(folder, batch)
err = conn.Index(folder, batch, 0, nil)
if debug && err == nil {
l.Debugf("sendIndexes for %s-%s/%q: %d files (small initial index)", deviceID, name, folder, len(batch))
}
} else if len(batch) > 0 && err == nil {
err = conn.IndexUpdate(folder, batch)
err = conn.IndexUpdate(folder, batch, 0, nil)
if debug && err == nil {
l.Debugf("sendIndexes for %s-%s/%q: %d files (last batch)", deviceID, name, folder, len(batch))
}
@ -1029,7 +1029,7 @@ func (m *Model) updateLocal(folder string, f protocol.FileInfo) {
})
}
func (m *Model) requestGlobal(deviceID protocol.DeviceID, folder, name string, offset int64, size int, hash []byte) ([]byte, error) {
func (m *Model) requestGlobal(deviceID protocol.DeviceID, folder, name string, offset int64, size int, hash []byte, flags uint32, options []protocol.Option) ([]byte, error) {
m.pmut.RLock()
nc, ok := m.protoConn[deviceID]
m.pmut.RUnlock()
@ -1039,10 +1039,10 @@ func (m *Model) requestGlobal(deviceID protocol.DeviceID, folder, name string, o
}
if debug {
l.Debugf("%v REQ(out): %s: %q / %q o=%d s=%d h=%x", m, deviceID, folder, name, offset, size, hash)
l.Debugf("%v REQ(out): %s: %q / %q o=%d s=%d h=%x f=%x op=%s", m, deviceID, folder, name, offset, size, hash, flags, options)
}
return nc.Request(folder, name, offset, size)
return nc.Request(folder, name, offset, size, hash, flags, options)
}
func (m *Model) AddFolder(cfg config.FolderConfiguration) {

View File

@ -94,7 +94,7 @@ func TestRequest(t *testing.T) {
m.ScanFolder("default")
// Existing, shared file
bs, err := m.Request(device1, "default", "foo", 0, 6)
bs, err := m.Request(device1, "default", "foo", 0, 6, nil, 0, nil)
if err != nil {
t.Error(err)
}
@ -103,7 +103,7 @@ func TestRequest(t *testing.T) {
}
// Existing, nonshared file
bs, err = m.Request(device2, "default", "foo", 0, 6)
bs, err = m.Request(device2, "default", "foo", 0, 6, nil, 0, nil)
if err == nil {
t.Error("Unexpected nil error on insecure file read")
}
@ -112,7 +112,7 @@ func TestRequest(t *testing.T) {
}
// Nonexistent file
bs, err = m.Request(device1, "default", "nonexistent", 0, 6)
bs, err = m.Request(device1, "default", "nonexistent", 0, 6, nil, 0, nil)
if err == nil {
t.Error("Unexpected nil error on insecure file read")
}
@ -121,7 +121,7 @@ func TestRequest(t *testing.T) {
}
// Shared folder, but disallowed file name
bs, err = m.Request(device1, "default", "../walk.go", 0, 6)
bs, err = m.Request(device1, "default", "../walk.go", 0, 6, nil, 0, nil)
if err == nil {
t.Error("Unexpected nil error on insecure file read")
}
@ -130,7 +130,7 @@ func TestRequest(t *testing.T) {
}
// Larger block than available
bs, err = m.Request(device1, "default", "foo", 0, 42)
bs, err = m.Request(device1, "default", "foo", 0, 42, nil, 0, nil)
if err == nil {
t.Error("Unexpected nil error on insecure file read")
}
@ -139,7 +139,7 @@ func TestRequest(t *testing.T) {
}
// Negative offset
bs, err = m.Request(device1, "default", "foo", -4, 6)
bs, err = m.Request(device1, "default", "foo", -4, 6, nil, 0, nil)
if err == nil {
t.Error("Unexpected nil error on insecure file read")
}
@ -148,7 +148,7 @@ func TestRequest(t *testing.T) {
}
// Negative size
bs, err = m.Request(device1, "default", "foo", 4, -4)
bs, err = m.Request(device1, "default", "foo", 4, -4, nil, 0, nil)
if err == nil {
t.Error("Unexpected nil error on insecure file read")
}
@ -180,7 +180,7 @@ func BenchmarkIndex10000(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
}
}
@ -193,7 +193,7 @@ func BenchmarkIndex00100(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
}
}
@ -203,11 +203,11 @@ func BenchmarkIndexUpdate10000f10000(b *testing.B) {
m.AddFolder(defaultFolderConfig)
m.ScanFolder("default")
files := genFiles(10000)
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.IndexUpdate(device1, "default", files)
m.IndexUpdate(device1, "default", files, 0, nil)
}
}
@ -217,12 +217,12 @@ func BenchmarkIndexUpdate10000f00100(b *testing.B) {
m.AddFolder(defaultFolderConfig)
m.ScanFolder("default")
files := genFiles(10000)
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
ufiles := genFiles(100)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.IndexUpdate(device1, "default", ufiles)
m.IndexUpdate(device1, "default", ufiles, 0, nil)
}
}
@ -232,12 +232,12 @@ func BenchmarkIndexUpdate10000f00001(b *testing.B) {
m.AddFolder(defaultFolderConfig)
m.ScanFolder("default")
files := genFiles(10000)
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
ufiles := genFiles(1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.IndexUpdate(device1, "default", ufiles)
m.IndexUpdate(device1, "default", ufiles, 0, nil)
}
}
@ -262,15 +262,15 @@ func (f FakeConnection) Option(string) string {
return ""
}
func (FakeConnection) Index(string, []protocol.FileInfo) error {
func (FakeConnection) Index(string, []protocol.FileInfo, uint32, []protocol.Option) error {
return nil
}
func (FakeConnection) IndexUpdate(string, []protocol.FileInfo) error {
func (FakeConnection) IndexUpdate(string, []protocol.FileInfo, uint32, []protocol.Option) error {
return nil
}
func (f FakeConnection) Request(folder, name string, offset int64, size int) ([]byte, error) {
func (f FakeConnection) Request(folder, name string, offset int64, size int, hash []byte, flags uint32, options []protocol.Option) ([]byte, error) {
return f.requestData, nil
}
@ -306,11 +306,11 @@ func BenchmarkRequest(b *testing.B) {
requestData: []byte("some data to return"),
}
m.AddConnection(fc, fc)
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
data, err := m.requestGlobal(device1, "default", files[i%n].Name, 0, 32, nil)
data, err := m.requestGlobal(device1, "default", files[i%n].Name, 0, 32, nil, 0, nil)
if err != nil {
b.Error(err)
}
@ -564,7 +564,7 @@ func TestRefuseUnknownBits(t *testing.T) {
Name: "valid",
Flags: protocol.FlagsAll &^ (protocol.FlagInvalid | protocol.FlagSymlink),
},
})
}, 0, nil)
for _, name := range []string{"invalid1", "invalid2", "invalid3"} {
f, ok := m.CurrentGlobalFile("default", name)
@ -666,7 +666,7 @@ func TestGlobalDirectoryTree(t *testing.T) {
return string(bytes)
}
m.Index(device1, "default", testdata)
m.Index(device1, "default", testdata, 0, nil)
result := m.GlobalDirectoryTree("default", "", -1, false)
@ -925,7 +925,7 @@ func TestGlobalDirectorySelfFixing(t *testing.T) {
return string(bytes)
}
m.Index(device1, "default", testdata)
m.Index(device1, "default", testdata, 0, nil)
result := m.GlobalDirectoryTree("default", "", -1, false)
@ -996,7 +996,7 @@ func BenchmarkTree_10000_50(b *testing.B) {
m.ScanFolder("default")
files := genDeepFiles(10000, 50)
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@ -1011,7 +1011,7 @@ func BenchmarkTree_10000_10(b *testing.B) {
m.ScanFolder("default")
files := genDeepFiles(10000, 10)
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@ -1026,7 +1026,7 @@ func BenchmarkTree_00100_50(b *testing.B) {
m.ScanFolder("default")
files := genDeepFiles(100, 50)
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@ -1041,7 +1041,7 @@ func BenchmarkTree_00100_10(b *testing.B) {
m.ScanFolder("default")
files := genDeepFiles(100, 10)
m.Index(device1, "default", files)
m.Index(device1, "default", files, 0, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {

View File

@ -918,7 +918,7 @@ func (p *rwFolder) pullerRoutine(in <-chan pullBlockState, out chan<- *sharedPul
// Fetch the block, while marking the selected device as in use so that
// leastBusy can select another device when someone else asks.
activity.using(selected)
buf, lastError := p.model.requestGlobal(selected, p.folder, state.file.Name, state.block.Offset, int(state.block.Size), state.block.Hash)
buf, lastError := p.model.requestGlobal(selected, p.folder, state.file.Name, state.block.Offset, int(state.block.Size), state.block.Hash, 0, nil)
activity.done(selected)
if lastError != nil {
continue