Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,34 @@ nodes continue to work without it.

## Forwarding retries

When a forwarding connection fails before the vote payload starts writing,
VotifierPlus retries that destination after 15 minutes. It uses 15-minute
delays for the first five retries, then 30-minute delays while the destination
remains eligible. Other destinations continue independently. Protocol or
payload preparation errors are terminal. Once a payload write begins, the
receiver may have accepted the vote, so VotifierPlus does not retry an error
from that point.
Eligible transport failures before a payload write can be retried. The first
retry always waits 60 seconds after the original failure. Later retries wait
`ForwardingRetry.RetryIntervalSeconds` seconds after the preceding failure
(default 300, valid range 1–3600). `ForwardingRetry.MaxRetries` counts retries
after the initial send (default 12, valid range 0–3600). Zero disables retrying.
Missing or invalid settings use their defaults. No retry begins at or after
one hour from the original failure, even when the configured count would
allow more attempts. With the defaults, up to 12 retries fit within that hour.

The receiver keeps up to 256 pending vote/destination pairs in memory. If the
queue fills, new failures are dropped from the retry queue. Pending retries
are discarded when the receiver reloads or shuts down. No retry state survives
a restart. Each retry checks the destination and uses its current credentials
for the same forwarding protocol.
Each destination can override those three settings under
`Forwarding.<destination>.ForwardingRetry`. Missing or invalid overrides inherit
the validated global values. Explicit `false` turns off the success gate and
explicit `0` for `MaxRetries` disables retries for that destination. The
60-second first delay and one-hour cutoff apply to every destination.

`ForwardingRetry.RequirePreviousSuccessBeforeRetry` defaults to `true`. Each
destination must first complete a normal vote payload write and flush on its
current configuration. A connection or handshake alone does not qualify.
Forwarding has no receiver acknowledgement, so transport success does not
confirm authentication or processing at the destination. New incoming votes
are still forwarded normally. Failures before the first transport success are
discarded and are never replayed. Set this option to `false` to retry eligible
failures before the first transport success.

The receiver keeps up to 256 pending vote–destination pairs in RAM. New
failures are dropped from the retry queue when full. A change to the target
host, port, protocol, credential, or effective retry settings invalidates cached success for that
destination and pending retries for the previous identity. Disabled or removed
targets cannot retry. Reload and shutdown clear pending retries and prior
successes. Protocol or payload errors and failures after writing begins are
terminal because the receiver may already have accepted the vote.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.security.Key;

import com.vexsoftware.votifier.net.ForwardRetryConfig;

import lombok.Getter;
import lombok.Setter;

Expand All @@ -18,13 +20,20 @@ public class ForwardServer {
@Getter
@Setter
private Key Token;
@Getter
private final ForwardRetryConfig retryConfig;

public ForwardServer(boolean enabled, String host, int port, String key, Key token) {
this(enabled, host, port, key, token, null);
}

public ForwardServer(boolean enabled, String host, int port, String key, Key token, ForwardRetryConfig retryConfig) {
this.enabled = enabled;
this.host = host;
this.port = port;
this.key = key;
this.Token = token;
this.retryConfig = retryConfig;
}

public boolean isUseTokens() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.vexsoftware.votifier.diagnostic.VotifierDiagnosticsSnapshot;
import com.vexsoftware.votifier.model.Vote;
import com.vexsoftware.votifier.model.VotifierEvent;
import com.vexsoftware.votifier.net.ForwardRetryConfig;
import com.vexsoftware.votifier.net.ThrottleConfig;
import com.vexsoftware.votifier.net.VoteReceiver;
import com.vexsoftware.votifier.util.ZipResourceReader;
Expand Down Expand Up @@ -308,7 +309,11 @@ public ForwardServer getServerData(String s) {
tokenKey = TokenUtil.createKeyFrom(token);
}
return new ForwardServer(d.getBoolean("Enabled"), d.getString("Host", ""), d.getInt("Port"),
d.getString("Key", ""), tokenKey);
d.getString("Key", ""), tokenKey,
getForwardRetryConfig().withOverrides(
d.get("ForwardingRetry.RetryIntervalSeconds"),
d.get("ForwardingRetry.MaxRetries"),
d.get("ForwardingRetry.RequirePreviousSuccessBeforeRetry")));
}

@Override
Expand Down Expand Up @@ -350,6 +355,14 @@ public java.util.Set<String> getTrustedProxyIps() {
return new java.util.HashSet<String>(getConfigFile().getData().getStringList("TrustedProxyIps"));
}

@Override
protected ForwardRetryConfig getForwardRetryConfig() {
return ForwardRetryConfig.parse(
getConfigFile().getData().get("ForwardingRetry.RetryIntervalSeconds"),
getConfigFile().getData().get("ForwardingRetry.MaxRetries"),
getConfigFile().getData().get("ForwardingRetry.RequirePreviousSuccessBeforeRetry"));
}

@Override
public ThrottleConfig getThrottleConfig() {
ConfigurationSection root = getConfigFile().getData().getConfigurationSection("ConnectionThrottle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.vexsoftware.votifier.diagnostic.VotifierDiagnostics;
import com.vexsoftware.votifier.diagnostic.VotifierDiagnosticsSnapshot;
import com.vexsoftware.votifier.model.Vote;
import com.vexsoftware.votifier.net.ForwardRetryConfig;
import com.vexsoftware.votifier.net.ThrottleConfig;
import com.vexsoftware.votifier.net.VoteReceiver;
import com.vexsoftware.votifier.util.ZipResourceReader;
Expand Down Expand Up @@ -177,7 +178,11 @@ public ForwardServer getServerData(String s) {
tokenKey = TokenUtil.createKeyFrom(token);
}
return new ForwardServer(d.getBoolean("Enabled"), d.getString("Host", ""), d.getInt("Port"),
d.getString("Key", ""), tokenKey);
d.getString("Key", ""), tokenKey,
getForwardRetryConfig().withOverrides(
d.get("ForwardingRetry.RetryIntervalSeconds"),
d.get("ForwardingRetry.MaxRetries"),
d.get("ForwardingRetry.RequirePreviousSuccessBeforeRetry")));
}

@Override
Expand Down Expand Up @@ -221,6 +226,14 @@ public java.util.Set<String> getTrustedProxyIps() {
return ips == null ? Collections.<String>emptySet() : new HashSet<String>(ips);
}

@Override
protected ForwardRetryConfig getForwardRetryConfig() {
return ForwardRetryConfig.parse(
getConfig().getData().get("ForwardingRetry.RetryIntervalSeconds"),
getConfig().getData().get("ForwardingRetry.MaxRetries"),
getConfig().getData().get("ForwardingRetry.RequirePreviousSuccessBeforeRetry"));
}

@Override
public ThrottleConfig getThrottleConfig() {
Configuration root = getConfig().getData().getSection("ConnectionThrottle");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.vexsoftware.votifier.net;

/** Settings for the receiver-owned, in-memory forwarding retry queue. */
public record ForwardRetryConfig(int retryIntervalSeconds, int maxRetries, boolean requirePreviousSuccessBeforeRetry) {
private static final int DEFAULT_INTERVAL_SECONDS = 300;
private static final int DEFAULT_MAX_RETRIES = 12;
private static final int MAX_SETTING = 3600;

public static final ForwardRetryConfig DEFAULT = new ForwardRetryConfig(DEFAULT_INTERVAL_SECONDS, DEFAULT_MAX_RETRIES, true);

public ForwardRetryConfig {
retryIntervalSeconds = validate(retryIntervalSeconds, 1, DEFAULT_INTERVAL_SECONDS);
maxRetries = validate(maxRetries, 0, DEFAULT_MAX_RETRIES);
}

public static ForwardRetryConfig parse(Object interval, Object count, Object requireSuccess) {
return DEFAULT.withOverrides(interval, count, requireSuccess);
}

public ForwardRetryConfig withOverrides(Object interval, Object count, Object requireSuccess) {
return new ForwardRetryConfig(
validate(parseInt(interval, retryIntervalSeconds), 1, retryIntervalSeconds),
validate(parseInt(count, maxRetries), 0, maxRetries),
parseBoolean(requireSuccess, requirePreviousSuccessBeforeRetry));
}

private static boolean parseBoolean(Object value, boolean fallback) {
if (value instanceof Boolean option) {
return option;
}
if (value instanceof String text) {
return switch (text.trim().toLowerCase(java.util.Locale.ROOT)) {
case "true" -> true;
case "false" -> false;
default -> fallback;
};
}
return fallback;
}

private static int validate(int value, int minimum, int fallback) {
return value >= minimum && value <= MAX_SETTING ? value : fallback;
}

private static int parseInt(Object value, int fallback) {
if (value instanceof Number || value instanceof String) {
try {
return Integer.parseInt(value.toString().trim());
} catch (NumberFormatException ignored) {
return fallback;
}
}
return fallback;
}
}
Loading
Loading