This adds the ability to have multiple concurrent connections to a single device. This is primarily useful when the network has multiple physical links for aggregated bandwidth. A single connection will never see a higher rate than a single link can give, but multiple connections are load-balanced over multiple links. It is also incidentally useful for older multi-core CPUs, where bandwidth could be limited by the TLS performance of a single CPU core -- using multiple connections achieves concurrency in the required crypto calculations... Co-authored-by: Simon Frei <freisim93@gmail.com> Co-authored-by: tomasz1986 <twilczynski@naver.com> Co-authored-by: bt90 <btom1990@googlemail.com>
This commit is contained in:
co-authored by
Simon Frei
tomasz1986
bt90
parent
38bbdebffa
commit
c6334e61aa
@@ -42,6 +42,7 @@ type internalConn struct {
|
||||
isLocal bool
|
||||
priority int
|
||||
establishedAt time.Time
|
||||
connectionID string // set after Hello exchange
|
||||
}
|
||||
|
||||
type connType int
|
||||
@@ -88,12 +89,13 @@ func (t connType) Transport() string {
|
||||
}
|
||||
|
||||
func newInternalConn(tc tlsConn, connType connType, isLocal bool, priority int) internalConn {
|
||||
now := time.Now()
|
||||
return internalConn{
|
||||
tlsConn: tc,
|
||||
connType: connType,
|
||||
isLocal: isLocal,
|
||||
priority: priority,
|
||||
establishedAt: time.Now().Truncate(time.Second),
|
||||
establishedAt: now.Truncate(time.Second),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,12 +140,16 @@ func (c internalConn) EstablishedAt() time.Time {
|
||||
return c.establishedAt
|
||||
}
|
||||
|
||||
func (c internalConn) ConnectionID() string {
|
||||
return c.connectionID
|
||||
}
|
||||
|
||||
func (c internalConn) String() string {
|
||||
t := "WAN"
|
||||
if c.isLocal {
|
||||
t = "LAN"
|
||||
}
|
||||
return fmt.Sprintf("%s-%s/%s/%s/%s-P%d", c.LocalAddr(), c.RemoteAddr(), c.Type(), c.Crypto(), t, c.Priority())
|
||||
return fmt.Sprintf("%s-%s/%s/%s/%s-P%d-%s", c.LocalAddr(), c.RemoteAddr(), c.Type(), c.Crypto(), t, c.Priority(), c.connectionID)
|
||||
}
|
||||
|
||||
type dialerFactory interface {
|
||||
@@ -160,6 +166,7 @@ type commonDialer struct {
|
||||
lanChecker *lanChecker
|
||||
lanPriority int
|
||||
wanPriority int
|
||||
allowsMultiConns bool
|
||||
}
|
||||
|
||||
func (d *commonDialer) RedialFrequency() time.Duration {
|
||||
@@ -173,10 +180,15 @@ func (d *commonDialer) Priority(host string) int {
|
||||
return d.wanPriority
|
||||
}
|
||||
|
||||
func (d *commonDialer) AllowsMultiConns() bool {
|
||||
return d.allowsMultiConns
|
||||
}
|
||||
|
||||
type genericDialer interface {
|
||||
Dial(context.Context, protocol.DeviceID, *url.URL) (internalConn, error)
|
||||
RedialFrequency() time.Duration
|
||||
Priority(host string) int
|
||||
AllowsMultiConns() bool
|
||||
}
|
||||
|
||||
type listenerFactory interface {
|
||||
@@ -212,10 +224,7 @@ type genericListener interface {
|
||||
type Model interface {
|
||||
protocol.Model
|
||||
AddConnection(conn protocol.Connection, hello protocol.Hello)
|
||||
NumConnections() int
|
||||
Connection(remoteID protocol.DeviceID) (protocol.Connection, bool)
|
||||
OnHello(protocol.DeviceID, net.Addr, protocol.Hello) error
|
||||
GetHello(protocol.DeviceID) protocol.HelloIntf
|
||||
DeviceStatistics() (map[protocol.DeviceID]stats.DeviceStatistics, error)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user