Merge branch 'master' into dynamic-select-file

dynamic-select-file
Tatsuhiro Tsujikawa 2016-05-22 20:57:33 +09:00
commit 9d40c47799
50 changed files with 223 additions and 282 deletions

View File

@ -30,7 +30,7 @@ RUN apt-get update && \
RUN curl -L -O https://gmplib.org/download/gmp/gmp-6.1.0.tar.lz && \
curl -L -o gmp-6.1.0.patch https://gmplib.org/repo/gmp-6.1/raw-rev/67d4ee9dead1 && \
curl -L -O http://downloads.sourceforge.net/project/expat/expat/2.1.0/expat-2.1.0.tar.gz && \
curl -L -O http://downloads.sourceforge.net/project/expat/expat/2.1.1/expat-2.1.1.tar.gz && \
curl -L -O https://www.sqlite.org/2016/sqlite-autoconf-3120100.tar.gz && \
curl -L -O http://zlib.net/zlib-1.2.8.tar.xz && \
curl -L -O http://c-ares.haxx.se/download/c-ares-1.11.0.tar.gz && \
@ -49,8 +49,8 @@ RUN tar xf gmp-6.1.0.tar.lz && \
CFLAGS="-mtune=generic -O2 -g0" && \
make install
RUN tar xf expat-2.1.0.tar.gz && \
cd expat-2.1.0 && \
RUN tar xf expat-2.1.1.tar.gz && \
cd expat-2.1.1 && \
./configure \
--disable-shared \
--enable-static \

View File

@ -43,7 +43,7 @@ aria2c executable was generated using android-ndk-r10d.
The following libraries were statically linked.
* openssl 1.0.2h
* expat 2.1.0
* expat 2.1.1
* c-ares 1.11.0
* libssh2 1.7.0

View File

@ -13,7 +13,7 @@ The executable is statically linked, so no extra DLLs are
necessary. The linked libraries are:
* gmp 6.1.0
* expat 2.1.0
* expat 2.1.1
* sqlite 3.10.2
* zlib 1.2.8
* c-ares 1.11.0

View File

@ -48,16 +48,12 @@ namespace aria2 {
const char BtBitfieldMessage::NAME[] = "bitfield";
BtBitfieldMessage::BtBitfieldMessage()
: SimpleBtMessage(ID, NAME), bitfieldLength_(0)
{
}
BtBitfieldMessage::BtBitfieldMessage() : SimpleBtMessage(ID, NAME) {}
BtBitfieldMessage::BtBitfieldMessage(const unsigned char* bitfield,
size_t bitfieldLength)
: SimpleBtMessage(ID, NAME), bitfieldLength_(0)
: SimpleBtMessage(ID, NAME), bitfield_(bitfield, bitfield + bitfieldLength)
{
setBitfield(bitfield, bitfieldLength);
}
BtBitfieldMessage::~BtBitfieldMessage() {}
@ -65,13 +61,7 @@ BtBitfieldMessage::~BtBitfieldMessage() {}
void BtBitfieldMessage::setBitfield(const unsigned char* bitfield,
size_t bitfieldLength)
{
if (bitfield_.get() == bitfield) {
return;
}
bitfieldLength_ = bitfieldLength;
bitfield_ = make_unique<unsigned char[]>(bitfieldLength_);
memcpy(bitfield_.get(), bitfield, bitfieldLength_);
bitfield_.assign(bitfield, bitfield + bitfieldLength);
}
std::unique_ptr<BtBitfieldMessage>
@ -89,15 +79,15 @@ void BtBitfieldMessage::doReceivedAction()
if (isMetadataGetMode()) {
return;
}
getPieceStorage()->updatePieceStats(bitfield_.get(), bitfieldLength_,
getPieceStorage()->updatePieceStats(bitfield_.data(), bitfield_.size(),
getPeer()->getBitfield());
getPeer()->setBitfield(bitfield_.get(), bitfieldLength_);
getPeer()->setBitfield(bitfield_.data(), bitfield_.size());
if (getPeer()->isSeeder() && getPieceStorage()->downloadFinished()) {
throw DL_ABORT_EX(MSG_GOOD_BYE_SEEDER);
}
}
unsigned char* BtBitfieldMessage::createMessage()
std::vector<unsigned char> BtBitfieldMessage::createMessage()
{
/**
* len --- 1+bitfieldLength, 4bytes
@ -105,20 +95,19 @@ unsigned char* BtBitfieldMessage::createMessage()
* bitfield --- bitfield, bitfieldLength bytes
* total: 5+bitfieldLength bytes
*/
const size_t msgLength = 5 + bitfieldLength_;
auto msg = new unsigned char[msgLength];
bittorrent::createPeerMessageString(msg, msgLength, 1 + bitfieldLength_, ID);
memcpy(msg + 5, bitfield_.get(), bitfieldLength_);
const size_t msgLength = 5 + bitfield_.size();
auto msg = std::vector<unsigned char>(msgLength);
bittorrent::createPeerMessageString(msg.data(), msgLength,
1 + bitfield_.size(), ID);
std::copy(std::begin(bitfield_), std::end(bitfield_), std::begin(msg) + 5);
return msg;
}
size_t BtBitfieldMessage::getMessageLength() { return 5 + bitfieldLength_; }
std::string BtBitfieldMessage::toString() const
{
std::string s = NAME;
s += " ";
s += util::toHex(bitfield_.get(), bitfieldLength_);
s += ' ';
s += util::toHex(bitfield_.data(), bitfield_.size());
return s;
}

View File

@ -41,8 +41,7 @@ namespace aria2 {
class BtBitfieldMessage : public SimpleBtMessage {
private:
std::unique_ptr<unsigned char[]> bitfield_;
size_t bitfieldLength_;
std::vector<unsigned char> bitfield_;
public:
BtBitfieldMessage();
@ -57,18 +56,16 @@ public:
void setBitfield(const unsigned char* bitfield, size_t bitfieldLength);
const unsigned char* getBitfield() const { return bitfield_.get(); }
const unsigned char* getBitfield() const { return bitfield_.data(); }
size_t getBitfieldLength() const { return bitfieldLength_; }
size_t getBitfieldLength() const { return bitfield_.size(); }
static std::unique_ptr<BtBitfieldMessage> create(const unsigned char* data,
size_t dataLength);
virtual void doReceivedAction() CXX11_OVERRIDE;
virtual unsigned char* createMessage() CXX11_OVERRIDE;
virtual size_t getMessageLength() CXX11_OVERRIDE;
virtual std::vector<unsigned char> createMessage() CXX11_OVERRIDE;
virtual std::string toString() const CXX11_OVERRIDE;
};

View File

@ -58,7 +58,7 @@ BtExtendedMessage::BtExtendedMessage(
{
}
unsigned char* BtExtendedMessage::createMessage()
std::vector<unsigned char> BtExtendedMessage::createMessage()
{
/**
* len --- 2+extpayload.length, 4bytes
@ -69,21 +69,15 @@ unsigned char* BtExtendedMessage::createMessage()
*/
std::string payload = extensionMessage_->getPayload();
msgLength_ = 6 + payload.size();
auto msg = new unsigned char[msgLength_];
bittorrent::createPeerMessageString(msg, msgLength_, 2 + payload.size(), ID);
*(msg + 5) = extensionMessage_->getExtensionMessageID();
memcpy(msg + 6, payload.data(), payload.size());
auto msg = std::vector<unsigned char>(msgLength_);
auto p = msg.data();
bittorrent::createPeerMessageString(p, msgLength_, 2 + payload.size(), ID);
p += 5;
*p++ = extensionMessage_->getExtensionMessageID();
std::copy(std::begin(payload), std::end(payload), p);
return msg;
}
size_t BtExtendedMessage::getMessageLength()
{
if (!msgLength_) {
msgLength_ = 6 + extensionMessage_->getPayload().size();
}
return msgLength_;
}
bool BtExtendedMessage::sendPredicate() const
{
return getPeer()->isExtendedMessagingEnabled();

View File

@ -61,9 +61,7 @@ public:
virtual void doReceivedAction() CXX11_OVERRIDE;
virtual unsigned char* createMessage() CXX11_OVERRIDE;
virtual size_t getMessageLength() CXX11_OVERRIDE;
virtual std::vector<unsigned char> createMessage() CXX11_OVERRIDE;
virtual bool sendPredicate() const CXX11_OVERRIDE;

View File

@ -81,10 +81,10 @@ BtHandshakeMessage::create(const unsigned char* data, size_t dataLength)
return msg;
}
unsigned char* BtHandshakeMessage::createMessage()
std::vector<unsigned char> BtHandshakeMessage::createMessage()
{
auto msg = new unsigned char[MESSAGE_LENGTH];
auto dst = msg;
auto msg = std::vector<unsigned char>(MESSAGE_LENGTH);
auto dst = msg.data();
*dst++ = pstrlen_;
dst = std::copy(std::begin(pstr_), std::end(pstr_), dst);
dst = std::copy(std::begin(reserved_), std::end(reserved_), dst);
@ -93,8 +93,6 @@ unsigned char* BtHandshakeMessage::createMessage()
return msg;
}
size_t BtHandshakeMessage::getMessageLength() { return MESSAGE_LENGTH; }
std::string BtHandshakeMessage::toString() const
{
return fmt("%s peerId=%s, reserved=%s", NAME,

View File

@ -79,9 +79,7 @@ public:
virtual void doReceivedAction() CXX11_OVERRIDE{};
virtual unsigned char* createMessage() CXX11_OVERRIDE;
virtual size_t getMessageLength() CXX11_OVERRIDE;
virtual std::vector<unsigned char> createMessage() CXX11_OVERRIDE;
virtual std::string toString() const CXX11_OVERRIDE;

View File

@ -39,17 +39,13 @@ namespace aria2 {
const char BtKeepAliveMessage::NAME[] = "keep alive";
unsigned char* BtKeepAliveMessage::createMessage()
std::vector<unsigned char> BtKeepAliveMessage::createMessage()
{
/**
* len --- 0, 4bytes
* total: 4bytes
*/
auto msg = new unsigned char[MESSAGE_LENGTH];
memset(msg, 0, MESSAGE_LENGTH);
return msg;
return std::vector<unsigned char>(MESSAGE_LENGTH);
}
size_t BtKeepAliveMessage::getMessageLength() { return MESSAGE_LENGTH; }
} // namespace aria2

View File

@ -52,9 +52,7 @@ public:
virtual void doReceivedAction() CXX11_OVERRIDE {}
virtual unsigned char* createMessage() CXX11_OVERRIDE;
virtual size_t getMessageLength() CXX11_OVERRIDE;
virtual std::vector<unsigned char> createMessage() CXX11_OVERRIDE;
virtual std::string toString() const CXX11_OVERRIDE { return NAME; }
};

View File

@ -213,17 +213,16 @@ void BtPieceMessage::send()
void BtPieceMessage::pushPieceData(int64_t offset, int32_t length) const
{
assert(length <= static_cast<int32_t>(16_k));
auto buf = make_unique<unsigned char[]>(length + MESSAGE_HEADER_LENGTH);
createMessageHeader(buf.get());
auto buf = std::vector<unsigned char>(length + MESSAGE_HEADER_LENGTH);
createMessageHeader(buf.data());
ssize_t r;
r = getPieceStorage()->getDiskAdaptor()->readData(
buf.get() + MESSAGE_HEADER_LENGTH, length, offset);
buf.data() + MESSAGE_HEADER_LENGTH, length, offset);
if (r == length) {
const auto& peer = getPeer();
getPeerConnection()->pushBytes(
buf.release(), length + MESSAGE_HEADER_LENGTH,
make_unique<PieceSendUpdate>(downloadContext_, peer,
MESSAGE_HEADER_LENGTH));
std::move(buf), make_unique<PieceSendUpdate>(downloadContext_, peer,
MESSAGE_HEADER_LENGTH));
peer->updateUploadSpeed(length);
downloadContext_->updateUploadSpeed(length);
}

View File

@ -100,7 +100,7 @@ void BtPortMessage::doReceivedAction()
}
}
unsigned char* BtPortMessage::createMessage()
std::vector<unsigned char> BtPortMessage::createMessage()
{
/**
* len --- 5, 4bytes
@ -108,14 +108,12 @@ unsigned char* BtPortMessage::createMessage()
* port --- port number, 2bytes
* total: 7bytes
*/
auto msg = new unsigned char[MESSAGE_LENGTH];
bittorrent::createPeerMessageString(msg, MESSAGE_LENGTH, 3, ID);
auto msg = std::vector<unsigned char>(MESSAGE_LENGTH);
bittorrent::createPeerMessageString(msg.data(), MESSAGE_LENGTH, 3, ID);
bittorrent::setShortIntParam(&msg[5], port_);
return msg;
}
size_t BtPortMessage::getMessageLength() { return MESSAGE_LENGTH; }
std::string BtPortMessage::toString() const
{
return fmt("%s port=%u", NAME, port_);

View File

@ -71,9 +71,7 @@ public:
virtual void doReceivedAction() CXX11_OVERRIDE;
virtual unsigned char* createMessage() CXX11_OVERRIDE;
virtual size_t getMessageLength() CXX11_OVERRIDE;
virtual std::vector<unsigned char> createMessage() CXX11_OVERRIDE;
virtual std::string toString() const CXX11_OVERRIDE;

View File

@ -626,7 +626,7 @@ void DefaultPieceStorage::initStorage()
{
if (downloadContext_->getFileEntries().size() == 1) {
A2_LOG_DEBUG("Instantiating DirectDiskAdaptor");
auto directDiskAdaptor = make_unique<DirectDiskAdaptor>();
auto directDiskAdaptor = std::make_shared<DirectDiskAdaptor>();
directDiskAdaptor->setTotalLength(downloadContext_->getTotalLength());
directDiskAdaptor->setFileEntries(
downloadContext_->getFileEntries().begin(),
@ -638,7 +638,7 @@ void DefaultPieceStorage::initStorage()
}
else {
A2_LOG_DEBUG("Instantiating MultiDiskAdaptor");
auto multiDiskAdaptor = make_unique<MultiDiskAdaptor>();
auto multiDiskAdaptor = std::make_shared<MultiDiskAdaptor>();
multiDiskAdaptor->setFileEntries(downloadContext_->getFileEntries().begin(),
downloadContext_->getFileEntries().end());
multiDiskAdaptor->setPieceLength(downloadContext_->getPieceLength());

View File

@ -39,28 +39,11 @@
namespace aria2 {
#ifdef __MINGW32__
bool FallocFileAllocationIterator::gainPrivilegeAttempted_ = false;
#endif // __MINGW32__
FallocFileAllocationIterator::FallocFileAllocationIterator(BinaryStream* stream,
int64_t offset,
int64_t totalLength)
: stream_(stream), offset_(offset), totalLength_(totalLength)
{
#ifdef __MINGW32__
// Windows build: --file-allocation=falloc uses SetFileValidData
// which requires SE_MANAGE_VOLUME_NAME privilege. SetFileValidData
// has security implications (see
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365544%28v=vs.85%29.aspx).
if (!gainPrivilegeAttempted_) {
if (!util::gainPrivilege(SE_MANAGE_VOLUME_NAME)) {
A2_LOG_WARN("--file-allocation=falloc will not work properly.");
}
gainPrivilegeAttempted_ = true;
}
#endif // __MINGW32__
}
void FallocFileAllocationIterator::allocateChunk()

View File

@ -47,10 +47,6 @@ private:
int64_t offset_;
int64_t totalLength_;
#ifdef __MINGW32__
static bool gainPrivilegeAttempted_;
#endif // __MINGW32__
public:
FallocFileAllocationIterator(BinaryStream* stream, int64_t offset,
int64_t totalLength);

View File

@ -39,7 +39,7 @@
namespace aria2 {
unsigned char* IndexBtMessage::createMessage()
std::vector<unsigned char> IndexBtMessage::createMessage()
{
/**
* len --- 5, 4bytes
@ -47,14 +47,12 @@ unsigned char* IndexBtMessage::createMessage()
* piece index --- index, 4bytes
* total: 9bytes
*/
auto msg = new unsigned char[MESSAGE_LENGTH];
bittorrent::createPeerMessageString(msg, MESSAGE_LENGTH, 5, getId());
auto msg = std::vector<unsigned char>(MESSAGE_LENGTH);
bittorrent::createPeerMessageString(msg.data(), MESSAGE_LENGTH, 5, getId());
bittorrent::setIntParam(&msg[5], index_);
return msg;
}
size_t IndexBtMessage::getMessageLength() { return MESSAGE_LENGTH; }
std::string IndexBtMessage::toString() const
{
return fmt("%s index=%lu", getName(), static_cast<unsigned long>(index_));

View File

@ -65,9 +65,7 @@ public:
size_t getIndex() const { return index_; }
virtual unsigned char* createMessage() CXX11_OVERRIDE;
virtual size_t getMessageLength() CXX11_OVERRIDE;
virtual std::vector<unsigned char> createMessage() CXX11_OVERRIDE;
virtual std::string toString() const CXX11_OVERRIDE;
};

View File

@ -64,7 +64,7 @@ namespace {
const size_t MAX_PAD_LENGTH = 512;
const size_t CRYPTO_BITFIELD_LENGTH = 4;
const unsigned char VC[] = {0, 0, 0, 0, 0, 0, 0, 0};
constexpr auto VC = std::array<unsigned char, MSEHandshake::VC_LENGTH>{};
const unsigned char* PRIME = reinterpret_cast<const unsigned char*>(
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B"
@ -123,13 +123,15 @@ void MSEHandshake::initEncryptionFacility(bool initiator)
void MSEHandshake::sendPublicKey()
{
A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Sending public key.", cuid_));
auto buf = make_unique<unsigned char[]>(KEY_LENGTH + MAX_PAD_LENGTH);
dh_->getPublicKey(buf.get(), KEY_LENGTH);
auto buf = std::vector<unsigned char>(KEY_LENGTH + MAX_PAD_LENGTH);
dh_->getPublicKey(buf.data(), KEY_LENGTH);
size_t padLength =
SimpleRandomizer::getInstance()->getRandomNumber(MAX_PAD_LENGTH + 1);
dh_->generateNonce(buf.get() + KEY_LENGTH, padLength);
socketBuffer_.pushBytes(buf.release(), KEY_LENGTH + padLength);
dh_->generateNonce(buf.data() + KEY_LENGTH, padLength);
buf.resize(KEY_LENGTH + padLength);
socketBuffer_.pushBytes(std::move(buf));
}
void MSEHandshake::read()
@ -209,16 +211,16 @@ void MSEHandshake::initCipher(const unsigned char* infoHash)
enc.init(peerCipherKey, sizeof(peerCipherKey));
// discard first 1024 bytes ARC4 output.
enc.encrypt(garbage.size(), garbage.data(), garbage.data());
enc.encrypt(VC_LENGTH, initiatorVCMarker_, VC);
enc.encrypt(VC_LENGTH, initiatorVCMarker_, VC.data());
}
}
// Given data is pushed to socketBuffer_ and data will be deleted by
// socketBuffer_.
void MSEHandshake::encryptAndSendData(unsigned char* data, size_t length)
void MSEHandshake::encryptAndSendData(std::vector<unsigned char> data)
{
encryptor_->encrypt(length, data, data);
socketBuffer_.pushBytes(data, length);
encryptor_->encrypt(data.size(), data.data(), data.data());
socketBuffer_.pushBytes(std::move(data));
}
void MSEHandshake::createReq1Hash(unsigned char* md) const
@ -264,27 +266,25 @@ void MSEHandshake::sendInitiatorStep2()
{
A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Sending negotiation step2.", cuid_));
// Assuming no exception
auto md = make_unique<unsigned char[]>((size_t)20);
createReq1Hash(md.get());
socketBuffer_.pushBytes(md.release(), 20);
auto md = std::vector<unsigned char>(20);
createReq1Hash(md.data());
socketBuffer_.pushBytes(std::move(md));
// Assuming no exception
md = make_unique<unsigned char[]>((size_t)20);
createReq23Hash(md.get(), infoHash_);
socketBuffer_.pushBytes(md.release(), 20);
md = std::vector<unsigned char>(20);
createReq23Hash(md.data(), infoHash_);
socketBuffer_.pushBytes(std::move(md));
// buffer is filled in this order:
// VC(VC_LENGTH bytes),
// crypto_provide(CRYPTO_BITFIELD_LENGTH bytes),
// len(padC)(2 bytes),
// padC(len(padC) bytes <= MAX_PAD_LENGTH),
// len(IA)(2 bytes)
auto buffer = make_unique<unsigned char[]>(
40 + VC_LENGTH + CRYPTO_BITFIELD_LENGTH + 2 + MAX_PAD_LENGTH + 2);
unsigned char* ptr = buffer.get();
auto buffer = std::vector<unsigned char>(VC_LENGTH + CRYPTO_BITFIELD_LENGTH +
2 + MAX_PAD_LENGTH + 2);
auto ptr = std::begin(buffer);
// VC
memcpy(ptr, VC, sizeof(VC));
ptr += sizeof(VC);
ptr += VC_LENGTH;
// crypto_provide
memset(ptr, 0, CRYPTO_BITFIELD_LENGTH);
if (!option_->getAsBool(PREF_BT_FORCE_ENCRYPTION) &&
option_->get(PREF_BT_MIN_CRYPTO_LEVEL) == V_PLAIN) {
ptr[3] = CRYPTO_PLAIN_TEXT;
@ -294,24 +294,21 @@ void MSEHandshake::sendInitiatorStep2()
// len(padC)
uint16_t padCLength =
SimpleRandomizer::getInstance()->getRandomNumber(MAX_PAD_LENGTH + 1);
{
uint16_t padCLengthBE = htons(padCLength);
memcpy(ptr, &padCLengthBE, sizeof(padCLengthBE));
}
ptr += 2;
uint16_t padCLengthBE = htons(padCLength);
ptr = std::copy_n(reinterpret_cast<unsigned char*>(&padCLengthBE),
sizeof(padCLengthBE), ptr);
// padC
memset(ptr, 0, padCLength);
ptr += padCLength;
// len(IA)
// currently, IA is zero-length.
uint16_t iaLength = 0;
{
uint16_t iaLengthBE = htons(iaLength);
memcpy(ptr, &iaLengthBE, sizeof(iaLengthBE));
ptr = std::copy_n(reinterpret_cast<unsigned char*>(&iaLengthBE),
sizeof(iaLengthBE), ptr);
}
ptr += 2;
size_t buflen = ptr - buffer.get();
encryptAndSendData(buffer.release(), buflen);
buffer.erase(ptr, std::end(buffer));
encryptAndSendData(std::move(buffer));
}
// This function reads exactly until the end of VC marker is reached.
@ -494,8 +491,8 @@ bool MSEHandshake::receiveReceiverIA()
wantRead_ = true;
return false;
}
ia_ = make_unique<unsigned char[]>(iaLength_);
decryptor_->encrypt(iaLength_, ia_.get(), rbuf_);
ia_ = std::vector<unsigned char>(iaLength_);
decryptor_->encrypt(iaLength_, ia_.data(), rbuf_);
A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - IA received.", cuid_));
// shift rbuf_
shiftBuffer(iaLength_);
@ -509,27 +506,24 @@ void MSEHandshake::sendReceiverStep2()
// cryptoSelect(CRYPTO_BITFIELD_LENGTH bytes),
// len(padD)(2bytes),
// padD(len(padD)bytes <= MAX_PAD_LENGTH)
auto buffer = make_unique<unsigned char[]>(
VC_LENGTH + CRYPTO_BITFIELD_LENGTH + 2 + MAX_PAD_LENGTH);
unsigned char* ptr = buffer.get();
auto buffer = std::vector<unsigned char>(VC_LENGTH + CRYPTO_BITFIELD_LENGTH +
2 + MAX_PAD_LENGTH);
auto ptr = std::begin(buffer);
// VC
memcpy(ptr, VC, sizeof(VC));
ptr += sizeof(VC);
ptr += VC_LENGTH;
// crypto_select
memset(ptr, 0, CRYPTO_BITFIELD_LENGTH);
ptr[3] = negotiatedCryptoType_;
ptr += CRYPTO_BITFIELD_LENGTH;
// len(padD)
uint16_t padDLength =
SimpleRandomizer::getInstance()->getRandomNumber(MAX_PAD_LENGTH + 1);
uint16_t padDLengthBE = htons(padDLength);
memcpy(ptr, &padDLengthBE, sizeof(padDLengthBE));
ptr += sizeof(padDLengthBE);
ptr = std::copy_n(reinterpret_cast<unsigned char*>(&padDLengthBE),
sizeof(padDLengthBE), ptr);
// padD, all zeroed
memset(ptr, 0, padDLength);
ptr += padDLength;
size_t buflen = ptr - buffer.get();
encryptAndSendData(buffer.release(), buflen);
buffer.erase(ptr, std::end(buffer));
encryptAndSendData(std::move(buffer));
}
uint16_t MSEHandshake::verifyPadLength(const unsigned char* padlenbuf,
@ -549,7 +543,7 @@ void MSEHandshake::verifyVC(unsigned char* vcbuf)
{
A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Verifying VC.", cuid_));
decryptor_->encrypt(VC_LENGTH, vcbuf, vcbuf);
if (memcmp(VC, vcbuf, VC_LENGTH) != 0) {
if (!std::equal(std::begin(VC), std::end(VC), vcbuf)) {
throw DL_ABORT_EX(
fmt("Invalid VC: %s", util::toHex(vcbuf, VC_LENGTH).c_str()));
}

View File

@ -67,14 +67,15 @@ public:
CRYPTO_ARC4 = 0x02u
};
static constexpr size_t VC_LENGTH = 8U;
private:
static const size_t PRIME_BITS = 768U;
static const size_t KEY_LENGTH = (PRIME_BITS + 7U) / 8U;
static const size_t VC_LENGTH = 8U;
static constexpr size_t PRIME_BITS = 768U;
static constexpr size_t KEY_LENGTH = (PRIME_BITS + 7U) / 8U;
// The largest buffering occurs when receiver receives step2
// handshake. We believe that IA is less than or equal to
// BtHandshakeMessage::MESSAGE_LENGTH
static const size_t MAX_BUFFER_LENGTH = 636U;
static constexpr size_t MAX_BUFFER_LENGTH = 636U;
cuid_t cuid_;
std::shared_ptr<SocketCore> socket_;
@ -97,10 +98,10 @@ private:
size_t markerIndex_;
uint16_t padLength_;
uint16_t iaLength_;
std::unique_ptr<unsigned char[]> ia_;
std::vector<unsigned char> ia_;
std::unique_ptr<MessageDigest> sha1_;
void encryptAndSendData(unsigned char* data, size_t length);
void encryptAndSendData(std::vector<unsigned char> data);
void createReq1Hash(unsigned char* md) const;
@ -171,7 +172,7 @@ public:
void sendReceiverStep2();
// returns plain text IA
const unsigned char* getIA() const { return ia_.get(); }
const unsigned char* getIA() const { return ia_.data(); }
size_t getIALength() const { return iaLength_; }

View File

@ -83,13 +83,13 @@ PeerConnection::PeerConnection(cuid_t cuid, const std::shared_ptr<Peer>& peer,
PeerConnection::~PeerConnection() {}
void PeerConnection::pushBytes(unsigned char* data, size_t len,
void PeerConnection::pushBytes(std::vector<unsigned char> data,
std::unique_ptr<ProgressUpdate> progressUpdate)
{
if (encryptionEnabled_) {
encryptor_->encrypt(len, data, data);
encryptor_->encrypt(data.size(), data.data(), data.data());
}
socketBuffer_.pushBytes(data, len, std::move(progressUpdate));
socketBuffer_.pushBytes(std::move(data), std::move(progressUpdate));
}
bool PeerConnection::receiveMessage(unsigned char* data, size_t& dataLength)

View File

@ -95,7 +95,7 @@ public:
// Pushes data into send buffer. After this call, this object gets
// ownership of data, so caller must not delete or alter it.
void pushBytes(unsigned char* data, size_t len,
void pushBytes(std::vector<unsigned char> data,
std::unique_ptr<ProgressUpdate> progressUpdate =
std::unique_ptr<ProgressUpdate>{});

View File

@ -45,7 +45,7 @@ RangeBtMessage::RangeBtMessage(uint8_t id, const char* name, size_t index,
{
}
unsigned char* RangeBtMessage::createMessage()
std::vector<unsigned char> RangeBtMessage::createMessage()
{
/**
* len --- 13, 4bytes
@ -55,16 +55,14 @@ unsigned char* RangeBtMessage::createMessage()
* length -- length, 4bytes
* total: 17bytes
*/
auto msg = new unsigned char[MESSAGE_LENGTH];
bittorrent::createPeerMessageString(msg, MESSAGE_LENGTH, 13, getId());
auto msg = std::vector<unsigned char>(MESSAGE_LENGTH);
bittorrent::createPeerMessageString(msg.data(), MESSAGE_LENGTH, 13, getId());
bittorrent::setIntParam(&msg[5], index_);
bittorrent::setIntParam(&msg[9], begin_);
bittorrent::setIntParam(&msg[13], length_);
return msg;
}
size_t RangeBtMessage::getMessageLength() { return MESSAGE_LENGTH; }
std::string RangeBtMessage::toString() const
{
return fmt("%s index=%lu, begin=%d, length=%d", getName(),

View File

@ -75,9 +75,7 @@ public:
void setLength(int32_t length) { length_ = length; }
virtual unsigned char* createMessage() CXX11_OVERRIDE;
virtual size_t getMessageLength() CXX11_OVERRIDE;
virtual std::vector<unsigned char> createMessage() CXX11_OVERRIDE;
virtual std::string toString() const CXX11_OVERRIDE;
};

View File

@ -604,6 +604,35 @@ void RequestGroup::initPieceStorage()
segmentMan_ =
std::make_shared<SegmentMan>(downloadContext_, tempPieceStorage);
pieceStorage_ = tempPieceStorage;
#ifdef __MINGW32__
// Windows build: --file-allocation=falloc uses SetFileValidData
// which requires SE_MANAGE_VOLUME_NAME privilege. SetFileValidData
// has security implications (see
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365544%28v=vs.85%29.aspx).
static auto gainPrivilegeAttempted = false;
if (!gainPrivilegeAttempted &&
pieceStorage_->getDiskAdaptor()->getFileAllocationMethod() ==
DiskAdaptor::FILE_ALLOC_FALLOC &&
isFileAllocationEnabled()) {
if (!util::gainPrivilege(SE_MANAGE_VOLUME_NAME)) {
A2_LOG_WARN("--file-allocation=falloc will not work properly.");
}
else {
A2_LOG_DEBUG("SE_MANAGE_VOLUME_NAME privilege acquired");
A2_LOG_WARN(
"--file-allocation=falloc will use SetFileValidData() API, and "
"aria2 uses uninitialized disk space which may contain "
"confidential data as the download file space. If it is "
"undesirable, --file-allocation=prealloc is slower, but safer "
"option.");
}
gainPrivilegeAttempted = true;
}
#endif // __MINGW32__
}
void RequestGroup::dropPieceStorage()

View File

@ -56,11 +56,10 @@ void SimpleBtMessage::send()
A2_LOG_INFO(fmt(MSG_SEND_PEER_MESSAGE, getCuid(),
getPeer()->getIPAddress().c_str(), getPeer()->getPort(),
toString().c_str()));
unsigned char* msg = createMessage();
size_t msgLength = getMessageLength();
auto msg = createMessage();
A2_LOG_DEBUG(
fmt("msglength = %lu bytes", static_cast<unsigned long>(msgLength)));
getPeerConnection()->pushBytes(msg, msgLength, getProgressUpdate());
fmt("msglength = %lu bytes", static_cast<unsigned long>(msg.size())));
getPeerConnection()->pushBytes(std::move(msg), getProgressUpdate());
}
std::unique_ptr<ProgressUpdate> SimpleBtMessage::getProgressUpdate()

View File

@ -37,6 +37,8 @@
#include "AbstractBtMessage.h"
#include <vector>
namespace aria2 {
struct ProgressUpdate;
@ -47,9 +49,7 @@ public:
virtual void send() CXX11_OVERRIDE;
virtual unsigned char* createMessage() = 0;
virtual size_t getMessageLength() = 0;
virtual std::vector<unsigned char> createMessage() = 0;
virtual std::unique_ptr<ProgressUpdate> getProgressUpdate();

View File

@ -47,31 +47,34 @@
namespace aria2 {
SocketBuffer::ByteArrayBufEntry::ByteArrayBufEntry(
unsigned char* bytes, size_t length,
std::vector<unsigned char> bytes,
std::unique_ptr<ProgressUpdate> progressUpdate)
: BufEntry(std::move(progressUpdate)), bytes_(bytes), length_(length)
: BufEntry(std::move(progressUpdate)), bytes_(std::move(bytes))
{
}
SocketBuffer::ByteArrayBufEntry::~ByteArrayBufEntry() { delete[] bytes_; }
SocketBuffer::ByteArrayBufEntry::~ByteArrayBufEntry() {}
ssize_t
SocketBuffer::ByteArrayBufEntry::send(const std::shared_ptr<SocketCore>& socket,
size_t offset)
{
return socket->writeData(bytes_ + offset, length_ - offset);
return socket->writeData(bytes_.data() + offset, bytes_.size() - offset);
}
bool SocketBuffer::ByteArrayBufEntry::final(size_t offset) const
{
return length_ <= offset;
return bytes_.size() <= offset;
}
size_t SocketBuffer::ByteArrayBufEntry::getLength() const { return length_; }
size_t SocketBuffer::ByteArrayBufEntry::getLength() const
{
return bytes_.size();
}
const unsigned char* SocketBuffer::ByteArrayBufEntry::getData() const
{
return bytes_;
return bytes_.data();
}
SocketBuffer::StringBufEntry::StringBufEntry(
@ -106,12 +109,12 @@ SocketBuffer::SocketBuffer(std::shared_ptr<SocketCore> socket)
SocketBuffer::~SocketBuffer() {}
void SocketBuffer::pushBytes(unsigned char* bytes, size_t len,
void SocketBuffer::pushBytes(std::vector<unsigned char> bytes,
std::unique_ptr<ProgressUpdate> progressUpdate)
{
if (len > 0) {
bufq_.push_back(
make_unique<ByteArrayBufEntry>(bytes, len, std::move(progressUpdate)));
if (!bytes.empty()) {
bufq_.push_back(make_unique<ByteArrayBufEntry>(std::move(bytes),
std::move(progressUpdate)));
}
}

View File

@ -40,6 +40,7 @@
#include <string>
#include <deque>
#include <memory>
#include <vector>
namespace aria2 {
@ -77,7 +78,7 @@ private:
class ByteArrayBufEntry : public BufEntry {
public:
ByteArrayBufEntry(unsigned char* bytes, size_t length,
ByteArrayBufEntry(std::vector<unsigned char> bytes,
std::unique_ptr<ProgressUpdate> progressUpdate);
virtual ~ByteArrayBufEntry();
virtual ssize_t send(const std::shared_ptr<SocketCore>& socket,
@ -87,8 +88,7 @@ private:
virtual const unsigned char* getData() const CXX11_OVERRIDE;
private:
unsigned char* bytes_;
size_t length_;
std::vector<unsigned char> bytes_;
};
class StringBufEntry : public BufEntry {
@ -123,13 +123,11 @@ public:
SocketBuffer(const SocketBuffer&) = delete;
SocketBuffer& operator=(const SocketBuffer&) = delete;
// Feeds data pointed by bytes with length len into queue. This
// object gets ownership of bytes, so caller must not delete or
// later bytes after this call. This function doesn't send data. If
// Feeds |bytes| into queue. This function doesn't send data. If
// progressUpdate is not null, its update() function will be called
// each time the data is sent. It will be deleted by this object. It
// can be null.
void pushBytes(unsigned char* bytes, size_t len,
void pushBytes(std::vector<unsigned char> bytes,
std::unique_ptr<ProgressUpdate> progressUpdate = nullptr);
// Feeds data into queue. This function doesn't send data. If

View File

@ -42,20 +42,18 @@ ZeroBtMessage::ZeroBtMessage(uint8_t id, const char* name)
{
}
unsigned char* ZeroBtMessage::createMessage()
std::vector<unsigned char> ZeroBtMessage::createMessage()
{
/**
* len --- 1, 4bytes
* id --- ?, 1byte
* total: 5bytes
*/
auto msg = new unsigned char[MESSAGE_LENGTH];
bittorrent::createPeerMessageString(msg, MESSAGE_LENGTH, 1, getId());
auto msg = std::vector<unsigned char>(MESSAGE_LENGTH);
bittorrent::createPeerMessageString(msg.data(), MESSAGE_LENGTH, 1, getId());
return msg;
}
size_t ZeroBtMessage::getMessageLength() { return MESSAGE_LENGTH; }
std::string ZeroBtMessage::toString() const { return getName(); }
} // namespace aria2

View File

@ -56,9 +56,7 @@ protected:
public:
ZeroBtMessage(uint8_t id, const char* name);
virtual unsigned char* createMessage() CXX11_OVERRIDE;
virtual size_t getMessageLength() CXX11_OVERRIDE;
virtual std::vector<unsigned char> createMessage() CXX11_OVERRIDE;
virtual std::string toString() const CXX11_OVERRIDE;
};

View File

@ -341,16 +341,6 @@ error_code::Value option_processing(Option& op, bool standalone,
op.remove(PREF_DEFERRED_INPUT);
}
#ifdef __MINGW32__
if (op.get(PREF_FILE_ALLOCATION) == V_FALLOC) {
A2_LOG_WARN(
"--file-allocation=falloc will use SetFileValidData() API, and "
"aria2 uses uninitialized disk space which may contain "
"confidential data as the download file space. If it is "
"undesirable, --file-allocation=prealloc is slower, but safer option.");
}
#endif // __MINGW32__
return error_code::FINISHED;
}

View File

@ -70,9 +70,9 @@ void BtAllowedFastMessageTest::testCreateMessage()
unsigned char data[9];
bittorrent::createPeerMessageString(data, sizeof(data), 5, 17);
bittorrent::setIntParam(&data[5], 12345);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 9) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)9, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtAllowedFastMessageTest::testDoReceivedAction()

View File

@ -76,10 +76,9 @@ void BtBitfieldMessageTest::testCreateMessage()
unsigned char data[5 + 2];
bittorrent::createPeerMessageString(data, sizeof(data), 3, 5);
memcpy(&data[5], bitfield, sizeof(bitfield));
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 7) == 0);
delete[] rawmsg;
CPPUNIT_ASSERT_EQUAL((size_t)7, msg.getMessageLength());
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)7, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtBitfieldMessageTest::testDoReceivedAction()

View File

@ -95,9 +95,9 @@ void BtCancelMessageTest::testCreateMessage()
bittorrent::setIntParam(&data[5], 12345);
bittorrent::setIntParam(&data[9], 256);
bittorrent::setIntParam(&data[13], 1_k);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 17) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)17, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtCancelMessageTest::testDoReceivedAction()

View File

@ -109,9 +109,9 @@ void BtChokeMessageTest::testCreateMessage()
BtChokeMessage msg;
unsigned char data[5];
bittorrent::createPeerMessageString(data, sizeof(data), 1, 0);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 5) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)5, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtChokeMessageTest::testDoReceivedAction()

View File

@ -78,10 +78,9 @@ void BtExtendedMessageTest::testCreateMessage()
bittorrent::createPeerMessageString(data, sizeof(data), 13, 20);
*(data + 5) = extendedMessageID;
memcpy(data + 6, payload.c_str(), payload.size());
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 17) == 0);
delete[] rawmsg;
CPPUNIT_ASSERT_EQUAL((size_t)17, msg.getMessageLength());
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)17, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtExtendedMessageTest::testDoReceivedAction()

View File

@ -73,23 +73,23 @@ void BtHandshakeMessageTest::testCreate()
void BtHandshakeMessageTest::testCreateMessage()
{
unsigned char infoHash[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
unsigned char peerId[] = {0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0};
constexpr unsigned char infoHash[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
constexpr unsigned char peerId[] = {0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0};
std::shared_ptr<BtHandshakeMessage> msg(new BtHandshakeMessage());
auto msg = std::make_shared<BtHandshakeMessage>();
msg->setInfoHash(infoHash);
msg->setPeerId(peerId);
unsigned char data[68];
createHandshakeMessageData(data);
unsigned char* rawmsg = msg->createMessage();
auto rawmsg = msg->createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)68, rawmsg.size());
CPPUNIT_ASSERT_EQUAL(util::toHex((const unsigned char*)data, 68),
util::toHex(rawmsg, 68));
delete[] rawmsg;
util::toHex(rawmsg.data(), 68));
}
void BtHandshakeMessageTest::testToString()

View File

@ -65,9 +65,9 @@ void BtHaveAllMessageTest::testCreateMessage()
BtHaveAllMessage msg;
unsigned char data[5];
bittorrent::createPeerMessageString(data, sizeof(data), 1, 14);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 5) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)5, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtHaveAllMessageTest::testDoReceivedAction()

View File

@ -71,9 +71,9 @@ void BtHaveMessageTest::testCreateMessage()
unsigned char data[9];
bittorrent::createPeerMessageString(data, sizeof(data), 5, 4);
bittorrent::setIntParam(&data[5], 12345);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 9) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)9, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtHaveMessageTest::testDoReceivedAction()

View File

@ -62,9 +62,9 @@ void BtHaveNoneMessageTest::testCreateMessage()
BtHaveNoneMessage msg;
unsigned char data[5];
bittorrent::createPeerMessageString(data, sizeof(data), 1, 15);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 5) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)5, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtHaveNoneMessageTest::testDoReceivedAction()

View File

@ -64,9 +64,9 @@ void BtInterestedMessageTest::testCreateMessage()
BtInterestedMessage msg;
unsigned char data[5];
bittorrent::createPeerMessageString(data, sizeof(data), 1, 2);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 5) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)5, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtInterestedMessageTest::testDoReceivedAction()

View File

@ -27,10 +27,9 @@ void BtKeepAliveMessageTest::testCreateMessage()
memset(data, 0, sizeof(data));
BtKeepAliveMessage message;
CPPUNIT_ASSERT_EQUAL((uint8_t)99, message.getId());
CPPUNIT_ASSERT_EQUAL((size_t)4, message.getMessageLength());
unsigned char* rawmsg = message.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 4) == 0);
delete[] rawmsg;
auto rawmsg = message.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)4, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtKeepAliveMessageTest::testToString()

View File

@ -64,9 +64,9 @@ void BtNotInterestedMessageTest::testCreateMessage()
BtNotInterestedMessage msg;
unsigned char data[5];
bittorrent::createPeerMessageString(data, sizeof(data), 1, 3);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 5) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)5, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtNotInterestedMessageTest::testDoReceivedAction()

View File

@ -99,9 +99,9 @@ void BtPortMessageTest::testCreateMessage()
unsigned char data[7];
bittorrent::createPeerMessageString(data, sizeof(data), 3, 9);
bittorrent::setShortIntParam(&data[5], 6881);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 7) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)7, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtPortMessageTest::testDoReceivedAction()

View File

@ -129,9 +129,9 @@ void BtRejectMessageTest::testCreateMessage()
bittorrent::setIntParam(&data[5], 12345);
bittorrent::setIntParam(&data[9], 256);
bittorrent::setIntParam(&data[13], 1_k);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 17) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)17, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtRejectMessageTest::testDoReceivedAction()

View File

@ -151,9 +151,9 @@ void BtRequestMessageTest::testCreateMessage()
bittorrent::setIntParam(&data[5], 12345);
bittorrent::setIntParam(&data[9], 256);
bittorrent::setIntParam(&data[13], 1_k);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 17) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)17, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtRequestMessageTest::testDoReceivedAction_hasPieceAndAmNotChoking()

View File

@ -62,9 +62,9 @@ void BtSuggestPieceMessageTest::testCreateMessage()
unsigned char data[9];
bittorrent::createPeerMessageString(data, sizeof(data), 5, 13);
bittorrent::setIntParam(&data[5], 12345);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 9) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)9, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtSuggestPieceMessageTest::testToString()

View File

@ -64,9 +64,9 @@ void BtUnchokeMessageTest::testCreateMessage()
BtUnchokeMessage msg;
unsigned char data[5];
bittorrent::createPeerMessageString(data, sizeof(data), 1, 1);
unsigned char* rawmsg = msg.createMessage();
CPPUNIT_ASSERT(memcmp(rawmsg, data, 5) == 0);
delete[] rawmsg;
auto rawmsg = msg.createMessage();
CPPUNIT_ASSERT_EQUAL((size_t)5, rawmsg.size());
CPPUNIT_ASSERT(std::equal(std::begin(rawmsg), std::end(rawmsg), data));
}
void BtUnchokeMessageTest::testDoReceivedAction()