2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Changed method signature:
	DHTAbstractNodeLookupTask::getNodesFromMessage
	* src/DHTAbstractNodeLookupTask.cc
	* src/DHTAbstractNodeLookupTask.h
	* src/DHTNodeLookupTask.cc
	* src/DHTNodeLookupTask.h
	* src/DHTPeerLookupTask.cc
	* src/DHTPeerLookupTask.h
pull/1/head
Tatsuhiro Tsujikawa 2008-05-11 09:53:11 +00:00
parent 825cfe7715
commit 83731bab5c
7 changed files with 34 additions and 15 deletions

View File

@ -1,3 +1,14 @@
2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Changed method signature:
DHTAbstractNodeLookupTask::getNodesFromMessage
* src/DHTAbstractNodeLookupTask.cc
* src/DHTAbstractNodeLookupTask.h
* src/DHTNodeLookupTask.cc
* src/DHTNodeLookupTask.h
* src/DHTPeerLookupTask.cc
* src/DHTPeerLookupTask.h
2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Pass std::deque<Command*> by reference to avoid unnecessary coping.

View File

@ -60,7 +60,10 @@ void DHTAbstractNodeLookupTask::onReceived(const SharedHandle<DHTMessage>& messa
{
--_inFlightMessage;
onReceivedInternal(message);
std::deque<SharedHandle<DHTNodeLookupEntry> > newEntries = toEntries(getNodesFromMessage(message));
std::deque<SharedHandle<DHTNode> > nodes;
getNodesFromMessage(nodes, message);
std::deque<SharedHandle<DHTNodeLookupEntry> > newEntries = toEntries(nodes);
size_t count = 0;
for(std::deque<SharedHandle<DHTNodeLookupEntry> >::const_iterator i = newEntries.begin();
i != newEntries.end(); ++i) {
@ -69,6 +72,7 @@ void DHTAbstractNodeLookupTask::onReceived(const SharedHandle<DHTMessage>& messa
++count;
}
}
_logger->debug("%u node lookup entries added.", count);
std::stable_sort(_entries.begin(), _entries.end(), DHTIDCloser(_targetID));
_entries.erase(std::unique(_entries.begin(), _entries.end()), _entries.end());

View File

@ -72,7 +72,8 @@ public:
virtual void onTimeout(const SharedHandle<DHTNode>& node);
virtual std::deque<SharedHandle<DHTNode> > getNodesFromMessage(const SharedHandle<DHTMessage>& message) = 0;
virtual void getNodesFromMessage(std::deque<SharedHandle<DHTNode> >& nodes,
const SharedHandle<DHTMessage>& message) = 0;
virtual void onReceivedInternal(const SharedHandle<DHTMessage>& message) {}

View File

@ -47,15 +47,15 @@ DHTNodeLookupTask::DHTNodeLookupTask(const unsigned char* targetNodeID):
DHTAbstractNodeLookupTask(targetNodeID)
{}
std::deque<SharedHandle<DHTNode> >
DHTNodeLookupTask::getNodesFromMessage(const SharedHandle<DHTMessage>& message)
void
DHTNodeLookupTask::getNodesFromMessage(std::deque<SharedHandle<DHTNode> >& nodes,
const SharedHandle<DHTMessage>& message)
{
SharedHandle<DHTFindNodeReplyMessage> m
(dynamic_pointer_cast<DHTFindNodeReplyMessage>(message));
if(m.isNull()) {
return std::deque<SharedHandle<DHTNode> >();
} else {
return m->getClosestKNodes();
if(!m.isNull()) {
const std::deque<SharedHandle<DHTNode> >& knodes = m->getClosestKNodes();
nodes.insert(nodes.end(), knodes.begin(), knodes.end());
}
}

View File

@ -43,7 +43,8 @@ class DHTNodeLookupTask:public DHTAbstractNodeLookupTask {
public:
DHTNodeLookupTask(const unsigned char* targetNodeID);
virtual std::deque<SharedHandle<DHTNode> > getNodesFromMessage(const SharedHandle<DHTMessage>& message);
virtual void getNodesFromMessage(std::deque<SharedHandle<DHTNode> >& nodes,
const SharedHandle<DHTMessage>& message);
virtual SharedHandle<DHTMessage> createMessage(const SharedHandle<DHTNode>& remoteNode);
};

View File

@ -56,13 +56,14 @@ DHTPeerLookupTask::DHTPeerLookupTask(const SharedHandle<BtContext>& btContext):
_peerStorage(PEER_STORAGE(btContext)),
_btRuntime(BT_RUNTIME(btContext)) {}
std::deque<SharedHandle<DHTNode> > DHTPeerLookupTask::getNodesFromMessage(const SharedHandle<DHTMessage>& message)
void
DHTPeerLookupTask::getNodesFromMessage(std::deque<SharedHandle<DHTNode> >& nodes,
const SharedHandle<DHTMessage>& message)
{
SharedHandle<DHTGetPeersReplyMessage> m(dynamic_pointer_cast<DHTGetPeersReplyMessage>(message));
if(m.isNull()) {
return std::deque<SharedHandle<DHTNode> >();
} else {
return m->getClosestKNodes();
if(!m.isNull()) {
const std::deque<SharedHandle<DHTNode> >& knodes = m->getClosestKNodes();
nodes.insert(nodes.end(), knodes.begin(), knodes.end());
}
}

View File

@ -59,7 +59,8 @@ private:
public:
DHTPeerLookupTask(const SharedHandle<BtContext>& btContext);
virtual std::deque<SharedHandle<DHTNode> > getNodesFromMessage(const SharedHandle<DHTMessage>& message);
virtual void getNodesFromMessage(std::deque<SharedHandle<DHTNode> >& nodes,
const SharedHandle<DHTMessage>& message);
virtual void onReceivedInternal(const SharedHandle<DHTMessage>& message);