Merge pull request #2689 from calmh/nohashalgo
Undo the hash algorithm additions, retain flag checks
This commit is contained in:
commit
d3fa67fe2e
@ -637,11 +637,10 @@ nextFolder:
|
|||||||
for _, folder := range cm.Folders {
|
for _, folder := range cm.Folders {
|
||||||
cfg := m.folderCfgs[folder.ID]
|
cfg := m.folderCfgs[folder.ID]
|
||||||
|
|
||||||
if _, err := protocol.HashAlgorithmFromFlagBits(folder.Flags); err != nil {
|
if folder.Flags&^protocol.FlagFolderAll != 0 {
|
||||||
// The hash algorithm failed to deserialize, so it's not SHA256
|
// There are flags set that we don't know what they mean. Scary!
|
||||||
// (the only acceptable algorithm).
|
l.Warnf("Device %v: unknown flags for folder %s", deviceID, folder.ID)
|
||||||
l.Warnf("Device %v: %v", deviceID, err)
|
cfg.Invalid = fmt.Sprintf("Unknown flags from device %v", deviceID)
|
||||||
cfg.Invalid = err.Error() + " from " + deviceID.String()
|
|
||||||
m.cfg.SetFolder(cfg)
|
m.cfg.SetFolder(cfg)
|
||||||
if srv := m.folderRunners[folder.ID]; srv != nil {
|
if srv := m.folderRunners[folder.ID]; srv != nil {
|
||||||
srv.setError(fmt.Errorf(cfg.Invalid))
|
srv.setError(fmt.Errorf(cfg.Invalid))
|
||||||
|
|||||||
@ -1,54 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Protocol Authors.
|
|
||||||
|
|
||||||
package protocol
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
type HashAlgorithm int
|
|
||||||
|
|
||||||
const (
|
|
||||||
SHA256 HashAlgorithm = iota
|
|
||||||
)
|
|
||||||
|
|
||||||
func (h HashAlgorithm) String() string {
|
|
||||||
switch h {
|
|
||||||
case SHA256:
|
|
||||||
return "sha256"
|
|
||||||
default:
|
|
||||||
return "unknown"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FlagBits returns the bits that we should or into the folder flag field to
|
|
||||||
// indicate the hash algorithm.
|
|
||||||
func (h HashAlgorithm) FlagBits() uint32 {
|
|
||||||
switch h {
|
|
||||||
case SHA256:
|
|
||||||
return FolderHashSHA256 << FolderHashShiftBits
|
|
||||||
default:
|
|
||||||
panic("unknown hash algorithm")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *HashAlgorithm) UnmarshalText(bs []byte) error {
|
|
||||||
switch string(bs) {
|
|
||||||
case "sha256":
|
|
||||||
*h = SHA256
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return fmt.Errorf("Unknown hash algorithm %q", string(bs))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *HashAlgorithm) MarshalText() ([]byte, error) {
|
|
||||||
return []byte(h.String()), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func HashAlgorithmFromFlagBits(flags uint32) (HashAlgorithm, error) {
|
|
||||||
algo := flags >> FolderHashShiftBits & FolderHashMask
|
|
||||||
switch algo {
|
|
||||||
case FolderHashSHA256:
|
|
||||||
return SHA256, nil
|
|
||||||
default:
|
|
||||||
return 0, fmt.Errorf("Unknown hash algorithm %d", algo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Protocol Authors.
|
|
||||||
|
|
||||||
package protocol
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
/*
|
|
||||||
0 1 2 3
|
|
||||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
| Reserved | Hash |D|P|R|
|
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
*/
|
|
||||||
func TestHashAlgorithmFromFlagBits(t *testing.T) {
|
|
||||||
// SHA256 is algorithm zero, shifted three bits to the left (for clarity,
|
|
||||||
// I know it doesn't actually do anything).
|
|
||||||
|
|
||||||
sha256 := uint32(0 << 3)
|
|
||||||
|
|
||||||
h, err := HashAlgorithmFromFlagBits(sha256)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
if h != SHA256 {
|
|
||||||
t.Error("Zero should have unmarshalled as SHA256")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Any other algorithm is unknown
|
|
||||||
unknown := uint32(1 << 3)
|
|
||||||
|
|
||||||
_, err = HashAlgorithmFromFlagBits(unknown)
|
|
||||||
if err == nil {
|
|
||||||
t.Error("Unknown algo should not have unmarshalled")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -66,13 +66,7 @@ const (
|
|||||||
FlagFolderReadOnly uint32 = 1 << 0
|
FlagFolderReadOnly uint32 = 1 << 0
|
||||||
FlagFolderIgnorePerms = 1 << 1
|
FlagFolderIgnorePerms = 1 << 1
|
||||||
FlagFolderIgnoreDelete = 1 << 2
|
FlagFolderIgnoreDelete = 1 << 2
|
||||||
|
FlagFolderAll = 1<<3 - 1
|
||||||
// The folder hash algorithm IDs, to be put in the flags field by shifting
|
|
||||||
// left FolderHashShiftBits. 1 through 15 currently reserved.
|
|
||||||
|
|
||||||
FolderHashSHA256 = 0
|
|
||||||
FolderHashMask = 15
|
|
||||||
FolderHashShiftBits = 3
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ClusterConfigMessage.Folders.Devices flags
|
// ClusterConfigMessage.Folders.Devices flags
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user