<commit_before>/*
 * This file is part of Bisq.
 *
 * Bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * Bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package bisq.core.network.p2p.inventory.model;

import bisq.common.util.Tuple2;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import lombok.Getter;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public enum InventoryItem {
    // Percentage deviation
    OfferPayload("OfferPayload",
            true,
            new DeviationByPercentage(0.8, 1.2, 0.9, 1.1), 5),
    MailboxStoragePayload("MailboxStoragePayload",
            true,
            new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2),
    TradeStatistics3("TradeStatistics3",
            true,
            new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2),
    AccountAgeWitness("AccountAgeWitness",
            true,
            new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2),
    SignedWitness("SignedWitness",
            true,
            new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2),

    // Should be same value
    Alert("Alert",
            true,
            new DeviationByIntegerDiff(1, 1), 2),
    Filter("Filter",
            true,
            new DeviationByIntegerDiff(1, 1), 2),
    Mediator("Mediator",
            true,
            new DeviationByIntegerDiff(1, 1), 2),
    RefundAgent("RefundAgent",
            true,
            new DeviationByIntegerDiff(1, 1), 2),

    // Should be very close values
    TempProposalPayload("TempProposalPayload",
            true,
            new DeviationByIntegerDiff(3, 5), 2),
    ProposalPayload("ProposalPayload",
            true,
            new DeviationByIntegerDiff(1, 2), 2),
    BlindVotePayload("BlindVotePayload",
            true,
            new DeviationByIntegerDiff(1, 2), 2),

    // Should be very close values
    daoStateChainHeight("daoStateChainHeight",
            true,
            new DeviationByIntegerDiff(2, 4), 3),
    numBsqBlocks("numBsqBlocks",
            true,
            new DeviationByIntegerDiff(2, 4), 3),

    // Has to be same values at same block
    daoStateHash("daoStateHash",
            false,
            new DeviationOfHashes(), 1),
    proposalHash("proposalHash",
            false,
            new DeviationOfHashes(), 1),
    blindVoteHash("blindVoteHash",
            false,
            new DeviationOfHashes(), 1),

    // Percentage deviation
    maxConnections("maxConnections",
            true,
            new DeviationByPercentage(0.33, 3, 0.4, 2.5), 2),
    numConnections("numConnections",
            true,
            new DeviationByPercentage(0, 3, 0, 2.5), 2),
    peakNumConnections("peakNumConnections",
            true,
            new DeviationByPercentage(0, 3, 0, 2.5), 2),
    numAllConnectionsLostEvents("numAllConnectionsLostEvents",
            true,
            new DeviationByIntegerDiff(1, 2), 3),
    sentBytesPerSec("sentBytesPerSec",
            true,
            new DeviationByPercentage(), 5),
    receivedBytesPerSec("receivedBytesPerSec",
            true,
            new DeviationByPercentage(), 5),
    receivedMessagesPerSec("receivedMessagesPerSec",
            true,
            new DeviationByPercentage(), 5),
    sentMessagesPerSec("sentMessagesPerSec",
            true,
            new DeviationByPercentage(), 5),

    // No deviation check
    sentBytes("sentBytes", true),
    receivedBytes("receivedBytes", true),

    // No deviation check
    version("version", false),
    commitHash("commitHash", false),
    usedMemory("usedMemory", true),
    jvmStartTime("jvmStartTime", true),
    filteredSeeds("filteredSeeds", false);

    @Getter
    private final String key;
    @Getter
    private final boolean isNumberValue;
    @Getter
    @Nullable
    private DeviationType deviationType;

    // The number of past requests we check to see if there have been repeated alerts or warnings. The higher the
    // number the more repeated alert need to have happened to cause a notification alert.
    @Getter
    private int deviationTolerance = 1;

    InventoryItem(String key, boolean isNumberValue) {
        this.key = key;
        this.isNumberValue = isNumberValue;
    }

    InventoryItem(String key, boolean isNumberValue, @NotNull DeviationType deviationType, int deviationTolerance) {
        this(key, isNumberValue);
        this.deviationType = deviationType;
        this.deviationTolerance = deviationTolerance;
    }<commit_msg>Decrease deviationTolerance for numAllConnectionsLostEvents<commit_after>/*
 * This file is part of Bisq.
 *
 * Bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * Bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package bisq.core.network.p2p.inventory.model;

import bisq.common.util.Tuple2;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import lombok.Getter;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public enum InventoryItem {
    // Percentage deviation
    OfferPayload("OfferPayload",
            true,
            new DeviationByPercentage(0.8, 1.2, 0.9, 1.1), 5),
    MailboxStoragePayload("MailboxStoragePayload",
            true,
            new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2),
    TradeStatistics3("TradeStatistics3",
            true,
            new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2),
    AccountAgeWitness("AccountAgeWitness",
            true,
            new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2),
    SignedWitness("SignedWitness",
            true,
            new DeviationByPercentage(0.9, 1.1, 0.95, 1.05), 2),

    // Should be same value
    Alert("Alert",
            true,
            new DeviationByIntegerDiff(1, 1), 2),
    Filter("Filter",
            true,
            new DeviationByIntegerDiff(1, 1), 2),
    Mediator("Mediator",
            true,
            new DeviationByIntegerDiff(1, 1), 2),
    RefundAgent("RefundAgent",
            true,
            new DeviationByIntegerDiff(1, 1), 2),

    // Should be very close values
    TempProposalPayload("TempProposalPayload",
            true,
            new DeviationByIntegerDiff(3, 5), 2),
    ProposalPayload("ProposalPayload",
            true,
            new DeviationByIntegerDiff(1, 2), 2),
    BlindVotePayload("BlindVotePayload",
            true,
            new DeviationByIntegerDiff(1, 2), 2),

    // Should be very close values
    daoStateChainHeight("daoStateChainHeight",
            true,
            new DeviationByIntegerDiff(2, 4), 3),
    numBsqBlocks("numBsqBlocks",
            true,
            new DeviationByIntegerDiff(2, 4), 3),

    // Has to be same values at same block
    daoStateHash("daoStateHash",
            false,
            new DeviationOfHashes(), 1),
    proposalHash("proposalHash",
            false,
            new DeviationOfHashes(), 1),
    blindVoteHash("blindVoteHash",
            false,
            new DeviationOfHashes(), 1),

    // Percentage deviation
    maxConnections("maxConnections",
            true,
            new DeviationByPercentage(0.33, 3, 0.4, 2.5), 2),
    numConnections("numConnections",
            true,
            new DeviationByPercentage(0, 3, 0, 2.5), 2),
    peakNumConnections("peakNumConnections",
            true,
            new DeviationByPercentage(0, 3, 0, 2.5), 2),
    numAllConnectionsLostEvents("numAllConnectionsLostEvents",
            true,
            new DeviationByIntegerDiff(1, 2), 1),
    sentBytesPerSec("sentBytesPerSec",
            true,
            new DeviationByPercentage(), 5),
    receivedBytesPerSec("receivedBytesPerSec",
            true,
            new DeviationByPercentage(), 5),
    receivedMessagesPerSec("receivedMessagesPerSec",
            true,
            new DeviationByPercentage(), 5),
    sentMessagesPerSec("sentMessagesPerSec",
            true,
            new DeviationByPercentage(), 5),

    // No deviation check
    sentBytes("sentBytes", true),
    receivedBytes("receivedBytes", true),

    // No deviation check
    version("version", false),
    commitHash("commitHash", false),
    usedMemory("usedMemory", true),
    jvmStartTime("jvmStartTime", true),
    filteredSeeds("filteredSeeds", false);

    @Getter
    private final String key;
    @Getter
    private final boolean isNumberValue;
    @Getter
    @Nullable
    private DeviationType deviationType;

    // The number of past requests we check to see if there have been repeated alerts or warnings. The higher the
    // number the more repeated alert need to have happened to cause a notification alert.
    // Smallest number is 1, as that takes only the last request data and does not look further back.
    @Getter
    private int deviationTolerance = 1;

    InventoryItem(String key, boolean isNumberValue) {
        this.key = key;
        this.isNumberValue = isNumberValue;
    }

    InventoryItem(String key, boolean isNumberValue, @NotNull DeviationType deviationType, int deviationTolerance) {
        this(key, isNumberValue);
        this.deviationType = deviationType;
        this.deviationTolerance = deviationTolerance;
    }
{'fraction_non_alphanumeric': 0.09534022226554884, 'fraction_numerical': 0.022908949112887503, 'mean_word_length': 2.5745644599303135, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2145980', 'n_tokens_mistral': 3089, 'n_tokens_neox': 2867, 'n_words': 835}