Fabcoin Core  0.16.2
P2P Digital Currency
Capability.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 "Common.h"
25 #include "HostCapability.h"
26 
27 namespace dev
28 {
29 namespace p2p
30 {
31 
32 class ReputationManager;
33 
34 class Capability: public std::enable_shared_from_this<Capability>
35 {
36  friend class Session;
37 
38 public:
39  Capability(std::shared_ptr<SessionFace> _s, HostCapabilityFace* _h, unsigned _idOffset, uint16_t _protocolID);
40  virtual ~Capability() {}
41 
42  // Implement these in the derived class.
43 /* static std::string name() { return ""; }
44  static u256 version() { return 0; }
45  static unsigned messageCount() { return 0; }
46 */
47 protected:
48  std::shared_ptr<SessionFace> session() const { return m_session.lock(); }
50 
51  virtual bool interpret(unsigned _id, RLP const&) = 0;
52 
53  void disable(std::string const& _problem);
54 
55  RLPStream& prep(RLPStream& _s, unsigned _id, unsigned _args = 0);
56  void sealAndSend(RLPStream& _s);
57  void addRating(int _r);
58 
59  uint16_t const c_protocolID;
60 
61 private:
62  std::weak_ptr<SessionFace> m_session;
64  bool m_enabled = true;
65  unsigned m_idOffset;
66 };
67 
68 }
69 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
std::weak_ptr< SessionFace > m_session
Definition: Capability.h:62
Capability(std::shared_ptr< SessionFace > _s, HostCapabilityFace *_h, unsigned _idOffset, uint16_t _protocolID)
Definition: Capability.cpp:31
void disable(std::string const &_problem)
Definition: Capability.cpp:37
std::shared_ptr< SessionFace > session() const
Definition: Capability.h:48
void addRating(int _r)
Definition: Capability.cpp:55
virtual bool interpret(unsigned _id, RLP const &)=0
uint16_t const c_protocolID
Definition: Capability.h:59
RLPStream & prep(RLPStream &_s, unsigned _id, unsigned _args=0)
Definition: Capability.cpp:43
HostCapabilityFace * hostCapability() const
Definition: Capability.h:49
HostCapabilityFace * m_hostCap
Definition: Capability.h:63
void sealAndSend(RLPStream &_s)
Definition: Capability.cpp:48
virtual ~Capability()
Definition: Capability.h:40
Class for writing to an RLP bytestream.
Definition: RLP.h:383
Class for interpreting Recursive Linear-Prefix Data.
Definition: RLP.h:64
The Session class.
Definition: Session.h:90