mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-13 00:36:28 +00:00
Add ability to lookup relay status
This commit is contained in:
parent
efa0a06947
commit
d1f3d95c96
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
syncthingprotocol "github.com/syncthing/protocol"
|
syncthingprotocol "github.com/syncthing/protocol"
|
||||||
"github.com/syncthing/relaysrv/protocol"
|
"github.com/syncthing/relaysrv/protocol"
|
||||||
|
"github.com/syncthing/syncthing/internal/sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProtocolClient struct {
|
type ProtocolClient struct {
|
||||||
@ -28,6 +29,9 @@ type ProtocolClient struct {
|
|||||||
stopped chan struct{}
|
stopped chan struct{}
|
||||||
|
|
||||||
conn *tls.Conn
|
conn *tls.Conn
|
||||||
|
|
||||||
|
mut sync.RWMutex
|
||||||
|
connected bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProtocolClient(uri *url.URL, certs []tls.Certificate, invitations chan protocol.SessionInvitation) *ProtocolClient {
|
func NewProtocolClient(uri *url.URL, certs []tls.Certificate, invitations chan protocol.SessionInvitation) *ProtocolClient {
|
||||||
@ -49,6 +53,9 @@ func NewProtocolClient(uri *url.URL, certs []tls.Certificate, invitations chan p
|
|||||||
|
|
||||||
stop: make(chan struct{}),
|
stop: make(chan struct{}),
|
||||||
stopped: make(chan struct{}),
|
stopped: make(chan struct{}),
|
||||||
|
|
||||||
|
mut: sync.NewRWMutex(),
|
||||||
|
connected: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +89,9 @@ func (c *ProtocolClient) Serve() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer c.cleanup()
|
defer c.cleanup()
|
||||||
|
c.mut.Lock()
|
||||||
|
c.connected = true
|
||||||
|
c.mut.Unlock()
|
||||||
|
|
||||||
messages := make(chan interface{})
|
messages := make(chan interface{})
|
||||||
errors := make(chan error, 1)
|
errors := make(chan error, 1)
|
||||||
@ -149,6 +159,13 @@ func (c *ProtocolClient) Stop() {
|
|||||||
<-c.stopped
|
<-c.stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ProtocolClient) StatusOK() bool {
|
||||||
|
c.mut.RLock()
|
||||||
|
con := c.connected
|
||||||
|
c.mut.RUnlock()
|
||||||
|
return con
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ProtocolClient) String() string {
|
func (c *ProtocolClient) String() string {
|
||||||
return fmt.Sprintf("ProtocolClient@%p", c)
|
return fmt.Sprintf("ProtocolClient@%p", c)
|
||||||
}
|
}
|
||||||
@ -187,6 +204,10 @@ func (c *ProtocolClient) cleanup() {
|
|||||||
l.Debugln(c, "cleaning up")
|
l.Debugln(c, "cleaning up")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.mut.Lock()
|
||||||
|
c.connected = false
|
||||||
|
c.mut.Unlock()
|
||||||
|
|
||||||
c.conn.Close()
|
c.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user