2015-01-13 05:31:14 -07:00
|
|
|
// Copyright (C) 2014 The Protocol Authors.
|
2014-09-22 12:42:11 -07:00
|
|
|
|
|
|
|
package protocol
|
|
|
|
|
2016-04-08 18:10:31 -07:00
|
|
|
import "time"
|
2014-09-22 12:42:11 -07:00
|
|
|
|
|
|
|
type TestModel struct {
|
2016-07-04 03:40:29 -07:00
|
|
|
data []byte
|
|
|
|
folder string
|
|
|
|
name string
|
|
|
|
offset int64
|
|
|
|
size int
|
|
|
|
hash []byte
|
|
|
|
fromTemporary bool
|
|
|
|
closedCh chan struct{}
|
|
|
|
closedErr error
|
2014-09-22 12:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func newTestModel() *TestModel {
|
|
|
|
return &TestModel{
|
2016-01-12 01:19:44 -07:00
|
|
|
closedCh: make(chan struct{}),
|
2014-09-22 12:42:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
func (t *TestModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
2014-09-22 12:42:11 -07:00
|
|
|
}
|
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
func (t *TestModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
|
2014-09-22 12:42:11 -07:00
|
|
|
}
|
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
func (t *TestModel) Request(deviceID DeviceID, folder, name string, offset int64, hash []byte, fromTemporary bool, buf []byte) error {
|
2014-09-28 04:00:38 -07:00
|
|
|
t.folder = folder
|
2014-09-22 12:42:11 -07:00
|
|
|
t.name = name
|
|
|
|
t.offset = offset
|
2015-08-09 01:00:28 -07:00
|
|
|
t.size = len(buf)
|
2015-01-24 14:56:12 -07:00
|
|
|
t.hash = hash
|
2016-07-04 03:40:29 -07:00
|
|
|
t.fromTemporary = fromTemporary
|
2015-07-29 13:23:43 -07:00
|
|
|
copy(buf, t.data)
|
|
|
|
return nil
|
2014-09-22 12:42:11 -07:00
|
|
|
}
|
|
|
|
|
2016-08-10 02:37:32 -07:00
|
|
|
func (t *TestModel) Closed(conn Connection, err error) {
|
2016-01-12 01:19:44 -07:00
|
|
|
t.closedErr = err
|
2014-09-22 12:42:11 -07:00
|
|
|
close(t.closedCh)
|
|
|
|
}
|
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
func (t *TestModel) ClusterConfig(deviceID DeviceID, config ClusterConfig) {
|
2014-09-22 12:42:11 -07:00
|
|
|
}
|
|
|
|
|
2016-07-04 03:40:29 -07:00
|
|
|
func (t *TestModel) DownloadProgress(DeviceID, string, []FileDownloadProgressUpdate) {
|
2016-04-15 03:59:41 -07:00
|
|
|
}
|
|
|
|
|
2016-01-12 01:19:44 -07:00
|
|
|
func (t *TestModel) closedError() error {
|
2014-09-22 12:42:11 -07:00
|
|
|
select {
|
|
|
|
case <-t.closedCh:
|
2016-01-12 01:19:44 -07:00
|
|
|
return t.closedErr
|
2014-09-22 12:42:11 -07:00
|
|
|
case <-time.After(1 * time.Second):
|
2016-01-12 01:19:44 -07:00
|
|
|
return nil // Timeout
|
2014-09-22 12:42:11 -07:00
|
|
|
}
|
|
|
|
}
|