|
@@ -22,6 +22,7 @@ import (
|
|
|
"github.com/syncthing/syncthing/lib/events"
|
|
"github.com/syncthing/syncthing/lib/events"
|
|
|
"github.com/syncthing/syncthing/lib/model"
|
|
"github.com/syncthing/syncthing/lib/model"
|
|
|
"github.com/syncthing/syncthing/lib/osutil"
|
|
"github.com/syncthing/syncthing/lib/osutil"
|
|
|
|
|
+ "github.com/syncthing/syncthing/lib/relay"
|
|
|
|
|
|
|
|
"github.com/thejerf/suture"
|
|
"github.com/thejerf/suture"
|
|
|
)
|
|
)
|
|
@@ -44,6 +45,7 @@ type connectionSvc struct {
|
|
|
tlsCfg *tls.Config
|
|
tlsCfg *tls.Config
|
|
|
discoverer *discover.Discoverer
|
|
discoverer *discover.Discoverer
|
|
|
conns chan model.IntermediateConnection
|
|
conns chan model.IntermediateConnection
|
|
|
|
|
+ relaySvc *relay.Svc
|
|
|
|
|
|
|
|
lastRelayCheck map[protocol.DeviceID]time.Time
|
|
lastRelayCheck map[protocol.DeviceID]time.Time
|
|
|
|
|
|
|
@@ -52,7 +54,7 @@ type connectionSvc struct {
|
|
|
relaysEnabled bool
|
|
relaysEnabled bool
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func newConnectionSvc(cfg *config.Wrapper, myID protocol.DeviceID, mdl *model.Model, tlsCfg *tls.Config, discoverer *discover.Discoverer) *connectionSvc {
|
|
|
|
|
|
|
+func newConnectionSvc(cfg *config.Wrapper, myID protocol.DeviceID, mdl *model.Model, tlsCfg *tls.Config, discoverer *discover.Discoverer, relaySvc *relay.Svc) *connectionSvc {
|
|
|
svc := &connectionSvc{
|
|
svc := &connectionSvc{
|
|
|
Supervisor: suture.NewSimple("connectionSvc"),
|
|
Supervisor: suture.NewSimple("connectionSvc"),
|
|
|
cfg: cfg,
|
|
cfg: cfg,
|
|
@@ -60,6 +62,7 @@ func newConnectionSvc(cfg *config.Wrapper, myID protocol.DeviceID, mdl *model.Mo
|
|
|
model: mdl,
|
|
model: mdl,
|
|
|
tlsCfg: tlsCfg,
|
|
tlsCfg: tlsCfg,
|
|
|
discoverer: discoverer,
|
|
discoverer: discoverer,
|
|
|
|
|
+ relaySvc: relaySvc,
|
|
|
conns: make(chan model.IntermediateConnection),
|
|
conns: make(chan model.IntermediateConnection),
|
|
|
|
|
|
|
|
connType: make(map[protocol.DeviceID]model.ConnectionType),
|
|
connType: make(map[protocol.DeviceID]model.ConnectionType),
|
|
@@ -104,6 +107,10 @@ func newConnectionSvc(cfg *config.Wrapper, myID protocol.DeviceID, mdl *model.Mo
|
|
|
}
|
|
}
|
|
|
svc.Add(serviceFunc(svc.handle))
|
|
svc.Add(serviceFunc(svc.handle))
|
|
|
|
|
|
|
|
|
|
+ if svc.relaySvc != nil {
|
|
|
|
|
+ svc.Add(serviceFunc(svc.acceptRelayConns))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return svc
|
|
return svc
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -385,6 +392,12 @@ func (s *connectionSvc) connect() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (s *connectionSvc) acceptRelayConns() {
|
|
|
|
|
+ for {
|
|
|
|
|
+ s.conns <- s.relaySvc.Accept()
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (s *connectionSvc) shouldLimit(addr net.Addr) bool {
|
|
func (s *connectionSvc) shouldLimit(addr net.Addr) bool {
|
|
|
if s.cfg.Options().LimitBandwidthInLan {
|
|
if s.cfg.Options().LimitBandwidthInLan {
|
|
|
return true
|
|
return true
|