Fabcoin Core  0.16.2
P2P Digital Currency
WhisperPeer.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
22 #pragma once
23 
24 #include <mutex>
25 #include <array>
26 #include <set>
27 #include <memory>
28 #include <utility>
29 
30 #include <libdevcore/RLP.h>
31 #include <libdevcore/Guards.h>
32 #include <libdevcore/SHA3.h>
33 #include "Common.h"
34 #include "Message.h"
35 
36 namespace dev
37 {
38 namespace shh
39 {
40 
41 using p2p::SessionFace;
42 using p2p::HostCapabilityFace;
43 using p2p::HostCapability;
44 using p2p::Capability;
45 using p2p::CapDesc;
46 
47 class WhisperPeer: public Capability
48 {
49  friend class WhisperHost;
50 
51 public:
52  WhisperPeer(std::shared_ptr<SessionFace> _s, HostCapabilityFace* _h, unsigned _i, CapDesc const& _cap, uint16_t _capID);
53  virtual ~WhisperPeer();
54  WhisperHost* host() const;
55  static std::string name() { return "shh"; }
56  static u256 version() { return WhisperProtocolVersion; }
57  static unsigned messageCount() { return PacketCount; }
59  void sendTopicsOfInterest(TopicBloomFilterHash const& _bloom);
61 
62 private:
63  virtual bool interpret(unsigned _id, RLP const&) override;
64  void sendMessages();
65  unsigned ratingForPeer(Envelope const& e) const;
66  void noteNewMessage(h256 _h, Envelope const& _m);
68 
70  std::multimap<unsigned, h256> m_unseen;
71  std::chrono::system_clock::time_point m_timer = std::chrono::system_clock::now();
72 
75 
78 };
79 
80 }
81 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
WhisperHost * host() const
Definition: WhisperPeer.cpp:43
unsigned ratingForPeer(Envelope const &e) const
std::chrono::system_clock::time_point m_timer
Definition: WhisperPeer.h:71
std::pair< std::string, u256 > CapDesc
Definition: Common.h:142
virtual bool interpret(unsigned _id, RLP const &) override
Definition: WhisperPeer.cpp:48
static u256 version()
Definition: WhisperPeer.h:56
#define g(i)
Definition: sha.cpp:735
dev::Mutex x_advertiseTopicsOfInterest
Definition: WhisperPeer.h:76
std::multimap< unsigned, h256 > m_unseen
Rated according to what they want.
Definition: WhisperPeer.h:70
TopicBloomFilterHash bloom() const
Definition: WhisperPeer.h:58
std::lock_guard< std::mutex > Guard
Definition: Guards.h:41
void noteAdvertiseTopicsOfInterest()
Definition: WhisperPeer.h:60
void setBloom(TopicBloomFilterHash const &_b)
Definition: WhisperPeer.h:67
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
static std::string name()
Definition: WhisperPeer.h:55
TopicBloomFilterHash m_bloom
Peer&#39;s topics of interest.
Definition: WhisperPeer.h:74
clock::time_point time_point
Definition: bench.h:49
WhisperPeer(std::shared_ptr< SessionFace > _s, HostCapabilityFace *_h, unsigned _i, CapDesc const &_cap, uint16_t _capID)
Definition: WhisperPeer.cpp:31
#define e(i)
Definition: sha.cpp:733
void noteNewMessage(h256 _h, Envelope const &_m)
std::mutex Mutex
Definition: Guards.h:37
void sendTopicsOfInterest(TopicBloomFilterHash const &_bloom)
sends our bloom filter to remote peer
bool m_advertiseTopicsOfInterest
Definition: WhisperPeer.h:77
static unsigned messageCount()
Definition: WhisperPeer.h:57
Class for interpreting Recursive Linear-Prefix Data.
Definition: RLP.h:64