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:
+46
-86
@@ -50,11 +50,11 @@ type Model struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 error
|
||||
}
|
||||
ClusterConfigStub func(protocol.Connection, protocol.ClusterConfig) error
|
||||
ClusterConfigStub func(protocol.Connection, *protocol.ClusterConfig) error
|
||||
clusterConfigMutex sync.RWMutex
|
||||
clusterConfigArgsForCall []struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 protocol.ClusterConfig
|
||||
arg2 *protocol.ClusterConfig
|
||||
}
|
||||
clusterConfigReturns struct {
|
||||
result1 error
|
||||
@@ -198,12 +198,11 @@ type Model struct {
|
||||
dismissPendingFolderReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
DownloadProgressStub func(protocol.Connection, string, []protocol.FileDownloadProgressUpdate) error
|
||||
DownloadProgressStub func(protocol.Connection, *protocol.DownloadProgress) error
|
||||
downloadProgressMutex sync.RWMutex
|
||||
downloadProgressArgsForCall []struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 string
|
||||
arg3 []protocol.FileDownloadProgressUpdate
|
||||
arg2 *protocol.DownloadProgress
|
||||
}
|
||||
downloadProgressReturns struct {
|
||||
result1 error
|
||||
@@ -290,12 +289,11 @@ type Model struct {
|
||||
result1 []*model.TreeEntry
|
||||
result2 error
|
||||
}
|
||||
IndexStub func(protocol.Connection, string, []protocol.FileInfo) error
|
||||
IndexStub func(protocol.Connection, *protocol.Index) error
|
||||
indexMutex sync.RWMutex
|
||||
indexArgsForCall []struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 string
|
||||
arg3 []protocol.FileInfo
|
||||
arg2 *protocol.Index
|
||||
}
|
||||
indexReturns struct {
|
||||
result1 error
|
||||
@@ -303,12 +301,11 @@ type Model struct {
|
||||
indexReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
IndexUpdateStub func(protocol.Connection, string, []protocol.FileInfo) error
|
||||
IndexUpdateStub func(protocol.Connection, *protocol.IndexUpdate) error
|
||||
indexUpdateMutex sync.RWMutex
|
||||
indexUpdateArgsForCall []struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 string
|
||||
arg3 []protocol.FileInfo
|
||||
arg2 *protocol.IndexUpdate
|
||||
}
|
||||
indexUpdateReturns struct {
|
||||
result1 error
|
||||
@@ -424,18 +421,11 @@ type Model struct {
|
||||
result1 []db.FileInfoTruncated
|
||||
result2 error
|
||||
}
|
||||
RequestStub func(protocol.Connection, string, string, int32, int32, int64, []byte, uint32, bool) (protocol.RequestResponse, error)
|
||||
RequestStub func(protocol.Connection, *protocol.Request) (protocol.RequestResponse, error)
|
||||
requestMutex sync.RWMutex
|
||||
requestArgsForCall []struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 string
|
||||
arg3 string
|
||||
arg4 int32
|
||||
arg5 int32
|
||||
arg6 int64
|
||||
arg7 []byte
|
||||
arg8 uint32
|
||||
arg9 bool
|
||||
arg2 *protocol.Request
|
||||
}
|
||||
requestReturns struct {
|
||||
result1 protocol.RequestResponse
|
||||
@@ -733,12 +723,12 @@ func (fake *Model) ClosedArgsForCall(i int) (protocol.Connection, error) {
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *Model) ClusterConfig(arg1 protocol.Connection, arg2 protocol.ClusterConfig) error {
|
||||
func (fake *Model) ClusterConfig(arg1 protocol.Connection, arg2 *protocol.ClusterConfig) error {
|
||||
fake.clusterConfigMutex.Lock()
|
||||
ret, specificReturn := fake.clusterConfigReturnsOnCall[len(fake.clusterConfigArgsForCall)]
|
||||
fake.clusterConfigArgsForCall = append(fake.clusterConfigArgsForCall, struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 protocol.ClusterConfig
|
||||
arg2 *protocol.ClusterConfig
|
||||
}{arg1, arg2})
|
||||
stub := fake.ClusterConfigStub
|
||||
fakeReturns := fake.clusterConfigReturns
|
||||
@@ -759,13 +749,13 @@ func (fake *Model) ClusterConfigCallCount() int {
|
||||
return len(fake.clusterConfigArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Model) ClusterConfigCalls(stub func(protocol.Connection, protocol.ClusterConfig) error) {
|
||||
func (fake *Model) ClusterConfigCalls(stub func(protocol.Connection, *protocol.ClusterConfig) error) {
|
||||
fake.clusterConfigMutex.Lock()
|
||||
defer fake.clusterConfigMutex.Unlock()
|
||||
fake.ClusterConfigStub = stub
|
||||
}
|
||||
|
||||
func (fake *Model) ClusterConfigArgsForCall(i int) (protocol.Connection, protocol.ClusterConfig) {
|
||||
func (fake *Model) ClusterConfigArgsForCall(i int) (protocol.Connection, *protocol.ClusterConfig) {
|
||||
fake.clusterConfigMutex.RLock()
|
||||
defer fake.clusterConfigMutex.RUnlock()
|
||||
argsForCall := fake.clusterConfigArgsForCall[i]
|
||||
@@ -1453,25 +1443,19 @@ func (fake *Model) DismissPendingFolderReturnsOnCall(i int, result1 error) {
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Model) DownloadProgress(arg1 protocol.Connection, arg2 string, arg3 []protocol.FileDownloadProgressUpdate) error {
|
||||
var arg3Copy []protocol.FileDownloadProgressUpdate
|
||||
if arg3 != nil {
|
||||
arg3Copy = make([]protocol.FileDownloadProgressUpdate, len(arg3))
|
||||
copy(arg3Copy, arg3)
|
||||
}
|
||||
func (fake *Model) DownloadProgress(arg1 protocol.Connection, arg2 *protocol.DownloadProgress) error {
|
||||
fake.downloadProgressMutex.Lock()
|
||||
ret, specificReturn := fake.downloadProgressReturnsOnCall[len(fake.downloadProgressArgsForCall)]
|
||||
fake.downloadProgressArgsForCall = append(fake.downloadProgressArgsForCall, struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 string
|
||||
arg3 []protocol.FileDownloadProgressUpdate
|
||||
}{arg1, arg2, arg3Copy})
|
||||
arg2 *protocol.DownloadProgress
|
||||
}{arg1, arg2})
|
||||
stub := fake.DownloadProgressStub
|
||||
fakeReturns := fake.downloadProgressReturns
|
||||
fake.recordInvocation("DownloadProgress", []interface{}{arg1, arg2, arg3Copy})
|
||||
fake.recordInvocation("DownloadProgress", []interface{}{arg1, arg2})
|
||||
fake.downloadProgressMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1, arg2, arg3)
|
||||
return stub(arg1, arg2)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
@@ -1485,17 +1469,17 @@ func (fake *Model) DownloadProgressCallCount() int {
|
||||
return len(fake.downloadProgressArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Model) DownloadProgressCalls(stub func(protocol.Connection, string, []protocol.FileDownloadProgressUpdate) error) {
|
||||
func (fake *Model) DownloadProgressCalls(stub func(protocol.Connection, *protocol.DownloadProgress) error) {
|
||||
fake.downloadProgressMutex.Lock()
|
||||
defer fake.downloadProgressMutex.Unlock()
|
||||
fake.DownloadProgressStub = stub
|
||||
}
|
||||
|
||||
func (fake *Model) DownloadProgressArgsForCall(i int) (protocol.Connection, string, []protocol.FileDownloadProgressUpdate) {
|
||||
func (fake *Model) DownloadProgressArgsForCall(i int) (protocol.Connection, *protocol.DownloadProgress) {
|
||||
fake.downloadProgressMutex.RLock()
|
||||
defer fake.downloadProgressMutex.RUnlock()
|
||||
argsForCall := fake.downloadProgressArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *Model) DownloadProgressReturns(result1 error) {
|
||||
@@ -1898,25 +1882,19 @@ func (fake *Model) GlobalDirectoryTreeReturnsOnCall(i int, result1 []*model.Tree
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *Model) Index(arg1 protocol.Connection, arg2 string, arg3 []protocol.FileInfo) error {
|
||||
var arg3Copy []protocol.FileInfo
|
||||
if arg3 != nil {
|
||||
arg3Copy = make([]protocol.FileInfo, len(arg3))
|
||||
copy(arg3Copy, arg3)
|
||||
}
|
||||
func (fake *Model) Index(arg1 protocol.Connection, arg2 *protocol.Index) error {
|
||||
fake.indexMutex.Lock()
|
||||
ret, specificReturn := fake.indexReturnsOnCall[len(fake.indexArgsForCall)]
|
||||
fake.indexArgsForCall = append(fake.indexArgsForCall, struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 string
|
||||
arg3 []protocol.FileInfo
|
||||
}{arg1, arg2, arg3Copy})
|
||||
arg2 *protocol.Index
|
||||
}{arg1, arg2})
|
||||
stub := fake.IndexStub
|
||||
fakeReturns := fake.indexReturns
|
||||
fake.recordInvocation("Index", []interface{}{arg1, arg2, arg3Copy})
|
||||
fake.recordInvocation("Index", []interface{}{arg1, arg2})
|
||||
fake.indexMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1, arg2, arg3)
|
||||
return stub(arg1, arg2)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
@@ -1930,17 +1908,17 @@ func (fake *Model) IndexCallCount() int {
|
||||
return len(fake.indexArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Model) IndexCalls(stub func(protocol.Connection, string, []protocol.FileInfo) error) {
|
||||
func (fake *Model) IndexCalls(stub func(protocol.Connection, *protocol.Index) error) {
|
||||
fake.indexMutex.Lock()
|
||||
defer fake.indexMutex.Unlock()
|
||||
fake.IndexStub = stub
|
||||
}
|
||||
|
||||
func (fake *Model) IndexArgsForCall(i int) (protocol.Connection, string, []protocol.FileInfo) {
|
||||
func (fake *Model) IndexArgsForCall(i int) (protocol.Connection, *protocol.Index) {
|
||||
fake.indexMutex.RLock()
|
||||
defer fake.indexMutex.RUnlock()
|
||||
argsForCall := fake.indexArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *Model) IndexReturns(result1 error) {
|
||||
@@ -1966,25 +1944,19 @@ func (fake *Model) IndexReturnsOnCall(i int, result1 error) {
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *Model) IndexUpdate(arg1 protocol.Connection, arg2 string, arg3 []protocol.FileInfo) error {
|
||||
var arg3Copy []protocol.FileInfo
|
||||
if arg3 != nil {
|
||||
arg3Copy = make([]protocol.FileInfo, len(arg3))
|
||||
copy(arg3Copy, arg3)
|
||||
}
|
||||
func (fake *Model) IndexUpdate(arg1 protocol.Connection, arg2 *protocol.IndexUpdate) error {
|
||||
fake.indexUpdateMutex.Lock()
|
||||
ret, specificReturn := fake.indexUpdateReturnsOnCall[len(fake.indexUpdateArgsForCall)]
|
||||
fake.indexUpdateArgsForCall = append(fake.indexUpdateArgsForCall, struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 string
|
||||
arg3 []protocol.FileInfo
|
||||
}{arg1, arg2, arg3Copy})
|
||||
arg2 *protocol.IndexUpdate
|
||||
}{arg1, arg2})
|
||||
stub := fake.IndexUpdateStub
|
||||
fakeReturns := fake.indexUpdateReturns
|
||||
fake.recordInvocation("IndexUpdate", []interface{}{arg1, arg2, arg3Copy})
|
||||
fake.recordInvocation("IndexUpdate", []interface{}{arg1, arg2})
|
||||
fake.indexUpdateMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1, arg2, arg3)
|
||||
return stub(arg1, arg2)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
@@ -1998,17 +1970,17 @@ func (fake *Model) IndexUpdateCallCount() int {
|
||||
return len(fake.indexUpdateArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Model) IndexUpdateCalls(stub func(protocol.Connection, string, []protocol.FileInfo) error) {
|
||||
func (fake *Model) IndexUpdateCalls(stub func(protocol.Connection, *protocol.IndexUpdate) error) {
|
||||
fake.indexUpdateMutex.Lock()
|
||||
defer fake.indexUpdateMutex.Unlock()
|
||||
fake.IndexUpdateStub = stub
|
||||
}
|
||||
|
||||
func (fake *Model) IndexUpdateArgsForCall(i int) (protocol.Connection, string, []protocol.FileInfo) {
|
||||
func (fake *Model) IndexUpdateArgsForCall(i int) (protocol.Connection, *protocol.IndexUpdate) {
|
||||
fake.indexUpdateMutex.RLock()
|
||||
defer fake.indexUpdateMutex.RUnlock()
|
||||
argsForCall := fake.indexUpdateArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *Model) IndexUpdateReturns(result1 error) {
|
||||
@@ -2521,31 +2493,19 @@ func (fake *Model) RemoteNeedFolderFilesReturnsOnCall(i int, result1 []db.FileIn
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *Model) Request(arg1 protocol.Connection, arg2 string, arg3 string, arg4 int32, arg5 int32, arg6 int64, arg7 []byte, arg8 uint32, arg9 bool) (protocol.RequestResponse, error) {
|
||||
var arg7Copy []byte
|
||||
if arg7 != nil {
|
||||
arg7Copy = make([]byte, len(arg7))
|
||||
copy(arg7Copy, arg7)
|
||||
}
|
||||
func (fake *Model) Request(arg1 protocol.Connection, arg2 *protocol.Request) (protocol.RequestResponse, error) {
|
||||
fake.requestMutex.Lock()
|
||||
ret, specificReturn := fake.requestReturnsOnCall[len(fake.requestArgsForCall)]
|
||||
fake.requestArgsForCall = append(fake.requestArgsForCall, struct {
|
||||
arg1 protocol.Connection
|
||||
arg2 string
|
||||
arg3 string
|
||||
arg4 int32
|
||||
arg5 int32
|
||||
arg6 int64
|
||||
arg7 []byte
|
||||
arg8 uint32
|
||||
arg9 bool
|
||||
}{arg1, arg2, arg3, arg4, arg5, arg6, arg7Copy, arg8, arg9})
|
||||
arg2 *protocol.Request
|
||||
}{arg1, arg2})
|
||||
stub := fake.RequestStub
|
||||
fakeReturns := fake.requestReturns
|
||||
fake.recordInvocation("Request", []interface{}{arg1, arg2, arg3, arg4, arg5, arg6, arg7Copy, arg8, arg9})
|
||||
fake.recordInvocation("Request", []interface{}{arg1, arg2})
|
||||
fake.requestMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
|
||||
return stub(arg1, arg2)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1, ret.result2
|
||||
@@ -2559,17 +2519,17 @@ func (fake *Model) RequestCallCount() int {
|
||||
return len(fake.requestArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *Model) RequestCalls(stub func(protocol.Connection, string, string, int32, int32, int64, []byte, uint32, bool) (protocol.RequestResponse, error)) {
|
||||
func (fake *Model) RequestCalls(stub func(protocol.Connection, *protocol.Request) (protocol.RequestResponse, error)) {
|
||||
fake.requestMutex.Lock()
|
||||
defer fake.requestMutex.Unlock()
|
||||
fake.RequestStub = stub
|
||||
}
|
||||
|
||||
func (fake *Model) RequestArgsForCall(i int) (protocol.Connection, string, string, int32, int32, int64, []byte, uint32, bool) {
|
||||
func (fake *Model) RequestArgsForCall(i int) (protocol.Connection, *protocol.Request) {
|
||||
fake.requestMutex.RLock()
|
||||
defer fake.requestMutex.RUnlock()
|
||||
argsForCall := fake.requestArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4, argsForCall.arg5, argsForCall.arg6, argsForCall.arg7, argsForCall.arg8, argsForCall.arg9
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *Model) RequestReturns(result1 protocol.RequestResponse, result2 error) {
|
||||
|
||||
Reference in New Issue
Block a user