booter updates
This commit is contained in:
@@ -64,7 +64,8 @@ function readSwarmPolicyEnv(env) {
|
||||
* lastLatencyMs: number | null,
|
||||
* reconnectBudget: number,
|
||||
* earliestRetryAtMs: number,
|
||||
* retryTier: 'none' | 'short' | 'medium' | 'long' | 'xlong'
|
||||
* retryTier: 'none' | 'short' | 'medium' | 'long' | 'xlong',
|
||||
* failByClass: Record<string, number>
|
||||
* }} PeerState
|
||||
*/
|
||||
|
||||
@@ -103,7 +104,8 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
lastLatencyMs: null,
|
||||
reconnectBudget: 32,
|
||||
earliestRetryAtMs: 0,
|
||||
retryTier: 'none'
|
||||
retryTier: 'none',
|
||||
failByClass: {}
|
||||
}
|
||||
this._peers.set(k, st)
|
||||
}
|
||||
@@ -131,7 +133,7 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
/**
|
||||
* @param {string} peerKey
|
||||
* @param {boolean} ok
|
||||
* @param {{ latencyMs?: number }} [probeMeta]
|
||||
* @param {{ latencyMs?: number, failClass?: string }} [probeMeta]
|
||||
*/
|
||||
noteProbe(peerKey, ok, probeMeta = {}) {
|
||||
const k = this._key(peerKey)
|
||||
@@ -161,6 +163,10 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
} else {
|
||||
st.fail++
|
||||
st.consecutiveFail++
|
||||
const failClass = String(probeMeta.failClass || 'unknown')
|
||||
.trim()
|
||||
.slice(0, 32) || 'unknown'
|
||||
st.failByClass[failClass] = (st.failByClass[failClass] || 0) + 1
|
||||
const retry = this._retryDelayFor(st)
|
||||
st.retryTier = retry.tier
|
||||
st.earliestRetryAtMs = now + retry.delayMs
|
||||
@@ -202,6 +208,7 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
const st = this._peers.get(k)
|
||||
const now = Date.now()
|
||||
if (!st) return true
|
||||
if (this._globalReconnectBudget <= 0) return false
|
||||
if (st.banUntilMs > now) return false
|
||||
if (st.earliestRetryAtMs > now) return false
|
||||
if (st.reconnectBudget <= 0) return false
|
||||
@@ -259,12 +266,15 @@ export class BareOsSwarmPeerPolicyEngine {
|
||||
if (!total) return 0
|
||||
const successRate = st.ok / total
|
||||
const failPenalty = Math.min(0.5, st.fail * 0.05)
|
||||
const protocolPenalty = Math.min(0.25, (st.failByClass.protocol || 0) * 0.03)
|
||||
const policyPenalty = Math.min(0.2, (st.failByClass.policy || 0) * 0.02)
|
||||
const timeoutPenalty = Math.min(0.15, (st.failByClass.timeout || 0) * 0.01)
|
||||
const now = Date.now()
|
||||
const banned = st.banUntilMs > now ? 0.35 : 0
|
||||
const lat = st.ewmaLatencyMs
|
||||
const latPenalty =
|
||||
lat > 0 ? Math.min(0.25, Math.log10(1 + lat / 50) * 0.08) : 0
|
||||
return successRate - failPenalty - banned - latPenalty
|
||||
return successRate - failPenalty - protocolPenalty - policyPenalty - timeoutPenalty - banned - latPenalty
|
||||
}
|
||||
|
||||
snapshot() {
|
||||
|
||||
Reference in New Issue
Block a user