feat: installer fetched from the direct address sets it as the agent's own with the main one as fallback (and downloads from it); agents fall back to whichever address is not theirs; (direct) beside the connection status
This commit is contained in:
1 parent
021da93229
commit
79828e3f8a
11 files changed
+72
-25
No files matched your search
+12
-6
@@ -54,10 +54,16 @@ func (a *Agent) fallback() string {
|
||||
return a.state.Fallback
|
||||
}
|
||||
|
||||
// learnFallback keeps the direct address the server tells.
|
||||
func (a *Agent) learnFallback(v string) {
|
||||
v = strings.TrimRight(strings.TrimSpace(v), "/")
|
||||
if v == "" || a.cfg.Fallback != "" {
|
||||
// learnAddrs keeps the server's other address from the two it tells: the
|
||||
// direct one, or the main one when the agent was set to the direct one.
|
||||
func (a *Agent) learnAddrs(main, direct string) {
|
||||
main = strings.TrimRight(strings.TrimSpace(main), "/")
|
||||
direct = strings.TrimRight(strings.TrimSpace(direct), "/")
|
||||
v := direct
|
||||
if direct != "" && strings.EqualFold(direct, a.cfg.Host) {
|
||||
v = main
|
||||
}
|
||||
if v == "" || strings.EqualFold(v, a.cfg.Host) || a.cfg.Fallback != "" {
|
||||
return
|
||||
}
|
||||
a.stateMu.Lock()
|
||||
@@ -67,7 +73,7 @@ func (a *Agent) learnFallback(v string) {
|
||||
}
|
||||
a.stateMu.Unlock()
|
||||
if !same {
|
||||
log.Printf("direct address: %s", v)
|
||||
log.Printf("fallback address: %s", v)
|
||||
_ = a.saveState()
|
||||
}
|
||||
}
|
||||
@@ -163,7 +169,7 @@ func (a *Agent) reachableAt(ctx context.Context, base string) bool {
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode < 300 {
|
||||
a.learnFallback(resp.Header.Get(proto.FallbackHeader))
|
||||
a.learnAddrs(resp.Header.Get(proto.MainHeader), resp.Header.Get(proto.FallbackHeader))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
Reference in new issue
Block a user