mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 15:51:21 +00:00
549260d650
* Persist terminator precedence. Fix link cost use/scaling. Fix link removal related panic. Fix service cache clearing on terminator change. Fixes GH-112 Fixes GH-121 Fixes GH-122 Fixes GH-123 Fixes GH-124
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package xt_common
|
|
|
|
import (
|
|
"github.com/openziti/fabric/controller/xt"
|
|
"math"
|
|
)
|
|
|
|
type CostVisitor struct {
|
|
FailureCosts xt.FailureCosts
|
|
SessionCost uint16
|
|
}
|
|
|
|
func (visitor *CostVisitor) VisitDialFailed(event xt.TerminatorEvent) {
|
|
change := visitor.FailureCosts.Failure(event.GetTerminator().GetId())
|
|
|
|
if change > 0 {
|
|
xt.GlobalCosts().UpdateDynamicCost(event.GetTerminator().GetId(), func(cost uint16) uint16 {
|
|
if cost < (math.MaxUint16 - change) {
|
|
return cost + change
|
|
}
|
|
return math.MaxUint16
|
|
})
|
|
}
|
|
}
|
|
|
|
func (visitor *CostVisitor) VisitDialSucceeded(event xt.TerminatorEvent) {
|
|
credit := visitor.FailureCosts.Success(event.GetTerminator().GetId())
|
|
if credit != visitor.SessionCost {
|
|
xt.GlobalCosts().UpdateDynamicCost(event.GetTerminator().GetId(), func(cost uint16) uint16 {
|
|
if visitor.SessionCost > credit {
|
|
increase := visitor.SessionCost - credit
|
|
if cost < (math.MaxUint16 - increase) {
|
|
// pfxlog.Logger().Infof("%v: dial+ %v -> %v", event.GetTerminator().GetId(), cost, cost+increase)
|
|
return cost + increase
|
|
}
|
|
// pfxlog.Logger().Infof("%v: dial+ %v -> %v", event.GetTerminator().GetId(), cost, math.MaxUint16)
|
|
return math.MaxUint16
|
|
}
|
|
|
|
decrease := credit - visitor.SessionCost
|
|
if decrease > cost {
|
|
// pfxlog.Logger().Infof("%v: dial+ %v -> %v", event.GetTerminator().GetId(), cost, 0)
|
|
return 0
|
|
}
|
|
// pfxlog.Logger().Infof("%v: dial+ %v -> %v", event.GetTerminator().GetId(), cost, cost-decrease)
|
|
return cost - decrease
|
|
})
|
|
}
|
|
}
|
|
|
|
func (visitor *CostVisitor) VisitSessionEnded(event xt.TerminatorEvent) {
|
|
xt.GlobalCosts().UpdateDynamicCost(event.GetTerminator().GetId(), func(cost uint16) uint16 {
|
|
if cost > visitor.SessionCost {
|
|
// pfxlog.Logger().Infof("%v: sess- %v -> %v", event.GetTerminator().GetId(), cost, cost-1)
|
|
return cost - visitor.SessionCost
|
|
}
|
|
// pfxlog.Logger().Infof("%v: sess- %v -> %v", event.GetTerminator().GetId(), cost, 0)
|
|
return 0
|
|
})
|
|
}
|