Fabcoin Core  0.16.2
P2P Digital Currency
Interface.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 class Watch;
42 
44 {
45  InstalledFilter(Topics const& _t): full(_t), filter(_t) {}
46 
49  unsigned refCount = 1;
50 };
51 
53 {
55  explicit ClientWatch(h256 _id): id(_id) {}
56 
59 };
60 
61 class Interface
62 {
63 public:
64  virtual ~Interface();
65 
66  virtual void inject(Envelope const& _m, WhisperPeer* _from = nullptr) = 0;
67 
68  virtual Topics const& fullTopics(unsigned _id) const = 0;
69  virtual unsigned installWatch(Topics const& _filter) = 0;
70  virtual void uninstallWatch(unsigned _watchId) = 0;
71  virtual h256s peekWatch(unsigned _watchId) const = 0;
72  virtual h256s checkWatch(unsigned _watchId) = 0;
73  virtual h256s watchMessages(unsigned _watchId) = 0;
74 
75  virtual Envelope envelope(h256 _m) const = 0;
76 
77  void post(bytes const& _payload, Topics _topics, unsigned _ttl = 50, unsigned _workToProve = 50) { inject(Message(_payload).seal(_topics, _ttl, _workToProve)); }
78  void post(Public _to, bytes const& _payload, Topics _topics, unsigned _ttl = 50, unsigned _workToProve = 50) { inject(Message(_payload).sealTo(_to, _topics, _ttl, _workToProve)); }
79  void post(Secret const& _from, bytes const& _payload, Topics _topics, unsigned _ttl = 50, unsigned _workToProve = 50) { inject(Message(_payload).seal(_from, _topics, _ttl, _workToProve)); }
80  void post(Secret const& _from, Public _to, bytes const& _payload, Topics _topics, unsigned _ttl = 50, unsigned _workToProve = 50) { inject(Message(_payload).sealTo(_from, _to, _topics, _ttl, _workToProve)); }
81 };
82 
83 struct WatshhChannel: public dev::LogChannel { static const char* name() { return "shh"; } static const int verbosity = 1; };
84 #define cwatshh dev::LogOutputStream<shh::WatshhChannel, true>()
85 
86 }
87 }
88 
89 namespace std { void swap(dev::shh::Watch& _a, dev::shh::Watch& _b); }
90 
91 namespace dev
92 {
93 namespace shh
94 {
95 
96 class Watch: public boost::noncopyable
97 {
98  friend void std::swap(Watch& _a, Watch& _b);
99 
100 public:
101  Watch() {}
102  Watch(Interface& _c, Topics const& _t): m_c(&_c), m_id(_c.installWatch(_t)) {}
103  ~Watch() { if (m_c) m_c->uninstallWatch(m_id); }
104 
105  h256s check() { return m_c ? m_c->checkWatch(m_id) : h256s(); }
106  h256s peek() { return m_c ? m_c->peekWatch(m_id) : h256s(); }
107 
108 private:
110  unsigned m_id;
111 };
112 
113 }
114 }
115 
116 namespace std
117 {
118 
119 inline void swap(dev::shh::Watch& _a, dev::shh::Watch& _b)
120 {
121  swap(_a.m_c, _b.m_c);
122  swap(_a.m_id, _b.m_id);
123 }
124 
125 }
126 
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
Watch(Interface &_c, Topics const &_t)
Definition: Interface.h:102
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
Definition: Interface.h:284
void post(Public _to, bytes const &_payload, Topics _topics, unsigned _ttl=50, unsigned _workToProve=50)
Definition: Interface.h:78
Interface * m_c
Definition: Interface.h:109
ClientWatch(h256 _id)
Definition: Interface.h:55
h256s Topics
Definition: Common.h:69
std::hash for asio::adress
Definition: Common.h:323
void swap(dev::shh::Watch &_a, dev::shh::Watch &_b)
Definition: Interface.h:119
h256s check()
Definition: Interface.h:105
const char * name
Definition: rest.cpp:36
std::vector< byte > bytes
Definition: Common.h:75
void post(Secret const &_from, Public _to, bytes const &_payload, Topics _topics, unsigned _ttl=50, unsigned _workToProve=50)
Definition: Interface.h:80
InstalledFilter(Topics const &_t)
Definition: Interface.h:45
An (unencrypted) message, constructed from the combination of an Envelope, and, potentially, a Secret key to decrypt the Message.
Definition: Message.h:100
unsigned m_id
Definition: Interface.h:110
void post(bytes const &_payload, Topics _topics, unsigned _ttl=50, unsigned _workToProve=50)
Definition: Interface.h:77
void post(Secret const &_from, bytes const &_payload, Topics _topics, unsigned _ttl=50, unsigned _workToProve=50)
Definition: Interface.h:79
The default logging channels.
Definition: Log.h:130
std::vector< h256 > h256s
Definition: FixedHash.h:345
h256s peek()
Definition: Interface.h:106