aria2/test/MockDHTMessageFactory.h

129 lines
3.7 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 "DHTPingMessage.h"
#include "DHTPingReplyMessage.h"
#include "DHTFindNodeMessage.h"
#include "DHTFindNodeReplyMessage.h"
#include "DHTGetPeersMessage.h"
#include "DHTGetPeersReplyMessage.h"
#include "DHTAnnouncePeerMessage.h"
#include "DHTAnnouncePeerReplyMessage.h"
#include "DHTUnknownMessage.h"
namespace aria2 {
class MockDHTMessageFactory:public DHTMessageFactory {
protected:
std::shared_ptr<DHTNode> localNode_;
public:
MockDHTMessageFactory() {}
virtual std::unique_ptr<DHTQueryMessage>
createQueryMessage(const Dict* dict,
const std::string& ipaddr, uint16_t port)
{
return nullptr;
}
virtual std::unique_ptr<DHTResponseMessage>
createResponseMessage(const std::string& messageType,
const Dict* dict,
const std::string& ipaddr, uint16_t port)
{
auto remoteNode = std::make_shared<DHTNode>();
// TODO At this point, removeNode's ID is random.
remoteNode->setIPAddress(ipaddr);
remoteNode->setPort(port);
return make_unique<MockDHTResponseMessage>
(localNode_, remoteNode, downcast<String>(dict->get("t"))->s());
}
virtual std::unique_ptr<DHTPingMessage>
createPingMessage(const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID = "")
{
return nullptr;
}
virtual std::unique_ptr<DHTPingReplyMessage>
createPingReplyMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* remoteNodeID,
const std::string& transactionID)
{
return nullptr;
}
virtual std::unique_ptr<DHTFindNodeMessage>
createFindNodeMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* targetNodeID,
const std::string& transactionID = "")
{
return nullptr;
}
virtual std::unique_ptr<DHTFindNodeReplyMessage>
createFindNodeReplyMessage
(const std::shared_ptr<DHTNode>& remoteNode,
std::vector<std::shared_ptr<DHTNode>> closestKNodes,
const std::string& transactionID)
{
return nullptr;
}
virtual std::unique_ptr<DHTGetPeersMessage>
createGetPeersMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
const std::string& transactionID)
{
return nullptr;
}
virtual std::unique_ptr<DHTGetPeersReplyMessage>
createGetPeersReplyMessage
(const std::shared_ptr<DHTNode>& remoteNode,
std::vector<std::shared_ptr<DHTNode>> closestKNodes,
std::vector<std::shared_ptr<Peer>> peers,
2010-08-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> Added IPv6 DHT. Added --dht-entry-porint6, --dht-file-path6, --dht-listen-addr6 and --enable-dht6 option. IPv6 DHT is disabled by default. To use IPv6 DHT, you need to use --enable-dht6 and specify a global unicast address to --dht-listen-addr6. IPv6 DHT is highly experimental. * src/BtSetup.cc * src/DHTAutoSaveCommand.cc * src/DHTAutoSaveCommand.h * src/DHTConnectionImpl.cc * src/DHTConnectionImpl.h * src/DHTEntryPointNameResolveCommand.cc * src/DHTFindNodeReplyMessage.cc * src/DHTFindNodeReplyMessage.h * src/DHTGetPeersMessage.cc * src/DHTGetPeersReplyMessage.cc * src/DHTGetPeersReplyMessage.h * src/DHTMessageFactory.h * src/DHTMessageFactoryImpl.cc * src/DHTMessageFactoryImpl.h * src/DHTMessageTracker.cc * src/DHTRegistry.cc * src/DHTRegistry.h * src/DHTRoutingTableDeserializer.cc * src/DHTRoutingTableDeserializer.h * src/DHTRoutingTableSerializer.cc * src/DHTRoutingTableSerializer.h * src/DHTSetup.cc * src/DHTSetup.h * src/FtpConnection.cc * src/LpdMessageReceiver.cc * src/OptionHandlerFactory.cc * src/OptionHandlerImpl.h * src/PeerInteractionCommand.cc * src/RequestGroup.cc * src/SocketCore.cc * src/SocketCore.h * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/prefs.cc * src/prefs.h * src/usage_text.h * test/DHTConnectionImplTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTRoutingTableDeserializerTest.cc * test/DHTRoutingTableSerializerTest.cc * test/LpdMessageDispatcherTest.cc * test/MockDHTMessageFactory.h
2010-08-07 14:15:21 +00:00
const std::string& token,
const std::string& transactionID)
{
return nullptr;
}
2012-10-01 14:52:22 +00:00
virtual std::unique_ptr<DHTAnnouncePeerMessage>
createAnnouncePeerMessage(const std::shared_ptr<DHTNode>& remoteNode,
const unsigned char* infoHash,
uint16_t tcpPort,
const std::string& token,
const std::string& transactionID = "")
{
return nullptr;
}
virtual std::unique_ptr<DHTAnnouncePeerReplyMessage>
createAnnouncePeerReplyMessage(const std::shared_ptr<DHTNode>& remoteNode,
const std::string& transactionID)
{
return nullptr;
}
virtual std::unique_ptr<DHTUnknownMessage>
createUnknownMessage(const unsigned char* data, size_t length,
const std::string& ipaddr, uint16_t port)
{
return nullptr;
}
void setLocalNode(const std::shared_ptr<DHTNode>& node)
{
localNode_ = node;
}
};
} // namespace aria2
#endif // D_MOCK_DHT_MESSAGE_FACTORY_H