mirror of
https://github.com/syncthing/syncthing.git
synced 2026-05-18 13:52:00 -04:00
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user