Fix vet and lint complaints

This commit is contained in:
Jakob Borg 2015-09-22 20:34:24 +02:00
parent a4673f3007
commit 7fdfa81fb8
6 changed files with 51 additions and 49 deletions

View File

@ -14,7 +14,7 @@ const (
) )
var ( var (
ErrNoError error = nil ErrNoError error
ErrGeneric = errors.New("generic error") ErrGeneric = errors.New("generic error")
ErrNoSuchFile = errors.New("no such file") ErrNoSuchFile = errors.New("no such file")
ErrInvalid = errors.New("file is invalid") ErrInvalid = errors.New("file is invalid")

View File

@ -15,10 +15,10 @@ import (
) )
const ( const (
// Data block size (128 KiB) // BlockSize is the standard ata block size (128 KiB)
BlockSize = 128 << 10 BlockSize = 128 << 10
// We reject messages larger than this when encountered on the wire. (64 MiB) // MaxMessageLen is the largest message size allowed on the wire. (64 MiB)
MaxMessageLen = 64 << 20 MaxMessageLen = 64 << 20
) )
@ -145,9 +145,11 @@ type isEofer interface {
} }
const ( const (
// We make sure to send a message at least this often, by triggering pings. // PingSendInterval is how often we make sure to send a message, by
// triggering pings if necessary.
PingSendInterval = 90 * time.Second PingSendInterval = 90 * time.Second
// If we haven't received a message from the other side for this long, close the connection. // ReceiveTimeout is the longest we'll wait for a message from the other
// side before closing the connection.
ReceiveTimeout = 300 * time.Second ReceiveTimeout = 300 * time.Second
) )

View File

@ -2,21 +2,21 @@
package protocol package protocol
// The Vector type represents a version vector. The zero value is a usable // The Vector type represents v version vector. The zero value is v usable
// version vector. The vector has slice semantics and some operations on it // version vector. The vector has slice semantics and some operations on it
// are "append-like" in that they may return the same vector modified, or a // are "append-like" in that they may return the same vector modified, or v
// new allocated Vector with the modified contents. // new allocated Vector with the modified contents.
type Vector []Counter type Vector []Counter
// Counter represents a single counter in the version vector. // Counter represents v single counter in the version vector.
type Counter struct { type Counter struct {
ID uint64 ID uint64
Value uint64 Value uint64
} }
// Update returns a Vector with the index for the specific ID incremented by // Update returns v Vector with the index for the specific ID incremented by
// one. If it is possible, the vector v is updated and returned. If it is not, // one. If it is possible, the vector v is updated and returned. If it is not,
// a copy will be created, updated and returned. // v copy will be created, updated and returned.
func (v Vector) Update(ID uint64) Vector { func (v Vector) Update(ID uint64) Vector {
for i := range v { for i := range v {
if v[i].ID == ID { if v[i].ID == ID {
@ -24,7 +24,7 @@ func (v Vector) Update(ID uint64) Vector {
v[i].Value++ v[i].Value++
return v return v
} else if v[i].ID > ID { } else if v[i].ID > ID {
// Insert a new index // Insert v new index
nv := make(Vector, len(v)+1) nv := make(Vector, len(v)+1)
copy(nv, v[:i]) copy(nv, v[:i])
nv[i].ID = ID nv[i].ID = ID
@ -33,43 +33,43 @@ func (v Vector) Update(ID uint64) Vector {
return nv return nv
} }
} }
// Append a new new index // Append v new new index
return append(v, Counter{ID, 1}) return append(v, Counter{ID, 1})
} }
// Merge returns the vector containing the maximum indexes from a and b. If it // Merge returns the vector containing the maximum indexes from v and b. If it
// is possible, the vector a is updated and returned. If it is not, a copy // is possible, the vector v is updated and returned. If it is not, v copy
// will be created, updated and returned. // will be created, updated and returned.
func (a Vector) Merge(b Vector) Vector { func (v Vector) Merge(b Vector) Vector {
var ai, bi int var vi, bi int
for bi < len(b) { for bi < len(b) {
if ai == len(a) { if vi == len(v) {
// We've reach the end of a, all that remains are appends // We've reach the end of v, all that remains are appends
return append(a, b[bi:]...) return append(v, b[bi:]...)
} }
if a[ai].ID > b[bi].ID { if v[vi].ID > b[bi].ID {
// The index from b should be inserted here // The index from b should be inserted here
n := make(Vector, len(a)+1) n := make(Vector, len(v)+1)
copy(n, a[:ai]) copy(n, v[:vi])
n[ai] = b[bi] n[vi] = b[bi]
copy(n[ai+1:], a[ai:]) copy(n[vi+1:], v[vi:])
a = n v = n
} }
if a[ai].ID == b[bi].ID { if v[vi].ID == b[bi].ID {
if v := b[bi].Value; v > a[ai].Value { if val := b[bi].Value; val > v[vi].Value {
a[ai].Value = v v[vi].Value = val
} }
} }
if bi < len(b) && a[ai].ID == b[bi].ID { if bi < len(b) && v[vi].ID == b[bi].ID {
bi++ bi++
} }
ai++ vi++
} }
return a return v
} }
// Copy returns an identical vector that is not shared with v. // Copy returns an identical vector that is not shared with v.
@ -80,27 +80,27 @@ func (v Vector) Copy() Vector {
} }
// Equal returns true when the two vectors are equivalent. // Equal returns true when the two vectors are equivalent.
func (a Vector) Equal(b Vector) bool { func (v Vector) Equal(b Vector) bool {
return a.Compare(b) == Equal return v.Compare(b) == Equal
} }
// LesserEqual returns true when the two vectors are equivalent or a is Lesser // LesserEqual returns true when the two vectors are equivalent or v is Lesser
// than b. // than b.
func (a Vector) LesserEqual(b Vector) bool { func (v Vector) LesserEqual(b Vector) bool {
comp := a.Compare(b) comp := v.Compare(b)
return comp == Lesser || comp == Equal return comp == Lesser || comp == Equal
} }
// LesserEqual returns true when the two vectors are equivalent or a is Greater // GreaterEqual returns true when the two vectors are equivalent or v is Greater
// than b. // than b.
func (a Vector) GreaterEqual(b Vector) bool { func (v Vector) GreaterEqual(b Vector) bool {
comp := a.Compare(b) comp := v.Compare(b)
return comp == Greater || comp == Equal return comp == Greater || comp == Equal
} }
// Concurrent returns true when the two vectors are concrurrent. // Concurrent returns true when the two vectors are concrurrent.
func (a Vector) Concurrent(b Vector) bool { func (v Vector) Concurrent(b Vector) bool {
comp := a.Compare(b) comp := v.Compare(b)
return comp == ConcurrentGreater || comp == ConcurrentLesser return comp == ConcurrentGreater || comp == ConcurrentLesser
} }

View File

@ -123,12 +123,12 @@ func TestMerge(t *testing.T) {
func TestCounterValue(t *testing.T) { func TestCounterValue(t *testing.T) {
v0 := Vector{Counter{42, 1}, Counter{64, 5}} v0 := Vector{Counter{42, 1}, Counter{64, 5}}
if v0.Counter(42) != 1 { if v0.Counter(42) != 1 {
t.Error("Counter error, %d != %d", v0.Counter(42), 1) t.Errorf("Counter error, %d != %d", v0.Counter(42), 1)
} }
if v0.Counter(64) != 5 { if v0.Counter(64) != 5 {
t.Error("Counter error, %d != %d", v0.Counter(64), 5) t.Errorf("Counter error, %d != %d", v0.Counter(64), 5)
} }
if v0.Counter(72) != 0 { if v0.Counter(72) != 0 {
t.Error("Counter error, %d != %d", v0.Counter(72), 0) t.Errorf("Counter error, %d != %d", v0.Counter(72), 0)
} }
} }

View File

@ -182,7 +182,7 @@ func (c *ProtocolClient) String() string {
func (c *ProtocolClient) connect() error { func (c *ProtocolClient) connect() error {
if c.URI.Scheme != "relay" { if c.URI.Scheme != "relay" {
return fmt.Errorf("Unsupported relay schema:", c.URI.Scheme) return fmt.Errorf("Unsupported relay schema: %v", c.URI.Scheme)
} }
t0 := time.Now() t0 := time.Now()

View File

@ -17,7 +17,7 @@ import (
func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs []tls.Certificate) (protocol.SessionInvitation, error) { func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs []tls.Certificate) (protocol.SessionInvitation, error) {
if uri.Scheme != "relay" { if uri.Scheme != "relay" {
return protocol.SessionInvitation{}, fmt.Errorf("Unsupported relay scheme:", uri.Scheme) return protocol.SessionInvitation{}, fmt.Errorf("Unsupported relay scheme: %v", uri.Scheme)
} }
conn, err := tls.Dial("tcp", uri.Host, configForCerts(certs)) conn, err := tls.Dial("tcp", uri.Host, configForCerts(certs))