From 52b8552eea938626967879ee9a408a3b9d5013bd Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Sat, 12 Jun 2021 11:53:49 +0200 Subject: [PATCH] pitch-black-mitigation: prevent undamped oscillations of the pitch-black-mitigation --- src/freenet/node/LocationManager.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/freenet/node/LocationManager.java b/src/freenet/node/LocationManager.java index 03b58fc0eb7..66d4a68d957 100644 --- a/src/freenet/node/LocationManager.java +++ b/src/freenet/node/LocationManager.java @@ -278,10 +278,14 @@ private void tryToRequestPitchBlackCheckFromYesterday( try { sskFetchResult = highLevelSimpleClient.fetch(insertFromYesterday.getURI()); if (!Arrays.equals(expectedContent, sskFetchResult.asByteArray())) { + // if we received false data, this is definitely an attack: move there to provide a good node in the location switchLocationToDefendAgainstPitchBlackAttack(insertFromYesterday); } } catch (FetchException e) { - if (isRequestExceptionBecauseUriIsNotAvailable(e)) { + if (isRequestExceptionBecauseUriIsNotAvailable(e) && node.fastWeakRandom.nextBoolean()) { + // switch to the attacked location with only 50% probability, + // because it could be caused by the defensive swap of another node + // which made its current content inaccessible. switchLocationToDefendAgainstPitchBlackAttack(insertFromYesterday); } return; @@ -310,7 +314,10 @@ private void tryToRequestPitchBlackCheckFromYesterday( try { highLevelSimpleClient.fetch(calculatedChkUri); } catch (FetchException e) { - if (isRequestExceptionBecauseUriIsNotAvailable(e)) { + if (isRequestExceptionBecauseUriIsNotAvailable(e) && node.fastWeakRandom.nextBoolean()) { + // switch to the attacked location with only 50% probability, + // because it could be caused by the defensive swap of another node + // which made its current content inaccessible. try { switchLocationToDefendAgainstPitchBlackAttack(new ClientCHK(calculatedChkUri)); } catch (MalformedURLException exception) {