Capability.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. This file is part of cpp-ethereum.
  3. cpp-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. cpp-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file Capability.cpp
  15. * @author Gav Wood <i@gavwood.com>
  16. * @date 2014
  17. */
  18. #include "Capability.h"
  19. #include <libdevcore/Log.h>
  20. #include "Session.h"
  21. #include "Host.h"
  22. using namespace std;
  23. using namespace dev;
  24. using namespace dev::p2p;
  25. Capability::Capability(std::shared_ptr<Session> _s, HostCapabilityFace* _h, unsigned _idOffset, uint16_t _protocolID):
  26. c_protocolID(_protocolID), m_session(_s), m_hostCap(_h), m_idOffset(_idOffset)
  27. {
  28. clog(NetConnect) << "New session for capability" << m_hostCap->name() << "; idOffset:" << m_idOffset << "; protocolID:" << c_protocolID;
  29. }
  30. void Capability::disable(std::string const& _problem)
  31. {
  32. clog(NetTriviaSummary) << "DISABLE: Disabling capability '" << m_hostCap->name() << "'. Reason:" << _problem;
  33. m_enabled = false;
  34. }
  35. RLPStream& Capability::prep(RLPStream& _s, unsigned _id, unsigned _args)
  36. {
  37. return _s.appendRaw(bytes(1, _id + m_idOffset)).appendList(_args);
  38. }
  39. void Capability::sealAndSend(RLPStream& _s)
  40. {
  41. shared_ptr<Session> session = m_session.lock();
  42. if (session)
  43. session->sealAndSend(_s, c_protocolID);
  44. }
  45. void Capability::addRating(int _r)
  46. {
  47. shared_ptr<Session> session = m_session.lock();
  48. if (session)
  49. session->addRating(_r);
  50. }
  51. ReputationManager& Capability::repMan() const
  52. {
  53. return host()->repMan();
  54. }