diff --git a/cmd/syncthing/connections.go b/cmd/syncthing/connections.go index f02489ee1..960e0e32a 100644 --- a/cmd/syncthing/connections.go +++ b/cmd/syncthing/connections.go @@ -394,7 +394,11 @@ func (s *connectionSvc) connect() { func (s *connectionSvc) acceptRelayConns() { for { - s.conns <- s.relaySvc.Accept() + conn := s.relaySvc.Accept() + s.conns <- model.IntermediateConnection{ + Conn: conn, + Type: model.ConnectionTypeRelayAccept, + } } } diff --git a/lib/relay/relay.go b/lib/relay/relay.go index a651a2156..c763f9229 100644 --- a/lib/relay/relay.go +++ b/lib/relay/relay.go @@ -18,15 +18,26 @@ import ( "github.com/syncthing/relaysrv/protocol" "github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/discover" - "github.com/syncthing/syncthing/lib/model" "github.com/syncthing/syncthing/lib/osutil" "github.com/syncthing/syncthing/lib/sync" "github.com/thejerf/suture" ) +type Svc struct { + *suture.Supervisor + cfg *config.Wrapper + tlsCfg *tls.Config + + tokens map[string]suture.ServiceToken + clients map[string]*client.ProtocolClient + mut sync.RWMutex + invitations chan protocol.SessionInvitation + conns chan *tls.Conn +} + func NewSvc(cfg *config.Wrapper, tlsCfg *tls.Config) *Svc { - conns := make(chan model.IntermediateConnection) + conns := make(chan *tls.Conn) svc := &Svc{ Supervisor: suture.New("Svc", suture.Spec{ @@ -65,18 +76,6 @@ func NewSvc(cfg *config.Wrapper, tlsCfg *tls.Config) *Svc { return svc } -type Svc struct { - *suture.Supervisor - cfg *config.Wrapper - tlsCfg *tls.Config - - tokens map[string]suture.ServiceToken - clients map[string]*client.ProtocolClient - mut sync.RWMutex - invitations chan protocol.SessionInvitation - conns chan model.IntermediateConnection -} - func (s *Svc) VerifyConfiguration(from, to config.Configuration) error { for _, addr := range to.Options.RelayServers { _, err := url.Parse(addr) @@ -210,14 +209,15 @@ func (s *Svc) ClientStatus() map[string]bool { return status } -func (s *Svc) Accept() model.IntermediateConnection { +// Accept returns a new *tls.Conn. The connection is already handshaken. +func (s *Svc) Accept() *tls.Conn { return <-s.conns } type invitationReceiver struct { invitations chan protocol.SessionInvitation tlsCfg *tls.Config - conns chan<- model.IntermediateConnection + conns chan<- *tls.Conn stop chan struct{} } @@ -254,9 +254,7 @@ func (r *invitationReceiver) Serve() { tc.Close() continue } - r.conns <- model.IntermediateConnection{ - tc, model.ConnectionTypeRelayAccept, - } + r.conns <- tc case <-r.stop: return