diff --git a/lib/connections/service.go b/lib/connections/service.go index c72222b84..f84af88a6 100644 --- a/lib/connections/service.go +++ b/lib/connections/service.go @@ -1340,7 +1340,7 @@ func (c *deviceConnectionTracker) accountAddedConnection(conn protocol.Connectio // how many total connections they want d := conn.DeviceID() c.connections[d] = append(c.connections[d], conn) - c.wantConnections[d] = int(h.NumConnections) + c.wantConnections[d] = h.NumConnections l.Debugf("Added connection for %s (now %d), they want %d connections", d.Short(), len(c.connections[d]), h.NumConnections) // Update active connections metric diff --git a/lib/stun/filter.go b/lib/stun/filter.go deleted file mode 100644 index b33e0f32c..000000000 --- a/lib/stun/filter.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2019 The Syncthing Authors. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at https://mozilla.org/MPL/2.0/. - -package stun - -import ( - "bytes" - "net" - "sync" - "time" -) - -const ( - stunFilterPriority = 10 - otherDataPriority = 100 -) - -type stunFilter struct { - ids map[string]time.Time - mut sync.Mutex -} - -func (f *stunFilter) Outgoing(out []byte, _ net.Addr) { - if !f.isStunPayload(out) { - panic("not a stun payload") - } - f.mut.Lock() - f.ids[string(out[8:20])] = time.Now().Add(time.Minute) - f.reap() - f.mut.Unlock() -} - -func (f *stunFilter) ClaimIncoming(in []byte, _ net.Addr) bool { - if f.isStunPayload(in) { - f.mut.Lock() - _, ok := f.ids[string(in[8:20])] - f.reap() - f.mut.Unlock() - return ok - } - return false -} - -func (*stunFilter) isStunPayload(data []byte) bool { - // Need at least 20 bytes - if len(data) < 20 { - return false - } - - // First two bits always unset, and should always send magic cookie. - return data[0]&0xc0 == 0 && bytes.Equal(data[4:8], []byte{0x21, 0x12, 0xA4, 0x42}) -} - -func (f *stunFilter) reap() { - now := time.Now() - for id, timeout := range f.ids { - if timeout.Before(now) { - delete(f.ids, id) - } - } -} diff --git a/lib/syncthing/internals.go b/lib/syncthing/internals.go index af82b9ac4..27004875d 100644 --- a/lib/syncthing/internals.go +++ b/lib/syncthing/internals.go @@ -45,7 +45,7 @@ func (m *Internals) SetIgnores(folderID string, content []string) error { } func (m *Internals) DownloadBlock(ctx context.Context, deviceID protocol.DeviceID, folderID string, path string, blockNumber int, blockInfo protocol.BlockInfo, allowFromTemporary bool) ([]byte, error) { - return m.model.RequestGlobal(ctx, deviceID, folderID, path, int(blockNumber), blockInfo.Offset, blockInfo.Size, blockInfo.Hash, allowFromTemporary) + return m.model.RequestGlobal(ctx, deviceID, folderID, path, blockNumber, blockInfo.Offset, blockInfo.Size, blockInfo.Hash, allowFromTemporary) } func (m *Internals) BlockAvailability(folderID string, file protocol.FileInfo, block protocol.BlockInfo) ([]model.Availability, error) { diff --git a/lib/ur/usage_report.go b/lib/ur/usage_report.go index f60dfd4b2..d654c0adc 100644 --- a/lib/ur/usage_report.go +++ b/lib/ur/usage_report.go @@ -89,10 +89,10 @@ func (s *Service) reportData(ctx context.Context, urVersion int, preview bool) ( if err != nil { return nil, err } - totFiles += int(global.Files) + totFiles += global.Files totBytes += global.Bytes - if int(global.Files) > maxFiles { - maxFiles = int(global.Files) + if global.Files > maxFiles { + maxFiles = global.Files } if global.Bytes > maxBytes { maxBytes = global.Bytes