<commit_before>// Copyright (c) 2014-2018 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef NETFULFILLEDMAN_H
#define NETFULFILLEDMAN_H

#include "netaddress.h"
#include "serialize.h"
#include "sync.h"

class CNetFulfilledRequestManager;
extern CNetFulfilledRequestManager netfulfilledman;

// Fulfilled requests are used to prevent nodes from asking for the same data on sync
// and from being banned for doing so too often.
class CNetFulfilledRequestManager
{
    // Temporary measure, remove after switch to evo znodes
    friend class CZnodeSync;
private:
    typedef std::map<std::string, int64_t> fulfilledreqmapentry_t;
    typedef std::map<CService, fulfilledreqmapentry_t> fulfilledreqmap_t;

    //keep track of what node has/was asked for and when
    fulfilledreqmap_t mapFulfilledRequests;
    CCriticalSection cs_mapFulfilledRequests;

    void RemoveFulfilledRequest(const CService& addr, const std::string& strRequest);

public:
    CNetFulfilledRequestManager() {}

    ADD_SERIALIZE_METHODS;

    template <typename Stream, typename Operation>
    inline void SerializationOp(Stream& s, Operation ser_action) {
        LOCK(cs_mapFulfilledRequests);
        READWRITE(mapFulfilledRequests);
    }
<commit_msg>Read netfulfilled.dat in legacy mode in case of upgrade from 0.13.*<commit_after>// Copyright (c) 2014-2018 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef NETFULFILLEDMAN_H
#define NETFULFILLEDMAN_H

#include "netaddress.h"
#include "serialize.h"
#include "sync.h"

class CNetFulfilledRequestManager;
extern CNetFulfilledRequestManager netfulfilledman;

// Fulfilled requests are used to prevent nodes from asking for the same data on sync
// and from being banned for doing so too often.
class CNetFulfilledRequestManager
{
    // Temporary measure, remove after switch to evo znodes
    friend class CZnodeSync;
private:
    typedef std::map<std::string, int64_t> fulfilledreqmapentry_t;
    typedef std::map<CService, fulfilledreqmapentry_t> fulfilledreqmap_t;

    //keep track of what node has/was asked for and when
    fulfilledreqmap_t mapFulfilledRequests;
    CCriticalSection cs_mapFulfilledRequests;

    void RemoveFulfilledRequest(const CService& addr, const std::string& strRequest);

public:
    CNetFulfilledRequestManager() {}

    ADD_SERIALIZE_METHODS;

    template <typename Stream, typename Operation>
    inline void SerializationOp(Stream& s, Operation ser_action) {
        LOCK(cs_mapFulfilledRequests);
        if (ser_action.ForRead()) {
            // Do we need to upgrade from old version?
            // Read all the data to the end (only CDataStream is supported)
            typename Stream::size_type bytesLeft = s.size();
            try {
                READWRITE(mapFulfilledRequests);
            }
            catch (std::exception &e) {
                // Rewind the stream and try to re-read it in legacy mode
                s.Rewind(bytesLeft - s.size());
                std::map<CNetAddr, fulfilledreqmapentry_t> legacyMapFulfilledRequests;
                READWRITE(legacyMapFulfilledRequests);
                mapFulfilledRequests.clear();
                int defaultPort = Params().GetDefaultPort();
                for (const auto &fe: legacyMapFulfilledRequests)
                    mapFulfilledRequests[CService(fe.first, defaultPort)] = fe.second;
            }
        }
        else {
            READWRITE(mapFulfilledRequests);
        }
    }

{'fraction_non_alphanumeric': 0.0762137238947654, 'fraction_numerical': 0.007323026851098454, 'mean_word_length': 3.3748517200474497, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '315853', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1052, 'n_words': 308}