all: Implement suture v4-api (#6947)
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/syncthing/syncthing/lib/sync"
|
||||
"github.com/syncthing/syncthing/lib/util"
|
||||
|
||||
"github.com/thejerf/suture"
|
||||
"github.com/thejerf/suture/v4"
|
||||
)
|
||||
|
||||
type relayClientFactory func(uri *url.URL, certs []tls.Certificate, invitations chan protocol.SessionInvitation, timeout time.Duration) RelayClient
|
||||
@@ -61,7 +61,7 @@ func newCommonClient(invitations chan protocol.SessionInvitation, serve func(con
|
||||
defer c.cleanup()
|
||||
return serve(ctx)
|
||||
}
|
||||
c.ServiceWithError = util.AsServiceWithError(newServe, creator)
|
||||
c.ServiceWithError = util.AsService(newServe, creator)
|
||||
if c.invitations == nil {
|
||||
c.closeInvitationsOnFinish = true
|
||||
c.invitations = make(chan protocol.SessionInvitation)
|
||||
|
||||
@@ -93,7 +93,7 @@ func (c *dynamicClient) serve(ctx context.Context) error {
|
||||
c.client = client
|
||||
c.mut.Unlock()
|
||||
|
||||
c.client.Serve()
|
||||
c.client.Serve(ctx)
|
||||
|
||||
c.mut.Lock()
|
||||
c.client = nil
|
||||
@@ -104,15 +104,6 @@ func (c *dynamicClient) serve(ctx context.Context) error {
|
||||
return errors.New("could not find a connectable relay")
|
||||
}
|
||||
|
||||
func (c *dynamicClient) Stop() {
|
||||
c.mut.RLock()
|
||||
if c.client != nil {
|
||||
c.client.Stop()
|
||||
}
|
||||
c.mut.RUnlock()
|
||||
c.commonClient.Stop()
|
||||
}
|
||||
|
||||
func (c *dynamicClient) Error() error {
|
||||
c.mut.RLock()
|
||||
defer c.mut.RUnlock()
|
||||
|
||||
@@ -120,11 +120,12 @@ func TestRelay(ctx context.Context, uri *url.URL, certs []tls.Certificate, sleep
|
||||
close(invs)
|
||||
return fmt.Errorf("creating client: %w", err)
|
||||
}
|
||||
go c.Serve()
|
||||
defer func() {
|
||||
c.Stop()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
c.Serve(ctx)
|
||||
close(invs)
|
||||
}()
|
||||
defer cancel()
|
||||
|
||||
for i := 0; i < times; i++ {
|
||||
_, err = GetInvitationFromRelay(ctx, uri, id, certs, timeout)
|
||||
|
||||
Reference in New Issue
Block a user