lib/relay need not depend on lib/model any more

This commit is contained in:
Jakob Borg 2015-09-14 20:19:39 +02:00
parent 3d09090c4e
commit 7e3c06191e
2 changed files with 22 additions and 20 deletions

View File

@ -394,7 +394,11 @@ func (s *connectionSvc) connect() {
func (s *connectionSvc) acceptRelayConns() { func (s *connectionSvc) acceptRelayConns() {
for { for {
s.conns <- s.relaySvc.Accept() conn := s.relaySvc.Accept()
s.conns <- model.IntermediateConnection{
Conn: conn,
Type: model.ConnectionTypeRelayAccept,
}
} }
} }

View File

@ -18,15 +18,26 @@ import (
"github.com/syncthing/relaysrv/protocol" "github.com/syncthing/relaysrv/protocol"
"github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/discover" "github.com/syncthing/syncthing/lib/discover"
"github.com/syncthing/syncthing/lib/model"
"github.com/syncthing/syncthing/lib/osutil" "github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/sync" "github.com/syncthing/syncthing/lib/sync"
"github.com/thejerf/suture" "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 { func NewSvc(cfg *config.Wrapper, tlsCfg *tls.Config) *Svc {
conns := make(chan model.IntermediateConnection) conns := make(chan *tls.Conn)
svc := &Svc{ svc := &Svc{
Supervisor: suture.New("Svc", suture.Spec{ Supervisor: suture.New("Svc", suture.Spec{
@ -65,18 +76,6 @@ func NewSvc(cfg *config.Wrapper, tlsCfg *tls.Config) *Svc {
return 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 { func (s *Svc) VerifyConfiguration(from, to config.Configuration) error {
for _, addr := range to.Options.RelayServers { for _, addr := range to.Options.RelayServers {
_, err := url.Parse(addr) _, err := url.Parse(addr)
@ -210,14 +209,15 @@ func (s *Svc) ClientStatus() map[string]bool {
return status 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 return <-s.conns
} }
type invitationReceiver struct { type invitationReceiver struct {
invitations chan protocol.SessionInvitation invitations chan protocol.SessionInvitation
tlsCfg *tls.Config tlsCfg *tls.Config
conns chan<- model.IntermediateConnection conns chan<- *tls.Conn
stop chan struct{} stop chan struct{}
} }
@ -254,9 +254,7 @@ func (r *invitationReceiver) Serve() {
tc.Close() tc.Close()
continue continue
} }
r.conns <- model.IntermediateConnection{ r.conns <- tc
tc, model.ConnectionTypeRelayAccept,
}
case <-r.stop: case <-r.stop:
return return