mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
This commit is contained in:
parent
49798552f2
commit
4aa2199d5b
@ -46,8 +46,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
perDeviceWarningIntv = 15 * time.Minute
|
perDeviceWarningIntv = 15 * time.Minute
|
||||||
tlsHandshakeTimeout = 10 * time.Second
|
tlsHandshakeTimeout = 10 * time.Second
|
||||||
|
minConnectionReplaceAge = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// From go/src/crypto/tls/cipher_suites.go
|
// From go/src/crypto/tls/cipher_suites.go
|
||||||
@ -276,7 +277,7 @@ func (s *service) handle(ctx context.Context) {
|
|||||||
ct, connected := s.model.Connection(remoteID)
|
ct, connected := s.model.Connection(remoteID)
|
||||||
|
|
||||||
// Lower priority is better, just like nice etc.
|
// Lower priority is better, just like nice etc.
|
||||||
if connected && ct.Priority() > c.priority {
|
if connected && (ct.Priority() > c.priority || time.Since(ct.Statistics().StartedAt) > minConnectionReplaceAge) {
|
||||||
l.Debugf("Switching connections %s (existing: %s new: %s)", remoteID, ct, c)
|
l.Debugf("Switching connections %s (existing: %s new: %s)", remoteID, ct, c)
|
||||||
} else if connected {
|
} else if connected {
|
||||||
// We should not already be connected to the other party. TODO: This
|
// We should not already be connected to the other party. TODO: This
|
||||||
|
@ -145,9 +145,10 @@ type Connection interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type rawConnection struct {
|
type rawConnection struct {
|
||||||
id DeviceID
|
id DeviceID
|
||||||
name string
|
name string
|
||||||
receiver Model
|
receiver Model
|
||||||
|
startTime time.Time
|
||||||
|
|
||||||
cr *countingReader
|
cr *countingReader
|
||||||
cw *countingWriter
|
cw *countingWriter
|
||||||
@ -236,6 +237,7 @@ func (c *rawConnection) Start() {
|
|||||||
go c.writerLoop()
|
go c.writerLoop()
|
||||||
go c.pingSender()
|
go c.pingSender()
|
||||||
go c.pingReceiver()
|
go c.pingReceiver()
|
||||||
|
c.startTime = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *rawConnection) ID() DeviceID {
|
func (c *rawConnection) ID() DeviceID {
|
||||||
@ -958,6 +960,7 @@ type Statistics struct {
|
|||||||
At time.Time
|
At time.Time
|
||||||
InBytesTotal int64
|
InBytesTotal int64
|
||||||
OutBytesTotal int64
|
OutBytesTotal int64
|
||||||
|
StartedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *rawConnection) Statistics() Statistics {
|
func (c *rawConnection) Statistics() Statistics {
|
||||||
@ -965,6 +968,7 @@ func (c *rawConnection) Statistics() Statistics {
|
|||||||
At: time.Now(),
|
At: time.Now(),
|
||||||
InBytesTotal: c.cr.Tot(),
|
InBytesTotal: c.cr.Tot(),
|
||||||
OutBytesTotal: c.cw.Tot(),
|
OutBytesTotal: c.cw.Tot(),
|
||||||
|
StartedAt: c.startTime,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user