Skip to content

Commit

Permalink
Fix dns loop complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed May 18, 2024
1 parent eda44d7 commit 39cdb1a
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions internal/dns/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
l.useUnencryptedDNS(fallback)
}
l.logAndWait(ctx, err)
settings = l.GetSettings()
}

settings = l.GetSettings()
Expand All @@ -62,37 +63,43 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {

l.userTrigger = false

stayHere := true
for stayHere {
select {
case <-ctx.Done():
stopErr := l.server.Stop()
if stopErr != nil {
l.logger.Error("stopping DoT server: " + stopErr.Error())
}
// TODO revert OS and Go nameserver when exiting
return
case <-l.stop:
l.userTrigger = true
l.logger.Info("stopping")
const fallback = false
l.useUnencryptedDNS(fallback)
err := l.server.Stop()
if err != nil {
l.logger.Error("stopping DoT server: " + err.Error())
}
l.stopped <- struct{}{}
case <-l.start:
l.userTrigger = true
l.logger.Info("starting")
stayHere = false
case err := <-runError: // unexpected error
l.statusManager.SetStatus(constants.Crashed)
const fallback = true
l.useUnencryptedDNS(fallback)
l.logAndWait(ctx, err)
stayHere = false
exitLoop := l.runWait(ctx, runError)
if exitLoop {
return
}
}
}

func (l *Loop) runWait(ctx context.Context, runError <-chan error) (exitLoop bool) {
for {
select {
case <-ctx.Done():
stopErr := l.server.Stop()
if stopErr != nil {
l.logger.Error("stopping DoT server: " + stopErr.Error())
}
// TODO revert OS and Go nameserver when exiting
return true
case <-l.stop:
l.userTrigger = true
l.logger.Info("stopping")
const fallback = false
l.useUnencryptedDNS(fallback)
err := l.server.Stop()
if err != nil {
l.logger.Error("stopping DoT server: " + err.Error())
}
l.stopped <- struct{}{}
case <-l.start:
l.userTrigger = true
l.logger.Info("starting")
return false
case err := <-runError: // unexpected error
l.statusManager.SetStatus(constants.Crashed)
const fallback = true
l.useUnencryptedDNS(fallback)
l.logAndWait(ctx, err)
return false
}
}
}

0 comments on commit 39cdb1a

Please sign in to comment.