Skip to content

Commit

Permalink
add sequential_download mode
Browse files Browse the repository at this point in the history
Signed-off-by: Date Huang <[email protected]>
  • Loading branch information
tjjh89017 committed Apr 2, 2024
1 parent 7a2ef37 commit e3e03d8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void ezio::wait(int interval_second)
}
}

void ezio::add_torrent(std::string torrent_body, std::string save_path, bool seeding_mode = false, int max_uploads = 3, int max_connections = 5)
void ezio::add_torrent(std::string torrent_body, std::string save_path, bool seeding_mode = false, int max_uploads = 3, int max_connections = 5, bool sequential_download = false)
{
lt::span<const char> torrent_byte(torrent_body);

Expand All @@ -59,6 +59,10 @@ void ezio::add_torrent(std::string torrent_body, std::string save_path, bool see
atp.flags |= libtorrent::torrent_flags::seed_mode;
}

if (sequential_download) {
atp.flags |= libtorrent::torrent_flags::sequential_download;
}

if (ec) {
throw std::invalid_argument("failed to save path");
}
Expand Down
2 changes: 1 addition & 1 deletion daemon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ezio : boost::noncopyable

void stop();
void wait(int interval_second);
void add_torrent(std::string torrent_body, std::string save_path, bool seeding_mode, int max_uploads, int max_connections);
void add_torrent(std::string torrent_body, std::string save_path, bool seeding_mode, int max_uploads, int max_connections, bool sequential_download);
std::map<std::string, torrent_status> get_torrent_status(std::vector<std::string> hashes);
void pause_torrent(std::string hash);
void resume_torrent(std::string hash);
Expand Down
2 changes: 2 additions & 0 deletions ezio.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ message AddRequest {
int32 max_uploads = 4;
// max total connection
int32 max_connections = 5;
// force sequential download
bool sequential_download = 6;
}

message AddResponse {
Expand Down
2 changes: 1 addition & 1 deletion service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Status gRPCService::AddTorrent(ServerContext *context,
SPDLOG_INFO("AddTorrent");

try {
daemon_.add_torrent(request->torrent(), request->save_path(), request->seeding_mode(), request->max_uploads(), request->max_connections());
daemon_.add_torrent(request->torrent(), request->save_path(), request->seeding_mode(), request->max_uploads(), request->max_connections(), request->sequential_download());
} catch (const std::exception &e) {
return Status(grpc::StatusCode::UNAVAILABLE, e.what());
}
Expand Down
1 change: 1 addition & 0 deletions utils/ezio_add_torrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
request = ezio_pb2.AddRequest()
request.max_uploads = 2
request.max_connections = 3
request.sequential_download = True
request.save_path = sys.argv[2]
with open(sys.argv[1], 'rb') as f:
request.torrent = f.read()
Expand Down

0 comments on commit e3e03d8

Please sign in to comment.