diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-27 13:30:14 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-27 13:30:14 +0200 |
| commit | 0bebec08cd89039c32bd9b9e73d80d573b6bf0b3 (patch) | |
| tree | 429222b73e259a3f1e3f2d9d229164a4841b41f3 /src/main/java/protocols/VSAbstractProtocol.java | |
| parent | 35def2831acd67ace6943e06f502a356529c3357 (diff) | |
sr: fix Raft replay leader election
Diffstat (limited to 'src/main/java/protocols/VSAbstractProtocol.java')
| -rw-r--r-- | src/main/java/protocols/VSAbstractProtocol.java | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/main/java/protocols/VSAbstractProtocol.java b/src/main/java/protocols/VSAbstractProtocol.java index da12d31..ee0d6c2 100644 --- a/src/main/java/protocols/VSAbstractProtocol.java +++ b/src/main/java/protocols/VSAbstractProtocol.java @@ -180,8 +180,8 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { * This method: * <ul> * <li>Filters out messages for other protocols</li> - * <li>Ensures server/client initialization</li> - * <li>Delegates to onServerRecv() or onClientRecv() based on context</li> + * <li>Routes messages to the active role(s) without double-delivering + * to dual-role peers</li> * </ul> * * @param message the received message @@ -192,6 +192,21 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { if (isIncorrectProtocol(message)) return; + if (isServer && isClient) { + if (message.isServerMessage()) { + currentContextIsServer(false); + if (!isClientInitialized) + onInit(); + onClientRecv(message); + } else { + currentContextIsServer(true); + if (!isServerInitialized) + onInit(); + onServerRecv(message); + } + return; + } + if (isServer) { currentContextIsServer(true); if (!isServerInitialized) @@ -226,6 +241,18 @@ abstract public class VSAbstractProtocol extends VSAbstractEvent { if (isIncorrectProtocol(message)) return false; + return isRelevantMessageForContext(message); + } + + /** + * Checks whether a message is relevant for this protocol instance. + * Subclasses can relax or specialize the default server/client routing + * rules while keeping the protocol-name filter intact. + * + * @param message the message to check + * @return true if the message should be processed by this protocol instance + */ + protected boolean isRelevantMessageForContext(VSMessage message) { if (message.isServerMessage()) { if (!isClient) return false; |
