MCPcopy Create free account
hub / github.com/cppla/moto / HandleBoost

Function HandleBoost

controller/boost.go:105–207  ·  view source on GitHub ↗

HandleBoost 同时发起多路拨号,挑选最先成功的连接并套上单边加速。

(conn net.Conn, rule *config.Rule)

Source from the content-addressed store, hash-verified

103 return defaultRoutingRuntime.loadBoostWinner(key)
104}
105
106func (runtime *routingRuntime) loadBoostWinner(key string) (string, bool, time.Time) {
107 now := time.Now()
108 runtime.boost.cache.Lock()
109 defer runtime.boost.cache.Unlock()
110 entry, ok := runtime.boost.cache.entries[key]
111 if !ok {
112 return "", false, time.Time{}
113 }
114 if !now.Before(entry.expires) {
115 delete(runtime.boost.cache.entries, key)
116 return "", false, time.Time{}
117 }
118 return entry.addr, true, entry.expires
119}
120
121func (runtime *routingRuntime) loadBoostWinnerToken(key string) (boostWinnerEntry, bool) {
122 now := time.Now()
123 runtime.boost.cache.Lock()
124 defer runtime.boost.cache.Unlock()
125 entry, ok := runtime.boost.cache.entries[key]
126 if !ok {
127 return boostWinnerEntry{}, false
128 }
129 if !now.Before(entry.expires) {
130 delete(runtime.boost.cache.entries, key)
131 return boostWinnerEntry{}, false
132 }
133 return entry, true
134}
135
136// loadUsableBoostWinnerToken rejects a cached winner whose currently selected
137// protocol is degraded. Eviction uses the generation token loaded with the
138// entry, so a concurrent refresh cannot be deleted by this stale observation.
139func (runtime *routingRuntime) loadUsableBoostWinnerToken(key string, rule *config.Rule, now time.Time) (boostWinnerEntry, bool) {
140 if runtime == nil {
141 return boostWinnerEntry{}, false
142 }
143 entry, ok := runtime.loadBoostWinnerToken(key)
144 if !ok || runtime.routes == nil {
145 return entry, ok
146 }
147 var target *config.Target
148 if rule != nil {
149 for _, candidate := range rule.Targets {
150 if candidate != nil && candidate.Address == entry.addr {
151 target = candidate
152 break
153 }
154 }
155 }
156 if target == nil || runtime.routes.protocolPenalty(rule, target, now) == 0 {
157 return entry, true
158 }
159 runtime.deleteBoostWinnerIfCurrent(boostWinnerToken{
160 key: key,
161 addr: entry.addr,
162 generation: entry.generation,

Callers 2

ListenFunction · 0.85
HandleRoundrobinFunction · 0.85

Calls 4

loadBoostWinnerFunction · 0.85
outboundDialFunction · 0.85
storeBoostWinnerFunction · 0.85
lazyRevalidateFunction · 0.85

Tested by

no test coverage detected