mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
674fc566bb
1. Removes separate relay lists and relay clients/services, just makes it a listen address 2. Easier plugging-in of other transports 3. Allows "hot" disabling and enabling NAT services 4. Allows "hot" listen address changes 5. Changes listen address list with a preferable "default" value just like for discovery 6. Debounces global discovery announcements as external addresses change (which it might alot upon starting) 7. Stops this whole "pick other peers relay by latency". This information is no longer available, but I don't think it matters as most of the time other peer only has one relay. 8. Rename ListenAddress to ListenAddresses, as well as in javascript land. 9. Stop serializing deprecated values to JSON GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/2982
89 lines
2.4 KiB
Go
89 lines
2.4 KiB
Go
// Copyright (C) 2016 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 http://mozilla.org/MPL/2.0/.
|
|
|
|
package connections
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/syncthing/syncthing/lib/config"
|
|
"github.com/syncthing/syncthing/lib/nat"
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
|
)
|
|
|
|
type IntermediateConnection struct {
|
|
*tls.Conn
|
|
Type string
|
|
Priority int
|
|
}
|
|
|
|
type Connection struct {
|
|
IntermediateConnection
|
|
protocol.Connection
|
|
}
|
|
|
|
type dialerFactory func(*config.Wrapper, *tls.Config) genericDialer
|
|
|
|
type genericDialer interface {
|
|
Dial(protocol.DeviceID, *url.URL) (IntermediateConnection, error)
|
|
Priority() int
|
|
RedialFrequency() time.Duration
|
|
String() string
|
|
}
|
|
|
|
type listenerFactory func(*url.URL, *tls.Config, chan IntermediateConnection, *nat.Service) genericListener
|
|
|
|
type genericListener interface {
|
|
Serve()
|
|
Stop()
|
|
URI() *url.URL
|
|
// A given address can potentially be mutated by the listener.
|
|
// For example we bind to tcp://0.0.0.0, but that for example might return
|
|
// tcp://gateway1.ip and tcp://gateway2.ip as WAN addresses due to there
|
|
// being multiple gateways, and us managing to get a UPnP mapping on both
|
|
// and tcp://192.168.0.1 and tcp://10.0.0.1 due to there being multiple
|
|
// network interfaces. (The later case for LAN addresses is made up just
|
|
// to provide an example)
|
|
WANAddresses() []*url.URL
|
|
LANAddresses() []*url.URL
|
|
Error() error
|
|
OnAddressesChanged(func(genericListener))
|
|
String() string
|
|
}
|
|
|
|
type Model interface {
|
|
protocol.Model
|
|
AddConnection(conn Connection, hello protocol.HelloMessage)
|
|
ConnectedTo(remoteID protocol.DeviceID) bool
|
|
IsPaused(remoteID protocol.DeviceID) bool
|
|
OnHello(protocol.DeviceID, net.Addr, protocol.HelloMessage)
|
|
GetHello(protocol.DeviceID) protocol.HelloMessage
|
|
}
|
|
|
|
// serviceFunc wraps a function to create a suture.Service without stop
|
|
// functionality.
|
|
type serviceFunc func()
|
|
|
|
func (f serviceFunc) Serve() { f() }
|
|
func (f serviceFunc) Stop() {}
|
|
|
|
type onAddressesChangedNotifier struct {
|
|
callbacks []func(genericListener)
|
|
}
|
|
|
|
func (o *onAddressesChangedNotifier) OnAddressesChanged(callback func(genericListener)) {
|
|
o.callbacks = append(o.callbacks, callback)
|
|
}
|
|
|
|
func (o *onAddressesChangedNotifier) notifyAddressesChanged(l genericListener) {
|
|
for _, callback := range o.callbacks {
|
|
callback(l)
|
|
}
|
|
}
|