mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-08 23:08:27 +00:00
lib/connections: Log errors in relay clients (#5917)
This commit is contained in:
parent
bc7dd02e2b
commit
77cc87dfca
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/syncthing/syncthing/lib/dialer"
|
"github.com/syncthing/syncthing/lib/dialer"
|
||||||
"github.com/syncthing/syncthing/lib/nat"
|
"github.com/syncthing/syncthing/lib/nat"
|
||||||
"github.com/syncthing/syncthing/lib/relay/client"
|
"github.com/syncthing/syncthing/lib/relay/client"
|
||||||
|
"github.com/syncthing/syncthing/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -26,6 +27,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type relayListener struct {
|
type relayListener struct {
|
||||||
|
util.ServiceWithError
|
||||||
onAddressesChangedNotifier
|
onAddressesChangedNotifier
|
||||||
|
|
||||||
uri *url.URL
|
uri *url.URL
|
||||||
@ -34,30 +36,22 @@ type relayListener struct {
|
|||||||
conns chan internalConn
|
conns chan internalConn
|
||||||
factory listenerFactory
|
factory listenerFactory
|
||||||
|
|
||||||
err error
|
|
||||||
client client.RelayClient
|
client client.RelayClient
|
||||||
mut sync.RWMutex
|
mut sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *relayListener) Serve() {
|
func (t *relayListener) serve(stop chan struct{}) error {
|
||||||
t.mut.Lock()
|
|
||||||
t.err = nil
|
|
||||||
t.mut.Unlock()
|
|
||||||
|
|
||||||
clnt, err := client.NewClient(t.uri, t.tlsCfg.Certificates, nil, 10*time.Second)
|
clnt, err := client.NewClient(t.uri, t.tlsCfg.Certificates, nil, 10*time.Second)
|
||||||
invitations := clnt.Invitations()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.mut.Lock()
|
l.Infoln("Listen (BEP/relay):", err)
|
||||||
t.err = err
|
return err
|
||||||
t.mut.Unlock()
|
|
||||||
l.Warnln("Listen (BEP/relay):", err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
invitations := clnt.Invitations()
|
||||||
go clnt.Serve()
|
|
||||||
|
|
||||||
t.mut.Lock()
|
t.mut.Lock()
|
||||||
t.client = clnt
|
t.client = clnt
|
||||||
|
go clnt.Serve()
|
||||||
|
defer clnt.Stop()
|
||||||
t.mut.Unlock()
|
t.mut.Unlock()
|
||||||
|
|
||||||
oldURI := clnt.URI()
|
oldURI := clnt.URI()
|
||||||
@ -69,7 +63,10 @@ func (t *relayListener) Serve() {
|
|||||||
select {
|
select {
|
||||||
case inv, ok := <-invitations:
|
case inv, ok := <-invitations:
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
if err := clnt.Error(); err != nil {
|
||||||
|
l.Infoln("Listen (BEP/relay):", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := client.JoinSession(inv)
|
conn, err := client.JoinSession(inv)
|
||||||
@ -114,18 +111,13 @@ func (t *relayListener) Serve() {
|
|||||||
oldURI = currentURI
|
oldURI = currentURI
|
||||||
t.notifyAddressesChanged(t)
|
t.notifyAddressesChanged(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case <-stop:
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *relayListener) Stop() {
|
|
||||||
t.mut.RLock()
|
|
||||||
if t.client != nil {
|
|
||||||
t.client.Stop()
|
|
||||||
}
|
|
||||||
t.mut.RUnlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *relayListener) URI() *url.URL {
|
func (t *relayListener) URI() *url.URL {
|
||||||
return t.uri
|
return t.uri
|
||||||
}
|
}
|
||||||
@ -152,18 +144,16 @@ func (t *relayListener) LANAddresses() []*url.URL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *relayListener) Error() error {
|
func (t *relayListener) Error() error {
|
||||||
t.mut.RLock()
|
err := t.ServiceWithError.Error()
|
||||||
err := t.err
|
|
||||||
var cerr error
|
|
||||||
if t.client != nil {
|
|
||||||
cerr = t.client.Error()
|
|
||||||
}
|
|
||||||
t.mut.RUnlock()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return cerr
|
t.mut.RLock()
|
||||||
|
defer t.mut.RUnlock()
|
||||||
|
if t.client != nil {
|
||||||
|
return t.client.Error()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *relayListener) Factory() listenerFactory {
|
func (t *relayListener) Factory() listenerFactory {
|
||||||
@ -181,13 +171,15 @@ func (t *relayListener) NATType() string {
|
|||||||
type relayListenerFactory struct{}
|
type relayListenerFactory struct{}
|
||||||
|
|
||||||
func (f *relayListenerFactory) New(uri *url.URL, cfg config.Wrapper, tlsCfg *tls.Config, conns chan internalConn, natService *nat.Service) genericListener {
|
func (f *relayListenerFactory) New(uri *url.URL, cfg config.Wrapper, tlsCfg *tls.Config, conns chan internalConn, natService *nat.Service) genericListener {
|
||||||
return &relayListener{
|
t := &relayListener{
|
||||||
uri: uri,
|
uri: uri,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
tlsCfg: tlsCfg,
|
tlsCfg: tlsCfg,
|
||||||
conns: conns,
|
conns: conns,
|
||||||
factory: f,
|
factory: f,
|
||||||
}
|
}
|
||||||
|
t.ServiceWithError = util.AsServiceWithError(t.serve)
|
||||||
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (relayListenerFactory) Valid(cfg config.Configuration) error {
|
func (relayListenerFactory) Valid(cfg config.Configuration) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user