[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/network/ktorrent
From: Joris Guisson <joris.guisson () gmail ! com>
Date: 2009-04-01 7:21:31
Message-ID: 1238570491.982083.25969.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 947690 by guisson:
- Use bytes (instead of chunks) to calculate availability percentage of a peer,this \
fixes 188575
- Keep track of last chunk size in Torrent class, so that we don't have to \
recalculate it all the time
BUG: 188575
M +1 -0 ChangeLog
M +1 -3 ktorrent/importdialog.cpp
M +1 -1 libbtcore/datachecker/multidatachecker.cpp
M +1 -2 libbtcore/datachecker/singledatachecker.cpp
M +2 -18 libbtcore/diskio/multifilecache.cpp
M +1 -1 libbtcore/diskio/singlefilecache.cpp
M +3 -3 libbtcore/download/downloader.cpp
M +4 -4 libbtcore/download/webseed.cpp
M +12 -2 libbtcore/peer/peer.cpp
M +12 -9 libbtcore/torrent/torrent.cpp
M +8 -4 libbtcore/torrent/torrent.h
M +2 -2 libbtcore/torrent/torrentcontrol.cpp
--- trunk/extragear/network/ktorrent/ChangeLog #947689:947690
@@ -20,6 +20,7 @@
- Don't send body of login page when redirecting to login page (188209)
- VideoWidget now inhibits screensaver
- Add feature to support a different speed limit when the screensaver is activated \
(172660) +- Use bytes to calculate availability percentage of a peer (188575)
Changes in 3.2.1 :
- Resort torrents if display name is changed
--- trunk/extragear/network/ktorrent/ktorrent/importdialog.cpp #947689:947690
@@ -338,9 +338,7 @@
Uint64 ImportDialog::calcImportedBytes(const bt::BitSet & chunks,const Torrent & \
tor) {
Uint64 nb = 0;
- Uint64 ls = tor.getFileLength() % tor.getChunkSize();
- if (ls == 0)
- ls = tor.getChunkSize();
+ Uint64 ls = tor.getLastChunkSize();
for (Uint32 i = 0;i < chunks.getNumBits();i++)
{
--- trunk/extragear/network/ktorrent/libbtcore/datachecker/multidatachecker.cpp \
#947689:947690 @@ -65,7 +65,7 @@
for (cur_chunk = 0;cur_chunk < num_chunks;cur_chunk++)
{
- Uint32 cs = (cur_chunk == num_chunks - 1) ? tor.getFileLength() % chunk_size : \
chunk_size; + Uint32 cs = (cur_chunk == num_chunks - 1) ? tor.getLastChunkSize() : \
chunk_size; if (cs == 0)
cs = chunk_size;
if (!loadChunk(cur_chunk,cs,tor))
--- trunk/extragear/network/ktorrent/libbtcore/datachecker/singledatachecker.cpp \
#947689:947690 @@ -75,8 +75,7 @@
if (!fptr.eof())
{
// read the chunk
- Uint32 size = i == num_chunks - 1 && tor.getFileLength() % tor.getChunkSize() > \
0 ?
- tor.getFileLength() % tor.getChunkSize() : (Uint32)tor.getChunkSize();
+ Uint32 size = i == num_chunks - 1 ? tor.getLastChunkSize() : tor.getChunkSize();
fptr.seek(File::BEGIN,(Int64)i*tor.getChunkSize());
fptr.read(buf,size);
--- trunk/extragear/network/ktorrent/libbtcore/diskio/multifilecache.cpp \
#947689:947690 @@ -768,15 +768,7 @@
if (!fptr.open(src_file,"rb"))
throw Error(i18n("Cannot open file %1 : %2",src_file,fptr.errorString()));
- Uint32 cs = 0;
- if (tf->getFirstChunk() == tor.getNumChunks() - 1)
- {
- cs = tor.getFileLength() % tor.getChunkSize();
- if (cs == 0)
- cs = tor.getChunkSize();
- }
- else
- cs = tor.getChunkSize();
+ Uint32 cs = (tf->getFirstChunk() == tor.getNumChunks() - 1) ? \
tor.getLastChunkSize() : tor.getChunkSize();
Uint8* tmp = new Uint8[tor.getChunkSize()];
try
@@ -834,15 +826,7 @@
}
}
- Uint32 cs = 0;
- if (tf->getFirstChunk() == tor.getNumChunks() - 1)
- {
- cs = tor.getFileLength() % tor.getChunkSize();
- if (cs == 0)
- cs = tor.getChunkSize();
- }
- else
- cs = tor.getChunkSize();
+ Uint32 cs = (tf->getFirstChunk() == tor.getNumChunks() - 1) ? \
tor.getLastChunkSize() : tor.getChunkSize();
File fptr;
if (!fptr.open(output_file,"r+b"))
--- trunk/extragear/network/ktorrent/libbtcore/diskio/singlefilecache.cpp \
#947689:947690 @@ -242,7 +242,7 @@
try
{
fd = new CacheFile();
- fd->open(output_file,tor.getFileLength());
+ fd->open(output_file,tor.getTotalSize());
}
catch (...)
{
--- trunk/extragear/network/ktorrent/libbtcore/download/downloader.cpp #947689:947690
@@ -60,7 +60,7 @@
else
chunk_selector = fac->createChunkSelector(cman,*this,pman);
- Uint64 total = tor.getFileLength();
+ Uint64 total = tor.getTotalSize();
downloaded = (total - cman.bytesLeft());
curr_chunks_downloaded = 0;
unnecessary_data = 0;
@@ -582,7 +582,7 @@
return;
// recalculate downloaded bytes
- downloaded = (tor.getFileLength() - cman.bytesLeft());
+ downloaded = (tor.getTotalSize() - cman.bytesLeft());
CurrentChunksHeader chdr;
fptr.read(&chdr,sizeof(CurrentChunksHeader));
@@ -738,7 +738,7 @@
void Downloader::recalcDownloaded()
{
- Uint64 total = tor.getFileLength();
+ Uint64 total = tor.getTotalSize();
downloaded = (total - cman.bytesLeft());
}
--- trunk/extragear/network/ktorrent/libbtcore/download/webseed.cpp #947689:947690
@@ -195,8 +195,8 @@
{
Uint64 len = (last_chunk - first_chunk) * tor.getChunkSize();
// last chunk can have a different size
- if (last_chunk == tor.getNumChunks() - 1 && tor.getFileLength() % \
tor.getChunkSize() > 0)
- len += tor.getFileLength() % tor.getChunkSize();
+ if (last_chunk == tor.getNumChunks() - 1)
+ len += tor.getLastChunkSize();
else
len += tor.getChunkSize();
@@ -242,8 +242,8 @@
{
Uint64 len = (last_chunk - first_chunk) * tor.getChunkSize();
// last chunk can have a different size
- if (last_chunk == tor.getNumChunks() - 1 && tor.getFileLength() % \
tor.getChunkSize() > 0)
- len += tor.getFileLength() % tor.getChunkSize();
+ if (last_chunk == tor.getNumChunks() - 1)
+ len += tor.getLastChunkSize();
else
len += tor.getChunkSize();
--- trunk/extragear/network/ktorrent/libbtcore/peer/peer.cpp #947689:947690
@@ -30,7 +30,7 @@
#include <bcodec/bdecoder.h>
#include <bcodec/bnode.h>
#include <torrent/server.h>
-
+#include <torrent/torrent.h>
#include "packetreader.h"
#include "packetwriter.h"
#include "peerdownloader.h"
@@ -538,7 +538,17 @@
float Peer::percentAvailable() const
{
- return (float)pieces.numOnBits() / (float)pieces.getNumBits() * 100.0;
+ // calculation needs to use bytes, instead of chunks, because
+ // the last chunk can have a different size
+ const Torrent & tor = pman->getTorrent();
+ Uint64 bytes = 0;
+ if (pieces.get(tor.getNumChunks() - 1))
+ bytes = tor.getChunkSize() * (pieces.numOnBits() - 1) + tor.getLastChunkSize();
+ else
+ bytes = tor.getChunkSize() * pieces.numOnBits();
+
+ Uint64 tbytes = tor.getChunkSize() * (pieces.getNumBits() - 1) + \
tor.getLastChunkSize(); + return (float)bytes / (float)tbytes * 100.0;
}
const PeerInterface::Stats & Peer::getStats() const
--- trunk/extragear/network/ktorrent/libbtcore/torrent/torrent.cpp #947689:947690
@@ -52,7 +52,7 @@
}
#endif
- Torrent::Torrent() : \
piece_length(0),file_length(0),priv_torrent(false),pos_cache_chunk(0),pos_cache_file(0),tmon(0)
+ Torrent::Torrent() : \
chunk_size(0),total_size(0),priv_torrent(false),pos_cache_chunk(0),pos_cache_file(0),tmon(0)
{
text_codec = QTextCodec::codecForName("utf-8");
trackers = 0;
@@ -145,12 +145,12 @@
if (!dict)
throw Error(i18n("Corrupted torrent."));
- piece_length = dict->getInt64("piece length");
+ chunk_size = dict->getInt64("piece length");
BListNode* files = dict->getList("files");
if (files)
loadFiles(files);
else
- file_length = dict->getInt64("length");
+ total_size = dict->getInt64("length");
loadHash(dict);
unencoded_name = dict->getByteArray("name");
@@ -163,9 +163,12 @@
priv_torrent = true;
// do a safety check to see if the number of hashes matches the file_length
- Uint32 num_chunks = (file_length / this->piece_length);
- if (file_length % piece_length > 0)
+ Uint32 num_chunks = (total_size / chunk_size);
+ last_chunk_size = total_size % chunk_size;
+ if (last_chunk_size > 0)
num_chunks++;
+ else
+ last_chunk_size = chunk_size;
if (num_chunks != (Uint32)hash_pieces.count())
{
@@ -211,11 +214,11 @@
throw Error(i18n("Corrupted torrent."));
Uint64 s = d->getInt64("length");
- TorrentFile file(this,idx,path,file_length,s,piece_length);
+ TorrentFile file(this,idx,path,total_size,s,chunk_size);
file.setUnencodedPath(unencoded_path);
// update file_length
- file_length += s;
+ total_size += s;
files.append(file);
idx++;
}
@@ -307,7 +310,7 @@
// for (KUrl::List::iterator i = tracker_urls.begin();i != tracker_urls.end();i++)
// Out(SYS_GEN|LOG_DEBUG) << "Tracker URL : " << *i << endl;
- Out(SYS_GEN|LOG_DEBUG) << "Piece Length : " << piece_length << endl;
+ Out(SYS_GEN|LOG_DEBUG) << "Piece Length : " << chunk_size << endl;
if (this->isMultiFile())
{
Out(SYS_GEN|LOG_DEBUG) << "Files : " << endl;
@@ -326,7 +329,7 @@
}
else
{
- Out(SYS_GEN|LOG_DEBUG) << "File Length : " << file_length << endl;
+ Out(SYS_GEN|LOG_DEBUG) << "File Length : " << total_size << endl;
}
Out(SYS_GEN|LOG_DEBUG) << "Pieces : " << hash_pieces.size() << endl;
}
--- trunk/extragear/network/ktorrent/libbtcore/torrent/torrent.h #947689:947690
@@ -133,8 +133,11 @@
Uint32 getNumChunks() const {return hash_pieces.size();}
/// Get the size of a chunk.
- Uint64 getChunkSize() const {return piece_length;}
+ Uint64 getChunkSize() const {return chunk_size;}
+ /// Get the size of the last chunk
+ Uint64 getLastChunkSize() const {return last_chunk_size;}
+
/// Get the info_hash.
const SHA1Hash & getInfoHash() const {return info_hash;}
@@ -142,7 +145,7 @@
const PeerID & getPeerID() const {return peer_id;}
/// Get the file size in number of bytes.
- Uint64 getFileLength() const {return file_length;}
+ Uint64 getTotalSize() const {return total_size;}
/// Get the suggested name.
QString getNameSuggestion() const {return name_suggestion;}
@@ -257,8 +260,9 @@
TrackerTier* trackers;
QString name_suggestion;
QByteArray unencoded_name;
- Uint64 piece_length;
- Uint64 file_length;
+ Uint64 chunk_size;
+ Uint64 last_chunk_size;
+ Uint64 total_size;
SHA1Hash info_hash;
PeerID peer_id;
QVector<SHA1Hash> hash_pieces;
--- trunk/extragear/network/ktorrent/libbtcore/torrent/torrentcontrol.cpp \
#947689:947690 @@ -604,7 +604,7 @@
stats.running = false;
stats.torrent_name = tor->getNameSuggestion();
stats.multi_file_torrent = tor->isMultiFile();
- stats.total_bytes = tor->getFileLength();
+ stats.total_bytes = tor->getTotalSize();
stats.priv_torrent = tor->isPrivate();
// check the stats file for the custom_output_name variable
@@ -1230,7 +1230,7 @@
stats.num_chunks_excluded = cman ? cman->chunksExcluded() : 0;
stats.chunk_size = tor ? tor->getChunkSize() : 0;
stats.num_chunks_left = cman ? cman->chunksLeft() : 0;
- stats.total_bytes_to_download = (tor && cman) ? tor->getFileLength() - \
cman->bytesExcluded() : 0; + stats.total_bytes_to_download = (tor && cman) ? \
tor->getTotalSize() - cman->bytesExcluded() : 0;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic