Skip to content
Browse files

Adding logic to decide which pieces are to be downloaded vs those tha…

…t are not based on config (hardcoded 64megs).
  • Loading branch information...
1 parent e6060f7 commit 8a04164f6cda836b466c397e70730eecef9c1dab @ngerakines committed
Showing with 36 additions and 5 deletions.
  1. +9 −0 README.markdown
  2. +3 −1 src/Config.hpp
  3. +23 −3 src/Core.cpp
  4. +1 −1 src/Core.hpp
View
9 README.markdown
@@ -3,6 +3,15 @@
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.
+# 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
$ ./oxen --directory /tmp/torrents/
View
4 src/Config.hpp
@@ -7,7 +7,7 @@ namespace oxen {
class Config {
public:
- Config() : directory_("/tmp") { }
+ Config() : directory_("/tmp"), maxMemory_(64) { }
~Config() { }
void directory(std::string directory) {
@@ -16,9 +16,11 @@ class Config {
std::string directory() {
return directory_;
}
+ int maxMemory() { return maxMemory_; }
private:
std::string directory_;
+ int maxMemory_;
};
}
View
26 src/Core.cpp
@@ -47,13 +47,15 @@ void Core::run() {
if (ti_->size() > index) {
for (int i = index; i < ti_->size(); i++) {
libtorrent::torrent_info *t = ti_->at(i);
- calculatePiecePriority(t);
+#if 1
libtorrent::add_torrent_params parms;
parms.save_path = savePath;
parms.ti = t;
parms.auto_managed = true;
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();
}
@@ -66,12 +68,30 @@ libtorrent::session* Core::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
* which pieces should be marked as priority 0 (don't download) and
* which should be marked 4 (normal). This should take into account
* the availability of a piece, time that the piece has been seeded
* 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);
+ }
+ }
}
View
2 src/Core.hpp
@@ -27,7 +27,7 @@ class Core {
libtorrent::session *session_;
void run();
- void calculatePiecePriority(libtorrent::torrent_info *torrent);
+ void calculatePiecePriority(libtorrent::torrent_info *torrent, libtorrent::torrent_handle handle);
};
}

0 comments on commit 8a04164

Please sign in to comment.
Something went wrong with that request. Please try again.