Skip to content

Commit

Permalink
Update aria2 to 1.37.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
MouriNaruto committed Nov 16, 2023
1 parent 088dc23 commit 6dd0223
Show file tree
Hide file tree
Showing 54 changed files with 300 additions and 167 deletions.
4 changes: 2 additions & 2 deletions Documents/BuildOriginalAria2.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ make install -j8
make clean
https://github.com/aria2/aria2/releases/download/release-1.36.0/aria2-1.36.0.tar.xz
https://github.com/aria2/aria2/releases/download/release-1.37.0/aria2-1.37.0.tar.xz
cd /c/msys2/aria2-1.36.0
cd /c/msys2/aria2-1.37.0
autoreconf -ifv
Expand Down
6 changes: 3 additions & 3 deletions Mile.Aria2.Library/AbstractDiskWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ ssize_t AbstractDiskWriter::writeDataInternal(const unsigned char* data,
size_t len, int64_t offset)
{
if (mapaddr_) {
memcpy(mapaddr_ + offset, data, len);
std::copy_n(data, len, mapaddr_ + offset);
return len;
}
else {
Expand Down Expand Up @@ -298,7 +298,7 @@ ssize_t AbstractDiskWriter::readDataInternal(unsigned char* data, size_t len,
return 0;
}
auto readlen = std::min(maplen_ - offset, static_cast<int64_t>(len));
memcpy(data, mapaddr_ + offset, readlen);
std::copy_n(mapaddr_ + offset, readlen, data);
return readlen;
}
else {
Expand Down Expand Up @@ -597,7 +597,7 @@ void AbstractDiskWriter::flushOSBuffers()
}
#ifdef __MINGW32__
FlushFileBuffers(fd_);
#else // !__MINGW32__
#else // !__MINGW32__
fsync(fd_);
#endif // __MINGW32__
}
Expand Down
29 changes: 15 additions & 14 deletions Mile.Aria2.Library/BitfieldMan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ BitfieldMan::BitfieldMan(int32_t blockLength, int64_t totalLength)
bitfieldLength_ = blocks_ / 8 + (blocks_ % 8 ? 1 : 0);
bitfield_ = new unsigned char[bitfieldLength_];
useBitfield_ = new unsigned char[bitfieldLength_];
memset(bitfield_, 0, bitfieldLength_);
memset(useBitfield_, 0, bitfieldLength_);
std::fill_n(bitfield_, bitfieldLength_, 0);
std::fill_n(useBitfield_, bitfieldLength_, 0);
updateCache();
}
}
Expand All @@ -85,11 +85,11 @@ BitfieldMan::BitfieldMan(const BitfieldMan& bitfieldMan)
blockLength_(bitfieldMan.blockLength_),
filterEnabled_(bitfieldMan.filterEnabled_)
{
memcpy(bitfield_, bitfieldMan.bitfield_, bitfieldLength_);
memcpy(useBitfield_, bitfieldMan.useBitfield_, bitfieldLength_);
std::copy_n(bitfieldMan.bitfield_, bitfieldLength_, bitfield_);
std::copy_n(bitfieldMan.useBitfield_, bitfieldLength_, useBitfield_);
if (filterEnabled_) {
filterBitfield_ = new unsigned char[bitfieldLength_];
memcpy(filterBitfield_, bitfieldMan.filterBitfield_, bitfieldLength_);
std::copy_n(bitfieldMan.filterBitfield_, bitfieldLength_, filterBitfield_);
}
updateCache();
}
Expand All @@ -105,16 +105,17 @@ BitfieldMan& BitfieldMan::operator=(const BitfieldMan& bitfieldMan)

delete[] bitfield_;
bitfield_ = new unsigned char[bitfieldLength_];
memcpy(bitfield_, bitfieldMan.bitfield_, bitfieldLength_);
std::copy_n(bitfieldMan.bitfield_, bitfieldLength_, bitfield_);

delete[] useBitfield_;
useBitfield_ = new unsigned char[bitfieldLength_];
memcpy(useBitfield_, bitfieldMan.useBitfield_, bitfieldLength_);
std::copy_n(bitfieldMan.useBitfield_, bitfieldLength_, useBitfield_);

delete[] filterBitfield_;
if (filterEnabled_) {
filterBitfield_ = new unsigned char[bitfieldLength_];
memcpy(filterBitfield_, bitfieldMan.filterBitfield_, bitfieldLength_);
std::copy_n(bitfieldMan.filterBitfield_, bitfieldLength_,
filterBitfield_);
}
else {
filterBitfield_ = nullptr;
Expand Down Expand Up @@ -662,17 +663,17 @@ bool BitfieldMan::isUseBitSet(size_t index) const
void BitfieldMan::setBitfield(const unsigned char* bitfield,
size_t bitfieldLength)
{
if (bitfieldLength_ != bitfieldLength) {
if (bitfieldLength_ == 0 || bitfieldLength_ != bitfieldLength) {
return;
}
memcpy(bitfield_, bitfield, bitfieldLength_);
memset(useBitfield_, 0, bitfieldLength_);
std::copy_n(bitfield, bitfieldLength_, bitfield_);
std::fill_n(useBitfield_, bitfieldLength_, 0);
updateCache();
}

void BitfieldMan::clearAllBit()
{
memset(bitfield_, 0, bitfieldLength_);
std::fill_n(bitfield_, bitfieldLength_, 0);
updateCache();
}

Expand All @@ -686,7 +687,7 @@ void BitfieldMan::setAllBit()

void BitfieldMan::clearAllUseBit()
{
memset(useBitfield_, 0, bitfieldLength_);
std::fill_n(useBitfield_, bitfieldLength_, 0);
updateCache();
}

Expand All @@ -706,7 +707,7 @@ void BitfieldMan::ensureFilterBitfield()
{
if (!filterBitfield_) {
filterBitfield_ = new unsigned char[bitfieldLength_];
memset(filterBitfield_, 0, bitfieldLength_);
std::fill_n(filterBitfield_, bitfieldLength_, 0);
}
}

Expand Down
3 changes: 1 addition & 2 deletions Mile.Aria2.Library/BtChokingEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@

namespace aria2 {

class BtChokingEvent {
};
class BtChokingEvent {};

} // namespace aria2

Expand Down
8 changes: 4 additions & 4 deletions Mile.Aria2.Library/BtLeecherStateChoke.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void BtLeecherStateChoke::PeerEntry::swap(PeerEntry& c)
swap(regularUnchoker_, c.regularUnchoker_);
}

BtLeecherStateChoke::PeerEntry& BtLeecherStateChoke::PeerEntry::
operator=(const PeerEntry& c)
BtLeecherStateChoke::PeerEntry&
BtLeecherStateChoke::PeerEntry::operator=(const PeerEntry& c)
{
if (this != &c) {
peer_ = c.peer_;
Expand Down Expand Up @@ -130,8 +130,8 @@ void swap(BtLeecherStateChoke::PeerEntry& a, BtLeecherStateChoke::PeerEntry& b)
a.swap(b);
}

bool BtLeecherStateChoke::PeerFilter::
operator()(const PeerEntry& peerEntry) const
bool BtLeecherStateChoke::PeerFilter::operator()(
const PeerEntry& peerEntry) const
{
return peerEntry.getPeer()->amChoking() == amChoking_ &&
peerEntry.getPeer()->peerInterested() == peerInterested_;
Expand Down
4 changes: 2 additions & 2 deletions Mile.Aria2.Library/BtSeederStateChoke.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ void BtSeederStateChoke::PeerEntry::swap(PeerEntry& c)
swap(uploadSpeed_, c.uploadSpeed_);
}

BtSeederStateChoke::PeerEntry& BtSeederStateChoke::PeerEntry::
operator=(const PeerEntry& c)
BtSeederStateChoke::PeerEntry&
BtSeederStateChoke::PeerEntry::operator=(const PeerEntry& c)
{
if (this != &c) {
peer_ = c.peer_;
Expand Down
4 changes: 3 additions & 1 deletion Mile.Aria2.Library/BufferedFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ int BufferedFile::onClose()
#else // __MINGW32__
_commit(fileno(fp_));
#endif // __MINGW32__
rv = fclose(fp_);
if (fp_ != stdin && fp_ != stderr) {
rv = fclose(fp_);
}
fp_ = nullptr;
}
return rv;
Expand Down
2 changes: 1 addition & 1 deletion Mile.Aria2.Library/ByteArrayDiskWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ByteArrayDiskWriter : public DiskWriter {
void clear();

public:
ByteArrayDiskWriter(size_t maxLength = 5_m);
ByteArrayDiskWriter(size_t maxLength = 15_m);
virtual ~ByteArrayDiskWriter();

virtual void initAndOpenFile(int64_t totalLength = 0) CXX11_OVERRIDE;
Expand Down
5 changes: 0 additions & 5 deletions Mile.Aria2.Library/ConsoleStatCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
namespace aria2 {

class SizeFormatter {
public:

typedef int64_t argument_type;
typedef std::string result_type;

protected:
virtual std::string format(int64_t size) const = 0;

Expand Down
28 changes: 14 additions & 14 deletions Mile.Aria2.Library/Context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,23 +270,23 @@ Context::Context(bool standalone, int argc, char** argv, const KeyVals& options)
}
else
#endif // ENABLE_METALINK
if (!op->blank(PREF_INPUT_FILE)) {
if (op->getAsBool(PREF_DEFERRED_INPUT)) {
uriListParser = openUriListParser(op->get(PREF_INPUT_FILE));
if (!op->blank(PREF_INPUT_FILE)) {
if (op->getAsBool(PREF_DEFERRED_INPUT)) {
uriListParser = openUriListParser(op->get(PREF_INPUT_FILE));
}
else {
createRequestGroupForUriList(requestGroups, op);
}
#if defined(ENABLE_BITTORRENT) || defined(ENABLE_METALINK)
}
else if (op->get(PREF_SHOW_FILES) == A2_V_TRUE) {
showFiles(args, op);
return;
#endif // ENABLE_METALINK || ENABLE_METALINK
}
else {
createRequestGroupForUriList(requestGroups, op);
createRequestGroupForUri(requestGroups, op, args, false, false, true);
}
#if defined(ENABLE_BITTORRENT) || defined(ENABLE_METALINK)
}
else if (op->get(PREF_SHOW_FILES) == A2_V_TRUE) {
showFiles(args, op);
return;
#endif // ENABLE_METALINK || ENABLE_METALINK
}
else {
createRequestGroupForUri(requestGroups, op, args, false, false, true);
}

// Remove option values which is only valid for URIs specified in
// command-line. If they are left, because op is used as a template
Expand Down
5 changes: 0 additions & 5 deletions Mile.Aria2.Library/CookieStorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,6 @@ class CookiePathDividerConverter {
namespace {
class OrderByPathDepthDesc {
public:

typedef Cookie first_argument_type;
typedef Cookie second_argument_type;
typedef bool result_type;

bool operator()(const CookiePathDivider& lhs,
const CookiePathDivider& rhs) const
{
Expand Down
6 changes: 3 additions & 3 deletions Mile.Aria2.Library/DHTPeerAnnounceStorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ DHTPeerAnnounceStorage::DHTPeerAnnounceStorage()
{
}

bool DHTPeerAnnounceStorage::InfoHashLess::
operator()(const std::shared_ptr<DHTPeerAnnounceEntry>& lhs,
const std::shared_ptr<DHTPeerAnnounceEntry>& rhs) const
bool DHTPeerAnnounceStorage::InfoHashLess::operator()(
const std::shared_ptr<DHTPeerAnnounceEntry>& lhs,
const std::shared_ptr<DHTPeerAnnounceEntry>& rhs) const
{
return memcmp(lhs->getInfoHash(), rhs->getInfoHash(), DHT_ID_LENGTH) < 0;
}
Expand Down
4 changes: 2 additions & 2 deletions Mile.Aria2.Library/DHTRoutingTableDeserializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ void DHTRoutingTableDeserializer::deserialize(const std::string& filename)

nodes.push_back(node);
}
localNode_ = localNode;
nodes_ = nodes;
localNode_ = std::move(localNode);
nodes_ = std::move(nodes);
A2_LOG_INFO("DHT routing table was loaded successfully");
}

Expand Down
2 changes: 1 addition & 1 deletion Mile.Aria2.Library/DHTSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DHTSetup {
~DHTSetup();

// Returns two vector of Commands. First one contains regular
// commands. Secod one contains so called routine commands, which
// commands. Second one contains so called routine commands, which
// executed once per event poll returns.
std::pair<std::vector<std::unique_ptr<Command>>,
std::vector<std::unique_ptr<Command>>>
Expand Down
18 changes: 12 additions & 6 deletions Mile.Aria2.Library/DefaultBtProgressInfoFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <cstring>
#include <cstdio>
#include <array>

#include "PieceStorage.h"
#include "Piece.h"
Expand All @@ -56,6 +57,7 @@
#include "DownloadContext.h"
#include "BufferedFile.h"
#include "SHA1IOFile.h"
#include "BtConstants.h"
#ifdef ENABLE_BITTORRENT
# include "PeerStorage.h"
# include "BtRuntime.h"
Expand Down Expand Up @@ -263,21 +265,21 @@ void DefaultBtProgressInfoFile::load()
if (version >= 1) {
infoHashLength = ntohl(infoHashLength);
}
if (infoHashLength == 0 && infoHashCheckEnabled) {
if (infoHashLength > INFO_HASH_LENGTH ||
(infoHashLength != INFO_HASH_LENGTH && infoHashCheckEnabled)) {
throw DL_ABORT_EX(fmt("Invalid info hash length: %d", infoHashLength));
}
if (infoHashLength > 0) {
auto savedInfoHash = make_unique<unsigned char[]>((size_t)infoHashLength);
READ_CHECK(fp, savedInfoHash.get(), infoHashLength);
std::array<unsigned char, INFO_HASH_LENGTH> savedInfoHash;
READ_CHECK(fp, savedInfoHash.data(), infoHashLength);
#ifdef ENABLE_BITTORRENT
if (infoHashCheckEnabled) {
const unsigned char* infoHash = bittorrent::getInfoHash(dctx_);
if (infoHashLength != INFO_HASH_LENGTH ||
memcmp(savedInfoHash.get(), infoHash, INFO_HASH_LENGTH) != 0) {
if (memcmp(savedInfoHash.data(), infoHash, INFO_HASH_LENGTH) != 0) {
throw DL_ABORT_EX(
fmt("info hash mismatch. expected: %s, actual: %s",
util::toHex(infoHash, INFO_HASH_LENGTH).c_str(),
util::toHex(savedInfoHash.get(), infoHashLength).c_str()));
util::toHex(savedInfoHash.data(), infoHashLength).c_str()));
}
}
#endif // ENABLE_BITTORRENT
Expand All @@ -289,6 +291,10 @@ void DefaultBtProgressInfoFile::load()
pieceLength = ntohl(pieceLength);
}

if (pieceLength == 0) {
throw DL_ABORT_EX("piece length must not be 0");
}

uint64_t totalLength;
READ_CHECK(fp, &totalLength, sizeof(totalLength));
if (version >= 1) {
Expand Down
2 changes: 1 addition & 1 deletion Mile.Aria2.Library/DiskAdaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DiskAdaptor : public BinaryStream {
virtual void writeCache(const WrDiskCacheEntry* entry) = 0;

// Force physical write of data from OS buffer cache.
virtual void flushOSBuffers() {};
virtual void flushOSBuffers(){};

void setFileAllocationMethod(FileAllocationMethod method)
{
Expand Down
2 changes: 1 addition & 1 deletion Mile.Aria2.Library/DiskWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DiskWriter : public BinaryStream {
virtual void closeFile() = 0;

/**
* Opens a file. If the file doesnot exists, an exception may be
* Opens a file. If the file does not exist, an exception may be
* thrown.
*/
virtual void openExistingFile(int64_t totalLength = 0) = 0;
Expand Down
6 changes: 3 additions & 3 deletions Mile.Aria2.Library/DownloadEngineFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ std::unique_ptr<EventPoll> createEventPoll(Option* op)
}
else
#endif // HAVE_POLL
if (pollMethod == V_SELECT) {
return make_unique<SelectEventPoll>();
}
if (pollMethod == V_SELECT) {
return make_unique<SelectEventPoll>();
}
assert(0);
return nullptr;
}
Expand Down
6 changes: 2 additions & 4 deletions Mile.Aria2.Library/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ class ADNSEvent : public Event<SocketEntry> {
};
#else // !ENABLE_ASYNC_DNS
template <typename SocketEntry, typename EventPoll>
class ADNSEvent : public Event<SocketEntry> {
};
class ADNSEvent : public Event<SocketEntry> {};
#endif // !ENABLE_ASYNC_DNS

template <typename CommandEvent, typename ADNSEvent> class SocketEntry {
Expand Down Expand Up @@ -362,8 +361,7 @@ template <typename EventPoll> class AsyncNameResolverEntry {
}
};
#else // !ENABLE_ASYNC_DNS
template <typename EventPoll> class AsyncNameResolverEntry {
};
template <typename EventPoll> class AsyncNameResolverEntry {};
#endif // !ENABLE_ASYNC_DNS

} // namespace aria2
Expand Down
Loading

0 comments on commit 6dd0223

Please sign in to comment.