Run go fmt -w
This commit is contained in:
parent
6c352dca74
commit
26e4669316
@ -353,12 +353,12 @@ func syncthingMain() {
|
|||||||
ID: "default",
|
ID: "default",
|
||||||
Directory: defaultFolder,
|
Directory: defaultFolder,
|
||||||
RescanIntervalS: 60,
|
RescanIntervalS: 60,
|
||||||
Devices: []config.FolderDeviceConfiguration{{DeviceID: myID}},
|
Devices: []config.FolderDeviceConfiguration{{DeviceID: myID}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cfg.Devices = []config.DeviceConfiguration{
|
cfg.Devices = []config.DeviceConfiguration{
|
||||||
{
|
{
|
||||||
DeviceID: myID,
|
DeviceID: myID,
|
||||||
Addresses: []string{"dynamic"},
|
Addresses: []string{"dynamic"},
|
||||||
Name: myName,
|
Name: myName,
|
||||||
},
|
},
|
||||||
@ -856,7 +856,7 @@ next:
|
|||||||
}
|
}
|
||||||
|
|
||||||
events.Default.Log(events.DeviceRejected, map[string]string{
|
events.Default.Log(events.DeviceRejected, map[string]string{
|
||||||
"device": remoteID.String(),
|
"device": remoteID.String(),
|
||||||
"address": conn.RemoteAddr().String(),
|
"address": conn.RemoteAddr().String(),
|
||||||
})
|
})
|
||||||
l.Infof("Connection from %s with unknown device ID %s; ignoring", conn.RemoteAddr(), remoteID)
|
l.Infof("Connection from %s with unknown device ID %s; ignoring", conn.RemoteAddr(), remoteID)
|
||||||
|
|||||||
@ -23,24 +23,24 @@ import (
|
|||||||
var l = logger.DefaultLogger
|
var l = logger.DefaultLogger
|
||||||
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
Location string `xml:"-" json:"-"`
|
Location string `xml:"-" json:"-"`
|
||||||
Version int `xml:"version,attr" default:"3"`
|
Version int `xml:"version,attr" default:"3"`
|
||||||
Folders []FolderConfiguration `xml:"folder"`
|
Folders []FolderConfiguration `xml:"folder"`
|
||||||
Devices []DeviceConfiguration `xml:"device"`
|
Devices []DeviceConfiguration `xml:"device"`
|
||||||
GUI GUIConfiguration `xml:"gui"`
|
GUI GUIConfiguration `xml:"gui"`
|
||||||
Options OptionsConfiguration `xml:"options"`
|
Options OptionsConfiguration `xml:"options"`
|
||||||
XMLName xml.Name `xml:"configuration" json:"-"`
|
XMLName xml.Name `xml:"configuration" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FolderConfiguration struct {
|
type FolderConfiguration struct {
|
||||||
ID string `xml:"id,attr"`
|
ID string `xml:"id,attr"`
|
||||||
Directory string `xml:"directory,attr"`
|
Directory string `xml:"directory,attr"`
|
||||||
Devices []FolderDeviceConfiguration `xml:"device"`
|
Devices []FolderDeviceConfiguration `xml:"device"`
|
||||||
ReadOnly bool `xml:"ro,attr"`
|
ReadOnly bool `xml:"ro,attr"`
|
||||||
RescanIntervalS int `xml:"rescanIntervalS,attr" default:"60"`
|
RescanIntervalS int `xml:"rescanIntervalS,attr" default:"60"`
|
||||||
IgnorePerms bool `xml:"ignorePerms,attr"`
|
IgnorePerms bool `xml:"ignorePerms,attr"`
|
||||||
Invalid string `xml:"-"` // Set at runtime when there is an error, not saved
|
Invalid string `xml:"-"` // Set at runtime when there is an error, not saved
|
||||||
Versioning VersioningConfiguration `xml:"versioning"`
|
Versioning VersioningConfiguration `xml:"versioning"`
|
||||||
|
|
||||||
deviceIDs []protocol.DeviceID
|
deviceIDs []protocol.DeviceID
|
||||||
}
|
}
|
||||||
@ -96,12 +96,12 @@ func (r *FolderConfiguration) DeviceIDs() []protocol.DeviceID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DeviceConfiguration struct {
|
type DeviceConfiguration struct {
|
||||||
DeviceID protocol.DeviceID `xml:"id,attr"`
|
DeviceID protocol.DeviceID `xml:"id,attr"`
|
||||||
Name string `xml:"name,attr,omitempty"`
|
Name string `xml:"name,attr,omitempty"`
|
||||||
Addresses []string `xml:"address,omitempty"`
|
Addresses []string `xml:"address,omitempty"`
|
||||||
Compression bool `xml:"compression,attr"`
|
Compression bool `xml:"compression,attr"`
|
||||||
CertName string `xml:"certName,attr,omitempty"`
|
CertName string `xml:"certName,attr,omitempty"`
|
||||||
Introducer bool `xml:"introducer,attr"`
|
Introducer bool `xml:"introducer,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FolderDeviceConfiguration struct {
|
type FolderDeviceConfiguration struct {
|
||||||
@ -375,7 +375,7 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) {
|
|||||||
myName, _ := os.Hostname()
|
myName, _ := os.Hostname()
|
||||||
cfg.Devices = append(cfg.Devices, DeviceConfiguration{
|
cfg.Devices = append(cfg.Devices, DeviceConfiguration{
|
||||||
DeviceID: myID,
|
DeviceID: myID,
|
||||||
Name: myName,
|
Name: myName,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
sort.Sort(DeviceConfigurationList(cfg.Devices))
|
sort.Sort(DeviceConfigurationList(cfg.Devices))
|
||||||
@ -527,7 +527,7 @@ func convertV1V2(cfg *Configuration) {
|
|||||||
// Set and sort the list of devices.
|
// Set and sort the list of devices.
|
||||||
for _, device := range devices {
|
for _, device := range devices {
|
||||||
cfg.Devices = append(cfg.Devices, DeviceConfiguration{
|
cfg.Devices = append(cfg.Devices, DeviceConfiguration{
|
||||||
DeviceID: device.DeviceID,
|
DeviceID: device.DeviceID,
|
||||||
Name: device.Deprecated_Name,
|
Name: device.Deprecated_Name,
|
||||||
Addresses: device.Deprecated_Addresses,
|
Addresses: device.Deprecated_Addresses,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -57,20 +57,20 @@ func TestDeviceConfig(t *testing.T) {
|
|||||||
{
|
{
|
||||||
ID: "test",
|
ID: "test",
|
||||||
Directory: "~/Sync",
|
Directory: "~/Sync",
|
||||||
Devices: []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}},
|
Devices: []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}},
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
RescanIntervalS: 600,
|
RescanIntervalS: 600,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expectedDevices := []DeviceConfiguration{
|
expectedDevices := []DeviceConfiguration{
|
||||||
{
|
{
|
||||||
DeviceID: device1,
|
DeviceID: device1,
|
||||||
Name: "device one",
|
Name: "device one",
|
||||||
Addresses: []string{"a"},
|
Addresses: []string{"a"},
|
||||||
Compression: true,
|
Compression: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceID: device4,
|
DeviceID: device4,
|
||||||
Name: "device two",
|
Name: "device two",
|
||||||
Addresses: []string{"b"},
|
Addresses: []string{"b"},
|
||||||
Compression: true,
|
Compression: true,
|
||||||
@ -144,22 +144,22 @@ func TestDeviceAddressesDynamic(t *testing.T) {
|
|||||||
name, _ := os.Hostname()
|
name, _ := os.Hostname()
|
||||||
expected := []DeviceConfiguration{
|
expected := []DeviceConfiguration{
|
||||||
{
|
{
|
||||||
DeviceID: device1,
|
DeviceID: device1,
|
||||||
Addresses: []string{"dynamic"},
|
Addresses: []string{"dynamic"},
|
||||||
Compression: true,
|
Compression: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceID: device2,
|
DeviceID: device2,
|
||||||
Addresses: []string{"dynamic"},
|
Addresses: []string{"dynamic"},
|
||||||
Compression: true,
|
Compression: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceID: device3,
|
DeviceID: device3,
|
||||||
Addresses: []string{"dynamic"},
|
Addresses: []string{"dynamic"},
|
||||||
Compression: true,
|
Compression: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceID: device4,
|
DeviceID: device4,
|
||||||
Name: name, // Set when auto created
|
Name: name, // Set when auto created
|
||||||
Addresses: []string{"dynamic"},
|
Addresses: []string{"dynamic"},
|
||||||
},
|
},
|
||||||
@ -179,19 +179,19 @@ func TestDeviceAddressesStatic(t *testing.T) {
|
|||||||
name, _ := os.Hostname()
|
name, _ := os.Hostname()
|
||||||
expected := []DeviceConfiguration{
|
expected := []DeviceConfiguration{
|
||||||
{
|
{
|
||||||
DeviceID: device1,
|
DeviceID: device1,
|
||||||
Addresses: []string{"192.0.2.1", "192.0.2.2"},
|
Addresses: []string{"192.0.2.1", "192.0.2.2"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceID: device2,
|
DeviceID: device2,
|
||||||
Addresses: []string{"192.0.2.3:6070", "[2001:db8::42]:4242"},
|
Addresses: []string{"192.0.2.3:6070", "[2001:db8::42]:4242"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceID: device3,
|
DeviceID: device3,
|
||||||
Addresses: []string{"[2001:db8::44]:4444", "192.0.2.4:6090"},
|
Addresses: []string{"[2001:db8::44]:4444", "192.0.2.4:6090"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DeviceID: device4,
|
DeviceID: device4,
|
||||||
Name: name, // Set when auto created
|
Name: name, // Set when auto created
|
||||||
Addresses: []string{"dynamic"},
|
Addresses: []string{"dynamic"},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -380,8 +380,8 @@ func (d *Discoverer) registerDevice(addr net.Addr, device Device) bool {
|
|||||||
addrs[i] = current[i].addr
|
addrs[i] = current[i].addr
|
||||||
}
|
}
|
||||||
events.Default.Log(events.DeviceDiscovered, map[string]interface{}{
|
events.Default.Log(events.DeviceDiscovered, map[string]interface{}{
|
||||||
"device": id.String(),
|
"device": id.String(),
|
||||||
"addrs": addrs,
|
"addrs": addrs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Query struct {
|
type Query struct {
|
||||||
Magic uint32
|
Magic uint32
|
||||||
DeviceID []byte // max:32
|
DeviceID []byte // max:32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ const (
|
|||||||
|
|
||||||
type fileVersion struct {
|
type fileVersion struct {
|
||||||
version uint64
|
version uint64
|
||||||
device []byte
|
device []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type versionList struct {
|
type versionList struct {
|
||||||
@ -355,7 +355,7 @@ func ldbUpdateGlobal(db dbReader, batch dbWriter, folder, device, file []byte, v
|
|||||||
|
|
||||||
var fl versionList
|
var fl versionList
|
||||||
nv := fileVersion{
|
nv := fileVersion{
|
||||||
device: device,
|
device: device,
|
||||||
version: version,
|
version: version,
|
||||||
}
|
}
|
||||||
if svl != nil {
|
if svl != nil {
|
||||||
@ -455,7 +455,7 @@ func ldbWithHave(db *leveldb.DB, folder, device []byte, truncate bool, fn fileIt
|
|||||||
func ldbWithAllFolderTruncated(db *leveldb.DB, folder []byte, fn func(device []byte, f protocol.FileInfoTruncated) bool) {
|
func ldbWithAllFolderTruncated(db *leveldb.DB, folder []byte, fn func(device []byte, f protocol.FileInfoTruncated) bool) {
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
|
|
||||||
start := deviceKey(folder, nil, nil) // before all folder/device files
|
start := deviceKey(folder, nil, nil) // before all folder/device files
|
||||||
limit := deviceKey(folder, protocol.LocalDeviceID[:], []byte{0xff, 0xff, 0xff, 0xff}) // after all folder/device files
|
limit := deviceKey(folder, protocol.LocalDeviceID[:], []byte{0xff, 0xff, 0xff, 0xff}) // after all folder/device files
|
||||||
snap, err := db.GetSnapshot()
|
snap, err := db.GetSnapshot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -29,14 +29,14 @@ type bitset uint64
|
|||||||
type Set struct {
|
type Set struct {
|
||||||
localVersion map[protocol.DeviceID]uint64
|
localVersion map[protocol.DeviceID]uint64
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
folder string
|
folder string
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSet(folder string, db *leveldb.DB) *Set {
|
func NewSet(folder string, db *leveldb.DB) *Set {
|
||||||
var s = Set{
|
var s = Set{
|
||||||
localVersion: make(map[protocol.DeviceID]uint64),
|
localVersion: make(map[protocol.DeviceID]uint64),
|
||||||
folder: folder,
|
folder: folder,
|
||||||
db: db,
|
db: db,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,29 +69,29 @@ type Model struct {
|
|||||||
cfg *config.Configuration
|
cfg *config.Configuration
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
|
|
||||||
deviceName string
|
deviceName string
|
||||||
clientName string
|
clientName string
|
||||||
clientVersion string
|
clientVersion string
|
||||||
|
|
||||||
folderCfgs map[string]config.FolderConfiguration // folder -> cfg
|
folderCfgs map[string]config.FolderConfiguration // folder -> cfg
|
||||||
folderFiles map[string]*files.Set // folder -> files
|
folderFiles map[string]*files.Set // folder -> files
|
||||||
folderDevices map[string][]protocol.DeviceID // folder -> deviceIDs
|
folderDevices map[string][]protocol.DeviceID // folder -> deviceIDs
|
||||||
deviceFolders map[protocol.DeviceID][]string // deviceID -> folders
|
deviceFolders map[protocol.DeviceID][]string // deviceID -> folders
|
||||||
deviceStatRefs map[protocol.DeviceID]*stats.DeviceStatisticsReference // deviceID -> statsRef
|
deviceStatRefs map[protocol.DeviceID]*stats.DeviceStatisticsReference // deviceID -> statsRef
|
||||||
folderIgnores map[string]ignore.Patterns // folder -> list of ignore patterns
|
folderIgnores map[string]ignore.Patterns // folder -> list of ignore patterns
|
||||||
rmut sync.RWMutex // protects the above
|
rmut sync.RWMutex // protects the above
|
||||||
|
|
||||||
folderState map[string]folderState // folder -> state
|
folderState map[string]folderState // folder -> state
|
||||||
folderStateChanged map[string]time.Time // folder -> time when state changed
|
folderStateChanged map[string]time.Time // folder -> time when state changed
|
||||||
smut sync.RWMutex
|
smut sync.RWMutex
|
||||||
|
|
||||||
protoConn map[protocol.DeviceID]protocol.Connection
|
protoConn map[protocol.DeviceID]protocol.Connection
|
||||||
rawConn map[protocol.DeviceID]io.Closer
|
rawConn map[protocol.DeviceID]io.Closer
|
||||||
deviceVer map[protocol.DeviceID]string
|
deviceVer map[protocol.DeviceID]string
|
||||||
pmut sync.RWMutex // protects protoConn and rawConn
|
pmut sync.RWMutex // protects protoConn and rawConn
|
||||||
|
|
||||||
addedFolder bool
|
addedFolder bool
|
||||||
started bool
|
started bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -104,22 +104,22 @@ var (
|
|||||||
// for file data without altering the local folder in any way.
|
// for file data without altering the local folder in any way.
|
||||||
func NewModel(indexDir string, cfg *config.Configuration, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model {
|
func NewModel(indexDir string, cfg *config.Configuration, deviceName, clientName, clientVersion string, db *leveldb.DB) *Model {
|
||||||
m := &Model{
|
m := &Model{
|
||||||
indexDir: indexDir,
|
indexDir: indexDir,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
db: db,
|
db: db,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
clientName: clientName,
|
clientName: clientName,
|
||||||
clientVersion: clientVersion,
|
clientVersion: clientVersion,
|
||||||
folderCfgs: make(map[string]config.FolderConfiguration),
|
folderCfgs: make(map[string]config.FolderConfiguration),
|
||||||
folderFiles: make(map[string]*files.Set),
|
folderFiles: make(map[string]*files.Set),
|
||||||
folderDevices: make(map[string][]protocol.DeviceID),
|
folderDevices: make(map[string][]protocol.DeviceID),
|
||||||
deviceFolders: make(map[protocol.DeviceID][]string),
|
deviceFolders: make(map[protocol.DeviceID][]string),
|
||||||
deviceStatRefs: make(map[protocol.DeviceID]*stats.DeviceStatisticsReference),
|
deviceStatRefs: make(map[protocol.DeviceID]*stats.DeviceStatisticsReference),
|
||||||
folderIgnores: make(map[string]ignore.Patterns),
|
folderIgnores: make(map[string]ignore.Patterns),
|
||||||
folderState: make(map[string]folderState),
|
folderState: make(map[string]folderState),
|
||||||
folderStateChanged: make(map[string]time.Time),
|
folderStateChanged: make(map[string]time.Time),
|
||||||
protoConn: make(map[protocol.DeviceID]protocol.Connection),
|
protoConn: make(map[protocol.DeviceID]protocol.Connection),
|
||||||
rawConn: make(map[protocol.DeviceID]io.Closer),
|
rawConn: make(map[protocol.DeviceID]io.Closer),
|
||||||
deviceVer: make(map[protocol.DeviceID]string),
|
deviceVer: make(map[protocol.DeviceID]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ func (m *Model) StartFolderRW(folder string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p := Puller{
|
p := Puller{
|
||||||
folder: folder,
|
folder: folder,
|
||||||
dir: cfg.Directory,
|
dir: cfg.Directory,
|
||||||
scanIntv: time.Duration(cfg.RescanIntervalS) * time.Second,
|
scanIntv: time.Duration(cfg.RescanIntervalS) * time.Second,
|
||||||
model: m,
|
model: m,
|
||||||
@ -411,8 +411,8 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F
|
|||||||
files.Replace(deviceID, fs)
|
files.Replace(deviceID, fs)
|
||||||
|
|
||||||
events.Default.Log(events.RemoteIndexUpdated, map[string]interface{}{
|
events.Default.Log(events.RemoteIndexUpdated, map[string]interface{}{
|
||||||
"device": deviceID.String(),
|
"device": deviceID.String(),
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
"items": len(fs),
|
"items": len(fs),
|
||||||
"version": files.LocalVersion(deviceID),
|
"version": files.LocalVersion(deviceID),
|
||||||
})
|
})
|
||||||
@ -452,8 +452,8 @@ func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []prot
|
|||||||
files.Update(deviceID, fs)
|
files.Update(deviceID, fs)
|
||||||
|
|
||||||
events.Default.Log(events.RemoteIndexUpdated, map[string]interface{}{
|
events.Default.Log(events.RemoteIndexUpdated, map[string]interface{}{
|
||||||
"device": deviceID.String(),
|
"device": deviceID.String(),
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
"items": len(fs),
|
"items": len(fs),
|
||||||
"version": files.LocalVersion(deviceID),
|
"version": files.LocalVersion(deviceID),
|
||||||
})
|
})
|
||||||
@ -890,7 +890,7 @@ func (m *Model) updateLocal(folder string, f protocol.FileInfo) {
|
|||||||
m.folderFiles[folder].Update(protocol.LocalDeviceID, []protocol.FileInfo{f})
|
m.folderFiles[folder].Update(protocol.LocalDeviceID, []protocol.FileInfo{f})
|
||||||
m.rmut.RUnlock()
|
m.rmut.RUnlock()
|
||||||
events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
|
events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
"name": f.Name,
|
"name": f.Name,
|
||||||
"modified": time.Unix(f.Modified, 0),
|
"modified": time.Unix(f.Modified, 0),
|
||||||
"flags": fmt.Sprintf("0%o", f.Flags),
|
"flags": fmt.Sprintf("0%o", f.Flags),
|
||||||
@ -1022,7 +1022,7 @@ func (m *Model) ScanFolderSub(folder, sub string) error {
|
|||||||
batch := make([]protocol.FileInfo, 0, 00)
|
batch := make([]protocol.FileInfo, 0, 00)
|
||||||
for f := range fchan {
|
for f := range fchan {
|
||||||
events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
|
events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
"name": f.Name,
|
"name": f.Name,
|
||||||
"modified": time.Unix(f.Modified, 0),
|
"modified": time.Unix(f.Modified, 0),
|
||||||
"flags": fmt.Sprintf("0%o", f.Flags),
|
"flags": fmt.Sprintf("0%o", f.Flags),
|
||||||
@ -1070,7 +1070,7 @@ func (m *Model) ScanFolderSub(folder, sub string) error {
|
|||||||
Version: f.Version, // The file is still the same, so don't bump version
|
Version: f.Version, // The file is still the same, so don't bump version
|
||||||
}
|
}
|
||||||
events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
|
events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
"name": f.Name,
|
"name": f.Name,
|
||||||
"modified": time.Unix(f.Modified, 0),
|
"modified": time.Unix(f.Modified, 0),
|
||||||
"flags": fmt.Sprintf("0%o", f.Flags),
|
"flags": fmt.Sprintf("0%o", f.Flags),
|
||||||
@ -1086,7 +1086,7 @@ func (m *Model) ScanFolderSub(folder, sub string) error {
|
|||||||
Version: lamport.Default.Tick(f.Version),
|
Version: lamport.Default.Tick(f.Version),
|
||||||
}
|
}
|
||||||
events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
|
events.Default.Log(events.LocalIndexUpdated, map[string]interface{}{
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
"name": f.Name,
|
"name": f.Name,
|
||||||
"modified": time.Unix(f.Modified, 0),
|
"modified": time.Unix(f.Modified, 0),
|
||||||
"flags": fmt.Sprintf("0%o", f.Flags),
|
"flags": fmt.Sprintf("0%o", f.Flags),
|
||||||
@ -1153,7 +1153,7 @@ func (m *Model) setState(folder string, state folderState) {
|
|||||||
m.folderStateChanged[folder] = time.Now()
|
m.folderStateChanged[folder] = time.Now()
|
||||||
eventData := map[string]interface{}{
|
eventData := map[string]interface{}{
|
||||||
"folder": folder,
|
"folder": folder,
|
||||||
"to": state.String(),
|
"to": state.String(),
|
||||||
}
|
}
|
||||||
if ok {
|
if ok {
|
||||||
eventData["duration"] = time.Since(changed).Seconds()
|
eventData["duration"] = time.Since(changed).Seconds()
|
||||||
|
|||||||
@ -287,7 +287,7 @@ func TestClusterConfig(t *testing.T) {
|
|||||||
cfg := config.New("/tmp/test", device1)
|
cfg := config.New("/tmp/test", device1)
|
||||||
cfg.Devices = []config.DeviceConfiguration{
|
cfg.Devices = []config.DeviceConfiguration{
|
||||||
{
|
{
|
||||||
DeviceID: device1,
|
DeviceID: device1,
|
||||||
Introducer: true,
|
Introducer: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -26,9 +26,9 @@ const (
|
|||||||
copiersPerFolder = 1
|
copiersPerFolder = 1
|
||||||
pullersPerFolder = 16
|
pullersPerFolder = 16
|
||||||
finishersPerFolder = 2
|
finishersPerFolder = 2
|
||||||
pauseIntv = 60 * time.Second
|
pauseIntv = 60 * time.Second
|
||||||
nextPullIntv = 10 * time.Second
|
nextPullIntv = 10 * time.Second
|
||||||
checkPullIntv = 1 * time.Second
|
checkPullIntv = 1 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// A pullBlockState is passed to the puller routine for each block that needs
|
// A pullBlockState is passed to the puller routine for each block that needs
|
||||||
@ -46,12 +46,12 @@ type copyBlocksState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
activity = newDeviceActivity()
|
activity = newDeviceActivity()
|
||||||
errNoDevice = errors.New("no available source device")
|
errNoDevice = errors.New("no available source device")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Puller struct {
|
type Puller struct {
|
||||||
folder string
|
folder string
|
||||||
dir string
|
dir string
|
||||||
scanIntv time.Duration
|
scanIntv time.Duration
|
||||||
model *Model
|
model *Model
|
||||||
@ -129,7 +129,7 @@ loop:
|
|||||||
// version that includes those files in curVer. So we
|
// version that includes those files in curVer. So we
|
||||||
// catch the case that localVersion might have
|
// catch the case that localVersion might have
|
||||||
// decresed here.
|
// decresed here.
|
||||||
l.Debugln(p,"adjusting curVer",lv)
|
l.Debugln(p, "adjusting curVer", lv)
|
||||||
curVer = lv
|
curVer = lv
|
||||||
}
|
}
|
||||||
prevVer = curVer
|
prevVer = curVer
|
||||||
@ -241,7 +241,7 @@ func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int) int {
|
|||||||
|
|
||||||
events.Default.Log(events.ItemStarted, map[string]string{
|
events.Default.Log(events.ItemStarted, map[string]string{
|
||||||
"folder": p.folder,
|
"folder": p.folder,
|
||||||
"item": file.Name,
|
"item": file.Name,
|
||||||
})
|
})
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
@ -384,7 +384,7 @@ func (p *Puller) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocksSt
|
|||||||
|
|
||||||
s := sharedPullerState{
|
s := sharedPullerState{
|
||||||
file: file,
|
file: file,
|
||||||
folder: p.folder,
|
folder: p.folder,
|
||||||
tempName: tempName,
|
tempName: tempName,
|
||||||
realName: realName,
|
realName: realName,
|
||||||
pullNeeded: len(pullBlocks),
|
pullNeeded: len(pullBlocks),
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import (
|
|||||||
type sharedPullerState struct {
|
type sharedPullerState struct {
|
||||||
// Immutable, does not require locking
|
// Immutable, does not require locking
|
||||||
file protocol.FileInfo
|
file protocol.FileInfo
|
||||||
folder string
|
folder string
|
||||||
tempName string
|
tempName string
|
||||||
realName string
|
realName string
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
type TestModel struct {
|
type TestModel struct {
|
||||||
data []byte
|
data []byte
|
||||||
folder string
|
folder string
|
||||||
name string
|
name string
|
||||||
offset int64
|
offset int64
|
||||||
size int
|
size int
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import "fmt"
|
|||||||
|
|
||||||
type IndexMessage struct {
|
type IndexMessage struct {
|
||||||
Folder string // max:64
|
Folder string // max:64
|
||||||
Files []FileInfo
|
Files []FileInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
@ -91,9 +91,9 @@ func (b BlockInfo) String() string {
|
|||||||
|
|
||||||
type RequestMessage struct {
|
type RequestMessage struct {
|
||||||
Folder string // max:64
|
Folder string // max:64
|
||||||
Name string // max:8192
|
Name string // max:8192
|
||||||
Offset uint64
|
Offset uint64
|
||||||
Size uint32
|
Size uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseMessage struct {
|
type ResponseMessage struct {
|
||||||
@ -101,10 +101,10 @@ type ResponseMessage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ClusterConfigMessage struct {
|
type ClusterConfigMessage struct {
|
||||||
ClientName string // max:64
|
ClientName string // max:64
|
||||||
ClientVersion string // max:64
|
ClientVersion string // max:64
|
||||||
Folders []Folder // max:64
|
Folders []Folder // max:64
|
||||||
Options []Option // max:64
|
Options []Option // max:64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ClusterConfigMessage) GetOption(key string) string {
|
func (o *ClusterConfigMessage) GetOption(key string) string {
|
||||||
@ -117,7 +117,7 @@ func (o *ClusterConfigMessage) GetOption(key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Folder struct {
|
type Folder struct {
|
||||||
ID string // max:64
|
ID string // max:64
|
||||||
Devices []Device // max:64
|
Devices []Device // max:64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,13 +24,13 @@ type DeviceStatistics struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DeviceStatisticsReference struct {
|
type DeviceStatisticsReference struct {
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
device protocol.DeviceID
|
device protocol.DeviceID
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeviceStatisticsReference(db *leveldb.DB, device protocol.DeviceID) *DeviceStatisticsReference {
|
func NewDeviceStatisticsReference(db *leveldb.DB, device protocol.DeviceID) *DeviceStatisticsReference {
|
||||||
return &DeviceStatisticsReference{
|
return &DeviceStatisticsReference{
|
||||||
db: db,
|
db: db,
|
||||||
device: device,
|
device: device,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ func init() {
|
|||||||
|
|
||||||
// The type holds our configuration
|
// The type holds our configuration
|
||||||
type Simple struct {
|
type Simple struct {
|
||||||
keep int
|
keep int
|
||||||
folderPath string
|
folderPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ func NewSimple(folderID, folderPath string, params map[string]string) Versioner
|
|||||||
}
|
}
|
||||||
|
|
||||||
s := Simple{
|
s := Simple{
|
||||||
keep: keep,
|
keep: keep,
|
||||||
folderPath: folderPath,
|
folderPath: folderPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ type Interval struct {
|
|||||||
type Staggered struct {
|
type Staggered struct {
|
||||||
versionsPath string
|
versionsPath string
|
||||||
cleanInterval int64
|
cleanInterval int64
|
||||||
folderPath string
|
folderPath string
|
||||||
interval [4]Interval
|
interval [4]Interval
|
||||||
mutex *sync.Mutex
|
mutex *sync.Mutex
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ func NewStaggered(folderID, folderPath string, params map[string]string) Version
|
|||||||
s := Staggered{
|
s := Staggered{
|
||||||
versionsPath: versionsDir,
|
versionsPath: versionsDir,
|
||||||
cleanInterval: cleanInterval,
|
cleanInterval: cleanInterval,
|
||||||
folderPath: folderPath,
|
folderPath: folderPath,
|
||||||
interval: [4]Interval{
|
interval: [4]Interval{
|
||||||
Interval{30, 3600}, // first hour -> 30 sec between versions
|
Interval{30, 3600}, // first hour -> 30 sec between versions
|
||||||
Interval{3600, 86400}, // next day -> 1 h between versions
|
Interval{3600, 86400}, // next day -> 1 h between versions
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user