forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFloodgate.h
67 lines (54 loc) · 1.86 KB
/
Floodgate.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
// Copyright 2014 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "overlay/Peer.h"
#include "overlay/StellarXDR.h"
#include <map>
/**
* FloodGate keeps track of which peers have sent us which broadcast messages,
* in order to ensure that for each broadcast message M and for each peer P, we
* either send M to P once (and only once), or receive M _from_ P (thereby
* inhibit sending M to P at all).
*
* The broadcast message types are TRANSACTION and SCP_MESSAGE.
*
* All messages are marked with the ledger sequence number to which they
* relate, and all flood-management information for a given ledger number
* is purged from the FloodGate when the ledger closes.
*/
namespace medida
{
class Counter;
}
namespace stellar
{
class Floodgate
{
class FloodRecord
{
public:
typedef std::shared_ptr<FloodRecord> pointer;
uint32_t mLedgerSeq;
StellarMessage mMessage;
std::set<std::string> mPeersTold;
FloodRecord(StellarMessage const& msg, uint32_t ledger,
Peer::pointer peer);
};
std::map<uint256, FloodRecord::pointer> mFloodMap;
Application& mApp;
medida::Counter& mFloodMapSize;
medida::Meter& mSendFromBroadcast;
bool mShuttingDown;
public:
Floodgate(Application& app);
// Floodgate will be cleared after every ledger close
void clearBelow(uint32_t currentLedger);
// returns true if this is a new record
bool addRecord(StellarMessage const& msg, Peer::pointer fromPeer);
void broadcast(StellarMessage const& msg, bool force);
// returns the list of peers that sent us the item with hash `h`
std::set<Peer::pointer> getPeersKnows(Hash const& h);
void shutdown();
};
}