Changeset View
Changeset View
Standalone View
Standalone View
src/dht/getpeersrsp.cpp
Show All 26 Lines | |||||
27 | #include "dht.h" | 27 | #include "dht.h" | ||
28 | 28 | | |||
29 | 29 | | |||
30 | using namespace bt; | 30 | using namespace bt; | ||
31 | 31 | | |||
32 | namespace dht | 32 | namespace dht | ||
33 | { | 33 | { | ||
34 | GetPeersRsp::GetPeersRsp() | 34 | GetPeersRsp::GetPeersRsp() | ||
35 | : RPCMsg(QByteArray(), dht::GET_PEERS, dht::RSP_MSG, Key()) | 35 | : RPCMsg(QByteArray(), dht::GET_PEERS, dht::RSP_MSG, QByteArray()) | ||
36 | { | 36 | { | ||
37 | } | 37 | } | ||
38 | 38 | | |||
39 | GetPeersRsp::GetPeersRsp(const QByteArray & mtid, const Key & id, const Key & token) | 39 | GetPeersRsp::GetPeersRsp(const QByteArray & mtid, const Key & id, const QByteArray & token) | ||
40 | : RPCMsg(mtid, dht::GET_PEERS, dht::RSP_MSG, id), | 40 | : RPCMsg(mtid, dht::GET_PEERS, dht::RSP_MSG, id), | ||
41 | token(token) | 41 | token(token) | ||
42 | { | 42 | { | ||
43 | } | 43 | } | ||
44 | 44 | | |||
45 | GetPeersRsp::GetPeersRsp(const QByteArray & mtid, const Key & id, const DBItemList & values, const Key & token) | 45 | GetPeersRsp::GetPeersRsp(const QByteArray & mtid, const Key & id, const DBItemList & values, const QByteArray & token) | ||
46 | : RPCMsg(mtid, dht::GET_PEERS, dht::RSP_MSG, id), | 46 | : RPCMsg(mtid, dht::GET_PEERS, dht::RSP_MSG, id), | ||
47 | token(token), | 47 | token(token), | ||
48 | items(values) | 48 | items(values) | ||
49 | {} | 49 | {} | ||
50 | 50 | | |||
51 | GetPeersRsp::~GetPeersRsp() | 51 | GetPeersRsp::~GetPeersRsp() | ||
52 | {} | 52 | {} | ||
53 | 53 | | |||
Show All 24 Lines | 72 | { | |||
78 | } | 78 | } | ||
79 | 79 | | |||
80 | if (nodes6.size() > 0) | 80 | if (nodes6.size() > 0) | ||
81 | { | 81 | { | ||
82 | enc.write(QByteArrayLiteral("nodes6")); | 82 | enc.write(QByteArrayLiteral("nodes6")); | ||
83 | enc.write(nodes6); | 83 | enc.write(nodes6); | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | enc.write(QByteArrayLiteral("token")); enc.write(token.getData(), 20); | 86 | // must cast data() to (const Uint8*) to call right write() overload | ||
87 | enc.write(QByteArrayLiteral("token")); enc.write((const Uint8*)token.data(), token.size()); | ||||
87 | 88 | | |||
88 | if (items.size() > 0) | 89 | if (items.size() > 0) | ||
89 | { | 90 | { | ||
90 | enc.write(QByteArrayLiteral("values")); enc.beginList(); | 91 | enc.write(QByteArrayLiteral("values")); enc.beginList(); | ||
91 | DBItemList::const_iterator i = items.begin(); | 92 | DBItemList::const_iterator i = items.begin(); | ||
92 | while (i != items.end()) | 93 | while (i != items.end()) | ||
93 | { | 94 | { | ||
94 | const DBItem & item = *i; | 95 | const DBItem & item = *i; | ||
Show All 14 Lines | |||||
109 | 110 | | |||
110 | void GetPeersRsp::parse(BDictNode* dict) | 111 | void GetPeersRsp::parse(BDictNode* dict) | ||
111 | { | 112 | { | ||
112 | dht::RPCMsg::parse(dict); | 113 | dht::RPCMsg::parse(dict); | ||
113 | BDictNode* args = dict->getDict(RSP); | 114 | BDictNode* args = dict->getDict(RSP); | ||
114 | if (!args) | 115 | if (!args) | ||
115 | throw bt::Error("Invalid response, arguments missing"); | 116 | throw bt::Error("Invalid response, arguments missing"); | ||
116 | 117 | | |||
117 | token = Key(args->getByteArray("token")); | 118 | token = args->getByteArray("token").left(MAX_TOKEN_SIZE); | ||
118 | 119 | | |||
119 | BListNode* vals = args->getList("values"); | 120 | BListNode* vals = args->getList("values"); | ||
120 | if (vals) | 121 | if (vals) | ||
121 | { | 122 | { | ||
122 | for (Uint32 i = 0;i < vals->getNumChildren();i++) | 123 | for (Uint32 i = 0;i < vals->getNumChildren();i++) | ||
123 | { | 124 | { | ||
124 | QByteArray d = vals->getByteArray(i); | 125 | QByteArray d = vals->getByteArray(i); | ||
125 | if (d.length() == 6) // IPv4 | 126 | if (d.length() == 6) // IPv4 | ||
Show All 30 Lines |