all: Implement suture v4-api (#6947)

This commit is contained in:
Simon Frei
2020-11-17 13:19:04 +01:00
committed by GitHub
parent e8fc465ea8
commit 9524b51708
65 changed files with 617 additions and 693 deletions
+5 -12
View File
@@ -14,7 +14,6 @@ import (
"github.com/AudriusButkevicius/pfilter"
"github.com/ccding/go-stun/stun"
"github.com/thejerf/suture"
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/util"
@@ -60,8 +59,6 @@ type Subscriber interface {
}
type Service struct {
suture.Service
name string
cfg config.Wrapper
subscriber Subscriber
@@ -105,28 +102,24 @@ func New(cfg config.Wrapper, subscriber Subscriber, conn net.PacketConn) (*Servi
natType: NATUnknown,
addr: nil,
}
s.Service = util.AsService(s.serve, s.String())
return s, otherDataConn
}
func (s *Service) Stop() {
_ = s.stunConn.Close()
s.Service.Stop()
}
func (s *Service) serve(ctx context.Context) {
func (s *Service) Serve(ctx context.Context) error {
defer func() {
s.setNATType(NATUnknown)
s.setExternalAddress(nil, "")
}()
util.OnDone(ctx, func() { _ = s.stunConn.Close() })
timer := time.NewTimer(time.Millisecond)
for {
disabled:
select {
case <-ctx.Done():
return
return ctx.Err()
case <-timer.C:
}
@@ -146,7 +139,7 @@ func (s *Service) serve(ctx context.Context) {
// Have we been asked to stop?
select {
case <-ctx.Done():
return
return ctx.Err()
default:
}