2009-01-07 06:53:29 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2009-2014 Mnemosyne LLC
|
2006-07-16 19:39:23 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2006-07-16 19:39:23 +00:00
|
|
|
*
|
2009-01-07 06:53:29 +00:00
|
|
|
*/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2017-11-14 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "transmission.h"
|
2011-03-28 16:31:05 +00:00
|
|
|
#include "bitfield.h"
|
2017-04-21 07:40:57 +00:00
|
|
|
#include "utils.h" /* tr_getRatio() */
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_completion
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_torrent* tor;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-11 17:29:14 +00:00
|
|
|
// Changed to non-owning pointer temporarily till tr_completion becomes C++-constructible and destructible
|
|
|
|
// TODO: remove * and own the value
|
|
|
|
Bitfield* blockBitfield;
|
2011-02-15 16:04:56 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* number of bytes we'll have when done downloading. [0..info.totalSize]
|
|
|
|
DON'T access this directly; it's a lazy field.
|
2017-04-21 07:40:57 +00:00
|
|
|
use tr_cpSizeWhenDone() instead! */
|
2017-04-19 12:04:45 +00:00
|
|
|
uint64_t sizeWhenDoneLazy;
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* whether or not sizeWhenDone needs to be recalculated */
|
|
|
|
bool sizeWhenDoneIsDirty;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* number of bytes we'll have when done downloading. [0..info.totalSize]
|
|
|
|
DON'T access this directly; it's a lazy field.
|
2017-04-21 07:40:57 +00:00
|
|
|
use tr_cpHaveValid() instead! */
|
2017-04-19 12:04:45 +00:00
|
|
|
uint64_t haveValidLazy;
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* whether or not haveValidLazy needs to be recalculated */
|
|
|
|
bool haveValidIsDirty;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* number of bytes we want or have now. [0..sizeWhenDone] */
|
|
|
|
uint64_t sizeNow;
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
/**
|
|
|
|
*** Life Cycle
|
|
|
|
**/
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_cpConstruct(tr_completion*, tr_torrent*);
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2021-10-11 17:29:14 +00:00
|
|
|
void tr_cpBlockInit(tr_completion* cp, Bitfield const& blocks);
|
2011-03-29 01:17:18 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static inline void tr_cpDestruct(tr_completion* cp)
|
2011-03-29 01:17:18 +00:00
|
|
|
{
|
2021-10-11 17:29:14 +00:00
|
|
|
delete cp->blockBitfield;
|
2011-03-29 01:17:18 +00:00
|
|
|
}
|
2009-01-02 17:01:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** General
|
|
|
|
**/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
double tr_cpPercentComplete(tr_completion const* cp);
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
double tr_cpPercentDone(tr_completion const* cp);
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_completeness tr_cpGetStatus(tr_completion const*);
|
2011-02-15 16:04:56 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
uint64_t tr_cpHaveValid(tr_completion const*);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
uint64_t tr_cpSizeWhenDone(tr_completion const*);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
uint64_t tr_cpLeftUntilDone(tr_completion const*);
|
2011-09-26 06:18:48 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_cpGetAmountDone(tr_completion const* completion, float* tab, int tabCount);
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr uint64_t tr_cpHaveTotal(tr_completion const* cp)
|
2011-03-29 01:17:18 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return cp->sizeNow;
|
2011-03-29 01:17:18 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static inline bool tr_cpHasAll(tr_completion const* cp)
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
2021-10-11 17:29:14 +00:00
|
|
|
return tr_torrentHasMetadata(cp->tor) && cp->blockBitfield->hasAll();
|
2009-01-02 17:01:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static inline bool tr_cpHasNone(tr_completion const* cp)
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
2021-10-11 17:29:14 +00:00
|
|
|
return !tr_torrentHasMetadata(cp->tor) || cp->blockBitfield->hasNone();
|
2009-01-02 17:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-03-28 16:31:05 +00:00
|
|
|
*** Pieces
|
2009-01-02 17:01:55 +00:00
|
|
|
**/
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_cpPieceAdd(tr_completion* cp, tr_piece_index_t i);
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_cpPieceRem(tr_completion* cp, tr_piece_index_t i);
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
size_t tr_cpMissingBlocksInPiece(tr_completion const*, tr_piece_index_t);
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
size_t tr_cpMissingBytesInPiece(tr_completion const*, tr_piece_index_t);
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static inline bool tr_cpPieceIsComplete(tr_completion const* cp, tr_piece_index_t i)
|
2011-02-23 03:54:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return tr_cpMissingBlocksInPiece(cp, i) == 0;
|
2011-02-23 03:54:04 +00:00
|
|
|
}
|
2009-01-02 17:01:55 +00:00
|
|
|
|
|
|
|
/**
|
2011-03-28 16:31:05 +00:00
|
|
|
*** Blocks
|
2009-01-02 17:01:55 +00:00
|
|
|
**/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_cpBlockAdd(tr_completion* cp, tr_block_index_t i);
|
2011-03-29 01:17:18 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static inline bool tr_cpBlockIsComplete(tr_completion const* cp, tr_block_index_t i)
|
2009-04-11 03:24:36 +00:00
|
|
|
{
|
2021-10-11 17:29:14 +00:00
|
|
|
return cp->blockBitfield->readBit(i);
|
2009-04-11 03:24:36 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
/***
|
2011-03-28 16:31:05 +00:00
|
|
|
**** Misc
|
2009-01-02 17:01:55 +00:00
|
|
|
***/
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_cpFileIsComplete(tr_completion const* cp, tr_file_index_t);
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void* tr_cpCreatePieceBitfield(tr_completion const* cp, size_t* byte_count);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-06 22:24:04 +00:00
|
|
|
constexpr void tr_cpInvalidateDND(tr_completion* cp)
|
2011-03-29 01:17:18 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
cp->sizeWhenDoneIsDirty = true;
|
2011-03-29 01:17:18 +00:00
|
|
|
}
|