Fabcoin Core  0.16.2
P2P Digital Currency
Capability.cpp
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 #include "Capability.h"
23 
24 #include <libdevcore/Log.h>
25 #include "Session.h"
26 #include "Host.h"
27 using namespace std;
28 using namespace dev;
29 using namespace dev::p2p;
30 
31 Capability::Capability(std::shared_ptr<SessionFace> _s, HostCapabilityFace* _h, unsigned _idOffset, uint16_t _protocolID):
32  c_protocolID(_protocolID), m_session(_s), m_hostCap(_h), m_idOffset(_idOffset)
33 {
34  clog(NetConnect) << "New session for capability" << m_hostCap->name() << "; idOffset:" << m_idOffset << "; protocolID:" << c_protocolID;
35 }
36 
37 void Capability::disable(std::string const& _problem)
38 {
39  clog(NetTriviaSummary) << "DISABLE: Disabling capability '" << m_hostCap->name() << "'. Reason:" << _problem;
40  m_enabled = false;
41 }
42 
43 RLPStream& Capability::prep(RLPStream& _s, unsigned _id, unsigned _args)
44 {
45  return _s.appendRaw(bytes(1, _id + m_idOffset)).appendList(_args);
46 }
47 
49 {
50  shared_ptr<SessionFace> session = m_session.lock();
51  if (session)
52  session->sealAndSend(_s, c_protocolID);
53 }
54 
56 {
57  shared_ptr<SessionFace> session = m_session.lock();
58  if (session)
59  session->addRating(_r);
60 }
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
void disable(std::string const &_problem)
Definition: Capability.cpp:37
std::shared_ptr< SessionFace > session() const
Definition: Capability.h:48
std::hash for asio::adress
Definition: Common.h:323
void addRating(int _r)
Definition: Capability.cpp:55
std::vector< byte > bytes
Definition: Common.h:75
RLPStream & appendList(size_t _items)
Appends a list.
Definition: RLP.cpp:276
uint16_t const c_protocolID
Definition: Capability.h:59
RLPStream & prep(RLPStream &_s, unsigned _id, unsigned _args=0)
Definition: Capability.cpp:43
HostCapabilityFace * m_hostCap
Definition: Capability.h:63
void sealAndSend(RLPStream &_s)
Definition: Capability.cpp:48
virtual std::string name() const =0
#define clog(X)
Definition: Log.h:295
Class for writing to an RLP bytestream.
Definition: RLP.h:383
RLPStream & appendRaw(bytesConstRef _rlp, size_t _itemCount=1)
Appends raw (pre-serialised) RLP data. Use with caution.
Definition: RLP.cpp:230