diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-08-05 11:54:44 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-08-05 11:54:44 +0000 |
| commit | c685ea9de9efdea119828ded02414f72b8271f31 (patch) | |
| tree | 055e64aa8742f6e08e085751c146cb3a188a0d61 /src/UTPexExtensionMessage.cc | |
| parent | cba1283aaed888f4602b3e1426b0edf5aaf823fe (diff) | |
2010-08-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added support for peers6 key in tracker response. Added added6,
added6.f and dropped6 in ut_pex.
* src/BtAnnounce.cc
* src/BtAnnounce.h
* src/DefaultBtAnnounce.cc
* src/UTPexExtensionMessage.cc
* src/UTPexExtensionMessage.h
* test/DefaultBtAnnounceTest.cc
* test/UTPexExtensionMessageTest.cc
Diffstat (limited to 'src/UTPexExtensionMessage.cc')
| -rw-r--r-- | src/UTPexExtensionMessage.cc | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/src/UTPexExtensionMessage.cc b/src/UTPexExtensionMessage.cc index 4618850f..3ac1e9a1 100644 --- a/src/UTPexExtensionMessage.cc +++ b/src/UTPexExtensionMessage.cc @@ -58,24 +58,41 @@ UTPexExtensionMessage::~UTPexExtensionMessage() {} std::string UTPexExtensionMessage::getPayload() { - std::pair<std::string, std::string> freshPeerPair = + std::pair<std::pair<std::string, std::string>, + std::pair<std::string, std::string> > freshPeerPair = createCompactPeerListAndFlag(freshPeers_); - std::pair<std::string, std::string> droppedPeerPair = + std::pair<std::pair<std::string, std::string>, + std::pair<std::string, std::string> > droppedPeerPair = createCompactPeerListAndFlag(droppedPeers_); Dict dict; - dict.put("added", freshPeerPair.first); - dict.put("added.f", freshPeerPair.second); - dict.put("dropped", droppedPeerPair.first); + if(!freshPeerPair.first.first.empty()) { + dict.put("added", freshPeerPair.first.first); + dict.put("added.f", freshPeerPair.first.second); + } + if(!droppedPeerPair.first.first.empty()) { + dict.put("dropped", droppedPeerPair.first.first); + } + if(!freshPeerPair.second.first.empty()) { + dict.put("added6", freshPeerPair.second.first); + dict.put("added6.f", freshPeerPair.second.second); + } + if(!droppedPeerPair.second.first.empty()) { + dict.put("dropped6", droppedPeerPair.second.first); + } + return bencode2::encode(&dict); } -std::pair<std::string, std::string> +std::pair<std::pair<std::string, std::string>, + std::pair<std::string, std::string> > UTPexExtensionMessage::createCompactPeerListAndFlag (const std::vector<SharedHandle<Peer> >& peers) { std::string addrstring; std::string flagstring; + std::string addrstring6; + std::string flagstring6; for(std::vector<SharedHandle<Peer> >::const_iterator itr = peers.begin(), eoi = peers.end(); itr != eoi; ++itr) { unsigned char compact[COMPACT_LEN_IPV6]; @@ -84,9 +101,13 @@ UTPexExtensionMessage::createCompactPeerListAndFlag if(compactlen == COMPACT_LEN_IPV4) { addrstring.append(&compact[0], &compact[compactlen]); flagstring += (*itr)->isSeeder() ? 0x02 : 0x00; + } else if(compactlen == COMPACT_LEN_IPV6) { + addrstring6.append(&compact[0], &compact[compactlen]); + flagstring6 += (*itr)->isSeeder() ? 0x02 : 0x00; } } - return std::pair<std::string, std::string>(addrstring, flagstring); + return std::make_pair(std::make_pair(addrstring, flagstring), + std::make_pair(addrstring6, flagstring6)); } std::string UTPexExtensionMessage::toString() const @@ -172,6 +193,16 @@ UTPexExtensionMessage::create(const unsigned char* data, size_t len) bittorrent::extractPeer (dropped, AF_INET, std::back_inserter(msg->droppedPeers_)); } + const String* added6 = asString(dict->get("added6")); + if(added6) { + bittorrent::extractPeer + (added6, AF_INET6, std::back_inserter(msg->freshPeers_)); + } + const String* dropped6 = asString(dict->get("dropped6")); + if(dropped6) { + bittorrent::extractPeer + (dropped6, AF_INET6, std::back_inserter(msg->droppedPeers_)); + } } return msg; } |
