aria2/test/MockDHTMessageFactory.h

129 lines
3.1 KiB
C
Raw Normal View History

#ifndef _D_MOCK_DHT_MESSAGE_FACTORY_H_
#define _D_MOCK_DHT_MESSAGE_FACTORY_H_
#include "DHTMessageFactory.h"
#include "DHTNode.h"
#include "MockDHTMessage.h"
#include "Dictionary.h"
#include "Data.h"
namespace aria2 {
class MockDHTMessageFactory:public DHTMessageFactory {
private:
SharedHandle<DHTNode> _localNode;
public:
MockDHTMessageFactory() {}
virtual ~MockDHTMessageFactory() {}
virtual SharedHandle<DHTMessage>
createQueryMessage(const Dictionary* d,
const std::string& ipaddr, uint16_t port)
{
return 0;
}
virtual SharedHandle<DHTMessage>
createResponseMessage(const std::string& messageType,
const Dictionary* d,
const SharedHandle<DHTNode>& remoteNode)
{
SharedHandle<MockDHTMessage> m =
new MockDHTMessage(_localNode, remoteNode,
reinterpret_cast<const Data*>(d->get("t"))->toString());
m->setReply(true);
return m;
}
virtual SharedHandle<DHTMessage>
createPingMessage(const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID = "")
{
return 0;
}
virtual SharedHandle<DHTMessage>
createPingReplyMessage(const SharedHandle<DHTNode>& remoteNode,
const unsigned char* remoteNodeID,
const std::string& transactionID)
{
return 0;
}
virtual SharedHandle<DHTMessage>
createFindNodeMessage(const SharedHandle<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID = "")
{
return 0;
}
virtual SharedHandle<DHTMessage>
createFindNodeReplyMessage(const SharedHandle<DHTNode>& remoteNode,
const std::deque<SharedHandle<DHTNode> >& closestKNodes,
const std::string& transactionID)
{
return 0;
}
virtual SharedHandle<DHTMessage>
createGetPeersMessage(const SharedHandle<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID)
{
return 0;
}
virtual SharedHandle<DHTMessage>
createGetPeersReplyMessage(const SharedHandle<DHTNode>& remoteNode,
const std::deque<SharedHandle<DHTNode> >& closestKNodes,
const std::string& transactionID,
const std::string& token = "")
{
return 0;
}
virtual SharedHandle<DHTMessage>
createGetPeersReplyMessage(const SharedHandle<DHTNode>& remoteNode,
const std::deque<SharedHandle<Peer> >& peers,
const std::string& transactionID,
const std::string& token = "")
{
return 0;
}
virtual SharedHandle<DHTMessage>
createAnnouncePeerMessage(const SharedHandle<DHTNode>& remoteNode,
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
const std::string& transactionID = "")
{
return 0;
}
virtual SharedHandle<DHTMessage>
createAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID)
{
return 0;
}
virtual SharedHandle<DHTMessage>
createUnknownMessage(const char* data, size_t length, const std::string& ipaddr,
uint16_t port)
{
return 0;
}
void setLocalNode(const SharedHandle<DHTNode>& node)
{
_localNode = node;
}
};
} // namespace aria2
#endif // _D_MOCK_DHT_MESSAGE_FACTORY_H_