Skip to content

Commit

Permalink
Adding logic to decide which pieces are to be downloaded vs those tha…
Browse files Browse the repository at this point in the history
…t are not based on config (hardcoded 64megs).
  • Loading branch information
ngerakines committed Feb 1, 2011
1 parent e6060f7 commit 8a04164
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.markdown
Expand Up @@ -3,6 +3,15 @@
Oxen is a hybrid torrent client that aims to allow peers with small ammounts Oxen is a hybrid torrent client that aims to allow peers with small ammounts
of disk space the ability to positively impact a peer group. of disk space the ability to positively impact a peer group.


# Status

So far you can ...

* Start the application and monitor a directory for new torrents.
* Add new torrents to the system
* Set a max memory usage value (defaulting to 64 megs)
* Download up to that max and seed any pieces known

# USAGE # USAGE


$ ./oxen --directory /tmp/torrents/ $ ./oxen --directory /tmp/torrents/
Expand Down
4 changes: 3 additions & 1 deletion src/Config.hpp
Expand Up @@ -7,7 +7,7 @@ namespace oxen {


class Config { class Config {
public: public:
Config() : directory_("/tmp") { } Config() : directory_("/tmp"), maxMemory_(64) { }
~Config() { } ~Config() { }


void directory(std::string directory) { void directory(std::string directory) {
Expand All @@ -16,9 +16,11 @@ class Config {
std::string directory() { std::string directory() {
return directory_; return directory_;
} }
int maxMemory() { return maxMemory_; }


private: private:
std::string directory_; std::string directory_;
int maxMemory_;
}; };


} }
Expand Down
26 changes: 23 additions & 3 deletions src/Core.cpp
Expand Up @@ -47,13 +47,15 @@ void Core::run() {
if (ti_->size() > index) { if (ti_->size() > index) {
for (int i = index; i < ti_->size(); i++) { for (int i = index; i < ti_->size(); i++) {
libtorrent::torrent_info *t = ti_->at(i); libtorrent::torrent_info *t = ti_->at(i);
calculatePiecePriority(t); #if 1
libtorrent::add_torrent_params parms; libtorrent::add_torrent_params parms;
parms.save_path = savePath; parms.save_path = savePath;
parms.ti = t; parms.ti = t;
parms.auto_managed = true; parms.auto_managed = true;
parms.storage = libtorrent::temp_storage_constructor; parms.storage = libtorrent::temp_storage_constructor;
session_->add_torrent(parms); libtorrent::torrent_handle handle = session_->add_torrent(parms);
calculatePiecePriority(t, handle);
#endif
} }
index = ti_->size(); index = ti_->size();
} }
Expand All @@ -66,12 +68,30 @@ libtorrent::session* Core::session() {
return session_; return session_;
} }


void Core::calculatePiecePriority(libtorrent::torrent_info * /* torrent */) { void Core::calculatePiecePriority(libtorrent::torrent_info *torrent, libtorrent::torrent_handle handle) {
/* Given the total size of the torrent and number of pieces, determine /* Given the total size of the torrent and number of pieces, determine
* which pieces should be marked as priority 0 (don't download) and * which pieces should be marked as priority 0 (don't download) and
* which should be marked 4 (normal). This should take into account * which should be marked 4 (normal). This should take into account
* the availability of a piece, time that the piece has been seeded * the availability of a piece, time that the piece has been seeded
* and some sort of fuzzy ratio approximation. */ * and some sort of fuzzy ratio approximation. */
cout << "torrent has " << torrent->num_pieces() << " pieces." << endl;
cout << "each piece is " << torrent->piece_length() << " long." << endl;
cout << "total size is " << torrent->total_size() << " long." << endl;

int maxMem = config_->maxMemory() * 1048576;
cout << "given that maxMemory is " << config_->maxMemory() << " megs (" << maxMem << ") ..." << endl;
if (maxMem > torrent->total_size()) {
cout << "we can seed all pieces at once." << endl;
} else {
cout << "we can seed " << (maxMem / torrent->piece_length()) << " pieces at once." << endl;
int pieceCount = (maxMem / torrent->piece_length());
for (int i = 0; i < pieceCount; i++) {
handle.piece_priority(i, 7);
}
for (int i = pieceCount; i < torrent->num_pieces(); i++) {
handle.piece_priority(i, 0);
}
}
} }




Expand Down
2 changes: 1 addition & 1 deletion src/Core.hpp
Expand Up @@ -27,7 +27,7 @@ class Core {
libtorrent::session *session_; libtorrent::session *session_;


void run(); void run();
void calculatePiecePriority(libtorrent::torrent_info *torrent); void calculatePiecePriority(libtorrent::torrent_info *torrent, libtorrent::torrent_handle handle);
}; };


} }
Expand Down

0 comments on commit 8a04164

Please sign in to comment.