mirror of
https://github.com/aria2/aria2.git
synced 2025-02-26 08:22:11 +00:00
Rewritten a portion of bittorrent implementation: * src/BtMessageValidator.h: New class. * src/BtBitfieldMessageValidator.h: New class. * src/BtHandshakeMessageValidator.h: New class. * src/BtRequestMessageValidator.h: New class. * src/BtSuggestPieceMessageValidator.h: New class. * src/BtAllowedFastMessageValidator.h: New class. * src/BtRejectMessageValidator.h: New class. * src/BtCancelMessageValidator.h: New class. * src/BtPieceMessageValidator.h: New class. * src/BtHaveMessageValidator.h: New class. * src/BtEventListener.h: New class. * src/AbstractBtEventListener.h: New class. * src/BtEvent.h: New class. * src/BtChokingEvent.h: New class. * src/BtChokedEvent.h: New class. * src/BtCancelSendingPieceEvent.h: New class. * src/BtAbortOutstandingRequestEvent.h: New class. * src/Randomizer.h: New class. * src/SimpleRandomizer.h: New class. * src/BtMessage.h: New class. * src/AbstractBtMessage.h: New class. * src/SimpleBtMessage.h: New class. * src/BtHaveMessage.h: New class. * src/BtInterestedMessage.h: New class. * src/BtAllowedFastMessage.h: New class. * src/BtUnchokeMessage.h: New class. * src/BtCancelMessage.h: New class. * src/BtNotInterestedMessage.h: New class. * src/BtChokeMessage.h: New class. * src/BtHaveNoneMessage.h: New class. * src/BtHandshakeMessage.h: New class. * src/BtSuggestPieceMessage.h: New class. * src/BtHaveMessage.h: New class. * src/BtPieceMessage.h: New class. * src/BtHaveAllMessage.h: New class. * src/BtKeepAliveMessage.h: New class. * src/BtPortMessage.h: New class. * src/BtRejectMessage.h: New class. * src/BtBitfieldMessage.h: New class. * src/BtRequestMessage.h: New class. * src/DefaultBtRequestFactory.h: New class. * src/DefaultBtMessageReceiver.h: New class. * src/BtInteractive.h: New class. * src/BtMessageDispatcher.h: New class. * src/DefaultBtMessageDispatcher.h: New class. * src/DefaultBtInteractive.h: New class. * src/BitfieldManFactory.h: New class. * src/HandleRegistry.h: New class. * src/BtMessageFactory.h: New class. * src/BtMessageReceiver.h: New class. * src/DefaultBtMessageFactory.h: New class. * src/PeerObject.h: New class. * src/BtRequestFactory.h: New class.
121 lines
2.4 KiB
C++
121 lines
2.4 KiB
C++
#ifndef _D_MOCK_BT_CONTEXT_H_
|
|
#define _D_MOCK_BT_CONTEXT_H_
|
|
|
|
#include "BtContext.h"
|
|
#include "Util.h"
|
|
|
|
class MockBtContext : public BtContext {
|
|
private:
|
|
unsigned char infoHash[20];
|
|
Strings pieceHashes;
|
|
long long int totalLength;
|
|
FILE_MODE fileMode;
|
|
string name;
|
|
int pieceLength;
|
|
int numPieces;
|
|
unsigned char peerId[20];
|
|
FileEntries fileEntries;
|
|
AnnounceTiers announceTiers;
|
|
public:
|
|
MockBtContext():totalLength(0),
|
|
pieceLength(0),
|
|
numPieces(0) {}
|
|
|
|
virtual ~MockBtContext() {}
|
|
|
|
virtual const unsigned char* getInfoHash() const {
|
|
return infoHash;
|
|
}
|
|
|
|
void setInfoHash(const unsigned char* infoHash) {
|
|
memcpy(this->infoHash, infoHash, sizeof(this->infoHash));
|
|
}
|
|
|
|
virtual int getInfoHashLength() const {
|
|
return sizeof(infoHash);
|
|
}
|
|
|
|
virtual string getInfoHashAsString() const {
|
|
return Util::toHex(infoHash, sizeof(infoHash));
|
|
}
|
|
|
|
virtual string getPieceHash(int index) const {
|
|
return pieceHashes.at(index);
|
|
}
|
|
|
|
void addPieceHash(const string pieceHash) {
|
|
pieceHashes.push_back(pieceHash);
|
|
}
|
|
|
|
virtual long long int getTotalLength() const {
|
|
return totalLength;
|
|
}
|
|
|
|
void setTotalLength(long long int length) {
|
|
this->totalLength = length;
|
|
}
|
|
|
|
virtual FILE_MODE getFileMode() const {
|
|
return fileMode;
|
|
}
|
|
|
|
void setFileMode(FILE_MODE fileMode) {
|
|
this->fileMode = fileMode;
|
|
}
|
|
|
|
virtual FileEntries getFileEntries() const {
|
|
return fileEntries;
|
|
}
|
|
|
|
void addFileEntry(const FileEntryHandle& fileEntry) {
|
|
fileEntries.push_back(fileEntry);
|
|
}
|
|
|
|
virtual AnnounceTiers getAnnounceTiers() const {
|
|
return announceTiers;
|
|
}
|
|
|
|
void addAnnounceTier(const AnnounceTierHandle& announceTier) {
|
|
announceTiers.push_back(announceTier);
|
|
}
|
|
|
|
virtual void load(const string& torrentFile) {}
|
|
|
|
virtual string getName() const {
|
|
return name;
|
|
}
|
|
|
|
void setName(const string& name) {
|
|
this->name = name;
|
|
}
|
|
|
|
virtual int getPieceLength() const {
|
|
return pieceLength;
|
|
}
|
|
|
|
void setPieceLength(int pieceLength) {
|
|
this->pieceLength = pieceLength;
|
|
}
|
|
|
|
virtual int getNumPieces() const {
|
|
return numPieces;
|
|
}
|
|
|
|
void setNumPieces(int numPieces) {
|
|
this->numPieces = numPieces;
|
|
}
|
|
|
|
virtual const unsigned char* getPeerId() {
|
|
return peerId;
|
|
}
|
|
|
|
void setPeerId(const unsigned char* peerId) {
|
|
memcpy(this->peerId, peerId, sizeof(this->peerId));
|
|
}
|
|
|
|
};
|
|
|
|
typedef SharedHandle<MockBtContext> MockBtContextHandle;
|
|
|
|
#endif // _D_MOCK_BT_CONTEXT_H_
|