You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

addrdb.h 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2016 The Starwels developers
  3. // Distributed under the MIT software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef STARWELS_ADDRDB_H
  6. #define STARWELS_ADDRDB_H
  7. #include "fs.h"
  8. #include "serialize.h"
  9. #include <string>
  10. #include <map>
  11. class CSubNet;
  12. class CAddrMan;
  13. class CDataStream;
  14. typedef enum BanReason
  15. {
  16. BanReasonUnknown = 0,
  17. BanReasonNodeMisbehaving = 1,
  18. BanReasonManuallyAdded = 2
  19. } BanReason;
  20. class CBanEntry
  21. {
  22. public:
  23. static const int CURRENT_VERSION=1;
  24. int nVersion;
  25. int64_t nCreateTime;
  26. int64_t nBanUntil;
  27. uint8_t banReason;
  28. CBanEntry()
  29. {
  30. SetNull();
  31. }
  32. CBanEntry(int64_t nCreateTimeIn)
  33. {
  34. SetNull();
  35. nCreateTime = nCreateTimeIn;
  36. }
  37. ADD_SERIALIZE_METHODS;
  38. template <typename Stream, typename Operation>
  39. inline void SerializationOp(Stream& s, Operation ser_action) {
  40. READWRITE(this->nVersion);
  41. READWRITE(nCreateTime);
  42. READWRITE(nBanUntil);
  43. READWRITE(banReason);
  44. }
  45. void SetNull()
  46. {
  47. nVersion = CBanEntry::CURRENT_VERSION;
  48. nCreateTime = 0;
  49. nBanUntil = 0;
  50. banReason = BanReasonUnknown;
  51. }
  52. std::string banReasonToString()
  53. {
  54. switch (banReason) {
  55. case BanReasonNodeMisbehaving:
  56. return "node misbehaving";
  57. case BanReasonManuallyAdded:
  58. return "manually added";
  59. default:
  60. return "unknown";
  61. }
  62. }
  63. };
  64. typedef std::map<CSubNet, CBanEntry> banmap_t;
  65. /** Access to the (IP) address database (peers.dat) */
  66. class CAddrDB
  67. {
  68. private:
  69. fs::path pathAddr;
  70. public:
  71. CAddrDB();
  72. bool Write(const CAddrMan& addr);
  73. bool Read(CAddrMan& addr);
  74. static bool Read(CAddrMan& addr, CDataStream& ssPeers);
  75. };
  76. /** Access to the banlist database (banlist.dat) */
  77. class CBanDB
  78. {
  79. private:
  80. fs::path pathBanlist;
  81. public:
  82. CBanDB();
  83. bool Write(const banmap_t& banSet);
  84. bool Read(banmap_t& banSet);
  85. };
  86. #endif // STARWELS_ADDRDB_H