-
Notifications
You must be signed in to change notification settings - Fork 36
Add reputation module #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5d09eb9
c30e1df
767954b
3013935
7a1f095
08c43db
745e074
6df3b4d
600c5b5
393bb0c
f1c737b
24534e5
59ffc17
0166f53
f9cef06
06e9600
e6e1c58
81a8824
ee1ebd0
5503d3b
7d234c8
f4bc554
b910e77
25d79b1
4d11775
4336070
6f1d0dd
2602fb2
220d849
8906664
69f1d90
81161a6
ed35623
580cc0a
e07b6ab
59d5c88
94e4d0b
1d5357f
9d5b7b8
8dc4a13
d61f7da
9980553
45cfc73
8206d52
2fa7c54
905748b
eb917d5
081c2d0
d5bba4a
a847a1a
65ee7ae
bbceece
e124509
4ee5e1a
f91fa40
9d310c7
342ff50
9cfceeb
0657c93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -333,6 +333,7 @@ def validate_positive_int(value, name): | |||||||
| "Flooding", | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
| # Get attack type from attack_params | ||||||||
| if attack_params and "attacks" in attack_params: | ||||||||
| attack = attack_params["attacks"] | ||||||||
|
|
@@ -544,7 +545,7 @@ def from_dict(cls, data): | |||||||
|
|
||||||||
| # Create the scenario object | ||||||||
| scenario = cls(**scenario_data) | ||||||||
|
|
||||||||
| return scenario | ||||||||
|
|
||||||||
|
|
||||||||
|
|
@@ -697,8 +698,26 @@ def __init__(self, scenario, user=None): | |||||||
| participant_config["adversarial_args"]["attack_params"] = node_config["attack_params"] | ||||||||
| else: | ||||||||
| participant_config["adversarial_args"]["attack_params"] = {"attacks": "No Attack"} | ||||||||
| participant_config["defense_args"]["reputation"] = self.scenario.reputation | ||||||||
|
|
||||||||
| # Defense parameters | ||||||||
|
||||||||
| # Defense parameters | |
| # Defense parameters | |
| participant_config["defense_args"].setdefault("reputation", {}) |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -137,6 +137,9 @@ async def _check_updates_already_received(self): | |||||||
| logging.info( | ||||||||
| f"Update already received from source: {se} | ({len(self._sources_received)}/{len(self._sources_expected)}) Updates received" | ||||||||
| ) | ||||||||
| logging.info( | ||||||||
| f"Update already received from source: {se} | ({len(self._sources_received)}/{len(self._sources_expected)}) Updates received" | ||||||||
| ) | ||||||||
|
Comment on lines
+140
to
+142
|
||||||||
| logging.info( | |
| f"Update already received from source: {se} | ({len(self._sources_received)}/{len(self._sources_expected)}) Updates received" | |
| ) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -333,6 +333,26 @@ async def get_event_data(self) -> tuple[str, tuple[float, float]]: | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| async def is_concurrent(self) -> bool: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| class DuplicatedMessageEvent(NodeEvent): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Event triggered when a message is received that has already been processed. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Attributes: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| source (str): The address of the node that sent the duplicated message. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def __init__(self, source: str, message_type: str): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| self.source = source | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def __str__(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"DuplicatedMessageEvent from {self.source}" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| async def get_event_data(self) -> tuple[str]: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return (self.source) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+346
to
+353
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| self.source = source | |
| def __str__(self): | |
| return f"DuplicatedMessageEvent from {self.source}" | |
| async def get_event_data(self) -> tuple[str]: | |
| return (self.source) | |
| super().__init__() # Ensure proper initialization of the base class | |
| self.source = source | |
| self.message_type = message_type | |
| def __str__(self): | |
| return f"DuplicatedMessageEvent from {self.source}, type: {self.message_type}" | |
| async def get_event_data(self) -> tuple[str, str]: | |
| """ | |
| Retrieves the event data. | |
| Returns: | |
| tuple[str, str]: A tuple containing: | |
| - The source of the duplicated message. | |
| - The type of the duplicated message. | |
| """ | |
| return (self.source, self.message_type) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,70 +60,62 @@ const ReputationManager = (function() { | |
| } | ||
|
|
||
| function getReputationConfig() { | ||
| const rep_metrics = []; | ||
|
|
||
| if (document.getElementById("model-similarity").checked) | ||
| rep_metrics.push("model_similarity"); | ||
| if (document.getElementById("num-messages").checked) | ||
| rep_metrics.push("num_messages"); | ||
| if (document.getElementById("model-arrival-latency").checked) | ||
| rep_metrics.push("model_arrival_latency"); | ||
| if (document.getElementById("fraction-parameters-changed").checked) | ||
| rep_metrics.push("fraction_parameters_changed"); | ||
|
|
||
| return { | ||
| enabled: document.getElementById("reputationSwitch").checked, | ||
| initialReputation: parseFloat(document.getElementById("initial-reputation").value), | ||
| weightingFactor: document.getElementById("weighting-factor").value, | ||
| metrics: { | ||
| model_similarity: { | ||
| enabled: document.getElementById("model-similarity").checked, | ||
| weight: parseFloat(document.getElementById("weight-model-similarity").value) | ||
| }, | ||
| num_messages: { | ||
| enabled: document.getElementById("num-messages").checked, | ||
| weight: parseFloat(document.getElementById("weight-num-messages").value) | ||
| }, | ||
| model_arrival_latency: { | ||
| enabled: document.getElementById("model-arrival-latency").checked, | ||
| weight: parseFloat(document.getElementById("weight-model-arrival-latency").value) | ||
| }, | ||
| fraction_parameters_changed: { | ||
| enabled: document.getElementById("fraction-parameters-changed").checked, | ||
| weight: parseFloat(document.getElementById("weight-fraction-parameters-changed").value) | ||
| } | ||
| } | ||
| with_reputation: document.getElementById("reputationSwitch").checked, | ||
| reputation_metrics: rep_metrics, | ||
| initial_reputation: parseFloat(document.getElementById("initial-reputation").value), | ||
| weighting_factor: document.getElementById("weighting-factor").value, | ||
| weight_model_arrival_latency: parseFloat(document.getElementById("weight-model-arrival-latency").value), | ||
| weight_model_similarity: parseFloat(document.getElementById("weight-model-similarity").value), | ||
| weight_num_messages: parseFloat(document.getElementById("weight-num-messages").value), | ||
| weight_fraction_params_changed: parseFloat(document.getElementById("weight-fraction-parameters-changed").value), | ||
| }; | ||
| } | ||
|
|
||
| function setReputationConfig(config) { | ||
| if (!config) return; | ||
|
|
||
| // Set reputation enabled/disabled | ||
| document.getElementById("reputationSwitch").checked = config.enabled; | ||
| document.getElementById("reputation-metrics").style.display = config.enabled ? "block" : "none"; | ||
| document.getElementById("reputation-settings").style.display = config.enabled ? "block" : "none"; | ||
| document.getElementById("weighting-settings").style.display = config.enabled ? "block" : "none"; | ||
| const enabled = config.with_reputation ?? config.enabled ?? false; | ||
|
|
||
| // Set reputation switch and visibility | ||
| document.getElementById("reputationSwitch").checked = enabled; | ||
| document.getElementById("reputation-metrics").style.display = enabled ? "block" : "none"; | ||
| document.getElementById("reputation-settings").style.display = enabled ? "block" : "none"; | ||
| document.getElementById("weighting-settings").style.display = enabled ? "block" : "none"; | ||
|
|
||
| // Set initial reputation | ||
| document.getElementById("initial-reputation").value = config.initialReputation || 0.6; | ||
| // Initial reputation and weighting factor | ||
| document.getElementById("initial-reputation").value = config.initial_reputation ?? config.initialReputation ?? 0.2; | ||
| document.getElementById("weighting-factor").value = config.weighting_factor ?? config.weightingFactor ?? "dynamic"; | ||
|
|
||
| // Set weighting factor | ||
| document.getElementById("weighting-factor").value = config.weightingFactor || "dynamic"; | ||
| const showWeights = config.weightingFactor === "static"; | ||
| const showWeights = (config.weighting_factor ?? config.weightingFactor) === "static"; | ||
| document.querySelectorAll(".weight-input").forEach(input => { | ||
| input.style.display = showWeights ? "inline-block" : "none"; | ||
| }); | ||
|
|
||
| // Set metrics | ||
| if (config.metrics) { | ||
| // Model Similarity | ||
| document.getElementById("model-similarity").checked = config.metrics.modelSimilarity?.enabled || false; | ||
| document.getElementById("weight-model-similarity").value = config.metrics.modelSimilarity?.weight || 0; | ||
| // Metrics (both legacy flat and nested) | ||
| document.getElementById("model-similarity").checked = config.reputation_metrics?.includes("modelSimilarity") ?? config.metrics?.modelSimilarity?.enabled ?? false; | ||
|
||
| document.getElementById("weight-model-similarity").value = config.weight_model_similarity ?? config.metrics?.modelSimilarity?.weight ?? 0; | ||
|
|
||
| // Number of Messages | ||
| document.getElementById("num-messages").checked = config.metrics.numMessages?.enabled || false; | ||
| document.getElementById("weight-num-messages").value = config.metrics.numMessages?.weight || 0; | ||
| document.getElementById("num-messages").checked = config.reputation_metrics?.includes("numMessages") ?? config.metrics?.numMessages?.enabled ?? false; | ||
| document.getElementById("weight-num-messages").value = config.weight_num_messages ?? config.metrics?.numMessages?.weight ?? 0; | ||
|
|
||
| // Model Arrival Latency | ||
| document.getElementById("model-arrival-latency").checked = config.metrics.modelArrivalLatency?.enabled || false; | ||
| document.getElementById("weight-model-arrival-latency").value = config.metrics.modelArrivalLatency?.weight || 0; | ||
| document.getElementById("model-arrival-latency").checked = config.reputation_metrics?.includes("modelArrivalLatency") ?? config.metrics?.modelArrivalLatency?.enabled ?? false; | ||
| document.getElementById("weight-model-arrival-latency").value = config.weight_model_arrival_latency ?? config.metrics?.modelArrivalLatency?.weight ?? 0; | ||
|
|
||
| // Fraction Parameters Changed | ||
| document.getElementById("fraction-parameters-changed").checked = config.metrics.fractionParametersChanged?.enabled || false; | ||
| document.getElementById("weight-fraction-parameters-changed").value = config.metrics.fractionParametersChanged?.weight || 0; | ||
| } | ||
| document.getElementById("fraction-parameters-changed").checked = config.reputation_metrics?.includes("fractionParametersChanged") ?? config.metrics?.fractionParametersChanged?.enabled ?? false; | ||
| document.getElementById("weight-fraction-parameters-changed").value = config.weight_fraction_params_changed ?? config.metrics?.fractionParametersChanged?.weight ?? 0; | ||
|
|
||
| // Validate weights | ||
| validateWeights(); | ||
| } | ||
|
|
||
|
|
@@ -133,7 +125,7 @@ const ReputationManager = (function() { | |
| document.getElementById("reputation-metrics").style.display = "none"; | ||
| document.getElementById("reputation-settings").style.display = "none"; | ||
| document.getElementById("weighting-settings").style.display = "none"; | ||
| document.getElementById("initial-reputation").value = "0.6"; | ||
| document.getElementById("initial-reputation").value = "0.2"; | ||
| document.getElementById("weighting-factor").value = "dynamic"; | ||
| document.getElementById("weight-warning").style.display = "none"; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line overwrites the outer
flooding_factorparameter with a hard-coded30, ignoring the configured value. Remove this override or use the passed-in factor.