lib/protocol: Refactor interface (#9375)
This is a refactor of the protocol/model interface to take the actual
message as the parameter, instead of the broken-out fields:
```diff
type Model interface {
// An index was received from the peer device
- Index(conn Connection, folder string, files []FileInfo) error
+ Index(conn Connection, idx *Index) error
// An index update was received from the peer device
- IndexUpdate(conn Connection, folder string, files []FileInfo) error
+ IndexUpdate(conn Connection, idxUp *IndexUpdate) error
// A request was made by the peer device
- Request(conn Connection, folder, name string, blockNo, size int32, offset int64, hash []byte, weakHash uint32, fromTemporary bool) (RequestResponse, error)
+ Request(conn Connection, req *Request) (RequestResponse, error)
// A cluster configuration message was received
- ClusterConfig(conn Connection, config ClusterConfig) error
+ ClusterConfig(conn Connection, config *ClusterConfig) error
// The peer device closed the connection or an error occurred
Closed(conn Connection, err error)
// The peer device sent progress updates for the files it is currently downloading
- DownloadProgress(conn Connection, folder string, updates []FileDownloadProgressUpdate) error
+ DownloadProgress(conn Connection, p *DownloadProgress) error
}
```
(and changing the `ClusterConfig` to `*ClusterConfig` for symmetry;
we'll be forced to use all pointers everywhere at some point anyway...)
The reason for this is that I have another thing cooking which is a
small troubleshooting change to check index consistency during transfer.
This required adding a field or two to the index/indexupdate messages,
and plumbing the extra parameters in umpteen changes is almost as big a
diff as this is. I figured let's do it once and avoid having to do that
in the future again...
The rest of the diff falls out of the change above, much of it being in
test code where we run these methods manually...
This commit is contained in:
@@ -45,7 +45,7 @@ func TestRecvOnlyRevertDeletes(t *testing.T) {
|
||||
|
||||
// Send and index update for the known stuff
|
||||
|
||||
must(t, m.Index(conn, "ro", knownFiles))
|
||||
must(t, m.Index(conn, &protocol.Index{Folder: "ro", Files: knownFiles}))
|
||||
f.updateLocalsFromScanning(knownFiles)
|
||||
|
||||
size := globalSize(t, m, "ro")
|
||||
@@ -122,7 +122,7 @@ func TestRecvOnlyRevertNeeds(t *testing.T) {
|
||||
|
||||
// Send and index update for the known stuff
|
||||
|
||||
must(t, m.Index(conn, "ro", knownFiles))
|
||||
must(t, m.Index(conn, &protocol.Index{Folder: "ro", Files: knownFiles}))
|
||||
f.updateLocalsFromScanning(knownFiles)
|
||||
|
||||
// Scan the folder.
|
||||
@@ -212,7 +212,7 @@ func TestRecvOnlyUndoChanges(t *testing.T) {
|
||||
|
||||
// Send an index update for the known stuff
|
||||
|
||||
must(t, m.Index(conn, "ro", knownFiles))
|
||||
must(t, m.Index(conn, &protocol.Index{Folder: "ro", Files: knownFiles}))
|
||||
f.updateLocalsFromScanning(knownFiles)
|
||||
|
||||
// Scan the folder.
|
||||
@@ -282,7 +282,7 @@ func TestRecvOnlyDeletedRemoteDrop(t *testing.T) {
|
||||
|
||||
// Send an index update for the known stuff
|
||||
|
||||
must(t, m.Index(conn, "ro", knownFiles))
|
||||
must(t, m.Index(conn, &protocol.Index{Folder: "ro", Files: knownFiles}))
|
||||
f.updateLocalsFromScanning(knownFiles)
|
||||
|
||||
// Scan the folder.
|
||||
@@ -347,7 +347,7 @@ func TestRecvOnlyRemoteUndoChanges(t *testing.T) {
|
||||
|
||||
// Send an index update for the known stuff
|
||||
|
||||
must(t, m.Index(conn, "ro", knownFiles))
|
||||
must(t, m.Index(conn, &protocol.Index{Folder: "ro", Files: knownFiles}))
|
||||
f.updateLocalsFromScanning(knownFiles)
|
||||
|
||||
// Scan the folder.
|
||||
@@ -402,7 +402,7 @@ func TestRecvOnlyRemoteUndoChanges(t *testing.T) {
|
||||
return true
|
||||
})
|
||||
snap.Release()
|
||||
must(t, m.IndexUpdate(conn, "ro", files))
|
||||
must(t, m.IndexUpdate(conn, &protocol.IndexUpdate{Folder: "ro", Files: files}))
|
||||
|
||||
// Ensure the pull to resolve conflicts (content identical) happened
|
||||
must(t, f.doInSync(func() error {
|
||||
@@ -470,7 +470,7 @@ func TestRecvOnlyRevertOwnID(t *testing.T) {
|
||||
}()
|
||||
|
||||
// Receive an index update with an older version, but valid and then revert
|
||||
must(t, m.Index(conn, f.ID, []protocol.FileInfo{fi}))
|
||||
must(t, m.Index(conn, &protocol.Index{Folder: f.ID, Files: []protocol.FileInfo{fi}}))
|
||||
f.Revert()
|
||||
|
||||
select {
|
||||
@@ -497,7 +497,7 @@ func TestRecvOnlyLocalChangeDoesNotCauseConflict(t *testing.T) {
|
||||
|
||||
// Send an index update for the known stuff
|
||||
|
||||
must(t, m.Index(conn, "ro", knownFiles))
|
||||
must(t, m.Index(conn, &protocol.Index{Folder: "ro", Files: knownFiles}))
|
||||
f.updateLocalsFromScanning(knownFiles)
|
||||
|
||||
// Scan the folder.
|
||||
|
||||
Reference in New Issue
Block a user