torrent-magnet.c
tr-dht.c
trevent.c
+ tr-assert.c
tr-getopt.c
tr-lpd.c
tr-udp.c
quark.h
rpcimpl.h
session-id.h
+ tr-assert.h
tr-getopt.h
transmission.h
utils.h
torrent.c \
torrent-ctor.c \
torrent-magnet.c \
+ tr-assert.c \
tr-dht.c \
tr-lpd.c \
tr-udp.c \
torrent-magnet.h \
tr-getopt.h \
transmission.h \
+ tr-assert.h \
tr-dht.h \
tr-udp.h \
tr-utp.h \
#include "peer-io.h"
#include "peer-mgr.h" /* tr_peerMgrCompactToPex() */
#include "ptrarray.h"
+#include "tr-assert.h"
#include "tr-udp.h"
#include "utils.h"
static void tau_tracker_free(struct tau_tracker* t)
{
- assert(t->dns_request == NULL);
+ TR_ASSERT(t->dns_request == NULL);
if (t->addr != NULL)
{
tr_ptrArray* reqs;
time_t const now = tr_time();
- assert(tracker->dns_request == NULL);
- assert(tracker->connecting_at == 0);
- assert(tracker->addr != NULL);
- assert(tracker->connection_expiration_time > now);
+ TR_ASSERT(tracker->dns_request == NULL);
+ TR_ASSERT(tracker->connecting_at == 0);
+ TR_ASSERT(tracker->addr != NULL);
+ TR_ASSERT(tracker->connection_expiration_time > now);
reqs = &tracker->announces;
*
*/
-#include <assert.h>
#include <limits.h> /* INT_MAX */
#include <stdio.h>
#include <stdlib.h> /* qsort() */
#include "ptrarray.h"
#include "session.h"
#include "torrent.h"
+#include "tr-assert.h"
#include "utils.h"
struct tr_tier;
{
tr_announcer* a;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
a = tr_new0(tr_announcer, 1);
a->stops = TR_PTR_ARRAY_INIT;
{
tr_torrent_tiers* tiers;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tiers = tiersNew();
tiers->callback = callback;
{
struct tr_torrent_tiers* tt = NULL;
- assert(tr_isTorrent(tor));
- assert(tor->tiers != NULL);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tor->tiers != NULL);
if (tor->isRunning)
{
static void tier_announce_event_push(tr_tier* tier, tr_announce_event e, time_t announceAt)
{
- assert(tier != NULL);
+ TR_ASSERT(tier != NULL);
dbgmsg_tier_announce_queue(tier);
dbgmsg(tier, "queued \"%s\"", tr_announce_event_get_string(e));
{
struct tr_torrent_tiers* tt = tor->tiers;
- assert(tr_isTorrent(tor));
- assert(type == TR_ANN_UP || type == TR_ANN_DOWN || type == TR_ANN_CORRUPT);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(type == TR_ANN_UP || type == TR_ANN_DOWN || type == TR_ANN_CORRUPT);
for (int i = 0; i < tt->tier_count; ++i)
{
tr_torrent* tor = tier->tor;
time_t const now = tr_time();
- assert(!tier->isAnnouncing);
- assert(tier->announce_event_count > 0);
+ TR_ASSERT(!tier->isAnnouncing);
+ TR_ASSERT(tier->announce_event_count > 0);
announce_event = tier_announce_event_pull(tier);
req = announce_request_new(announcer, tor, tier, announce_event);
struct tr_torrent_tiers* tt;
time_t const now = tr_time();
- assert(tr_isTorrent(torrent));
+ TR_ASSERT(tr_isTorrent(torrent));
tt = torrent->tiers;
tr_tier const keep = *tgt;
/* sanity clause */
- assert(trackerIndex < tgt->tracker_count);
- assert(tr_strcmp0(tgt->trackers[trackerIndex].announce, src->currentTracker->announce) == 0);
+ TR_ASSERT(trackerIndex < tgt->tracker_count);
+ TR_ASSERT(tr_strcmp0(tgt->trackers[trackerIndex].announce, src->currentTracker->announce) == 0);
/* bitwise copy will handle most of tr_tier's fields... */
*tgt = *src;
struct tr_torrent_tiers* tt = tor->tiers;
tr_torrent_tiers old = *tt;
- assert(tt != NULL);
+ TR_ASSERT(tt != NULL);
/* remove the old tiers / trackers */
tt->tiers = NULL;
*
*/
-#include <assert.h>
#include <string.h> /* memset() */
#include "transmission.h"
#include "crypto-utils.h" /* tr_rand_int_weak() */
#include "log.h"
#include "peer-io.h"
+#include "tr-assert.h"
#include "utils.h"
#define dbgmsg(...) tr_logAddDeepNamed(NULL, __VA_ARGS__)
void tr_bandwidthDestruct(tr_bandwidth* b)
{
- assert(tr_isBandwidth(b));
+ TR_ASSERT(tr_isBandwidth(b));
tr_bandwidthSetParent(b, NULL);
tr_ptrArrayDestruct(&b->children, NULL);
void tr_bandwidthSetParent(tr_bandwidth* b, tr_bandwidth* parent)
{
- assert(tr_isBandwidth(b));
- assert(b != parent);
+ TR_ASSERT(tr_isBandwidth(b));
+ TR_ASSERT(b != parent);
if (b->parent != NULL)
{
- assert(tr_isBandwidth(b->parent));
+ TR_ASSERT(tr_isBandwidth(b->parent));
tr_ptrArrayRemoveSortedPointer(&b->parent->children, b, compareBandwidth);
b->parent = NULL;
}
if (parent != NULL)
{
- assert(tr_isBandwidth(parent));
- assert(parent->parent != b);
+ TR_ASSERT(tr_isBandwidth(parent));
+ TR_ASSERT(parent->parent != b);
- assert(tr_ptrArrayFindSorted(&parent->children, b, compareBandwidth) == NULL);
+ TR_ASSERT(tr_ptrArrayFindSorted(&parent->children, b, compareBandwidth) == NULL);
tr_ptrArrayInsertSorted(&parent->children, b, compareBandwidth);
- assert(tr_ptrArrayFindSorted(&parent->children, b, compareBandwidth) == b);
+ TR_ASSERT(tr_ptrArrayFindSorted(&parent->children, b, compareBandwidth) == b);
b->parent = parent;
}
}
{
tr_priority_t const priority = MAX(parent_priority, b->priority);
- assert(tr_isBandwidth(b));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isBandwidth(b));
+ TR_ASSERT(tr_isDirection(dir));
/* set the available bandwidth */
if (b->band[dir].isLimited)
void tr_bandwidthSetPeer(tr_bandwidth* b, tr_peerIo* peer)
{
- assert(tr_isBandwidth(b));
- assert(peer == NULL || tr_isPeerIo(peer));
+ TR_ASSERT(tr_isBandwidth(b));
+ TR_ASSERT(peer == NULL || tr_isPeerIo(peer));
b->peer = peer;
}
static unsigned int bandwidthClamp(tr_bandwidth const* b, uint64_t now, tr_direction dir, unsigned int byteCount)
{
- assert(tr_isBandwidth(b));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isBandwidth(b));
+ TR_ASSERT(tr_isDirection(dir));
if (b != NULL)
{
unsigned int tr_bandwidthGetRawSpeed_Bps(tr_bandwidth const* b, uint64_t const now, tr_direction const dir)
{
- assert(tr_isBandwidth(b));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isBandwidth(b));
+ TR_ASSERT(tr_isDirection(dir));
return getSpeed_Bps(&b->band[dir].raw, HISTORY_MSEC, now);
}
unsigned int tr_bandwidthGetPieceSpeed_Bps(tr_bandwidth const* b, uint64_t const now, tr_direction const dir)
{
- assert(tr_isBandwidth(b));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isBandwidth(b));
+ TR_ASSERT(tr_isDirection(dir));
return getSpeed_Bps(&b->band[dir].piece, HISTORY_MSEC, now);
}
{
struct tr_band* band;
- assert(tr_isBandwidth(b));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isBandwidth(b));
+ TR_ASSERT(tr_isDirection(dir));
band = &b->band[dir];
#pragma once
-#include <assert.h>
-
#include "transmission.h"
#include "ptrarray.h"
+#include "tr-assert.h"
#include "utils.h" /* tr_new(), tr_free() */
struct tr_peerIo;
static inline bool tr_bandwidthAreParentLimitsHonored(tr_bandwidth const* bandwidth, tr_direction direction)
{
- assert(tr_isBandwidth(bandwidth));
- assert(tr_isDirection(direction));
+ TR_ASSERT(tr_isBandwidth(bandwidth));
+ TR_ASSERT(tr_isDirection(direction));
return bandwidth->band[direction].honorParentLimits;
}
*
*/
-#include <assert.h>
#include <string.h> /* memset */
#include "transmission.h"
#include "bitfield.h"
+#include "tr-assert.h"
#include "utils.h" /* tr_new0() */
tr_bitfield const TR_BITFIELD_INIT = { NULL, 0, 0, 0, false, false };
return 0;
}
- assert(begin < end);
- assert(b->bits != NULL);
+ TR_ASSERT(begin < end);
+ TR_ASSERT(b->bits != NULL);
if (first_byte == last_byte)
{
}
}
- assert(ret <= (begin - end));
+ TR_ASSERT(ret <= (begin - end));
return ret;
}
****
***/
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
static bool tr_bitfieldIsValid(tr_bitfield const* b)
{
- assert(b != NULL);
- assert((b->alloc_count == 0) == (b->bits == NULL));
- assert(b->bits == NULL || b->true_count == countArray(b));
+ TR_ASSERT(b != NULL);
+ TR_ASSERT((b->alloc_count == 0) == (b->bits == NULL));
+ TR_ASSERT(b->bits == NULL || b->true_count == countArray(b));
return true;
}
size_t tr_bitfieldCountTrueBits(tr_bitfield const* b)
{
- assert(tr_bitfieldIsValid(b));
+ TR_ASSERT(tr_bitfieldIsValid(b));
return b->true_count;
}
size_t const n = get_bytes_needed(b->bit_count);
uint8_t* bits = tr_new0(uint8_t, n);
- assert(b->bit_count > 0);
+ TR_ASSERT(b->bit_count > 0);
if (b->alloc_count != 0)
{
- assert(b->alloc_count <= n);
+ TR_ASSERT(b->alloc_count <= n);
memcpy(bits, b->bits, b->alloc_count);
}
else if (tr_bitfieldHasAll(b))
static void tr_bitfieldSetTrueCount(tr_bitfield* b, size_t n)
{
- assert(b->bit_count == 0 || n <= b->bit_count);
+ TR_ASSERT(b->bit_count == 0 || n <= b->bit_count);
b->true_count = n;
tr_bitfieldFreeArray(b);
}
- assert(tr_bitfieldIsValid(b));
+ TR_ASSERT(tr_bitfieldIsValid(b));
}
static void tr_bitfieldRebuildTrueCount(tr_bitfield* b)
static void tr_bitfieldIncTrueCount(tr_bitfield* b, size_t i)
{
- assert(b->bit_count == 0 || i <= b->bit_count);
- assert(b->bit_count == 0 || b->true_count <= b->bit_count - i);
+ TR_ASSERT(b->bit_count == 0 || i <= b->bit_count);
+ TR_ASSERT(b->bit_count == 0 || b->true_count <= b->bit_count - i);
tr_bitfieldSetTrueCount(b, b->true_count + i);
}
static void tr_bitfieldDecTrueCount(tr_bitfield* b, size_t i)
{
- assert(b->bit_count == 0 || i <= b->bit_count);
- assert(b->bit_count == 0 || b->true_count >= i);
+ TR_ASSERT(b->bit_count == 0 || i <= b->bit_count);
+ TR_ASSERT(b->bit_count == 0 || b->true_count >= i);
tr_bitfieldSetTrueCount(b, b->true_count - i);
}
b->have_all_hint = false;
b->have_none_hint = false;
- assert(tr_bitfieldIsValid(b));
+ TR_ASSERT(tr_bitfieldIsValid(b));
}
void tr_bitfieldSetHasNone(tr_bitfield* b)
b->have_all_hint = false;
b->have_none_hint = true;
- assert(tr_bitfieldIsValid(b));
+ TR_ASSERT(tr_bitfieldIsValid(b));
}
void tr_bitfieldSetHasAll(tr_bitfield* b)
b->have_all_hint = true;
b->have_none_hint = false;
- assert(tr_bitfieldIsValid(b));
+ TR_ASSERT(tr_bitfieldIsValid(b));
}
void tr_bitfieldSetFromBitfield(tr_bitfield* b, tr_bitfield const* src)
{
/* ensure the excess bits are set to '0' */
int const excess_bit_count = byte_count * 8 - b->bit_count;
- assert(excess_bit_count >= 0);
- assert(excess_bit_count <= 7);
+ TR_ASSERT(excess_bit_count >= 0);
+ TR_ASSERT(excess_bit_count <= 7);
if (excess_bit_count)
{
void tr_bitfieldRem(tr_bitfield* b, size_t nth)
{
- assert(tr_bitfieldIsValid(b));
+ TR_ASSERT(tr_bitfieldIsValid(b));
if (tr_bitfieldHas(b, nth) && tr_bitfieldEnsureNthBitAlloced(b, nth))
{
*
*/
-#include <assert.h>
#include <stdio.h>
#include <string.h> /* strlen() */
*
*/
-#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h> /* bsearch(), qsort() */
#include "file.h"
#include "log.h"
#include "net.h"
+#include "tr-assert.h"
#include "utils.h"
/***
void tr_blocklistFileSetEnabled(tr_blocklistFile* b, bool isEnabled)
{
- assert(b != NULL);
+ TR_ASSERT(b != NULL);
b->isEnabled = isEnabled;
}
uint32_t needle;
struct tr_ipv4_range const* range;
- assert(tr_address_is_valid(addr));
+ TR_ASSERT(tr_address_is_valid(addr));
if (!b->isEnabled || addr->type == TR_AF_INET6)
{
ranges_count = keep + 1 - ranges;
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
/* sanity checks: make sure the rules are sorted
* in ascending order and don't overlap */
{
for (size_t i = 0; i < ranges_count; ++i)
{
- assert(ranges[i].begin <= ranges[i].end);
+ TR_ASSERT(ranges[i].begin <= ranges[i].end);
}
for (size_t i = 1; i < ranges_count; ++i)
{
- assert(ranges[i - 1].end < ranges[i].begin);
+ TR_ASSERT(ranges[i - 1].end < ranges[i].begin);
}
}
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#include "ptrarray.h"
#include "torrent.h"
+#include "tr-assert.h"
#include "trevent.h"
#include "utils.h"
void tr_cacheFree(tr_cache* cache)
{
- assert(tr_ptrArrayEmpty(&cache->blocks));
+ TR_ASSERT(tr_ptrArrayEmpty(&cache->blocks));
tr_ptrArrayDestruct(&cache->blocks, NULL);
tr_free(cache);
}
{
struct cache_block* cb = findBlock(cache, torrent, piece, offset);
- assert(tr_amInEventThread(torrent->session));
+ TR_ASSERT(tr_amInEventThread(torrent->session));
if (cb == NULL)
{
cb->time = tr_time();
- assert(cb->length == length);
+ TR_ASSERT(cb->length == length);
evbuffer_drain(cb->evbuf, evbuffer_get_length(cb->evbuf));
evbuffer_remove_buffer(writeme, cb->evbuf, cb->length);
*
*/
-#include <assert.h>
-
#include "transmission.h"
#include "completion.h"
#include "torrent.h"
+#include "tr-assert.h"
#include "utils.h"
/***
/* set sizeNow */
cp->sizeNow = tr_bitfieldCountTrueBits(&cp->blockBitfield);
- assert(cp->sizeNow <= cp->tor->blockCount);
+ TR_ASSERT(cp->sizeNow <= cp->tor->blockCount);
cp->sizeNow *= cp->tor->blockSize;
if (tr_bitfieldHas(b, cp->tor->blockCount - 1))
cp->sizeNow -= (cp->tor->blockSize - cp->tor->lastBlockSize);
}
- assert(cp->sizeNow <= cp->tor->info.totalSize);
+ TR_ASSERT(cp->sizeNow <= cp->tor->info.totalSize);
}
/***
}
}
- assert(n <= tr_torPieceCountBytes(tor, p));
+ TR_ASSERT(n <= tr_torPieceCountBytes(tor, p));
size += n;
}
}
- assert(size <= inf->totalSize);
- assert(size >= cp->sizeNow);
+ TR_ASSERT(size <= inf->totalSize);
+ TR_ASSERT(size >= cp->sizeNow);
cp->sizeWhenDoneLazy = size;
cp->sizeWhenDoneIsDirty = false;
{
uint64_t const sizeWhenDone = tr_cpSizeWhenDone(cp);
- assert(sizeWhenDone >= cp->sizeNow);
+ TR_ASSERT(sizeWhenDone >= cp->sizeNow);
return sizeWhenDone - cp->sizeNow;
}
haveBytes += tr_torBlockCountBytes(cp->tor, l);
}
- assert(haveBytes <= pieceByteSize);
+ TR_ASSERT(haveBytes <= pieceByteSize);
return pieceByteSize - haveBytes;
}
}
tr_piece_index_t n;
tr_bitfield pieces;
- assert(tr_torrentHasMetadata(cp->tor));
+ TR_ASSERT(tr_torrentHasMetadata(cp->tor));
n = cp->tor->info.pieceCount;
tr_bitfieldConstruct(&pieces, n);
#define API_VERSION_HEX LIBCYASSL_VERSION_HEX
#endif
-#include <assert.h>
-
#include API_HEADER_CRYPT(arc4.h)
#include API_HEADER_CRYPT(dh.h)
#include API_HEADER_CRYPT(error-crypt.h)
#include "crypto-utils.h"
#include "log.h"
#include "platform.h"
+#include "tr-assert.h"
#include "utils.h"
#define TR_CRYPTO_DH_SECRET_FALLBACK
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
if (data_length == 0)
{
return true;
}
- assert(data != NULL);
+ TR_ASSERT(data != NULL);
return check_result(API(ShaUpdate)(handle, data, data_length));
}
if (hash != NULL)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
ret = check_result(API(ShaFinal)(handle, hash));
}
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
- assert(handle != NULL);
- assert(key != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(key != NULL);
API(Arc4SetKey)(handle, key, key_length);
}
void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t length)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
if (length == 0)
{
return;
}
- assert(input != NULL);
- assert(output != NULL);
+ TR_ASSERT(input != NULL);
+ TR_ASSERT(output != NULL);
API(Arc4Process)(handle, output, input, length);
}
{
struct tr_dh_ctx* handle = tr_new0(struct tr_dh_ctx, 1);
- assert(prime_num != NULL);
- assert(generator_num != NULL);
+ TR_ASSERT(prime_num != NULL);
+ TR_ASSERT(generator_num != NULL);
API(InitDhKey)(&handle->dh);
word32 my_public_key_length;
tr_lock* rng_lock = get_rng_lock();
- assert(handle != NULL);
- assert(public_key != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(public_key != NULL);
if (handle->private_key == NULL)
{
struct tr_dh_secret* ret;
word32 my_secret_key_length;
- assert(handle != NULL);
- assert(other_public_key != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(other_public_key != NULL);
ret = tr_dh_secret_new(handle->key_length);
bool ret;
tr_lock* rng_lock = get_rng_lock();
- assert(buffer != NULL);
+ TR_ASSERT(buffer != NULL);
tr_lockLock(rng_lock);
ret = check_result(API(RNG_GenerateBlock)(get_rng(), buffer, length));
implement missing (or duplicate) functionality without exposing internal
details in header files. */
-#include <assert.h>
-
#include "transmission.h"
#include "crypto-utils.h"
+#include "tr-assert.h"
#include "utils.h"
/***
{
struct tr_dh_secret* handle = raw_handle;
- assert(handle != NULL);
- assert(hash != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(hash != NULL);
return tr_sha1(hash, prepend_data == NULL ? "" : prepend_data, prepend_data == NULL ? 0 : (int)prepend_data_size,
handle->key, (int)handle->key_length, append_data, append_data == NULL ? 0 : (int)append_data_size, NULL);
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
-#include <assert.h>
-
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <openssl/dh.h>
#include "transmission.h"
#include "crypto-utils.h"
#include "log.h"
+#include "tr-assert.h"
#include "utils.h"
#define TR_CRYPTO_DH_SECRET_FALLBACK
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
if (data_length == 0)
{
return true;
}
- assert(data != NULL);
+ TR_ASSERT(data != NULL);
return check_result(EVP_DigestUpdate(handle, data, data_length));
}
{
unsigned int hash_length;
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
ret = check_result(EVP_DigestFinal_ex(handle, hash, &hash_length));
- assert(!ret || hash_length == SHA_DIGEST_LENGTH);
+ TR_ASSERT(!ret || hash_length == SHA_DIGEST_LENGTH);
}
EVP_MD_CTX_destroy(handle);
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
- assert(handle != NULL);
- assert(key != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(key != NULL);
if (!check_result(EVP_CIPHER_CTX_set_key_length(handle, key_length)))
{
{
int output_length;
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
if (length == 0)
{
return;
}
- assert(input != NULL);
- assert(output != NULL);
+ TR_ASSERT(input != NULL);
+ TR_ASSERT(output != NULL);
check_result(EVP_CipherUpdate(handle, output, &output_length, input, length));
}
BIGNUM* p;
BIGNUM* g;
- assert(prime_num != NULL);
- assert(generator_num != NULL);
+ TR_ASSERT(prime_num != NULL);
+ TR_ASSERT(generator_num != NULL);
p = BN_bin2bn(prime_num, prime_num_length, NULL);
g = BN_bin2bn(generator_num, generator_num_length, NULL);
int my_public_key_length;
BIGNUM const* my_public_key;
- assert(handle != NULL);
- assert(public_key != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(public_key != NULL);
DH_set_length(handle, private_key_length * 8);
int secret_key_length;
BIGNUM* other_key;
- assert(handle != NULL);
- assert(other_public_key != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(other_public_key != NULL);
if (!check_pointer(other_key = BN_bin2bn(other_public_key, other_public_key_length, NULL)))
{
bool tr_rand_buffer(void* buffer, size_t length)
{
- assert(buffer != NULL);
+ TR_ASSERT(buffer != NULL);
return check_result(RAND_bytes(buffer, (int)length));
}
#define API_VERSION_NUMBER POLARSSL_VERSION_NUMBER
#endif
-#include <assert.h>
-
#include API_HEADER(arc4.h)
#include API_HEADER(base64.h)
#include API_HEADER(ctr_drbg.h)
#include "crypto-utils.h"
#include "log.h"
#include "platform.h"
+#include "tr-assert.h"
#include "utils.h"
#define TR_CRYPTO_DH_SECRET_FALLBACK
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
if (data_length == 0)
{
return true;
}
- assert(data != NULL);
+ TR_ASSERT(data != NULL);
API(sha1_update)(handle, data, data_length);
return true;
{
if (hash != NULL)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
API(sha1_finish)(handle, hash);
}
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
- assert(handle != NULL);
- assert(key != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(key != NULL);
API(arc4_setup)(handle, key, key_length);
}
void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t length)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
if (length == 0)
{
return;
}
- assert(input != NULL);
- assert(output != NULL);
+ TR_ASSERT(input != NULL);
+ TR_ASSERT(output != NULL);
API(arc4_crypt)(handle, length, input, output);
}
{
API(dhm_context)* handle = tr_new0(API(dhm_context), 1);
- assert(prime_num != NULL);
- assert(generator_num != NULL);
+ TR_ASSERT(prime_num != NULL);
+ TR_ASSERT(generator_num != NULL);
#if API_VERSION_NUMBER >= 0x01030800
API(dhm_init)(handle);
{
API(dhm_context)* handle = raw_handle;
- assert(handle != NULL);
- assert(public_key != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(public_key != NULL);
if (public_key_length != NULL)
{
struct tr_dh_secret* ret;
size_t secret_key_length;
- assert(handle != NULL);
- assert(other_public_key != NULL);
+ TR_ASSERT(handle != NULL);
+ TR_ASSERT(other_public_key != NULL);
if (!check_result(API(dhm_read_public)(handle, other_public_key, other_public_key_length)))
{
bool ret;
tr_lock* rng_lock = get_rng_lock();
- assert(buffer != NULL);
+ TR_ASSERT(buffer != NULL);
tr_lockLock(rng_lock);
ret = check_result(API(ctr_drbg_random)(get_rng(), buffer, length));
*
*/
-#include <assert.h>
#include <stdarg.h>
#include <stdlib.h> /* abs(), srand(), rand() */
#include <string.h> /* memcpy(), memmove(), memset(), strcmp(), strlen() */
#include "transmission.h"
#include "crypto-utils.h"
+#include "tr-assert.h"
#include "utils.h"
/***
void tr_dh_align_key(uint8_t* key_buffer, size_t key_size, size_t buffer_size)
{
- assert(key_size <= buffer_size);
+ TR_ASSERT(key_size <= buffer_size);
/* DH can generate key sizes that are smaller than the size of
key buffer with exponentially decreasing probability, in which case
while ((data = va_arg(vl, void const*)) != NULL)
{
int const data_length = va_arg(vl, int);
- assert(data_length >= 0);
+ TR_ASSERT(data_length >= 0);
if (!tr_sha1_update(sha, data, data_length))
{
{
int noise;
- assert(upper_bound > 0);
+ TR_ASSERT(upper_bound > 0);
while (tr_rand_buffer(&noise, sizeof(noise)))
{
{
static bool init = false;
- assert(upper_bound > 0);
+ TR_ASSERT(upper_bound > 0);
if (!init)
{
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"./";
- assert(plain_text != NULL);
+ TR_ASSERT(plain_text != NULL);
unsigned char salt[saltval_len];
uint8_t sha[SHA_DIGEST_LENGTH];
bool tr_ssha1_matches(char const* ssha1, char const* plain_text)
{
- assert(ssha1 != NULL);
- assert(plain_text != NULL);
+ TR_ASSERT(ssha1 != NULL);
+ TR_ASSERT(plain_text != NULL);
size_t const brace_len = 1;
size_t const brace_and_hash_len = brace_len + 2 * SHA_DIGEST_LENGTH;
*
*/
-#include <assert.h>
#include <string.h> /* memcpy(), memmove(), memset() */
#include "transmission.h"
#include "crypto.h"
#include "crypto-utils.h"
+#include "tr-assert.h"
#include "utils.h"
/**
crypto->dh = tr_dh_new(dh_P, sizeof(dh_P), dh_G, sizeof(dh_G));
tr_dh_make_key(crypto->dh, DH_PRIVKEY_LEN, crypto->myPublicKey, &public_key_length);
- assert(public_key_length == KEY_LEN);
+ TR_ASSERT(public_key_length == KEY_LEN);
}
}
{
uint8_t buf[SHA_DIGEST_LENGTH];
- assert(crypto->torrentHashIsSet);
+ TR_ASSERT(crypto->torrentHashIsSet);
if (*setme == NULL)
{
bool tr_cryptoSecretKeySha1(tr_crypto const* crypto, void const* prepend_data, size_t prepend_data_size,
void const* append_data, size_t append_data_size, uint8_t* hash)
{
- assert(crypto != NULL);
- assert(crypto->mySecret != NULL);
+ TR_ASSERT(crypto != NULL);
+ TR_ASSERT(crypto->mySecret != NULL);
return tr_dh_secret_derive(crypto->mySecret, prepend_data, prepend_data_size, append_data, append_data_size, hash);
}
uint8_t const* tr_cryptoGetTorrentHash(tr_crypto const* crypto)
{
- assert(crypto);
+ TR_ASSERT(crypto != NULL);
return crypto->torrentHashIsSet ? crypto->torrentHash : NULL;
}
bool tr_cryptoHasTorrentHash(tr_crypto const* crypto)
{
- assert(crypto);
+ TR_ASSERT(crypto != NULL);
return crypto->torrentHashIsSet;
}
*
*/
-#include <assert.h>
-
#include "transmission.h"
#include "error.h"
+#include "tr-assert.h"
#include "utils.h"
tr_error* tr_error_new(int code, char const* message_format, ...)
tr_error* error;
va_list args;
- assert(message_format != NULL);
+ TR_ASSERT(message_format != NULL);
va_start(args, message_format);
error = tr_error_new_valist(code, message_format, args);
{
tr_error* error;
- assert(message != NULL);
+ TR_ASSERT(message != NULL);
error = tr_new(tr_error, 1);
error->code = code;
{
tr_error* error;
- assert(message_format != NULL);
+ TR_ASSERT(message_format != NULL);
error = tr_new(tr_error, 1);
error->code = code;
return;
}
- assert(*error == NULL);
- assert(message_format != NULL);
+ TR_ASSERT(*error == NULL);
+ TR_ASSERT(message_format != NULL);
va_start(args, message_format);
*error = tr_error_new_valist(code, message_format, args);
return;
}
- assert(*error == NULL);
- assert(message != NULL);
+ TR_ASSERT(*error == NULL);
+ TR_ASSERT(message != NULL);
*error = tr_error_new_literal(code, message);
}
void tr_error_propagate(tr_error** new_error, tr_error** old_error)
{
- assert(old_error != NULL);
- assert(*old_error != NULL);
+ TR_ASSERT(old_error != NULL);
+ TR_ASSERT(*old_error != NULL);
if (new_error != NULL)
{
- assert(*new_error == NULL);
+ TR_ASSERT(*new_error == NULL);
*new_error = *old_error;
*old_error = NULL;
char* prefix;
char* new_message;
- assert(error != NULL);
- assert(*error != NULL);
- assert(prefix_format != NULL);
+ TR_ASSERT(error != NULL);
+ TR_ASSERT(*error != NULL);
+ TR_ASSERT(prefix_format != NULL);
prefix = tr_strdup_vprintf(prefix_format, args);
{
va_list args;
- assert(prefix_format != NULL);
+ TR_ASSERT(prefix_format != NULL);
if (error == NULL || *error == NULL)
{
{
va_list args;
- assert(prefix_format != NULL);
+ TR_ASSERT(prefix_format != NULL);
tr_error_propagate(new_error, old_error);
*
*/
-#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include "log.h"
#include "session.h"
#include "torrent.h" /* tr_isTorrent() */
+#include "tr-assert.h"
#define dbgmsg(...) tr_logAddDeepNamed(NULL, __VA_ARGS__)
static inline bool cached_file_is_open(struct tr_cached_file const* o)
{
- assert(o != NULL);
+ TR_ASSERT(o != NULL);
return o->fd != TR_BAD_SYS_FILE;
}
static void cached_file_close(struct tr_cached_file* o)
{
- assert(cached_file_is_open(o));
+ TR_ASSERT(cached_file_is_open(o));
tr_sys_file_close(o->fd, NULL);
o->fd = TR_BAD_SYS_FILE;
type = _("sparse");
}
- assert(type != NULL);
+ TR_ASSERT(type != NULL);
if (!success)
{
static void ensureSessionFdInfoExists(tr_session* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (session->fdInfo == NULL)
{
void tr_fdTorrentClose(tr_session* session, int torrent_id)
{
- assert(tr_sessionIsLocked(session));
+ TR_ASSERT(tr_sessionIsLocked(session));
fileset_close_torrent(get_fileset(session), torrent_id);
}
{
tr_socket_t s = TR_BAD_SOCKET;
struct tr_fdInfo* gFd;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
ensureSessionFdInfoExists(session);
gFd = session->fdInfo;
++gFd->peerCount;
}
- assert(gFd->peerCount >= 0);
+ TR_ASSERT(gFd->peerCount >= 0);
if (s != TR_BAD_SOCKET)
{
struct tr_fdInfo* gFd;
struct sockaddr_storage sock;
- assert(tr_isSession(s));
- assert(addr != NULL);
- assert(port != NULL);
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(addr != NULL);
+ TR_ASSERT(port != NULL);
ensureSessionFdInfoExists(s);
gFd = s->fdInfo;
void tr_fdSocketClose(tr_session* session, tr_socket_t fd)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (session->fdInfo != NULL)
{
--gFd->peerCount;
}
- assert(gFd->peerCount >= 0);
+ TR_ASSERT(gFd->peerCount >= 0);
}
}
#undef _GNU_SOURCE
#define _GNU_SOURCE
-#include <assert.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h> /* O_LARGEFILE, posix_fadvise(), [posix_]fallocate() */
#include "file.h"
#include "log.h"
#include "platform.h"
+#include "tr-assert.h"
#include "utils.h"
#ifndef O_LARGEFILE
{
bool ret;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
ret = access(path, F_OK) != -1;
bool ret;
struct stat sb;
- assert(path != NULL);
- assert(info != NULL);
+ TR_ASSERT(path != NULL);
+ TR_ASSERT(info != NULL);
if ((flags & TR_SYS_PATH_NO_FOLLOW) == 0)
{
bool tr_sys_path_is_relative(char const* path)
{
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
return path[0] != '/';
}
struct stat sb1;
struct stat sb2;
- assert(path1 != NULL);
- assert(path2 != NULL);
+ TR_ASSERT(path1 != NULL);
+ TR_ASSERT(path2 != NULL);
if (stat(path1, &sb1) != -1 && stat(path2, &sb2) != -1)
{
char* ret = NULL;
char* tmp = NULL;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
#if defined(HAVE_CANONICALIZE_FILE_NAME)
char* ret = NULL;
char* tmp;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
tmp = tr_strdup(path);
ret = basename(tmp);
char* ret = NULL;
char* tmp;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
tmp = tr_strdup(path);
ret = dirname(tmp);
{
bool ret;
- assert(src_path != NULL);
- assert(dst_path != NULL);
+ TR_ASSERT(src_path != NULL);
+ TR_ASSERT(dst_path != NULL);
ret = rename(src_path, dst_path) != -1;
{
bool ret;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
ret = remove(path) != -1;
break;
default:
- assert(0 && "Unknown standard file");
+ TR_ASSERT_MSG(false, "unknown standard file %d", (int)std_file);
set_system_error(error, EINVAL);
}
tr_sys_file_t ret;
int native_flags = 0;
- assert(path != NULL);
- assert((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) != 0);
+ TR_ASSERT(path != NULL);
+ TR_ASSERT((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) != 0);
if ((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) == (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE))
{
{
tr_sys_file_t ret;
- assert(path_template != NULL);
+ TR_ASSERT(path_template != NULL);
ret = mkstemp(path_template);
{
bool ret;
- assert(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = close(handle) != -1;
bool ret;
struct stat sb;
- assert(handle != TR_BAD_SYS_FILE);
- assert(info != NULL);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(info != NULL);
ret = fstat(handle, &sb) != -1;
TR_STATIC_ASSERT(sizeof(*new_offset) >= sizeof(my_new_offset), "");
- assert(handle != TR_BAD_SYS_FILE);
- assert(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
my_new_offset = lseek(handle, offset, origin);
TR_STATIC_ASSERT(sizeof(*bytes_read) >= sizeof(my_bytes_read), "");
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL || size == 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL || size == 0);
my_bytes_read = read(handle, buffer, size);
TR_STATIC_ASSERT(sizeof(*bytes_read) >= sizeof(my_bytes_read), "");
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL || size == 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL || size == 0);
/* seek requires signed offset, so it should be in mod range */
- assert(offset < UINT64_MAX / 2);
+ TR_ASSERT(offset < UINT64_MAX / 2);
#ifdef HAVE_PREAD
TR_STATIC_ASSERT(sizeof(*bytes_written) >= sizeof(my_bytes_written), "");
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL || size == 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL || size == 0);
my_bytes_written = write(handle, buffer, size);
TR_STATIC_ASSERT(sizeof(*bytes_written) >= sizeof(my_bytes_written), "");
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL || size == 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL || size == 0);
/* seek requires signed offset, so it should be in mod range */
- assert(offset < UINT64_MAX / 2);
+ TR_ASSERT(offset < UINT64_MAX / 2);
#ifdef HAVE_PWRITE
{
bool ret;
- assert(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = fsync(handle) != -1;
{
bool ret;
- assert(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = ftruncate(handle, size) != -1;
int code;
- assert(handle != TR_BAD_SYS_FILE);
- assert(size > 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(size > 0);
code = posix_fadvise(handle, offset, size, POSIX_FADV_WILLNEED);
struct radvisory radv;
- assert(handle != TR_BAD_SYS_FILE);
- assert(size > 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(size > 0);
radv.ra_offset = offset;
radv.ra_count = size;
{
bool ret = false;
- assert(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
errno = 0;
{
void* ret;
- assert(handle != TR_BAD_SYS_FILE);
- assert(size > 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(size > 0);
ret = mmap(NULL, size, PROT_READ, MAP_SHARED, handle, offset);
{
bool ret;
- assert(address != NULL);
- assert(size > 0);
+ TR_ASSERT(address != NULL);
+ TR_ASSERT(size > 0);
ret = munmap((void*)address, size) != -1;
bool ret;
int native_operation = 0;
- assert(handle != TR_BAD_SYS_FILE);
- assert((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0);
- assert(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) +
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0);
+ TR_ASSERT(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) +
!!(operation & TR_SYS_FILE_LOCK_UN) == 1);
if ((operation & TR_SYS_FILE_LOCK_SH) != 0)
bool ret;
tr_error* my_error = NULL;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
if ((flags & TR_SYS_DIR_CREATE_PARENTS) != 0)
{
{
bool ret;
- assert(path_template != NULL);
+ TR_ASSERT(path_template != NULL);
#ifdef HAVE_MKDTEMP
TR_STATIC_ASSERT(TR_BAD_SYS_DIR == NULL, "values should match");
#endif
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
ret = opendir(path);
char const* ret = NULL;
struct dirent* entry;
- assert(handle != TR_BAD_SYS_DIR);
+ TR_ASSERT(handle != TR_BAD_SYS_DIR);
errno = 0;
entry = readdir(handle);
{
bool ret;
- assert(handle != TR_BAD_SYS_DIR);
+ TR_ASSERT(handle != TR_BAD_SYS_DIR);
ret = closedir(handle) != -1;
*
*/
-#include <assert.h>
#include <ctype.h> /* isalpha() */
#include <shlobj.h> /* SHCreateDirectoryEx() */
#include "crypto-utils.h" /* tr_rand_int() */
#include "error.h"
#include "file.h"
+#include "tr-assert.h"
#include "utils.h"
#ifndef MAXSIZE_T
{
uint64_t tmp = 0;
- assert(t != NULL);
+ TR_ASSERT(t != NULL);
tmp |= t->dwHighDateTime;
tmp <<= 32;
static void stat_to_sys_path_info(DWORD attributes, DWORD size_low, DWORD size_high, FILETIME const* mtime,
tr_sys_path_info* info)
{
- assert(mtime != NULL);
- assert(info != NULL);
+ TR_ASSERT(mtime != NULL);
+ TR_ASSERT(info != NULL);
if (attributes & FILE_ATTRIBUTE_DIRECTORY)
{
/* `-2` for UNC since we overwrite existing prefix slashes */
int const extra_chars_before = is_relative ? 0 : (is_unc ? TR_N_ELEMENTS(unc_prefix) - 2 : TR_N_ELEMENTS(local_prefix));
- /* TODO (?): assert(!is_relative); */
+ /* TODO (?): TR_ASSERT(!is_relative); */
wchar_t* const wide_path = tr_win32_utf8_to_native_ex(path, -1, extra_chars_before, extra_chars_after, real_result_size);
tr_sys_file_t ret = TR_BAD_SYS_FILE;
wchar_t* wide_path;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
wide_path = path_to_native_path(path);
wchar_t* wide_path;
DWORD error_code = ERROR_SUCCESS;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
(void)permissions;
size_t path_size;
tr_error* my_error = NULL;
- assert(path_template != NULL);
- assert(callback != NULL);
+ TR_ASSERT(path_template != NULL);
+ TR_ASSERT(callback != NULL);
path = tr_strdup(path_template);
path_size = strlen(path);
- assert(path_size > 0);
+ TR_ASSERT(path_size > 0);
for (int attempt = 0; attempt < 100; ++attempt)
{
--i;
}
- assert(path_size >= i + 6);
+ TR_ASSERT(path_size >= i + 6);
tr_error_clear(&my_error);
wchar_t* wide_path;
HANDLE handle = INVALID_HANDLE_VALUE;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
wide_path = path_to_native_path(path);
bool ret = false;
wchar_t* wide_path;
- assert(path != NULL);
- assert(info != NULL);
+ TR_ASSERT(path != NULL);
+ TR_ASSERT(info != NULL);
wide_path = path_to_native_path(path);
bool tr_sys_path_is_relative(char const* path)
{
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
/* UNC path: `\\...`. */
if (is_unc_path(path))
HANDLE handle2 = INVALID_HANDLE_VALUE;
BY_HANDLE_FILE_INFORMATION fi1, fi2;
- assert(path1 != NULL);
- assert(path2 != NULL);
+ TR_ASSERT(path1 != NULL);
+ TR_ASSERT(path2 != NULL);
wide_path1 = path_to_native_path(path1);
HANDLE handle = INVALID_HANDLE_VALUE;
DWORD wide_ret_size;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
wide_path = path_to_native_path(path);
wchar_t* wide_src_path;
wchar_t* wide_dst_path;
- assert(src_path != NULL);
- assert(dst_path != NULL);
+ TR_ASSERT(src_path != NULL);
+ TR_ASSERT(dst_path != NULL);
wide_src_path = path_to_native_path(src_path);
wide_dst_path = path_to_native_path(dst_path);
bool ret = false;
wchar_t* wide_path;
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
wide_path = path_to_native_path(path);
break;
default:
- assert(0 && "Unknown standard file");
+ TR_ASSERT_MSG(false, "unknown standard file %d", (int)std_file);
set_system_error(error, ERROR_INVALID_PARAMETER);
return TR_BAD_SYS_FILE;
}
DWORD native_flags = FILE_ATTRIBUTE_NORMAL;
bool success;
- assert(path != NULL);
- assert((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) != 0);
+ TR_ASSERT(path != NULL);
+ TR_ASSERT((flags & (TR_SYS_FILE_READ | TR_SYS_FILE_WRITE)) != 0);
(void)permissions;
{
tr_sys_file_t* result = (tr_sys_file_t*)param;
- assert(result != NULL);
+ TR_ASSERT(result != NULL);
*result = open_file(path, GENERIC_READ | GENERIC_WRITE, CREATE_NEW, FILE_ATTRIBUTE_TEMPORARY, error);
}
{
tr_sys_file_t ret = TR_BAD_SYS_FILE;
- assert(path_template != NULL);
+ TR_ASSERT(path_template != NULL);
create_temp_path(path_template, file_open_temp_callback, &ret, error);
{
bool ret;
- assert(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = CloseHandle(handle);
bool ret;
BY_HANDLE_FILE_INFORMATION attributes;
- assert(handle != TR_BAD_SYS_FILE);
- assert(info != NULL);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(info != NULL);
ret = GetFileInformationByHandle(handle, &attributes);
TR_STATIC_ASSERT(TR_SEEK_CUR == FILE_CURRENT, "values should match");
TR_STATIC_ASSERT(TR_SEEK_END == FILE_END, "values should match");
- assert(handle != TR_BAD_SYS_FILE);
- assert(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(origin == TR_SEEK_SET || origin == TR_SEEK_CUR || origin == TR_SEEK_END);
native_offset.QuadPart = offset;
bool ret = false;
DWORD my_bytes_read;
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL || size == 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL || size == 0);
if (size > MAXDWORD)
{
OVERLAPPED overlapped;
DWORD my_bytes_read;
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL || size == 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL || size == 0);
if (size > MAXDWORD)
{
bool ret = false;
DWORD my_bytes_written;
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL || size == 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL || size == 0);
if (size > MAXDWORD)
{
OVERLAPPED overlapped;
DWORD my_bytes_written;
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL || size == 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL || size == 0);
if (size > MAXDWORD)
{
{
bool ret;
- assert(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
ret = FlushFileBuffers(handle);
bool ret = false;
FILE_END_OF_FILE_INFO info;
- assert(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
info.EndOfFile.QuadPart = size;
{
bool ret = false;
- assert(handle != TR_BAD_SYS_FILE);
- assert(size > 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(size > 0);
(void)handle;
(void)offset;
bool tr_sys_file_preallocate(tr_sys_file_t handle, uint64_t size, int flags, tr_error** error)
{
- assert(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
if ((flags & TR_SYS_FILE_PREALLOC_SPARSE) != 0)
{
void* ret = NULL;
HANDLE mappingHandle;
- assert(handle != TR_BAD_SYS_FILE);
- assert(size > 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(size > 0);
if (size > MAXSIZE_T)
{
{
bool ret;
- assert(address != NULL);
- assert(size > 0);
+ TR_ASSERT(address != NULL);
+ TR_ASSERT(size > 0);
(void)size;
bool ret;
OVERLAPPED overlapped = { .Pointer = 0, .hEvent = NULL };
- assert(handle != TR_BAD_SYS_FILE);
- assert((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0);
- assert(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) +
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0);
+ TR_ASSERT(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) +
!!(operation & TR_SYS_FILE_LOCK_UN) == 1);
if ((operation & TR_SYS_FILE_LOCK_UN) == 0)
{
bool* result = (bool*)param;
- assert(result != NULL);
+ TR_ASSERT(result != NULL);
*result = create_dir(path, 0, 0, false, error);
}
{
bool ret = false;
- assert(path_template != NULL);
+ TR_ASSERT(path_template != NULL);
create_temp_path(path_template, dir_create_temp_callback, &ret, error);
TR_STATIC_ASSERT(TR_BAD_SYS_DIR == NULL, "values should match");
#endif
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
ret = tr_new(struct tr_sys_dir_win32, 1);
ret->pattern = path_to_native_path_ex(path, 2, &pattern_size);
char* ret;
DWORD error_code = ERROR_SUCCESS;
- assert(handle != TR_BAD_SYS_DIR);
+ TR_ASSERT(handle != TR_BAD_SYS_DIR);
if (handle->find_handle == INVALID_HANDLE_VALUE)
{
{
bool ret;
- assert(handle != TR_BAD_SYS_DIR);
+ TR_ASSERT(handle != TR_BAD_SYS_DIR);
ret = FindClose(handle->find_handle);
*
*/
-#include <assert.h>
#include <string.h> /* strlen() */
#include "transmission.h"
#include "error.h"
#include "file.h"
+#include "tr-assert.h"
#include "utils.h"
bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_size, tr_error** error)
size_t offset = 0;
uint64_t bytes_read;
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL);
- assert(buffer_size > 0);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL);
+ TR_ASSERT(buffer_size > 0);
while (buffer_size > 0)
{
{
bool ret;
- assert(handle != TR_BAD_SYS_FILE);
- assert(buffer != NULL);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(buffer != NULL);
ret = tr_sys_file_write(handle, buffer, strlen(buffer), NULL, error);
char* buffer;
va_list args;
- assert(handle != TR_BAD_SYS_FILE);
- assert(format != NULL);
+ TR_ASSERT(handle != TR_BAD_SYS_FILE);
+ TR_ASSERT(format != NULL);
va_start(args, error);
buffer = tr_strdup_vprintf(format, args);
*
*/
-#include <assert.h>
#include <errno.h>
#include <string.h> /* strcmp(), strlen(), strncmp() */
#include "peer-mgr.h"
#include "session.h"
#include "torrent.h"
+#include "tr-assert.h"
#include "tr-dht.h"
#include "utils.h"
memcpy(walk, peer_id, PEER_ID_LEN);
walk += PEER_ID_LEN;
- assert(walk - buf == HANDSHAKE_SIZE);
+ TR_ASSERT(walk - buf == HANDSHAKE_SIZE);
success = true;
}
/* torrent hash */
tr_peerIoReadBytes(handshake->io, inbuf, hash, sizeof(hash));
- assert(tr_peerIoHasTorrentHash(handshake->io));
+ TR_ASSERT(tr_peerIoHasTorrentHash(handshake->io));
if (!tr_torrentExists(handshake->session, hash) ||
memcmp(hash, tr_peerIoGetTorrentHash(handshake->io), SHA_DIGEST_LENGTH) != 0)
/* add our public key (Ya) */
public_key = tr_cryptoGetMyPublicKey(handshake->crypto, &len);
- assert(len == KEY_LEN);
- assert(public_key != NULL);
+ TR_ASSERT(len == KEY_LEN);
+ TR_ASSERT(public_key != NULL);
memcpy(walk, public_key, len);
walk += len;
evbuffer_drain(inbuf, 1);
/* pstr (BitTorrent) */
- assert(pstrlen == 19);
+ TR_ASSERT(pstrlen == 19);
tr_peerIoReadBytes(handshake->io, inbuf, pstr, pstrlen);
pstr[pstrlen] = '\0';
}
else
{
- assert(!tr_peerIoHasTorrentHash(handshake->io));
+ TR_ASSERT(!tr_peerIoHasTorrentHash(handshake->io));
tr_peerIoSetTorrentHash(handshake->io, hash);
}
}
else /* outgoing */
{
- assert(tr_peerIoHasTorrentHash(handshake->io));
+ TR_ASSERT(tr_peerIoHasTorrentHash(handshake->io));
if (memcmp(hash, tr_peerIoGetTorrentHash(handshake->io), SHA_DIGEST_LENGTH) != 0)
{
struct evbuffer* inbuf = tr_peerIoGetReadBuffer(io);
bool readyForMore = true;
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
/* no piece data in handshake */
*piece = 0;
break;
default:
- assert(0);
+ TR_ASSERT_MSG(false, "unhandled handshake state %d", (int)handshake->state);
}
if (ret != READ_NOW)
struct tr_peerIo* tr_handshakeGetIO(tr_handshake* handshake)
{
- assert(handshake != NULL);
- assert(handshake->io != NULL);
+ TR_ASSERT(handshake != NULL);
+ TR_ASSERT(handshake->io != NULL);
return handshake->io;
}
{
struct tr_peerIo* io;
- assert(handshake != NULL);
- assert(handshake->io != NULL);
+ TR_ASSERT(handshake != NULL);
+ TR_ASSERT(handshake->io != NULL);
io = handshake->io;
handshake->io = NULL;
tr_address const* tr_handshakeGetAddr(struct tr_handshake const* handshake, tr_port* port)
{
- assert(handshake != NULL);
- assert(handshake->io != NULL);
+ TR_ASSERT(handshake != NULL);
+ TR_ASSERT(handshake->io != NULL);
return tr_peerIoGetAddress(handshake->io, port);
}
*
*/
-#include <assert.h>
#include <string.h> /* memset() */
#include "transmission.h"
*
*/
-#include <assert.h>
#include <errno.h>
#include <stdlib.h> /* bsearch() */
#include <string.h> /* memcmp() */
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#include "stats.h" /* tr_statsFileCreated() */
#include "torrent.h"
+#include "tr-assert.h"
#include "utils.h"
/****
tr_info const* const info = &tor->info;
tr_file const* const file = &info->files[fileIndex];
- assert(fileIndex < info->fileCount);
- assert(file->length == 0 || fileOffset < file->length);
- assert(fileOffset + buflen <= file->length);
+ TR_ASSERT(fileIndex < info->fileCount);
+ TR_ASSERT(file->length == 0 || fileOffset < file->length);
+ TR_ASSERT(fileOffset + buflen <= file->length);
if (file->length == 0)
{
uint64_t const offset = tr_pieceOffset(tor, pieceIndex, pieceOffset, 0);
tr_file const* file;
- assert(tr_isTorrent(tor));
- assert(offset < tor->info.totalSize);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(offset < tor->info.totalSize);
file = bsearch(&offset, tor->info.files, tor->info.fileCount, sizeof(tr_file), compareOffsetToFile);
- assert(file != NULL);
+ TR_ASSERT(file != NULL);
*fileIndex = file - tor->info.files;
*fileOffset = offset - file->offset;
- assert(*fileIndex < tor->info.fileCount);
- assert(*fileOffset < file->length);
- assert(tor->info.files[*fileIndex].offset + *fileOffset == offset);
+ TR_ASSERT(*fileIndex < tor->info.fileCount);
+ TR_ASSERT(*fileOffset < file->length);
+ TR_ASSERT(tor->info.files[*fileIndex].offset + *fileOffset == offset);
}
/* returns 0 on success, or an errno on failure */
void* buffer = tr_valloc(buflen);
tr_sha1_ctx_t sha;
- assert(tor != NULL);
- assert(pieceIndex < tor->info.pieceCount);
- assert(buffer != NULL);
- assert(buflen > 0);
- assert(setme != NULL);
+ TR_ASSERT(tor != NULL);
+ TR_ASSERT(pieceIndex < tor->info.pieceCount);
+ TR_ASSERT(buffer != NULL);
+ TR_ASSERT(buflen > 0);
+ TR_ASSERT(setme != NULL);
sha = tr_sha1_init();
bytesLeft = tr_torPieceCountBytes(tor, pieceIndex);
*
*/
-#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h> /* mkstemp() */
#include "file.h"
#include "platform.h" /* TR_PATH_DELIMETER */
#include "torrent.h"
+#include "tr-assert.h"
#include "trevent.h"
#include "variant.h"
#include "libtransmission-test.h"
/* create the torrent ctor */
metainfo = tr_base64_decode_str(metainfo_base64, &metainfo_len);
- assert(metainfo != NULL);
- assert(metainfo_len > 0);
- assert(session != NULL);
+ TR_ASSERT(metainfo != NULL);
+ TR_ASSERT(metainfo_len > 0);
+ TR_ASSERT(session != NULL);
ctor = tr_ctorNew(session);
tr_ctorSetMetainfo(ctor, (uint8_t*)metainfo, metainfo_len);
tr_ctorSetPaused(ctor, TR_FORCE, true);
/* create the torrent */
err = 0;
tor = tr_torrentNew(ctor, &err, NULL);
- assert(err == 0);
+ TR_ASSERT(err == 0);
/* cleanup */
tr_free(metainfo);
tr_free(path);
path = tr_torrentFindFile(tor, i);
- assert(path != NULL);
+ TR_ASSERT(path != NULL);
err = errno;
- assert(tr_sys_path_exists(path, NULL));
+ TR_ASSERT(tr_sys_path_exists(path, NULL));
errno = err;
tr_free(path);
}
if (complete)
{
- assert(tr_torrentStat(tor)->leftUntilDone == 0);
+ TR_ASSERT(tr_torrentStat(tor)->leftUntilDone == 0);
}
else
{
- assert(tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
+ TR_ASSERT(tr_torrentStat(tor)->leftUntilDone == tor->info.pieceSize);
}
}
{
bool done = false;
- assert(tor->session != NULL);
- assert(!tr_amInEventThread(tor->session));
+ TR_ASSERT(tor->session != NULL);
+ TR_ASSERT(!tr_amInEventThread(tor->session));
tr_torrentVerify(tor, onVerifyDone, &done);
dir = tr_sys_path_dirname(path, NULL);
tr_sys_dir_create(dir, TR_SYS_DIR_CREATE_PARENTS, 0700, &error);
- assert(error == NULL);
+ TR_ASSERT(error == NULL);
tr_free(dir);
errno = tmperr;
*
*/
-#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include "file.h"
#include "log.h"
#include "platform.h" /* tr_lock */
+#include "tr-assert.h"
#include "utils.h"
tr_log_level __tr_message_level = TR_LOG_ERROR;
old->next = NULL;
tr_logFreeQueue(old);
--myQueueLength;
- assert(myQueueLength == TR_LOG_MAX_QUEUE_LENGTH);
+ TR_ASSERT(myQueueLength == TR_LOG_MAX_QUEUE_LENGTH);
}
}
else
*
*/
-#include <assert.h>
#include <string.h> /* strchr() */
#include <stdio.h> /* sscanf() */
#include "transmission.h"
#include "crypto-utils.h" /* tr_hex_to_sha1() */
#include "magnet.h"
+#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
#include "web.h"
memset(out, 0, 20);
- assert(inlen == 32);
+ TR_ASSERT(inlen == 32);
for (size_t i = 0, index = 0, offset = 0; i < inlen; ++i)
{
*
*/
-#include <assert.h>
#include <errno.h>
#include <stdlib.h> /* qsort */
#include <string.h> /* strcmp, strlen */
#include "session.h"
#include "makemeta.h"
#include "platform.h" /* threads, locks */
+#include "tr-assert.h"
#include "utils.h" /* buildpath */
#include "variant.h"
#include "version.h"
uint32_t const thisPieceSize = (uint32_t)MIN(b->pieceSize, totalRemain);
uint64_t leftInPiece = thisPieceSize;
- assert(b->pieceIndex < b->pieceCount);
+ TR_ASSERT(b->pieceIndex < b->pieceCount);
while (leftInPiece != 0)
{
}
}
- assert(bufptr - buf == (int)thisPieceSize);
- assert(leftInPiece == 0);
+ TR_ASSERT(bufptr - buf == (int)thisPieceSize);
+ TR_ASSERT(leftInPiece == 0);
tr_sha1(walk, buf, (int)thisPieceSize, NULL);
walk += SHA_DIGEST_LENGTH;
++b->pieceIndex;
}
- assert(b->abortFlag || walk - ret == (int)(SHA_DIGEST_LENGTH * b->pieceCount));
- assert(b->abortFlag || !totalRemain);
+ TR_ASSERT(b->abortFlag || walk - ret == (int)(SHA_DIGEST_LENGTH * b->pieceCount));
+ TR_ASSERT(b->abortFlag || !totalRemain);
if (fd != TR_BAD_SYS_FILE)
{
*
*/
-#include <assert.h>
#include <string.h> /* strlen() */
#include <event2/buffer.h>
#include "metainfo.h"
#include "platform.h" /* tr_getTorrentDir() */
#include "session.h"
+#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
*setme = NULL;
/* root's already been checked by caller */
- assert(!path_component_is_suspicious(root));
+ TR_ASSERT(!path_component_is_suspicious(root));
if (tr_variantIsList(path))
{
memcpy(walk, suffix, suffix_len);
walk += suffix_len;
*walk++ = '\0';
- assert(walk - scrape == (int)alloc_len);
+ TR_ASSERT(walk - scrape == (int)alloc_len);
}
/* Some torrents with UDP annouce URLs don't have /announce. */
else if (strncmp(announce, "udp:", 4) == 0)
*
*/
-#include <assert.h>
#include <string.h> /* strcmp() */
#include <stdio.h>
#include <errno.h>
#include <string.h>
-#include <assert.h>
#include <sys/types.h>
#include "transmission.h"
#include "fdlimit.h" /* tr_fdSocketClose() */
+#include "log.h"
#include "net.h"
#include "peer-io.h" /* tr_peerIoAddrStr() FIXME this should be moved to net.h */
#include "session.h" /* tr_sessionGetPublicAddress() */
+#include "tr-assert.h"
#include "tr-utp.h" /* tr_utpSendTo() */
-#include "log.h"
#include "utils.h" /* tr_time(), tr_logAddDebug() */
#ifndef IN_MULTICAST
char const* tr_address_to_string_with_buf(tr_address const* addr, char* buf, size_t buflen)
{
- assert(tr_address_is_valid(addr));
+ TR_ASSERT(tr_address_is_valid(addr));
if (addr->type == TR_AF_INET)
{
static socklen_t setup_sockaddr(tr_address const* addr, tr_port port, struct sockaddr_storage* sockaddr)
{
- assert(tr_address_is_valid(addr));
+ TR_ASSERT(tr_address_is_valid(addr));
if (addr->type == TR_AF_INET)
{
struct sockaddr_storage source_sock;
char err_buf[512];
- assert(tr_address_is_valid(addr));
+ TR_ASSERT(tr_address_is_valid(addr));
if (!tr_address_is_valid_for_peers(addr, port))
{
/* set source address */
source_addr = tr_sessionGetPublicAddress(session, addr->type, NULL);
- assert(source_addr);
+ TR_ASSERT(source_addr);
sourcelen = setup_sockaddr(source_addr, 0, &source_sock);
if (bind(s, (struct sockaddr*)&source_sock, sourcelen) == -1)
int addrlen;
int optval;
- assert(tr_address_is_valid(addr));
+ TR_ASSERT(tr_address_is_valid(addr));
fd = socket(domains[addr->type], SOCK_STREAM, 0);
{
static unsigned char const zeroes[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- assert(tr_address_is_valid(a));
+ TR_ASSERT(tr_address_is_valid(a));
switch (a->type)
{
*
*/
-#include <assert.h>
#include <errno.h>
#include <string.h>
#include "net.h"
#include "peer-common.h" /* MAX_BLOCK_SIZE */
#include "peer-io.h"
-#include "trevent.h" /* tr_runInEventThread() */
+#include "tr-assert.h"
#include "tr-utp.h"
+#include "trevent.h" /* tr_runInEventThread() */
#include "utils.h"
#ifdef _WIN32
break;
}
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
}
tr_sessionUnlock(session);
tr_direction const dir = TR_DOWN;
unsigned int const max = 256 * 1024;
- assert(tr_isPeerIo(io));
- assert(io->socket != TR_BAD_SOCKET);
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(io->socket != TR_BAD_SOCKET);
io->pendingEvents &= ~EV_READ;
tr_direction const dir = TR_UP;
char errstr[1024];
- assert(tr_isPeerIo(io));
- assert(io->socket != TR_BAD_SOCKET);
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(io->socket != TR_BAD_SOCKET);
io->pendingEvents &= ~EV_WRITE;
{
int rc;
tr_peerIo* io = closure;
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
rc = evbuffer_add(io->inbuf, buf, buflen);
dbgmsg(io, "utp_on_read got %zu bytes", buflen);
{
int rc;
tr_peerIo* io = closure;
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
rc = evbuffer_remove(io->outbuf, buf, buflen);
dbgmsg(io, "utp_on_write sending %zu bytes... evbuffer_remove returned %d", buflen, rc);
- assert(rc == (int)buflen); /* if this fails, we've corrupted our bookkeeping somewhere */
+ TR_ASSERT(rc == (int)buflen); /* if this fails, we've corrupted our bookkeeping somewhere */
if (rc < (long)buflen)
{
{
size_t bytes;
tr_peerIo* io = closure;
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
bytes = tr_bandwidthClamp(&io->bandwidth, TR_DOWN, UTP_READ_BUFFER_SIZE);
static void utp_on_state_change(void* closure, int state)
{
tr_peerIo* io = closure;
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
if (state == UTP_STATE_CONNECT)
{
static void utp_on_error(void* closure, int errcode)
{
tr_peerIo* io = closure;
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
dbgmsg(io, "utp_on_error -- errcode is %d", errcode);
static void utp_on_overhead(void* closure, uint8_t /* bool */ send, size_t count, int type UNUSED)
{
tr_peerIo* io = closure;
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
dbgmsg(io, "utp_on_overhead -- count is %zu", count);
{
tr_peerIo* io;
- assert(session != NULL);
- assert(session->events != NULL);
- assert(tr_amInEventThread(session));
- assert((socket == TR_BAD_SOCKET) == (utp_socket != NULL));
+ TR_ASSERT(session != NULL);
+ TR_ASSERT(session->events != NULL);
+ TR_ASSERT(tr_amInEventThread(session));
+ TR_ASSERT((socket == TR_BAD_SOCKET) == (utp_socket != NULL));
#ifndef WITH_UTP
- assert(socket != TR_BAD_SOCKET);
+ TR_ASSERT(socket != TR_BAD_SOCKET);
#endif
if (socket != TR_BAD_SOCKET)
tr_peerIo* tr_peerIoNewIncoming(tr_session* session, tr_bandwidth* parent, tr_address const* addr, tr_port port, tr_socket_t fd,
struct UTPSocket* utp_socket)
{
- assert(session != NULL);
- assert(tr_address_is_valid(addr));
+ TR_ASSERT(session != NULL);
+ TR_ASSERT(tr_address_is_valid(addr));
return tr_peerIoNew(session, parent, addr, port, NULL, true, false, fd, utp_socket);
}
tr_socket_t fd = TR_BAD_SOCKET;
struct UTPSocket* utp_socket = NULL;
- assert(session != NULL);
- assert(tr_address_is_valid(addr));
- assert(torrentHash != NULL);
+ TR_ASSERT(session != NULL);
+ TR_ASSERT(tr_address_is_valid(addr));
+ TR_ASSERT(torrentHash != NULL);
if (utp)
{
static void event_enable(tr_peerIo* io, short event)
{
- assert(tr_amInEventThread(io->session));
- assert(io->session != NULL);
- assert(io->session->events != NULL);
+ TR_ASSERT(tr_amInEventThread(io->session));
+ TR_ASSERT(io->session != NULL);
+ TR_ASSERT(io->session->events != NULL);
if (io->socket != TR_BAD_SOCKET)
{
- assert(event_initialized(io->event_read));
- assert(event_initialized(io->event_write));
+ TR_ASSERT(event_initialized(io->event_read));
+ TR_ASSERT(event_initialized(io->event_write));
}
if ((event & EV_READ) != 0 && (io->pendingEvents & EV_READ) == 0)
static void event_disable(struct tr_peerIo* io, short event)
{
- assert(tr_amInEventThread(io->session));
- assert(io->session != NULL);
- assert(io->session->events != NULL);
+ TR_ASSERT(tr_amInEventThread(io->session));
+ TR_ASSERT(io->session != NULL);
+ TR_ASSERT(io->session->events != NULL);
if (io->socket != TR_BAD_SOCKET)
{
- assert(event_initialized(io->event_read));
- assert(event_initialized(io->event_write));
+ TR_ASSERT(event_initialized(io->event_read));
+ TR_ASSERT(event_initialized(io->event_write));
}
if ((event & EV_READ) != 0 && (io->pendingEvents & EV_READ) != 0)
{
short const event = dir == TR_UP ? EV_WRITE : EV_READ;
- assert(tr_isPeerIo(io));
- assert(tr_isDirection(dir));
- assert(tr_amInEventThread(io->session));
- assert(io->session->events != NULL);
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(tr_isDirection(dir));
+ TR_ASSERT(tr_amInEventThread(io->session));
+ TR_ASSERT(io->session->events != NULL);
if (isEnabled)
{
{
tr_peerIo* io = vio;
- assert(tr_isPeerIo(io));
- assert(tr_amInEventThread(io->session));
- assert(io->session->events != NULL);
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(tr_amInEventThread(io->session));
+ TR_ASSERT(io->session->events != NULL);
dbgmsg(io, "in tr_peerIo destructor");
event_disable(io, EV_READ | EV_WRITE);
void tr_peerIoRefImpl(char const* file, int line, tr_peerIo* io)
{
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
dbgmsg(io, "%s:%d is incrementing the IO's refcount from %d to %d", file, line, io->refCount, io->refCount + 1);
void tr_peerIoUnrefImpl(char const* file, int line, tr_peerIo* io)
{
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
dbgmsg(io, "%s:%d is decrementing the IO's refcount from %d to %d", file, line, io->refCount, io->refCount - 1);
tr_address const* tr_peerIoGetAddress(tr_peerIo const* io, tr_port* port)
{
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
if (port != NULL)
{
short int pendingEvents;
tr_session* session;
- assert(tr_isPeerIo(io));
- assert(!tr_peerIoIsIncoming(io));
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(!tr_peerIoIsIncoming(io));
session = tr_peerIoGetSession(io);
void tr_peerIoSetTorrentHash(tr_peerIo* io, uint8_t const* hash)
{
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
tr_cryptoSetTorrentHash(&io->crypto, hash);
}
uint8_t const* tr_peerIoGetTorrentHash(tr_peerIo* io)
{
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
return tr_cryptoGetTorrentHash(&io->crypto);
}
bool tr_peerIoHasTorrentHash(tr_peerIo const* io)
{
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
return tr_cryptoHasTorrentHash(&io->crypto);
}
void tr_peerIoSetPeersId(tr_peerIo* io, uint8_t const* peer_id)
{
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
if ((io->peerIdIsSet = peer_id != NULL))
{
void tr_peerIoSetEncryption(tr_peerIo* io, tr_encryption_type encryption_type)
{
- assert(tr_isPeerIo(io));
- assert(encryption_type == PEER_ENCRYPTION_NONE || encryption_type == PEER_ENCRYPTION_RC4);
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(encryption_type == PEER_ENCRYPTION_NONE || encryption_type == PEER_ENCRYPTION_RC4);
io->encryption_type = encryption_type;
}
callback(crypto, iovec.iov_len, iovec.iov_base, iovec.iov_base);
- assert(size >= iovec.iov_len);
+ TR_ASSERT(size >= iovec.iov_len);
size -= iovec.iov_len;
}
while (!evbuffer_ptr_set(buffer, &pos, iovec.iov_len, EVBUFFER_PTR_ADD));
- assert(size == 0);
+ TR_ASSERT(size == 0);
}
static void addDatatype(tr_peerIo* io, size_t byteCount, bool isPieceData)
struct evbuffer* tmp;
size_t const old_length = evbuffer_get_length(outbuf);
- assert(tr_isPeerIo(io));
- assert(evbuffer_get_length(inbuf) >= byteCount);
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(evbuffer_get_length(inbuf) >= byteCount);
/* append it to outbuf */
tmp = evbuffer_new();
void tr_peerIoReadBytes(tr_peerIo* io, struct evbuffer* inbuf, void* bytes, size_t byteCount)
{
- assert(tr_isPeerIo(io));
- assert(evbuffer_get_length(inbuf) >= byteCount);
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(evbuffer_get_length(inbuf) >= byteCount);
switch (io->encryption_type)
{
break;
default:
- assert(false);
+ TR_ASSERT_MSG(false, "unhandled encryption type %d", (int)io->encryption_type);
}
}
{
int bytesUsed = 0;
- assert(tr_isPeerIo(io));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(tr_isDirection(dir));
if (dir == TR_DOWN)
{
static inline tr_session* tr_peerIoGetSession(tr_peerIo* io)
{
- assert(tr_isPeerIo(io));
- assert(io->session != NULL);
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(io->session != NULL);
return io->session;
}
static inline uint8_t const* tr_peerIoGetPeersId(tr_peerIo const* io)
{
- assert(tr_isPeerIo(io));
- assert(io->peerIdIsSet);
+ TR_ASSERT(tr_isPeerIo(io));
+ TR_ASSERT(io->peerIdIsSet);
return io->peerId;
}
static inline void tr_peerIoSetParent(tr_peerIo* io, struct tr_bandwidth* parent)
{
- assert(tr_isPeerIo(io));
+ TR_ASSERT(tr_isPeerIo(io));
tr_bandwidthSetParent(&io->bandwidth, parent);
}
*
*/
-#include <assert.h>
#include <errno.h> /* error codes ERANGE, ... */
#include <limits.h> /* INT_MAX */
#include <string.h> /* memcpy, memcmp, strstr */
#include "session.h"
#include "stats.h" /* tr_statsAddUploaded, tr_statsAddDownloaded */
#include "torrent.h"
+#include "tr-assert.h"
#include "tr-utp.h"
#include "utils.h"
#include "webseed.h"
tr_address addr;
};
-#ifdef NDEBUG
+#ifndef TR_ENABLE_ASSERTS
-#define tr_isAtom(a) (TRUE)
+#define tr_isAtom(a) (true)
#else
static bool tr_peerIsTransferringPieces(tr_peer const* peer, uint64_t now, tr_direction direction, unsigned int* Bps)
{
- assert(peer != NULL);
- assert(peer->funcs != NULL);
+ TR_ASSERT(peer != NULL);
+ TR_ASSERT(peer->funcs != NULL);
return (*peer->funcs->is_transferring_pieces)(peer, now, direction, Bps);
}
static void tr_peerFree(tr_peer* peer)
{
- assert(peer != NULL);
- assert(peer->funcs != NULL);
+ TR_ASSERT(peer != NULL);
+ TR_ASSERT(peer->funcs != NULL);
(*peer->funcs->destruct)(peer);
void tr_peerConstruct(tr_peer* peer, tr_torrent const* tor)
{
- assert(peer != NULL);
- assert(tr_isTorrent(tor));
+ TR_ASSERT(peer != NULL);
+ TR_ASSERT(tr_isTorrent(tor));
memset(peer, 0, sizeof(tr_peer));
void tr_peerDestruct(tr_peer* peer)
{
- assert(peer != NULL);
+ TR_ASSERT(peer != NULL);
if (peer->swarm != NULL)
{
managerUnlock(swarm->manager);
}
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
static inline int swarmIsLocked(tr_swarm const* swarm)
{
return tr_sessionIsLocked(swarm->manager->session);
}
-#endif /* NDEBUG */
+#endif /* TR_ENABLE_ASSERTS */
/**
***
{
struct peer_atom const* b = vb;
- assert(tr_isAtom(b));
+ TR_ASSERT(tr_isAtom(b));
return comparePeerAtomToAddress(va, &b->addr);
}
{
tr_swarm* s = (tr_swarm*)cs;
- assert(swarmIsLocked(s));
+ TR_ASSERT(swarmIsLocked(s));
return atom->peer != NULL || getExistingHandshake(&s->outgoingHandshakes, &atom->addr) ||
getExistingHandshake(&s->manager->incomingHandshakes, &atom->addr);
tr_piece_index_t const piece_count = s->tor->info.pieceCount;
int const n = tr_ptrArraySize(&s->peers);
- assert(!replicationExists(s));
+ TR_ASSERT(!replicationExists(s));
s->pieceReplicationSize = piece_count;
s->pieceReplication = tr_new0(uint16_t, piece_count);
{
tr_swarm* s = vs;
- assert(s != NULL);
- assert(!s->isRunning);
- assert(swarmIsLocked(s));
- assert(tr_ptrArrayEmpty(&s->outgoingHandshakes));
- assert(tr_ptrArrayEmpty(&s->peers));
+ TR_ASSERT(s != NULL);
+ TR_ASSERT(!s->isRunning);
+ TR_ASSERT(swarmIsLocked(s));
+ TR_ASSERT(tr_ptrArrayEmpty(&s->outgoingHandshakes));
+ TR_ASSERT(tr_ptrArrayEmpty(&s->peers));
tr_ptrArrayDestruct(&s->webseeds, (PtrArrayForeachFunc)tr_peerFree);
tr_ptrArrayDestruct(&s->pool, (PtrArrayForeachFunc)tr_free);
static void atomSetSeedProbability(struct peer_atom* atom, int seedProbability)
{
- assert(atom != NULL);
- assert(-1 <= seedProbability && seedProbability <= 100);
+ TR_ASSERT(atom != NULL);
+ TR_ASSERT(seedProbability >= -1);
+ TR_ASSERT(seedProbability <= 100);
atom->seedProbability = seedProbability;
bool exact;
int const pos = tr_lowerBound(&key, s->requests, s->requestCount, sizeof(struct block_request), compareReqByBlock,
&exact);
- assert(!exact);
+ TR_ASSERT(!exact);
memmove(s->requests + pos + 1, s->requests + pos, sizeof(struct block_request) * (s->requestCount++ - pos));
s->requests[pos] = key;
}
if (peer != NULL)
{
++peer->pendingReqsToPeer;
- assert(peer->pendingReqsToPeer >= 0);
+ TR_ASSERT(peer->pendingReqsToPeer >= 0);
}
// fprintf(stderr, "added request of block %lu from peer %s... there are now %d block\n", (unsigned long)block,
key.peer = NULL;
pos = tr_lowerBound(&key, s->requests, s->requestCount, sizeof(struct block_request), compareReqByBlock, &exact);
- assert(!exact); /* shouldn't have a request with .peer == NULL */
+ TR_ASSERT(!exact); /* shouldn't have a request with .peer == NULL */
for (int i = pos; i < s->requestCount; ++i)
{
if (b != NULL)
{
int const pos = b - s->requests;
- assert(pos < s->requestCount);
+ TR_ASSERT(pos < s->requestCount);
decrementPendingReqCount(b);
static void updateEndgame(tr_swarm* s)
{
- assert(s->requestCount >= 0);
+ TR_ASSERT(s->requestCount >= 0);
if (!testForEndgame(s))
{
static void pieceListSort(tr_swarm* s, enum piece_sort_state state)
{
- assert(state == PIECES_SORTED_BY_INDEX || state == PIECES_SORTED_BY_WEIGHT);
+ TR_ASSERT(state == PIECES_SORTED_BY_INDEX || state == PIECES_SORTED_BY_WEIGHT);
if (state == PIECES_SORTED_BY_WEIGHT)
{
for (int i = 0; i < t->pieceCount - 1; ++i)
{
- assert(comparePieceByWeight(&t->pieces[i], &t->pieces[i + 1]) <= 0);
+ TR_ASSERT(comparePieceByWeight(&t->pieces[i], &t->pieces[i + 1]) <= 0);
}
}
}
tr_peer const** peers = (tr_peer const**)tr_ptrArrayBase(&t->peers);
int const peer_count = tr_ptrArraySize(&t->peers);
- assert(piece_count == t->tor->info.pieceCount);
+ TR_ASSERT(piece_count == t->tor->info.pieceCount);
for (size_t piece_i = 0; piece_i < piece_count; ++piece_i)
{
}
}
- assert(rep[piece_i] == r);
+ TR_ASSERT(rep[piece_i] == r);
}
}
*/
static void tr_incrReplicationOfPiece(tr_swarm* s, size_t const index)
{
- assert(replicationExists(s));
- assert(s->pieceReplicationSize == s->tor->info.pieceCount);
+ TR_ASSERT(replicationExists(s));
+ TR_ASSERT(s->pieceReplicationSize == s->tor->info.pieceCount);
/* One more replication of this piece is present in the swarm */
++s->pieceReplication[index];
uint16_t* rep = s->pieceReplication;
size_t const n = s->tor->info.pieceCount;
- assert(replicationExists(s));
+ TR_ASSERT(replicationExists(s));
for (size_t i = 0; i < n; ++i)
{
*/
static void tr_incrReplication(tr_swarm* s)
{
- assert(replicationExists(s));
- assert(s->pieceReplicationSize == s->tor->info.pieceCount);
+ TR_ASSERT(replicationExists(s));
+ TR_ASSERT(s->pieceReplicationSize == s->tor->info.pieceCount);
for (size_t i = 0; i < s->pieceReplicationSize; ++i)
{
*/
static void tr_decrReplicationFromBitfield(tr_swarm* s, tr_bitfield const* b)
{
- assert(replicationExists(s));
- assert(s->pieceReplicationSize == s->tor->info.pieceCount);
+ TR_ASSERT(replicationExists(s));
+ TR_ASSERT(s->pieceReplicationSize == s->tor->info.pieceCount);
if (tr_bitfieldHasAll(b))
{
void tr_peerMgrRebuildRequests(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
pieceListRebuild(tor->swarm);
}
tr_bitfield const* const have = &peer->have;
/* sanity clause */
- assert(tr_isTorrent(tor));
- assert(numwant > 0);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(numwant > 0);
/* walk through the pieces and find blocks that should be requested */
s = tor->swarm;
if (msgs != NULL && request->sentAt <= too_old && !tr_peerMsgsIsReadingBlock(msgs, request->block))
{
- assert(cancel != NULL);
- assert(cancelCount < cancel_buflen);
+ TR_ASSERT(cancel != NULL);
+ TR_ASSERT(cancelCount < cancel_buflen);
cancel[cancelCount++] = *request;
}
{
#if 0
- assert(t != NULL);
- assert(peer != NULL);
- assert(peer->msgs != NULL);
+ TR_ASSERT(t != NULL);
+ TR_ASSERT(peer != NULL);
+ TR_ASSERT(peer->msgs != NULL);
/* is this a valid piece? */
if (pieceIndex >= t->tor->info.pieceCount)
swarmLock(s);
- assert(peer != NULL);
+ TR_ASSERT(peer != NULL);
switch (e->eventType)
{
break;
case TR_PEER_CLIENT_GOT_BITFIELD:
- assert(e->bitfield != NULL);
+ TR_ASSERT(e->bitfield != NULL);
if (replicationExists(s))
{
break;
default:
- assert(0);
+ TR_ASSERT_MSG(false, "unhandled peer event type %d", (int)e->eventType);
}
swarmUnlock(s);
{
struct peer_atom* a;
- assert(tr_address_is_valid(addr));
- assert(from < TR_PEER_FROM__MAX);
+ TR_ASSERT(tr_address_is_valid(addr));
+ TR_ASSERT(from < TR_PEER_FROM__MAX);
a = getExistingAtom(s, addr);
tr_peerMsgs* msgs;
tr_swarm* swarm;
- assert(atom != NULL);
- assert(tr_isTorrent(tor));
- assert(tor->swarm != NULL);
+ TR_ASSERT(atom != NULL);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tor->swarm != NULL);
swarm = tor->swarm;
++swarm->stats.peerCount;
++swarm->stats.peerFromCount[atom->fromFirst];
- assert(swarm->stats.peerCount == tr_ptrArraySize(&swarm->peers));
- assert(swarm->stats.peerFromCount[atom->fromFirst] <= swarm->stats.peerCount);
+ TR_ASSERT(swarm->stats.peerCount == tr_ptrArraySize(&swarm->peers));
+ TR_ASSERT(swarm->stats.peerFromCount[atom->fromFirst] <= swarm->stats.peerCount);
msgs = PEER_MSGS(peer);
tr_peerMsgsUpdateActive(msgs, TR_UP);
tr_peerMgr* manager = vmanager;
tr_swarm* s;
- assert(io != NULL);
+ TR_ASSERT(io != NULL);
s = tr_peerIoHasTorrentHash(io) ? getExistingSwarm(manager, tr_peerIoGetTorrentHash(io)) : NULL;
ensureAtomExists(s, addr, port, 0, -1, TR_PEER_FROM_INCOMING);
atom = getExistingAtom(s, addr);
- assert(atom != NULL);
+ TR_ASSERT(atom != NULL);
atom->time = tr_time();
atom->piece_data_time = 0;
managerLock(manager);
- assert(tr_isSession(manager->session));
+ TR_ASSERT(tr_isSession(manager->session));
session = manager->session;
if (tr_sessionIsAddressBlocked(session, addr))
tr_pex const* a = va;
tr_pex const* b = vb;
- assert(tr_isPex(a));
- assert(tr_isPex(b));
+ TR_ASSERT(tr_isPex(a));
+ TR_ASSERT(tr_isPex(b));
if ((i = tr_address_compare(&a->addr, &b->addr)) != 0)
{
struct peer_atom const* a = *(struct peer_atom const* const*)va;
struct peer_atom const* b = *(struct peer_atom const* const*)vb;
- assert(tr_isAtom(a));
- assert(tr_isAtom(b));
+ TR_ASSERT(tr_isAtom(a));
+ TR_ASSERT(tr_isAtom(b));
if (a->piece_data_time != b->piece_data_time)
{
tr_pex* pex;
tr_pex* walk;
- assert(tr_isTorrent(tor));
- assert(setme_pex != NULL);
- assert(af == TR_AF_INET || af == TR_AF_INET6);
- assert(list_mode == TR_PEERS_CONNECTED || list_mode == TR_PEERS_INTERESTING);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(setme_pex != NULL);
+ TR_ASSERT(af == TR_AF_INET || af == TR_AF_INET6);
+ TR_ASSERT(list_mode == TR_PEERS_CONNECTED || list_mode == TR_PEERS_INTERESTING);
managerLock(s->manager);
if (atom->addr.type == af)
{
- assert(tr_address_is_valid(&atom->addr));
+ TR_ASSERT(tr_address_is_valid(&atom->addr));
walk->addr = atom->addr;
walk->port = atom->port;
walk->flags = atom->flags;
qsort(pex, count, sizeof(tr_pex), tr_pexCompare);
- assert(walk - pex == count);
+ TR_ASSERT(walk - pex == count);
*setme_pex = pex;
/* cleanup */
{
tr_swarm* s;
- assert(tr_isTorrent(tor));
- assert(tr_torrentIsLocked(tor));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_torrentIsLocked(tor));
s = tor->swarm;
ensureMgrTimersExist(s->manager);
void tr_peerMgrStopTorrent(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
- assert(tr_torrentIsLocked(tor));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_torrentIsLocked(tor));
stopSwarm(tor->swarm);
}
void tr_peerMgrAddTorrent(tr_peerMgr* manager, tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
- assert(tr_torrentIsLocked(tor));
- assert(tor->swarm == NULL);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_torrentIsLocked(tor));
+ TR_ASSERT(tor->swarm == NULL);
tor->swarm = swarmNew(manager, tor);
}
void tr_peerMgrRemoveTorrent(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
- assert(tr_torrentIsLocked(tor));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_torrentIsLocked(tor));
stopSwarm(tor->swarm);
swarmFree(tor->swarm);
void tr_peerMgrTorrentAvailability(tr_torrent const* tor, int8_t* tab, unsigned int tabCount)
{
- assert(tr_isTorrent(tor));
- assert(tab != NULL);
- assert(tabCount > 0);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tab != NULL);
+ TR_ASSERT(tabCount > 0);
memset(tab, 0, tabCount);
void tr_swarmGetStats(tr_swarm const* swarm, tr_swarm_stats* setme)
{
- assert(swarm != NULL);
- assert(setme != NULL);
+ TR_ASSERT(swarm != NULL);
+ TR_ASSERT(setme != NULL);
*setme = swarm->stats;
}
--n;
}
- assert(0 <= n);
- assert(n <= swarm->stats.peerCount);
+ TR_ASSERT(n >= 0);
+ TR_ASSERT(n <= swarm->stats.peerCount);
swarm->stats.activePeerCount[direction] = n;
}
uint64_t desiredAvailable;
tr_swarm const* s;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
/* common shortcuts... */
}
}
- assert(desiredAvailable <= tor->info.totalSize);
+ TR_ASSERT(desiredAvailable <= tor->info.totalSize);
return desiredAvailable;
}
double* ret = NULL;
uint64_t const now = tr_time_msec();
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
s = tor->swarm;
n = tr_ptrArraySize(&s->webseeds);
ret = tr_new0(double, n);
- assert(s->manager != NULL);
- assert(n == tor->info.webseedCount);
+ TR_ASSERT(s->manager != NULL);
+ TR_ASSERT(n == tor->info.webseedCount);
for (unsigned int i = 0; i < n; ++i)
{
time_t const now = tr_time();
uint64_t const now_msec = tr_time_msec();
- assert(tr_isTorrent(tor));
- assert(tor->swarm->manager != NULL);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tor->swarm->manager != NULL);
s = tor->swarm;
peers = (tr_peer**)tr_ptrArrayBase(&s->peers);
tr_swarm* s = tor->swarm;
int const peerCount = tr_ptrArraySize(&s->peers);
- assert(tr_isTorrent(tor));
- assert(tr_torrentIsLocked(tor));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_torrentIsLocked(tor));
for (int i = 0; i < peerCount; ++i)
{
static bool isPeerInteresting(tr_torrent* const tor, bool const* const piece_is_interesting, tr_peer const* const peer)
{
/* these cases should have already been handled by the calling code... */
- assert(!tr_torrentIsSeed(tor));
- assert(tr_torrentIsPieceTransferAllowed(tor, TR_PEER_TO_CLIENT));
+ TR_ASSERT(!tr_torrentIsSeed(tor));
+ TR_ASSERT(tr_torrentIsPieceTransferAllowed(tor, TR_PEER_TO_CLIENT));
if (tr_peerIsSeed(peer))
{
bool const chokeAll = !tr_torrentIsPieceTransferAllowed(s->tor, TR_CLIENT_TO_PEER);
bool const isMaxedOut = isBandwidthMaxedOut(&s->tor->bandwidth, now, TR_UP);
- assert(swarmIsLocked(s));
+ TR_ASSERT(swarmIsLocked(s));
/* an optimistic unchoke peer's "optimistic"
* state lasts for N calls to rechokeUploads(). */
struct tr_peer** ret = NULL;
tr_peer** peers = (tr_peer**)tr_ptrArrayPeek(&s->peers, &peerCount);
- assert(swarmIsLocked(s));
+ TR_ASSERT(swarmIsLocked(s));
for (int i = 0; i < peerCount; ++i)
{
{
struct peer_atom* atom = peer->atom;
- assert(swarmIsLocked(s));
- assert(atom != NULL);
+ TR_ASSERT(swarmIsLocked(s));
+ TR_ASSERT(atom != NULL);
atom->time = tr_time();
tr_decrReplicationFromBitfield(s, &peer->have);
}
- assert(s->stats.peerCount == tr_ptrArraySize(&s->peers));
- assert(s->stats.peerFromCount[atom->fromFirst] >= 0);
+ TR_ASSERT(s->stats.peerCount == tr_ptrArraySize(&s->peers));
+ TR_ASSERT(s->stats.peerFromCount[atom->fromFirst] >= 0);
tr_peerFree(peer);
}
{
struct peer_atom* atom;
- assert(s != NULL);
- assert(peer != NULL);
+ TR_ASSERT(s != NULL);
+ TR_ASSERT(peer != NULL);
atom = peer->atom;
removePeer(s, tr_ptrArrayNth(&s->peers, 0));
}
- assert(!s->stats.peerCount);
+ TR_ASSERT(s->stats.peerCount == 0);
}
static void closeBadPeers(tr_swarm* s, time_t const now_sec)
}
/* sort 'em */
- assert(n == l - lives);
+ TR_ASSERT(n == l - lives);
qsort(lives, n, sizeof(struct peer_liveliness), compare);
l = lives;
}
}
- assert(n == l - lives);
+ TR_ASSERT(n == l - lives);
/* cleanup */
tr_free(lives);
static void queuePulse(tr_session* session, tr_direction dir)
{
- assert(tr_isSession(session));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(tr_isDirection(dir));
if (tr_sessionGetQueueEnabled(session, dir))
{
struct peer_atom const* a = *(struct peer_atom const* const*)va;
struct peer_atom const* b = *(struct peer_atom const* const*)vb;
- assert(tr_isAtom(a));
- assert(tr_isAtom(b));
+ TR_ASSERT(tr_isAtom(a));
+ TR_ASSERT(tr_isAtom(b));
return tr_address_compare(&a->addr, &b->addr);
}
int const data_time_cutoff_secs = 60 * 60;
time_t const tr_now = tr_time();
- assert(tr_isAtom(a));
- assert(tr_isAtom(b));
+ TR_ASSERT(tr_isAtom(a));
+ TR_ASSERT(tr_isAtom(b));
/* primary key: the last piece data time *if* it was within the last hour */
atime = a->piece_data_time;
tr_quickfindFirstK(candidates, candidate_count, sizeof(struct peer_candidate), comparePeerCandidates, select_count);
}
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
static bool checkBestScoresComeFirst(struct peer_candidate const* candidates, int n, int k)
{
for (int i = 0; i < x; i++)
{
- assert(candidates[i].score <= worstFirstScore);
+ TR_ASSERT(candidates[i].score <= worstFirstScore);
}
for (int i = x + 1; i < n; i++)
{
- assert(candidates[i].score >= worstFirstScore);
+ TR_ASSERT(candidates[i].score >= worstFirstScore);
}
return true;
}
-#endif /* NDEBUG */
+#endif /* TR_ENABLE_ASSERTS */
/** @return an array of all the atoms we might want to connect to */
static struct peer_candidate* getPeerCandidates(tr_session* session, int* candidateCount, int max)
selectPeerCandidates(candidates, walk - candidates, max);
}
- assert(checkBestScoresComeFirst(candidates, *candidateCount, max));
+ TR_ASSERT(checkBestScoresComeFirst(candidates, *candidateCount, max));
return candidates;
}
{
tr_handshake* handshake = tr_handshakeNew(io, mgr->session->encryptionMode, myHandshakeDoneCB, mgr);
- assert(tr_peerIoGetTorrentHash(io));
+ TR_ASSERT(tr_peerIoGetTorrentHash(io));
tr_peerIoUnref(io); /* balanced by the initial ref in tr_peerIoNewOutgoing() */
*
*/
-#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include "session.h"
#include "torrent.h"
#include "torrent-magnet.h"
+#include "tr-assert.h"
#include "tr-dht.h"
#include "utils.h"
#include "variant.h"
{
struct evbuffer* out = msgs->outMessages;
- assert(tr_peerIoSupportsFEXT(msgs->io));
+ TR_ASSERT(tr_peerIoSupportsFEXT(msgs->io));
evbuffer_add_uint32(out, sizeof(uint8_t) + 3 * sizeof(uint32_t));
evbuffer_add_uint8(out, BT_FEXT_REJECT);
tr_peerIo* io = msgs->io;
struct evbuffer* out = msgs->outMessages;
- assert(tr_peerIoSupportsFEXT(msgs->io));
+ TR_ASSERT(tr_peerIoSupportsFEXT(msgs->io));
evbuffer_add_uint32(io, out, sizeof(uint8_t) + sizeof(uint32_t));
evbuffer_add_uint8(io, out, BT_FEXT_ALLOWED_FAST);
{
struct evbuffer* out = msgs->outMessages;
- assert(tr_peerIoSupportsFEXT(msgs->io));
+ TR_ASSERT(tr_peerIoSupportsFEXT(msgs->io));
evbuffer_add_uint32(out, sizeof(uint8_t));
evbuffer_add_uint8(out, BT_FEXT_HAVE_ALL);
{
struct evbuffer* out = msgs->outMessages;
- assert(tr_peerIoSupportsFEXT(msgs->io));
+ TR_ASSERT(tr_peerIoSupportsFEXT(msgs->io));
evbuffer_add_uint32(out, sizeof(uint8_t));
evbuffer_add_uint8(out, BT_FEXT_HAVE_NONE);
{
size_t setSize = 0;
- assert(setmePieces != NULL);
- assert(desiredSetSize <= pieceCount);
- assert(desiredSetSize != 0);
- assert(pieceCount != 0);
- assert(infohash != NULL);
- assert(addr != NULL);
+ TR_ASSERT(setmePieces != NULL);
+ TR_ASSERT(desiredSetSize <= pieceCount);
+ TR_ASSERT(desiredSetSize != 0);
+ TR_ASSERT(pieceCount != 0);
+ TR_ASSERT(infohash != NULL);
+ TR_ASSERT(addr != NULL);
if (addr->type == TR_AF_INET)
{
memcpy(walk, infohash, SHA_DIGEST_LENGTH); /* (2) */
walk += SHA_DIGEST_LENGTH;
tr_sha1(x, w, walk - w, NULL); /* (3) */
- assert(sizeof(w) == walk - w);
+ TR_ASSERT(sizeof(w) == walk - w);
while (setSize < desiredSetSize)
{
{
bool is_active;
- assert(tr_isPeerMsgs(msgs));
- assert(tr_isDirection(direction));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isDirection(direction));
if (direction == TR_CLIENT_TO_PEER)
{
/* FIXME: https://trac.transmissionbt.com/ticket/5505
if (is_active)
{
- assert(!tr_peerIsSeed(&msgs->peer));
+ TR_ASSERT(!tr_peerIsSeed(&msgs->peer));
}
*/
}
if (is_active)
{
- assert(!tr_torrentIsSeed(msgs->torrent));
+ TR_ASSERT(!tr_torrentIsSeed(msgs->torrent));
}
}
}
{
bool is_active;
- assert(tr_isPeerMsgs(msgs));
- assert(tr_isDirection(direction));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isDirection(direction));
is_active = msgs->is_active[direction];
- assert(is_active == tr_peerMsgsCalculateActive(msgs, direction));
+ TR_ASSERT(is_active == tr_peerMsgsCalculateActive(msgs, direction));
return is_active;
}
{
struct evbuffer* out = msgs->outMessages;
- assert(msgs != NULL);
+ TR_ASSERT(msgs != NULL);
msgs->client_is_interested = b;
dbgmsg(msgs, "Sending %s", b ? "Interested" : "Not Interested");
time_t const now = tr_time();
time_t const fibrillationTime = now - MIN_CHOKE_PERIOD_SEC;
- assert(msgs != NULL);
+ TR_ASSERT(msgs != NULL);
if (msgs->chokeChangedAt > fibrillationTime)
{
{
uint8_t ltep_msgid;
- assert(msglen > 0);
+ TR_ASSERT(msglen > 0);
tr_peerIoReadUint8(msgs->io, inbuf, <ep_msgid);
msglen--;
{
struct peer_request* req = &msgs->incoming.blockReq;
- assert(evbuffer_get_length(inbuf) >= inlen);
+ TR_ASSERT(evbuffer_get_length(inbuf) >= inlen);
dbgmsg(msgs, "In readBtPiece");
if (req->length == 0)
uint32_t ui32;
uint32_t msglen = msgs->incoming.length;
uint8_t const id = msgs->incoming.id;
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
size_t const startBufLen = evbuffer_get_length(inbuf);
#endif
bool const fext = tr_peerIoSupportsFEXT(msgs->io);
- assert(msglen > 0);
+ TR_ASSERT(msglen > 0);
--msglen; /* id length */
}
case BT_PIECE:
- assert(0); /* handled elsewhere! */
+ TR_ASSERT(false); /* handled elsewhere! */
break;
case BT_PORT:
if (fext)
{
tr_bitfieldSetHasAll(&msgs->peer.have);
- assert(tr_bitfieldHasAll(&msgs->peer.have));
+ TR_ASSERT(tr_bitfieldHasAll(&msgs->peer.have));
fireClientGotHaveAll(msgs);
updatePeerProgress(msgs);
}
break;
}
- assert(msglen + 1 == msgs->incoming.length);
- assert(evbuffer_get_length(inbuf) == startBufLen - msglen);
+ TR_ASSERT(msglen + 1 == msgs->incoming.length);
+ TR_ASSERT(evbuffer_get_length(inbuf) == startBufLen - msglen);
msgs->state = AWAITING_BT_LENGTH;
return READ_NOW;
tr_torrent* tor = msgs->torrent;
tr_block_index_t const block = _tr_block(tor, req->index, req->offset);
- assert(msgs);
- assert(req);
+ TR_ASSERT(msgs != NULL);
+ TR_ASSERT(req != NULL);
if (!requestIsValid(msgs, req))
{
default:
ret = READ_ERR;
- assert(0);
+ TR_ASSERT_MSG(false, "unhandled peer messages state %d", (int)msgs->state);
}
}
tr_block_index_t* blocks;
int const numwant = msgs->desiredRequestCount - msgs->peer.pendingReqsToPeer;
- assert(tr_peerMsgsIsClientInterested(msgs));
- assert(!tr_peerMsgsIsClientChoked(msgs));
+ TR_ASSERT(tr_peerMsgsIsClientInterested(msgs));
+ TR_ASSERT(!tr_peerMsgsIsClientChoked(msgs));
blocks = tr_new(tr_block_index_t, numwant);
tr_peerMgrGetNextRequests(msgs->torrent, &msgs->peer, numwant, blocks, &n, false);
{
size_t const n = evbuffer_get_length(out);
dbgmsg(msgs, "sending block %u:%u->%u", req.index, req.offset, req.length);
- assert(n == msglen);
+ TR_ASSERT(n == msglen);
tr_peerIoWriteBuf(msgs->io, out, true);
bytesWritten += n;
msgs->clientSentAnythingAt = now;
size_t byte_count = 0;
struct evbuffer* out = msgs->outMessages;
- assert(tr_torrentHasMetadata(msgs->torrent));
+ TR_ASSERT(tr_torrentHasMetadata(msgs->torrent));
bytes = tr_torrentCreatePieceBitfield(msgs->torrent, &byte_count);
evbuffer_add_uint32(out, sizeof(uint8_t) + byte_count);
walk += 2;
}
- assert(walk - tmp == diffs.addedCount * 6);
+ TR_ASSERT(walk - tmp == diffs.addedCount * 6);
tr_variantDictAddRaw(&val, TR_KEY_added, tmp, walk - tmp);
tr_free(tmp);
*walk++ = diffs.added[i].flags & ~ADDED_F_HOLEPUNCH;
}
- assert(walk - tmp == diffs.addedCount);
+ TR_ASSERT(walk - tmp == diffs.addedCount);
tr_variantDictAddRaw(&val, TR_KEY_added_f, tmp, walk - tmp);
tr_free(tmp);
}
walk += 2;
}
- assert(walk - tmp == diffs.droppedCount * 6);
+ TR_ASSERT(walk - tmp == diffs.droppedCount * 6);
tr_variantDictAddRaw(&val, TR_KEY_dropped, tmp, walk - tmp);
tr_free(tmp);
}
walk += 2;
}
- assert(walk - tmp == diffs6.addedCount * 18);
+ TR_ASSERT(walk - tmp == diffs6.addedCount * 18);
tr_variantDictAddRaw(&val, TR_KEY_added6, tmp, walk - tmp);
tr_free(tmp);
*walk++ = diffs6.added[i].flags & ~ADDED_F_HOLEPUNCH;
}
- assert(walk - tmp == diffs6.addedCount);
+ TR_ASSERT(walk - tmp == diffs6.addedCount);
tr_variantDictAddRaw(&val, TR_KEY_added6_f, tmp, walk - tmp);
tr_free(tmp);
}
walk += 2;
}
- assert(walk - tmp == diffs6.droppedCount * 18);
+ TR_ASSERT(walk - tmp == diffs6.droppedCount * 18);
tr_variantDictAddRaw(&val, TR_KEY_dropped6, tmp, walk - tmp);
tr_free(tmp);
}
sendPex(msgs);
- assert(msgs->pexTimer != NULL);
+ TR_ASSERT(msgs->pexTimer != NULL);
tr_timerAdd(msgs->pexTimer, PEX_INTERVAL_SECS, 0);
}
{
tr_peerMsgs* msgs = PEER_MSGS(peer);
- assert(msgs != NULL);
+ TR_ASSERT(msgs != NULL);
tr_peerMsgsSetActive(msgs, TR_UP, false);
tr_peerMsgsSetActive(msgs, TR_DOWN, false);
time_t tr_peerMsgsGetConnectionAge(tr_peerMsgs const* msgs)
{
- assert(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
return tr_peerIoGetAge(msgs->io);
}
bool tr_peerMsgsIsPeerChoked(tr_peerMsgs const* msgs)
{
- assert(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->peer_is_choked;
}
bool tr_peerMsgsIsPeerInterested(tr_peerMsgs const* msgs)
{
- assert(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->peer_is_interested;
}
bool tr_peerMsgsIsClientChoked(tr_peerMsgs const* msgs)
{
- assert(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->client_is_choked;
}
bool tr_peerMsgsIsClientInterested(tr_peerMsgs const* msgs)
{
- assert(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->client_is_interested;
}
bool tr_peerMsgsIsUtpConnection(tr_peerMsgs const* msgs)
{
- assert(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
return msgs->io->utp_socket != NULL;
}
bool tr_peerMsgsIsEncrypted(tr_peerMsgs const* msgs)
{
- assert(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
return tr_peerIoIsEncrypted(msgs->io);
}
bool tr_peerMsgsIsIncomingConnection(tr_peerMsgs const* msgs)
{
- assert(tr_isPeerMsgs(msgs));
+ TR_ASSERT(tr_isPeerMsgs(msgs));
return tr_peerIoIsIncoming(msgs->io);
}
{
tr_peerMsgs* m;
- assert(io != NULL);
+ TR_ASSERT(io != NULL);
m = tr_new0(tr_peerMsgs, 1);
#define __USE_UNIX98 /* some older Linuxes need it spelt out for them */
#endif
-#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "log.h"
#include "platform.h"
#include "session.h"
+#include "tr-assert.h"
#include "utils.h"
/***
pthread_mutex_lock(&l->lock);
#endif
- assert(l->depth >= 0);
- assert(l->depth == 0 || tr_areThreadsEqual(l->lockThread, tr_getCurrentThread()));
+ TR_ASSERT(l->depth >= 0);
+ TR_ASSERT(l->depth == 0 || tr_areThreadsEqual(l->lockThread, tr_getCurrentThread()));
l->lockThread = tr_getCurrentThread();
++l->depth;
}
void tr_lockUnlock(tr_lock* l)
{
- assert(l->depth > 0);
- assert(tr_areThreadsEqual(l->lockThread, tr_getCurrentThread()));
+ TR_ASSERT(l->depth > 0);
+ TR_ASSERT(tr_areThreadsEqual(l->lockThread, tr_getCurrentThread()));
--l->depth;
- assert(l->depth >= 0);
+ TR_ASSERT(l->depth >= 0);
#ifdef _WIN32
LeaveCriticalSection(&l->lock);
char* appString = tr_malloc(appStringLength);
bool const success = CFStringGetFileSystemRepresentation(appRef, appString, appStringLength);
- assert(success);
+ TR_ASSERT(success);
CFRelease(appURL);
CFRelease(appRef);
*
*/
-#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
#include "port-forwarding.h"
#include "session.h"
#include "torrent.h"
+#include "tr-assert.h"
#include "upnp.h"
#include "utils.h"
{
tr_shared* s = vshared;
- assert(s != NULL);
- assert(s->timer != NULL);
+ TR_ASSERT(s != NULL);
+ TR_ASSERT(s->timer != NULL);
/* do something */
natPulse(s, s->doPortCheck);
*
*/
-#include <assert.h>
#include <string.h> /* memmove */
#include "ptrarray.h"
+#include "tr-assert.h"
#include "utils.h"
#define FLOOR 32
void tr_ptrArrayDestruct(tr_ptrArray* p, PtrArrayForeachFunc func)
{
- assert(p != NULL);
- assert(p->items != NULL || p->n_items == 0);
+ TR_ASSERT(p != NULL);
+ TR_ASSERT(p->items != NULL || p->n_items == 0);
if (func != NULL)
{
void tr_ptrArrayForeach(tr_ptrArray* t, PtrArrayForeachFunc func)
{
- assert(t != NULL);
- assert(t->items != NULL || t->n_items == 0);
- assert(func != NULL);
+ TR_ASSERT(t != NULL);
+ TR_ASSERT(t->items != NULL || t->n_items == 0);
+ TR_ASSERT(func != NULL);
for (int i = 0; i < t->n_items; ++i)
{
end = t->n_items;
}
- assert(begin >= 0);
- assert(begin < end);
- assert(end <= t->n_items);
+ TR_ASSERT(begin >= 0);
+ TR_ASSERT(begin < end);
+ TR_ASSERT(end <= t->n_items);
memmove(t->items + begin, t->items + end, sizeof(void*) * (t->n_items - end));
return pos;
}
-#ifdef NDEBUG
+#ifndef TR_ENABLE_ASSERTS
#define assertArrayIsSortedAndUnique(array, compare) /* no-op */
#define assertIndexIsSortedAndUnique(array, pos, compare) /* no-op */
{
for (int i = 0; i < t->n_items - 2; ++i)
{
- assert(compare(t->items[i], t->items[i + 1]) < 0);
+ TR_ASSERT(compare(t->items[i], t->items[i + 1]) < 0);
}
}
{
if (pos > 0)
{
- assert(compare(t->items[pos - 1], t->items[pos]) < 0);
+ TR_ASSERT(compare(t->items[pos - 1], t->items[pos]) < 0);
}
if (pos + 1 < t->n_items)
{
- assert(compare(t->items[pos], t->items[pos + 1]) < 0);
+ TR_ASSERT(compare(t->items[pos], t->items[pos + 1]) < 0);
}
}
if (match)
{
ret = t->items[pos];
- assert(compare(ret, ptr) == 0);
+ TR_ASSERT(compare(ret, ptr) == 0);
tr_ptrArrayErase(t, pos, pos + 1);
}
- assert((ret == NULL) || (compare(ret, ptr) == 0));
+ TR_ASSERT((ret == NULL) || (compare(ret, ptr) == 0));
return ret;
}
void tr_ptrArrayRemoveSortedPointer(tr_ptrArray* t, void const* ptr, int (* compare)(void const*, void const*))
{
-#ifdef NDEBUG
+#ifndef TR_ENABLE_ASSERTS
tr_ptrArrayRemoveSortedValue(t, ptr, compare);
#else
void* removed = tr_ptrArrayRemoveSortedValue(t, ptr, compare);
- assert(removed != NULL);
- assert(removed == ptr);
- assert(tr_ptrArrayFindSorted(t, ptr, compare) == NULL);
+ TR_ASSERT(removed != NULL);
+ TR_ASSERT(removed == ptr);
+ TR_ASSERT(tr_ptrArrayFindSorted(t, ptr, compare) == NULL);
#endif
}
#pragma once
-#include <assert.h>
-
#include "transmission.h"
+#include "tr-assert.h"
/**
* @addtogroup utils Utilities
@return the nth item in a tr_ptrArray */
static inline void* tr_ptrArrayNth(tr_ptrArray* array, int i)
{
- assert(array != NULL);
- assert(i >= 0);
- assert(i < array->n_items);
+ TR_ASSERT(array != NULL);
+ TR_ASSERT(i >= 0);
+ TR_ASSERT(i < array->n_items);
return array->items[i];
}
*
*/
-#include <assert.h>
#include <stdlib.h> /* bsearch() */
#include <string.h> /* memcmp() */
#include "transmission.h"
#include "ptrarray.h"
#include "quark.h"
+#include "tr-assert.h"
#include "utils.h" /* tr_memdup(), tr_strndup() */
struct tr_key_struct
static size_t const n_static = TR_N_ELEMENTS(my_static);
bool success = false;
- assert(n_static == TR_N_KEYS);
+ TR_ASSERT(n_static == TR_N_KEYS);
tmp.str = str;
tmp.len = len;
*
*/
-#include <assert.h>
#include <errno.h>
#include <stdio.h> /* fopen() */
#include <string.h> /* strcmp() */
#include "file.h"
#include "resume.h"
#include "torrent.h" /* tr_isTorrent() */
+#include "tr-assert.h"
#include "variant.h"
#include "libtransmission-test.h"
uint8_t* contents;
size_t contents_len;
- assert(tr_sys_path_exists(path, NULL));
+ TR_ASSERT(tr_sys_path_exists(path, NULL));
contents = tr_loadFile(path, &contents_len, NULL);
/* create the torrent ctor */
metainfo = tr_base64_decode_str(metainfo_base64, &metainfo_len);
- assert(metainfo != NULL);
- assert(metainfo_len > 0);
+ TR_ASSERT(metainfo != NULL);
+ TR_ASSERT(metainfo_len > 0);
tr_ctorSetMetainfo(ctor, (uint8_t*)metainfo, metainfo_len);
tr_ctorSetPaused(ctor, TR_FORCE, true);
/* create the torrent */
err = 0;
tor = tr_torrentNew(ctor, &err, NULL);
- assert(err == 0);
+ TR_ASSERT(err == 0);
/* cleanup */
tr_free(metainfo);
#include "resume.h"
#include "session.h"
#include "torrent.h"
+#include "tr-assert.h"
#include "utils.h" /* tr_buildPath */
#include "variant.h"
bool const wasDirty = tor->isDirty;
tr_error* error = NULL;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
filename = getResumeFilename(tor);
{
uint64_t ret = 0;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
ret |= useManditoryFields(tor, fieldsToLoad, ctor);
fieldsToLoad &= ~ret;
*
*/
-#include <assert.h>
#include <errno.h>
#include <string.h> /* memcpy */
#include "rpc-server.h"
#include "session.h"
#include "session-id.h"
+#include "tr-assert.h"
#include "trevent.h"
#include "utils.h"
#include "variant.h"
void tr_rpcSetPort(tr_rpc_server* server, tr_port port)
{
- assert(server != NULL);
+ TR_ASSERT(server != NULL);
if (server->port != port)
{
*
*/
-#include <assert.h>
#include <ctype.h> /* isdigit */
#include <errno.h>
#include <stdlib.h> /* strtol */
#include "session.h"
#include "session-id.h"
#include "torrent.h"
+#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
#include "version.h"
int torrentCount;
tr_torrent** torrents;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
qsort(torrents, torrentCount, sizeof(tr_torrent*), compareTorrentByQueuePosition);
int torrentCount;
tr_torrent** torrents;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
qsort(torrents, torrentCount, sizeof(tr_torrent*), compareTorrentByQueuePosition);
int torrentCount;
tr_torrent** torrents;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
bool deleteFlag;
tr_torrent** torrents;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
if (!tr_variantDictFindBool(args_in, TR_KEY_delete_local_data, &deleteFlag))
{
int torrentCount;
tr_torrent** torrents;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
int torrentCount;
tr_torrent** torrents;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
char const* strVal;
char const* errmsg = NULL;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
if (tr_variantDictFindStr(args_in, TR_KEY_ids, &strVal, NULL) && strcmp(strVal, "recently-active") == 0)
{
tr_torrent** torrents;
char const* errmsg = NULL;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
torrents = getTorrents(session, args_in, &torrentCount);
{
char const* location = NULL;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
if (!tr_variantDictFindStr(args_in, TR_KEY_location, &location, NULL))
{
char const* filename = NULL;
char const* metainfo_base64 = NULL;
- assert(idle_data != NULL);
+ TR_ASSERT(idle_data != NULL);
tr_variantDictFindStr(args_in, TR_KEY_filename, &filename, NULL);
tr_variantDictFindStr(args_in, TR_KEY_metainfo, &metainfo_base64, NULL);
static char const* sessionSet(tr_session* session, tr_variant* args_in, tr_variant* args_out UNUSED,
struct tr_rpc_idle_data* idle_data UNUSED)
{
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
char const* download_dir = NULL;
char const* incomplete_dir = NULL;
tr_session_stats cumulativeStats = { 0.0f, 0, 0, 0, 0, 0 };
tr_torrent* tor = NULL;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
while ((tor = tr_torrentNext(session, tor)) != NULL)
{
{
tr_variant* fields;
- assert(idle_data == NULL);
+ TR_ASSERT(idle_data == NULL);
if (tr_variantDictFindList(args_in, TR_KEY_fields, &fields))
{
*
*/
-#include <assert.h>
#include <errno.h> /* ENOENT */
#include <limits.h> /* INT_MAX */
#include <stdlib.h>
#include "session-id.h"
#include "stats.h"
#include "torrent.h"
+#include "tr-assert.h"
#include "tr-dht.h" /* tr_dhtUpkeep() */
#include "tr-udp.h"
#include "tr-utp.h"
tr_encryption_mode tr_sessionGetEncryption(tr_session* session)
{
- assert(session != NULL);
+ TR_ASSERT(session != NULL);
return session->encryptionMode;
}
void tr_sessionSetEncryption(tr_session* session, tr_encryption_mode mode)
{
- assert(session != NULL);
- assert(mode == TR_ENCRYPTION_PREFERRED || mode == TR_ENCRYPTION_REQUIRED || mode == TR_CLEAR_PREFERRED);
+ TR_ASSERT(session != NULL);
+ TR_ASSERT(mode == TR_ENCRYPTION_PREFERRED || mode == TR_ENCRYPTION_REQUIRED || mode == TR_CLEAR_PREFERRED);
session->encryptionMode = mode;
}
void tr_sessionGetDefaultSettings(tr_variant* d)
{
- assert(tr_variantIsDict(d));
+ TR_ASSERT(tr_variantIsDict(d));
tr_variantDictReserve(d, 63);
tr_variantDictAddBool(d, TR_KEY_blocklist_enabled, false);
void tr_sessionGetSettings(tr_session* s, tr_variant* d)
{
- assert(tr_variantIsDict(d));
+ TR_ASSERT(tr_variantIsDict(d));
tr_variantDictReserve(d, 63);
tr_variantDictAddBool(d, TR_KEY_blocklist_enabled, tr_blocklistIsEnabled(s));
bool success;
tr_error* error = NULL;
- assert(tr_variantIsDict(dict));
+ TR_ASSERT(tr_variantIsDict(dict));
/* initializing the defaults: caller may have passed in some app-level defaults.
* preserve those and use the session defaults to fill in any missing gaps. */
tr_variant settings;
char* filename = tr_buildPath(configDir, "settings.json", NULL);
- assert(tr_variantIsDict(clientSettings));
+ TR_ASSERT(tr_variantIsDict(clientSettings));
tr_variantInitDict(&settings, 0);
tr_session* session;
struct init_data data;
- assert(tr_variantIsDict(clientSettings));
+ TR_ASSERT(tr_variantIsDict(clientSettings));
tr_timeUpdate(time(NULL));
/* start the libtransmission thread */
tr_net_init(); /* must go before tr_eventInit */
tr_eventInit(session);
- assert(session->events != NULL);
+ TR_ASSERT(session->events != NULL);
/* run the rest in the libtransmission thread */
data.done = false;
tr_session* session = vsession;
time_t const now = time(NULL);
- assert(tr_isSession(session));
- assert(session->nowTimer != NULL);
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(session->nowTimer != NULL);
/**
*** tr_session things to do once per second
tr_variant* clientSettings = data->clientSettings;
tr_session* session = data->session;
- assert(tr_amInEventThread(session));
- assert(tr_variantIsDict(clientSettings));
+ TR_ASSERT(tr_amInEventThread(session));
+ TR_ASSERT(tr_variantIsDict(clientSettings));
dbgmsg("tr_sessionInit: the session's top-level bandwidth object is %p", (void*)&session->bandwidth);
tr_sessionGetDefaultSettings(&settings);
tr_variantMergeDicts(&settings, clientSettings);
- assert(session->event_base != NULL);
+ TR_ASSERT(session->event_base != NULL);
session->nowTimer = evtimer_new(session->event_base, onNowTimer, session);
onNowTimer(0, 0, session);
loadBlocklists(session);
}
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->saveTimer = evtimer_new(session->event_base, onSaveTimer, session);
tr_timerAdd(session->saveTimer, SAVE_INTERVAL_SECS, 0);
tr_variant* settings = data->clientSettings;
struct tr_turtle_info* turtle = &session->turtle;
- assert(tr_isSession(session));
- assert(tr_variantIsDict(settings));
- assert(tr_amInEventThread(session));
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(tr_variantIsDict(settings));
+ TR_ASSERT(tr_amInEventThread(session));
if (tr_variantDictFindInt(settings, TR_KEY_message_level, &i))
{
{
struct tr_device_info* info = NULL;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (dir != NULL)
{
{
char const* dir = NULL;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (session != NULL && session->downloadDir != NULL)
{
void tr_sessionSetIncompleteFileNamingEnabled(tr_session* session, bool b)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->isIncompleteFileNamingEnabled = b;
}
bool tr_sessionIsIncompleteFileNamingEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isIncompleteFileNamingEnabled;
}
void tr_sessionSetIncompleteDir(tr_session* session, char const* dir)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (session->incompleteDir != dir)
{
char const* tr_sessionGetIncompleteDir(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->incompleteDir;
}
void tr_sessionSetIncompleteDirEnabled(tr_session* session, bool b)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->isIncompleteDirEnabled = b;
}
bool tr_sessionIsIncompleteDirEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isIncompleteDirEnabled;
}
void tr_sessionLock(tr_session* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_lockLock(session->lock);
}
void tr_sessionUnlock(tr_session* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_lockUnlock(session->lock);
}
{
tr_torrent* tor = NULL;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
close_incoming_peer_port(session);
open_incoming_peer_port(session);
tr_port tr_sessionSetPeerPortRandom(tr_session* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_sessionSetPeerPort(session, getRandomPort(session));
return session->private_peer_port;
void tr_sessionSetPeerPortRandomOnStart(tr_session* session, bool random)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->isPortRandom = random;
}
bool tr_sessionGetPeerPortRandomOnStart(tr_session* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isPortRandom;
}
tr_port_forwarding tr_sessionGetPortForwarding(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_sharedTraversalStatus(session->shared);
}
void tr_sessionSetRatioLimited(tr_session* session, bool isLimited)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->isRatioLimited = isLimited;
}
void tr_sessionSetRatioLimit(tr_session* session, double desiredRatio)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->desiredRatio = desiredRatio;
}
bool tr_sessionIsRatioLimited(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isRatioLimited;
}
double tr_sessionGetRatioLimit(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->desiredRatio;
}
void tr_sessionSetIdleLimited(tr_session* session, bool isLimited)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->isIdleLimited = isLimited;
}
void tr_sessionSetIdleLimit(tr_session* session, uint16_t idleMinutes)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->idleLimitMinutes = idleMinutes;
}
bool tr_sessionIsIdleLimited(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isIdleLimited;
}
uint16_t tr_sessionGetIdleLimit(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->idleLimitMinutes;
}
tr_session* session = vsession;
struct tr_turtle_info* t = &session->turtle;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
updateBandwidth(session, TR_UP);
updateBandwidth(session, TR_DOWN);
static void useAltSpeed(tr_session* s, struct tr_turtle_info* t, bool enabled, bool byUser)
{
- assert(tr_isSession(s));
- assert(t != NULL);
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(t != NULL);
if (t->isEnabled != enabled)
{
bool alreadySwitched;
tr_auto_switch_state_t newAutoTurtleState;
- assert(t->isClockEnabled);
+ TR_ASSERT(t->isClockEnabled);
enabled = getInTurtleTime(t);
newAutoTurtleState = autoSwitchState(enabled);
void tr_sessionSetSpeedLimit_Bps(tr_session* s, tr_direction d, unsigned int Bps)
{
- assert(tr_isSession(s));
- assert(tr_isDirection(d));
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(tr_isDirection(d));
s->speedLimit_Bps[d] = Bps;
unsigned int tr_sessionGetSpeedLimit_Bps(tr_session const* s, tr_direction d)
{
- assert(tr_isSession(s));
- assert(tr_isDirection(d));
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(tr_isDirection(d));
return s->speedLimit_Bps[d];
}
void tr_sessionLimitSpeed(tr_session* s, tr_direction d, bool b)
{
- assert(tr_isSession(s));
- assert(tr_isDirection(d));
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(tr_isDirection(d));
s->speedLimitEnabled[d] = b;
bool tr_sessionIsSpeedLimited(tr_session const* s, tr_direction d)
{
- assert(tr_isSession(s));
- assert(tr_isDirection(d));
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(tr_isDirection(d));
return s->speedLimitEnabled[d];
}
void tr_sessionSetAltSpeed_Bps(tr_session* s, tr_direction d, unsigned int Bps)
{
- assert(tr_isSession(s));
- assert(tr_isDirection(d));
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(tr_isDirection(d));
s->turtle.speedLimit_Bps[d] = Bps;
unsigned int tr_sessionGetAltSpeed_Bps(tr_session const* s, tr_direction d)
{
- assert(tr_isSession(s));
- assert(tr_isDirection(d));
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(tr_isDirection(d));
return s->turtle.speedLimit_Bps[d];
}
{
struct tr_turtle_info* t = &s->turtle;
- assert(tr_isSession(s));
+ TR_ASSERT(tr_isSession(s));
if (t->isClockEnabled != b)
{
bool tr_sessionUsesAltSpeedTime(tr_session const* s)
{
- assert(tr_isSession(s));
+ TR_ASSERT(tr_isSession(s));
return s->turtle.isClockEnabled;
}
void tr_sessionSetAltSpeedBegin(tr_session* s, int minute)
{
- assert(tr_isSession(s));
- assert(0 <= minute && minute < 60 * 24);
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(minute >= 0);
+ TR_ASSERT(minute < 60 * 24);
if (s->turtle.beginMinute != minute)
{
int tr_sessionGetAltSpeedBegin(tr_session const* s)
{
- assert(tr_isSession(s));
+ TR_ASSERT(tr_isSession(s));
return s->turtle.beginMinute;
}
void tr_sessionSetAltSpeedEnd(tr_session* s, int minute)
{
- assert(tr_isSession(s));
- assert(0 <= minute && minute < 60 * 24);
+ TR_ASSERT(tr_isSession(s));
+ TR_ASSERT(minute >= 0);
+ TR_ASSERT(minute < 60 * 24);
if (s->turtle.endMinute != minute)
{
int tr_sessionGetAltSpeedEnd(tr_session const* s)
{
- assert(tr_isSession(s));
+ TR_ASSERT(tr_isSession(s));
return s->turtle.endMinute;
}
void tr_sessionSetAltSpeedDay(tr_session* s, tr_sched_day days)
{
- assert(tr_isSession(s));
+ TR_ASSERT(tr_isSession(s));
if (s->turtle.days != days)
{
tr_sched_day tr_sessionGetAltSpeedDay(tr_session const* s)
{
- assert(tr_isSession(s));
+ TR_ASSERT(tr_isSession(s));
return s->turtle.days;
}
bool tr_sessionUsesAltSpeed(tr_session const* s)
{
- assert(tr_isSession(s));
+ TR_ASSERT(tr_isSession(s));
return s->turtle.isEnabled;
}
void tr_sessionSetAltSpeedFunc(tr_session* session, tr_altSpeedFunc func, void* userData)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->turtle.callback = func;
session->turtle.callbackUserData = userData;
void tr_sessionSetPeerLimit(tr_session* session, uint16_t n)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->peerLimit = n;
}
uint16_t tr_sessionGetPeerLimit(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->peerLimit;
}
void tr_sessionSetPeerLimitPerTorrent(tr_session* session, uint16_t n)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->peerLimitPerTorrent = n;
}
uint16_t tr_sessionGetPeerLimitPerTorrent(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->peerLimitPerTorrent;
}
void tr_sessionSetPaused(tr_session* session, bool isPaused)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->pauseAddedTorrent = isPaused;
}
bool tr_sessionGetPaused(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->pauseAddedTorrent;
}
void tr_sessionSetDeleteSource(tr_session* session, bool deleteSource)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->deleteSourceTorrent = deleteSource;
}
bool tr_sessionGetDeleteSource(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->deleteSourceTorrent;
}
tr_torrent** torrents;
tr_torrent* tor;
- assert(tr_isSession(session));
- assert(setme_n != NULL);
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(setme_n != NULL);
n = tr_sessionCountTorrents(session);
*setme_n = n;
session->cache = NULL;
/* saveTimer is not used at this point, reusing for UDP shutdown wait */
- assert(session->saveTimer == NULL);
+ TR_ASSERT(session->saveTimer == NULL);
session->saveTimer = evtimer_new(session->event_base, sessionCloseImplWaitForIdleUdp, session);
tr_timerAdd(session->saveTimer, 0, 0);
}
{
tr_session* session = vsession;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
/* gotta keep udp running long enough to send out all
the &event=stopped UDP tracker messages */
{
tr_session* session = vsession;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
sessionCloseImplStart(session);
}
{
time_t const deadline = time(NULL) + SHUTDOWN_MAX_SECONDS;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
dbgmsg("shutting down transmission session %p... now is %zu, deadline is %zu", (void*)session, (size_t)time(NULL),
(size_t)deadline);
struct sessionLoadTorrentsData* data = vdata;
char const* dirname = tr_getTorrentDir(data->session);
- assert(tr_isSession(data->session));
+ TR_ASSERT(tr_isSession(data->session));
tr_ctorSetSave(data->ctor, false); /* since we already have them */
data->torrents[i++] = (tr_torrent*)l->data;
}
- assert(i == n);
+ TR_ASSERT(i == n);
tr_list_free(&list, NULL);
void tr_sessionSetPexEnabled(tr_session* session, bool enabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->isPexEnabled = enabled;
}
bool tr_sessionIsPexEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isPexEnabled;
}
bool tr_sessionIsDHTEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isDHTEnabled;
}
static void toggleDHTImpl(void* data)
{
tr_session* session = data;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_udpUninit(session);
session->isDHTEnabled = !session->isDHTEnabled;
void tr_sessionSetDHTEnabled(tr_session* session, bool enabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (enabled != session->isDHTEnabled)
{
bool tr_sessionIsUTPEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
#ifdef WITH_UTP
return session->isUTPEnabled;
{
tr_session* session = data;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->isUTPEnabled = !session->isUTPEnabled;
void tr_sessionSetUTPEnabled(tr_session* session, bool enabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (enabled != session->isUTPEnabled)
{
static void toggleLPDImpl(void* data)
{
tr_session* session = data;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (session->isLPDEnabled)
{
void tr_sessionSetLPDEnabled(tr_session* session, bool enabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (enabled != session->isLPDEnabled)
{
bool tr_sessionIsLPDEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isLPDEnabled;
}
void tr_sessionSetCacheLimit_MB(tr_session* session, int max_bytes)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_cacheSetLimit(session->cache, toMemBytes(max_bytes));
}
int tr_sessionGetCacheLimit_MB(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return toMemMB(tr_cacheGetLimit(session->cache));
}
bool tr_sessionIsPortForwardingEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_sharedTraversalIsEnabled(session->shared);
}
{
int n = 0;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
for (tr_list* l = session->blocklists; l != NULL; l = l->next)
{
bool tr_blocklistIsEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isBlocklistEnabled;
}
void tr_blocklistSetEnabled(tr_session* session, bool isEnabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->isBlocklistEnabled = isEnabled;
bool tr_blocklistExists(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->blocklists != NULL;
}
bool tr_sessionIsAddressBlocked(tr_session const* session, tr_address const* addr)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
for (tr_list* l = session->blocklists; l != NULL; l = l->next)
{
tr_variant* lookup;
int n = 0;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
/* walk through the directory and find the mappings */
lookup = tr_new0(tr_variant, 1);
void tr_sessionSetRPCEnabled(tr_session* session, bool isEnabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_rpcSetEnabled(session->rpcServer, isEnabled);
}
bool tr_sessionIsRPCEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_rpcIsEnabled(session->rpcServer);
}
void tr_sessionSetRPCPort(tr_session* session, tr_port port)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_rpcSetPort(session->rpcServer, port);
}
tr_port tr_sessionGetRPCPort(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_rpcGetPort(session->rpcServer);
}
void tr_sessionSetRPCUrl(tr_session* session, char const* url)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_rpcSetUrl(session->rpcServer, url);
}
char const* tr_sessionGetRPCUrl(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_rpcGetUrl(session->rpcServer);
}
void tr_sessionSetRPCCallback(tr_session* session, tr_rpc_func func, void* user_data)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->rpc_func = func;
session->rpc_func_user_data = user_data;
void tr_sessionSetRPCWhitelist(tr_session* session, char const* whitelist)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_rpcSetWhitelist(session->rpcServer, whitelist);
}
char const* tr_sessionGetRPCWhitelist(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_rpcGetWhitelist(session->rpcServer);
}
void tr_sessionSetRPCWhitelistEnabled(tr_session* session, bool isEnabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_rpcSetWhitelistEnabled(session->rpcServer, isEnabled);
}
bool tr_sessionGetRPCWhitelistEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_rpcGetWhitelistEnabled(session->rpcServer);
}
void tr_sessionSetRPCPassword(tr_session* session, char const* password)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_rpcSetPassword(session->rpcServer, password);
}
char const* tr_sessionGetRPCPassword(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_rpcGetPassword(session->rpcServer);
}
void tr_sessionSetRPCUsername(tr_session* session, char const* username)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_rpcSetUsername(session->rpcServer, username);
}
char const* tr_sessionGetRPCUsername(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_rpcGetUsername(session->rpcServer);
}
void tr_sessionSetRPCPasswordEnabled(tr_session* session, bool isEnabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_rpcSetPasswordEnabled(session->rpcServer, isEnabled);
}
bool tr_sessionIsRPCPasswordEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_rpcIsPasswordEnabled(session->rpcServer);
}
char const* tr_sessionGetRPCBindAddress(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return tr_rpcGetBindAddress(session->rpcServer);
}
bool tr_sessionIsTorrentDoneScriptEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->isTorrentDoneScriptEnabled;
}
void tr_sessionSetTorrentDoneScriptEnabled(tr_session* session, bool isEnabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->isTorrentDoneScriptEnabled = isEnabled;
}
char const* tr_sessionGetTorrentDoneScript(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->torrentDoneScript;
}
void tr_sessionSetTorrentDoneScript(tr_session* session, char const* scriptFilename)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (session->torrentDoneScript != scriptFilename)
{
void tr_sessionSetQueueSize(tr_session* session, tr_direction dir, int n)
{
- assert(tr_isSession(session));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(tr_isDirection(dir));
session->queueSize[dir] = n;
}
int tr_sessionGetQueueSize(tr_session const* session, tr_direction dir)
{
- assert(tr_isSession(session));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(tr_isDirection(dir));
return session->queueSize[dir];
}
void tr_sessionSetQueueEnabled(tr_session* session, tr_direction dir, bool is_enabled)
{
- assert(tr_isSession(session));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(tr_isDirection(dir));
session->queueEnabled[dir] = is_enabled;
}
bool tr_sessionGetQueueEnabled(tr_session const* session, tr_direction dir)
{
- assert(tr_isSession(session));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(tr_isDirection(dir));
return session->queueEnabled[dir];
}
void tr_sessionSetQueueStalledMinutes(tr_session* session, int minutes)
{
- assert(tr_isSession(session));
- assert(minutes > 0);
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(minutes > 0);
session->queueStalledMinutes = minutes;
}
void tr_sessionSetQueueStalledEnabled(tr_session* session, bool is_enabled)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
session->stalledEnabled = is_enabled;
}
bool tr_sessionGetQueueStalledEnabled(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->stalledEnabled;
}
int tr_sessionGetQueueStalledMinutes(tr_session const* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
return session->queueStalledMinutes;
}
struct TorrentAndPosition* candidates;
size_t num_candidates;
- assert(tr_isSession(session));
- assert(tr_isDirection(direction));
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(tr_isDirection(direction));
/* build an array of the candidates */
n = tr_sessionCountTorrents(session);
#include "magnet.h"
#include "session.h" /* tr_sessionFindTorrentFile() */
#include "torrent.h" /* tr_ctorGetSave() */
+#include "tr-assert.h"
#include "utils.h" /* tr_new0 */
#include "variant.h"
{
struct optional_args* args;
- assert(ctor != NULL);
- assert(mode == TR_FALLBACK || mode == TR_FORCE);
+ TR_ASSERT(ctor != NULL);
+ TR_ASSERT(mode == TR_FALLBACK || mode == TR_FORCE);
args = &ctor->optionalArgs[mode];
args->isSet_paused = true;
{
struct optional_args* args;
- assert(ctor != NULL);
- assert(mode == TR_FALLBACK || mode == TR_FORCE);
+ TR_ASSERT(ctor != NULL);
+ TR_ASSERT(mode == TR_FALLBACK || mode == TR_FORCE);
args = &ctor->optionalArgs[mode];
args->isSet_connected = true;
{
struct optional_args* args;
- assert(ctor != NULL);
- assert(mode == TR_FALLBACK || mode == TR_FORCE);
+ TR_ASSERT(ctor != NULL);
+ TR_ASSERT(mode == TR_FALLBACK || mode == TR_FORCE);
args = &ctor->optionalArgs[mode];
tr_free(args->downloadDir);
*
*/
-#include <assert.h>
#include <string.h> /* memcpy(), memset(), memcmp() */
#include <event2/buffer.h>
#include "resume.h"
#include "torrent.h"
#include "torrent-magnet.h"
+#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
#include "web.h"
static void ensureInfoDictOffsetIsCached(tr_torrent* tor)
{
- assert(tr_torrentHasMetadata(tor));
+ TR_ASSERT(tr_torrentHasMetadata(tor));
if (!tor->infoDictOffsetIsCached)
{
{
char* ret = NULL;
- assert(tr_isTorrent(tor));
- assert(piece >= 0);
- assert(len != NULL);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(piece >= 0);
+ TR_ASSERT(len != NULL);
if (tr_torrentHasMetadata(tor))
{
ensureInfoDictOffsetIsCached(tor);
- assert(tor->infoDictLength > 0);
+ TR_ASSERT(tor->infoDictLength > 0);
fd = tr_sys_file_open(tor->info.torrent, TR_SYS_FILE_READ, 0, NULL);
}
}
- assert(ret == NULL || *len > 0);
+ TR_ASSERT(ret == NULL || *len > 0);
return ret;
}
struct tr_incomplete_metadata* m;
int const offset = piece * METADATA_PIECE_SIZE;
- assert(tr_isTorrent(tor));
- assert(data != NULL);
- assert(len >= 0);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(data != NULL);
+ TR_ASSERT(len >= 0);
dbgmsg(tor, "got metadata piece %d of %d bytes", piece, len);
return;
}
- assert(offset <= m->metadata_size);
+ TR_ASSERT(offset <= m->metadata_size);
if (len == 0 || len > m->metadata_size - offset)
{
bool have_request = false;
struct tr_incomplete_metadata* m;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
m = tor->incompleteMetadata;
#include <windows.h> /* CreateProcess(), GetLastError() */
#endif
-#include <assert.h>
#include <math.h>
#include <stdarg.h>
#include <string.h> /* memcmp */
#include "session.h"
#include "torrent.h"
#include "torrent-magnet.h"
+#include "tr-assert.h"
#include "trevent.h" /* tr_runInEventThread() */
#include "utils.h"
#include "variant.h"
bool allowed = true;
unsigned int limit;
- assert(tr_isTorrent(tor));
- assert(tr_isDirection(direction));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_isDirection(direction));
if (tr_torrentUsesSpeedLimit(tor, direction))
{
void tr_torrentSetSpeedLimit_Bps(tr_torrent* tor, tr_direction dir, unsigned int Bps)
{
- assert(tr_isTorrent(tor));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_isDirection(dir));
if (tr_bandwidthSetDesiredSpeed_Bps(&tor->bandwidth, dir, Bps))
{
unsigned int tr_torrentGetSpeedLimit_Bps(tr_torrent const* tor, tr_direction dir)
{
- assert(tr_isTorrent(tor));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_isDirection(dir));
return tr_bandwidthGetDesiredSpeed_Bps(&tor->bandwidth, dir);
}
unsigned int tr_torrentGetSpeedLimit_KBps(tr_torrent const* tor, tr_direction dir)
{
- assert(tr_isTorrent(tor));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_isDirection(dir));
return toSpeedKBps(tr_torrentGetSpeedLimit_Bps(tor, dir));
}
void tr_torrentUseSpeedLimit(tr_torrent* tor, tr_direction dir, bool do_use)
{
- assert(tr_isTorrent(tor));
- assert(tr_isDirection(dir));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_isDirection(dir));
if (tr_bandwidthSetLimited(&tor->bandwidth, dir, do_use))
{
bool tr_torrentUsesSpeedLimit(tr_torrent const* tor, tr_direction dir)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tr_bandwidthIsLimited(&tor->bandwidth, dir);
}
{
bool changed;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
changed = tr_bandwidthHonorParentLimits(&tor->bandwidth, TR_UP, doUse);
changed |= tr_bandwidthHonorParentLimits(&tor->bandwidth, TR_DOWN, doUse);
bool tr_torrentUsesSessionLimits(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tr_bandwidthAreParentLimitsHonored(&tor->bandwidth, TR_UP);
}
void tr_torrentSetRatioMode(tr_torrent* tor, tr_ratiolimit mode)
{
- assert(tr_isTorrent(tor));
- assert(mode == TR_RATIOLIMIT_GLOBAL || mode == TR_RATIOLIMIT_SINGLE || mode == TR_RATIOLIMIT_UNLIMITED);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(mode == TR_RATIOLIMIT_GLOBAL || mode == TR_RATIOLIMIT_SINGLE || mode == TR_RATIOLIMIT_UNLIMITED);
if (mode != tor->ratioLimitMode)
{
tr_ratiolimit tr_torrentGetRatioMode(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tor->ratioLimitMode;
}
void tr_torrentSetRatioLimit(tr_torrent* tor, double desiredRatio)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if ((int)(desiredRatio * 100.0) != (int)(tor->desiredRatio * 100.0))
{
double tr_torrentGetRatioLimit(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tor->desiredRatio;
}
{
bool isLimited;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
switch (tr_torrentGetRatioMode(tor))
{
double seedRatio;
bool seedRatioApplies = false;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tr_torrentGetSeedRatio(tor, &seedRatio))
{
void tr_torrentSetIdleMode(tr_torrent* tor, tr_idlelimit mode)
{
- assert(tr_isTorrent(tor));
- assert(mode == TR_IDLELIMIT_GLOBAL || mode == TR_IDLELIMIT_SINGLE || mode == TR_IDLELIMIT_UNLIMITED);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(mode == TR_IDLELIMIT_GLOBAL || mode == TR_IDLELIMIT_SINGLE || mode == TR_IDLELIMIT_UNLIMITED);
if (mode != tor->idleLimitMode)
{
tr_idlelimit tr_torrentGetIdleMode(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tor->idleLimitMode;
}
void tr_torrentSetIdleLimit(tr_torrent* tor, uint16_t idleMinutes)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (idleMinutes > 0)
{
uint16_t tr_torrentGetIdleLimit(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tor->idleLimitMinutes;
}
void tr_torrentCheckSeedLimit(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (!tor->isRunning || tor->isStopping || !tr_torrentIsSeed(tor))
{
{
va_list ap;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
va_start(ap, fmt);
tor->error = TR_STAT_LOCAL_ERROR;
{
tr_piece_index_t piece;
- assert(info != NULL);
- assert(info->pieceSize != 0);
+ TR_ASSERT(info != NULL);
+ TR_ASSERT(info->pieceSize != 0);
piece = byteOffset / info->pieceSize;
uint64_t firstByte;
uint64_t lastByte;
- assert(info);
- assert(fileIndex < info->fileCount);
+ TR_ASSERT(info != NULL);
+ TR_ASSERT(fileIndex < info->fileCount);
file = &info->files[fileIndex];
firstByte = file->offset;
for (tr_piece_index_t p = 0; p < inf->pieceCount; ++p)
{
tr_file_index_t f = firstFiles[p];
- assert(inf->files[f].firstPiece <= p);
- assert(inf->files[f].lastPiece >= p);
+ TR_ASSERT(inf->files[f].firstPiece <= p);
+ TR_ASSERT(inf->files[f].lastPiece >= p);
if (f > 0)
{
- assert(inf->files[f - 1].lastPiece < p);
+ TR_ASSERT(inf->files[f - 1].lastPiece < p);
}
f = 0;
}
}
- assert((int)f == firstFiles[p]);
+ TR_ASSERT((int)f == firstFiles[p]);
}
#endif
/* check our work */
if (tor->blockSize != 0)
{
- assert(info->pieceSize % tor->blockSize == 0);
+ TR_ASSERT(info->pieceSize % tor->blockSize == 0);
}
t = info->pieceCount - 1;
t *= info->pieceSize;
t += tor->lastPieceSize;
- assert(t == info->totalSize);
+ TR_ASSERT(t == info->totalSize);
t = tor->blockCount - 1;
t *= tor->blockSize;
t += tor->lastBlockSize;
- assert(t == info->totalSize);
+ TR_ASSERT(t == info->totalSize);
t = info->pieceCount - 1;
t *= tor->blockCountInPiece;
t += tor->blockCountInLastPiece;
- assert(t == (uint64_t)tor->blockCount);
+ TR_ASSERT(t == (uint64_t)tor->blockCount);
tr_cpConstruct(&tor->completion, tor);
tr_session* session = tr_ctorGetSession(ctor);
static int nextUniqueId = 1;
- assert(session != NULL);
+ TR_ASSERT(session != NULL);
tr_sessionLock(session);
tr_peerMgrAddTorrent(session->peerMgr, tor);
- assert(tor->downloadedCur == 0);
- assert(tor->uploadedCur == 0);
+ TR_ASSERT(tor->downloadedCur == 0);
+ TR_ASSERT(tor->uploadedCur == 0);
tr_torrentSetAddedDate(tor, tr_time()); /* this is a default value to be overwritten by the resume file */
tr_parse_result r;
tr_torrent* tor = NULL;
- assert(ctor != NULL);
- assert(tr_isSession(tr_ctorGetSession(ctor)));
+ TR_ASSERT(ctor != NULL);
+ TR_ASSERT(tr_isSession(tr_ctorGetSession(ctor)));
r = torrentParseImpl(ctor, &tmpInfo, &hasInfo, &len, setme_duplicate_id);
void tr_torrentSetDownloadDir(tr_torrent* tor, char const* path)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (path == NULL || tor->downloadDir == NULL || strcmp(path, tor->downloadDir) != 0)
{
char const* tr_torrentGetDownloadDir(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tor->downloadDir;
}
char const* tr_torrentGetCurrentDir(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tor->currentDir;
}
void tr_torrentChangeMyPort(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tor->isRunning)
{
{
tr_torrent* tor = vtor;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tor->isRunning)
{
void tr_torrentManualUpdate(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tr_runInEventThread(tor->session, tr_torrentManualUpdateImpl, tor);
}
void tr_torrentSetVerifyState(tr_torrent* tor, tr_verify_state state)
{
- assert(tr_isTorrent(tor));
- assert(state == TR_VERIFY_NONE || state == TR_VERIFY_WAIT || state == TR_VERIFY_NOW);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(state == TR_VERIFY_NONE || state == TR_VERIFY_WAIT || state == TR_VERIFY_NOW);
tor->verifyState = state;
tor->anyDate = tr_time();
unsigned int pieceDownloadSpeed_Bps;
struct tr_swarm_stats swarm_stats;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->lastStatTime = tr_time();
}
/* test some of the constraints */
- assert(s->sizeWhenDone <= tor->info.totalSize);
- assert(s->leftUntilDone <= s->sizeWhenDone);
- assert(s->desiredAvailable <= s->leftUntilDone);
+ TR_ASSERT(s->sizeWhenDone <= tor->info.totalSize);
+ TR_ASSERT(s->leftUntilDone <= s->sizeWhenDone);
+ TR_ASSERT(s->desiredAvailable <= s->leftUntilDone);
return s;
}
tr_file_stat* walk = files;
bool const isSeed = tor->completeness == TR_SEED;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
for (tr_file_index_t i = 0; i < n; ++i, ++walk)
{
double* tr_torrentWebSpeeds_KBps(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tr_peerMgrWebSpeeds_KBps(tor);
}
tr_peer_stat* tr_torrentPeers(tr_torrent const* tor, int* peerCount)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tr_peerMgrPeerStats(tor, peerCount);
}
tr_tracker_stat* tr_torrentTrackers(tr_torrent const* tor, int* setmeTrackerCount)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tr_announcerStats(tor, setmeTrackerCount);
}
void tr_torrentAvailability(tr_torrent const* tor, int8_t* tab, int size)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tab != NULL && size > 0)
{
void tr_torrentSetHasPiece(tr_torrent* tor, tr_piece_index_t pieceIndex, bool has)
{
- assert(tr_isTorrent(tor));
- assert(pieceIndex < tor->info.pieceCount);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(pieceIndex < tor->info.pieceCount);
if (has)
{
****
***/
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
static bool queueIsSequenced(tr_session*);
#endif
tr_info* inf = &tor->info;
time_t const now = tr_time();
- assert(!tor->isRunning);
+ TR_ASSERT(!tor->isRunning);
tr_sessionLock(session);
}
/* decrement the torrent count */
- assert(session->torrentCount >= 1);
+ TR_ASSERT(session->torrentCount >= 1);
session->torrentCount--;
/* resequence the queue positions */
}
}
- assert(queueIsSequenced(session));
+ TR_ASSERT(queueIsSequenced(session));
tr_bandwidthDestruct(&tor->bandwidth);
time_t now;
tr_torrent* tor = vtor;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tr_sessionLock(tor->session);
static void onVerifyDone(tr_torrent* tor, bool aborted, void* vdata)
{
struct verify_data* data = vdata;
- assert(data->tor == tor);
+ TR_ASSERT(data->tor == tor);
if (tor->isDeleting)
{
void tr_torrentSave(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tor->isDirty)
{
tr_torrent* tor = vtor;
tr_logAddTorInfo(tor, "%s", "Pausing");
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tr_torrentLock(tor);
void tr_torrentStop(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tr_isTorrent(tor))
{
tr_variant* d;
tr_torrent* tor = vtor;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
d = tr_variantListAddDict(&tor->session->removedTorrents, 2);
tr_variantDictAddInt(d, TR_KEY_id, tor->uniqueId);
if (tr_isTorrent(tor))
{
tr_session* session = tor->session;
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
tr_sessionLock(session);
tr_torrentClearCompletenessCallback(tor);
{
struct remove_data* data;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->isDeleting = true;
data = tr_new0(struct remove_data, 1);
static void fireCompletenessChange(tr_torrent* tor, tr_completeness status, bool wasRunning)
{
- assert(status == TR_LEECH || status == TR_SEED || status == TR_PARTIAL_SEED);
+ TR_ASSERT(status == TR_LEECH || status == TR_SEED || status == TR_PARTIAL_SEED);
if (tor->completeness_func != NULL)
{
void tr_torrentSetCompletenessCallback(tr_torrent* tor, tr_torrent_completeness_func func, void* user_data)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->completeness_func = func;
tor->completeness_func_user_data = user_data;
void tr_torrentSetRatioLimitHitCallback(tr_torrent* tor, tr_torrent_ratio_limit_hit_func func, void* user_data)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->ratio_limit_hit_func = func;
tor->ratio_limit_hit_func_user_data = user_data;
void tr_torrentSetIdleLimitHitCallback(tr_torrent* tor, tr_torrent_idle_limit_hit_func func, void* user_data)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->idle_limit_hit_func = func;
tor->idle_limit_hit_func_user_data = user_data;
tr_logAddTorInfo(tor, "Calling script \"%s\"", script);
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
/* Win32 environment block strings should be sorted alphabetically */
for (size_t i = 1; env[i] != NULL; ++i)
{
- assert(strcmp(env[i - 1], env[i]) < 0);
+ TR_ASSERT(strcmp(env[i - 1], env[i]) < 0);
}
#endif
static void tr_torrentFireMetadataCompleted(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tor->metadata_func != NULL)
{
void tr_torrentSetMetadataCallback(tr_torrent* tor, tr_torrent_metadata_func func, void* user_data)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->metadata_func = func;
tor->metadata_func_user_data = user_data;
{
tr_file* file;
- assert(tr_isTorrent(tor));
- assert(fileIndex < tor->info.fileCount);
- assert(tr_isPriority(priority));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(fileIndex < tor->info.fileCount);
+ TR_ASSERT(tr_isPriority(priority));
file = &tor->info.files[fileIndex];
file->priority = priority;
void tr_torrentSetFilePriorities(tr_torrent* tor, tr_file_index_t const* files, tr_file_index_t fileCount,
tr_priority_t priority)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tr_torrentLock(tor);
for (tr_file_index_t i = 0; i < fileCount; ++i)
{
tr_priority_t* p;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
p = tr_new0(tr_priority_t, tor->info.fileCount);
void tr_torrentInitFileDLs(tr_torrent* tor, tr_file_index_t const* files, tr_file_index_t fileCount, bool doDownload)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tr_torrentLock(tor);
void tr_torrentSetFileDLs(tr_torrent* tor, tr_file_index_t const* files, tr_file_index_t fileCount, bool doDownload)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tr_torrentLock(tor);
tr_torrentInitFileDLs(tor, files, fileCount, doDownload);
tr_priority_t tr_torrentGetPriority(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tor->bandwidth.priority;
}
void tr_torrentSetPriority(tr_torrent* tor, tr_priority_t priority)
{
- assert(tr_isTorrent(tor));
- assert(tr_isPriority(priority));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_isPriority(priority));
if (tor->bandwidth.priority != priority)
{
void tr_torrentSetPeerLimit(tr_torrent* tor, uint16_t maxConnectedPeers)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tor->maxConnectedPeers != maxConnectedPeers)
{
uint16_t tr_torrentGetPeerLimit(tr_torrent const* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
return tor->maxConnectedPeers;
}
{
tr_block_index_t ret;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
ret = index;
ret *= tor->info.pieceSize / tor->blockSize;
{
int err = 0;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (index >= tor->info.pieceCount)
{
{
uint64_t ret;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
ret = tor->info.pieceSize;
ret *= index;
void tr_torrentSetPieceChecked(tr_torrent* tor, tr_piece_index_t pieceIndex)
{
- assert(tr_isTorrent(tor));
- assert(pieceIndex < tor->info.pieceCount);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(pieceIndex < tor->info.pieceCount);
tor->info.pieces[pieceIndex].timeChecked = tr_time();
}
void tr_torrentSetChecked(tr_torrent* tor, time_t when)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
for (tr_piece_index_t i = 0; i < tor->info.pieceCount; ++i)
{
tr_torrentLock(tor);
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
/* ensure the trackers' tiers are in ascending order */
trackers = tr_memdup(trackers_in, sizeof(tr_tracker_info) * trackerCount);
void tr_torrentSetAddedDate(tr_torrent* tor, time_t t)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->addedDate = t;
tor->anyDate = MAX(tor->anyDate, tor->addedDate);
void tr_torrentSetActivityDate(tr_torrent* tor, time_t t)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->activityDate = t;
tor->anyDate = MAX(tor->anyDate, tor->activityDate);
void tr_torrentSetDoneDate(tr_torrent* tor, time_t t)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->doneDate = t;
tor->anyDate = MAX(tor->anyDate, tor->doneDate);
{
uint64_t bytesLeft = 0;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
for (tr_file_index_t i = 0; i < tor->info.fileCount; ++i)
{
static void tr_torrentDeleteLocalData(tr_torrent* tor, tr_fileFunc func)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (func == NULL)
{
double bytesHandled = 0;
tr_torrentLock(tor);
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tr_logAddDebug("Moving \"%s\" location from currentDir \"%s\" to \"%s\"", tr_torrentName(tor), tor->currentDir, location);
{
struct LocationData* data;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (setme_state != NULL)
{
{
bool const block_is_new = !tr_torrentBlockIsComplete(tor, block);
- assert(tr_isTorrent(tor));
- assert(tr_amInEventThread(tor->session));
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(tr_amInEventThread(tor->session));
if (block_is_new)
{
char const* s = NULL;
tr_sys_path_info file_info;
- assert(tr_isTorrent(tor));
- assert(fileNum < tor->info.fileCount);
+ TR_ASSERT(tr_isTorrent(tor));
+ TR_ASSERT(fileNum < tor->info.fileCount);
file = &tor->info.files[fileNum];
dir = tor->incompleteDir;
}
- assert(dir != NULL);
- assert(dir == tor->downloadDir || dir == tor->incompleteDir);
+ TR_ASSERT(dir != NULL);
+ TR_ASSERT(dir == tor->downloadDir || dir == tor->incompleteDir);
tor->currentDir = dir;
}
return a->queuePosition - b->queuePosition;
}
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
static bool queueIsSequenced(tr_session* session)
{
tor->queuePosition = MIN(pos, back + 1);
tor->anyDate = now;
- assert(queueIsSequenced(tor->session));
+ TR_ASSERT(queueIsSequenced(tor->session));
}
void tr_torrentsQueueMoveTop(tr_torrent** torrents_in, int n)
static void torrentSetQueued(tr_torrent* tor, bool queued)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tr_torrentIsQueued(tor) != queued)
{
****
***/
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (!renameArgsAreValid(oldpath, newname))
{
#include "bandwidth.h" /* tr_bandwidth */
#include "completion.h" /* tr_completion */
#include "session.h" /* tr_sessionLock(), tr_sessionUnlock() */
+#include "tr-assert.h"
#include "utils.h" /* TR_GNUC_PRINTF */
struct tr_torrent_tiers;
* needs to be saved when the torrent is closed */
static inline void tr_torrentSetDirty(tr_torrent* tor)
{
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tor->isDirty = true;
}
--- /dev/null
+/*
+ * This file Copyright (C) 2017 Mnemosyne LLC
+ *
+ * It may be used under the GNU GPL versions 2 or 3
+ * or any future license endorsed by Mnemosyne LLC.
+ *
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "tr-assert.h"
+
+#if !defined(NDEBUG) || defined(TR_FORCE_ASSERTIONS)
+
+bool tr_assert_report(char const* file, int line, char const* message_fmt, ...)
+{
+ va_list args;
+ va_start(args, message_fmt);
+
+ fprintf(stderr, "assertion failed: ");
+ vfprintf(stderr, message_fmt, args);
+ fprintf(stderr, " (%s:%d)\n", file, line);
+
+ va_end(args);
+
+ abort();
+}
+
+#endif
--- /dev/null
+/*
+ * This file Copyright (C) 2017 Mnemosyne LLC
+ *
+ * It may be used under the GNU GPL versions 2 or 3
+ * or any future license endorsed by Mnemosyne LLC.
+ *
+ */
+
+#pragma once
+
+#if !defined(NDEBUG) || defined(TR_FORCE_ASSERTIONS)
+
+#include <stdbool.h>
+
+#ifndef TR_LIKELY
+#if defined(__GNUC__)
+#define TR_LIKELY(x) __builtin_expect(!!(x), true)
+#else
+#define TR_LIKELY(x) (x)
+#endif
+#endif
+
+#ifndef TR_NORETURN
+#if defined(__GNUC__)
+#define TR_NORETURN __attribute__((noreturn))
+#elif defined(_MSC_VER)
+#define TR_NORETURN __declspec(noreturn)
+#else
+#define TR_NORETURN
+#endif
+#endif
+
+#ifndef TR_GNUC_PRINTF
+#if defined(__GNUC__)
+#define TR_GNUC_PRINTF(fmt, args) __attribute__((format(printf, fmt, args)))
+#else
+#define TR_GNUC_PRINTF(fmt, args)
+#endif
+#endif
+
+bool TR_NORETURN tr_assert_report(char const* file, int line, char const* message_fmt, ...) TR_GNUC_PRINTF(3, 4);
+
+#define TR_ASSERT(x) (TR_LIKELY(x) || tr_assert_report(__FILE__, __LINE__, "%s", #x))
+#define TR_ASSERT_MSG(x, ...) (TR_LIKELY(x) || tr_assert_report(__FILE__, __LINE__, __VA_ARGS__))
+
+#define TR_ENABLE_ASSERTS
+
+#else
+
+#define TR_ASSERT(x) ((void)0)
+#define TR_ASSERT_MSG(x, ...) ((void)0)
+
+#undef TR_ENABLE_ASSERTS
+
+#endif
#include "platform.h" /* tr_threadNew() */
#include "session.h"
#include "torrent.h" /* tr_torrentFindFromHash() */
+#include "tr-assert.h"
#include "tr-dht.h"
#include "trevent.h" /* tr_runInEventThread() */
#include "utils.h"
time_t tosleep;
int rc;
- assert(tr_isSession(sv));
+ TR_ASSERT(tr_isSession(sv));
if (sv != session)
{
int dht_gettimeofday(struct timeval* tv, struct timezone* tz)
{
- assert(tz == NULL);
+ TR_ASSERT(tz == NULL);
return tr_gettimeofday(tv);
}
#include "peer-mgr.h" /* tr_peerMgrAddPex() */
#include "session.h"
#include "torrent.h" /* tr_torrentFindFromHash() */
+#include "tr-assert.h"
#include "tr-lpd.h"
#include "utils.h"
#include "version.h"
int minor = -1;
size_t len;
- assert(s != NULL);
+ TR_ASSERT(s != NULL);
len = strlen(s);
/* something might be rotten with this chunk of data */
char sstr[maxLength] = { 0 };
char const* pos;
- assert(str != NULL && name != NULL);
- assert(val != NULL);
+ TR_ASSERT(str != NULL);
+ TR_ASSERT(name != NULL);
+ TR_ASSERT(val != NULL);
if (strlen(name) > maxLength - strlen(CRLF ": "))
{
return -1;
}
- assert(lpd_announceInterval > 0);
- assert(lpd_announceScope > 0);
+ TR_ASSERT(lpd_announceInterval > 0);
+ TR_ASSERT(lpd_announceScope > 0);
lpd_port = tr_sessionGetPeerPort(ss);
* @see DoS */
static void event_callback(evutil_socket_t s UNUSED, short type, void* ignore UNUSED)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
/* do not allow announces to be processed if LPD is disabled */
if (!tr_sessionAllowsLPD(session))
*/
-#include <assert.h>
#include <string.h> /* memcmp(), memcpy(), memset() */
#include <stdlib.h> /* malloc(), free() */
#include "log.h"
#include "net.h"
#include "session.h"
+#include "tr-assert.h"
#include "tr-dht.h"
#include "tr-utp.h"
#include "tr-udp.h"
struct sockaddr_storage from;
tr_session* ss = sv;
- assert(tr_isSession(sv));
- assert(type == EV_READ);
+ TR_ASSERT(tr_isSession(sv));
+ TR_ASSERT(type == EV_READ);
fromlen = sizeof(from);
rc = recvfrom(s, (void*)buf, 4096 - 1, 0, (struct sockaddr*)&from, &fromlen);
struct sockaddr_in sin;
int rc;
- assert(ss->udp_socket == TR_BAD_SOCKET);
- assert(ss->udp6_socket == TR_BAD_SOCKET);
+ TR_ASSERT(ss->udp_socket == TR_BAD_SOCKET);
+ TR_ASSERT(ss->udp6_socket == TR_BAD_SOCKET);
ss->udp_port = tr_sessionGetPeerPort(ss);
*/
-#include <assert.h>
-
#include <event2/event.h>
#include <libutp/utp.h>
#include "session.h"
#include "crypto-utils.h" /* tr_rand_int_weak() */
#include "peer-mgr.h"
+#include "tr-assert.h"
#include "tr-utp.h"
#include "utils.h"
{
tr_logAddNamedError(MY_NAME, "UTP_Close(%p) was called.", socket);
dbgmsg("UTP_Close(%p) was called.", socket);
- assert(0); /* FIXME: this is too much for the long term, but probably needed in the short term */
+ TR_ASSERT(false); /* FIXME: this is too much for the long term, but probably needed in the short term */
}
void UTP_RBDrained(struct UTPSocket* socket)
{
tr_logAddNamedError(MY_NAME, "UTP_RBDrained(%p) was called.", socket);
dbgmsg("UTP_RBDrained(%p) was called.", socket);
- assert(0); /* FIXME: this is too much for the long term, but probably needed in the short term */
+ TR_ASSERT(false); /* FIXME: this is too much for the long term, but probably needed in the short term */
}
bool UTP_Write(struct UTPSocket* socket, size_t count)
{
tr_logAddNamedError(MY_NAME, "UTP_RBDrained(%p, %zu) was called.", socket, count);
dbgmsg("UTP_RBDrained(%p, %zu) was called.", socket, count);
- assert(0); /* FIXME: this is too much for the long term, but probably needed in the short term */
+ TR_ASSERT(false); /* FIXME: this is too much for the long term, but probably needed in the short term */
return false;
}
*
*/
-#include <assert.h>
#include <errno.h>
#include <string.h>
#include "transmission.h"
#include "platform.h" /* tr_lockLock() */
+#include "tr-assert.h"
#include "trevent.h"
#include "utils.h"
default:
{
- assert(0 && "unhandled command type!");
+ TR_ASSERT_MSG(false, "unhandled command type %d", (int)ch);
break;
}
}
void tr_eventClose(tr_session* session)
{
- assert(tr_isSession(session));
+ TR_ASSERT(tr_isSession(session));
if (session->events == NULL)
{
bool tr_amInEventThread(tr_session const* session)
{
- assert(tr_isSession(session));
- assert(session->events != NULL);
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(session->events != NULL);
return tr_amInThread(session->events->thread);
}
void tr_runInEventThread(tr_session* session, void (* func)(void*), void* user_data)
{
- assert(tr_isSession(session));
- assert(session->events != NULL);
+ TR_ASSERT(tr_isSession(session));
+ TR_ASSERT(session->events != NULL);
if (tr_amInThread(session->events->thread))
{
*
*/
-#include <assert.h>
#include <errno.h>
#ifdef SYSTEM_MINIUPNP
#include "log.h"
#include "port-forwarding.h"
#include "session.h"
+#include "tr-assert.h"
#include "upnp.h"
#include "utils.h"
void tr_upnpClose(tr_upnp* handle)
{
- assert(!handle->isMapped);
- assert(handle->state == TR_UPNP_IDLE || handle->state == TR_UPNP_ERR || handle->state == TR_UPNP_DISCOVER);
+ TR_ASSERT(!handle->isMapped);
+ TR_ASSERT(handle->state == TR_UPNP_IDLE || handle->state == TR_UPNP_ERR || handle->state == TR_UPNP_DISCOVER);
if (handle->hasDiscovered)
{
#define HAVE_VALLOC
#endif
-#include <assert.h>
#include <ctype.h> /* isdigit(), tolower() */
#include <errno.h>
#include <float.h> /* DBL_EPSILON */
#include "list.h"
#include "log.h"
#include "net.h"
-#include "utils.h"
#include "platform.h" /* tr_lockLock() */
#include "platform-quota.h" /* tr_device_info_create(), tr_device_info_get_free_space(), tr_device_info_free() */
+#include "tr-assert.h"
+#include "utils.h"
#include "variant.h"
#include "version.h"
tv.tv_sec = seconds;
tv.tv_usec = microseconds;
- assert(tv.tv_sec >= 0);
- assert(tv.tv_usec >= 0);
- assert(tv.tv_usec < 1000000);
+ TR_ASSERT(tv.tv_sec >= 0);
+ TR_ASSERT(tv.tv_usec >= 0);
+ TR_ASSERT(tv.tv_usec < 1000000);
evtimer_add(timer, &tv);
}
/* file size should be able to fit into size_t */
if (sizeof(info.size) > sizeof(*size))
{
- assert(info.size <= SIZE_MAX);
+ TR_ASSERT(info.size <= SIZE_MAX);
}
/* Load the torrent file into our buffer */
*pch++ = '\0';
/* sanity checks & return */
- assert(pch - buf == (ptrdiff_t)bufLen);
+ TR_ASSERT(pch - buf == (ptrdiff_t)bufLen);
return buf;
}
char const* s = src;
size_t n = siz;
- assert(s);
- assert(d);
+ TR_ASSERT(s != NULL);
+ TR_ASSERT(d != NULL);
/* Copy as many bytes as will fit */
if (n != 0)
SWAP(base + (size * right), base + (size * storeIndex), size);
/* sanity check the partition */
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
- assert(storeIndex >= left);
- assert(storeIndex <= right);
+ TR_ASSERT(storeIndex >= left);
+ TR_ASSERT(storeIndex <= right);
for (size_t i = left; i < storeIndex; ++i)
{
- assert((*compar)(base + (size * i), base + (size * storeIndex)) <= 0);
+ TR_ASSERT((*compar)(base + (size * i), base + (size * storeIndex)) <= 0);
}
for (size_t i = storeIndex + 1; i <= right; ++i)
{
- assert((*compar)(base + (size * i), base + (size * storeIndex)) >= 0);
+ TR_ASSERT((*compar)(base + (size * i), base + (size * storeIndex)) >= 0);
}
#endif
}
}
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
static void checkBestScoresComeFirst(char* base, size_t nmemb, size_t size, int (* compar)(void const*, void const*), size_t k)
{
for (size_t i = 0; i < k; ++i)
{
- assert((*compar)(base + (size * i), base + (size * worstFirstPos)) <= 0);
+ TR_ASSERT((*compar)(base + (size * i), base + (size * worstFirstPos)) <= 0);
}
for (size_t i = k; i < nmemb; ++i)
{
- assert((*compar)(base + (size * i), base + (size * worstFirstPos)) >= 0);
+ TR_ASSERT((*compar)(base + (size * i), base + (size * worstFirstPos)) >= 0);
}
}
{
quickfindFirstK(base, 0, nmemb - 1, size, compar, k);
-#ifndef NDEBUG
+#ifdef TR_ENABLE_ASSERTS
checkBestScoresComeFirst(base, nmemb, size, compar, k);
#endif
}
ret = to_utf8(str, max_len);
}
- assert(tr_utf8_validate(ret, TR_BAD_SIZE, NULL));
+ TR_ASSERT(tr_utf8_validate(ret, TR_BAD_SIZE, NULL));
return ret;
}
return;
}
- assert(*argc == my_argc);
+ TR_ASSERT(*argc == my_argc);
char** my_argv = tr_new(char*, my_argc + 1);
int processed_argc = 0;
}
qsort(sorted, n, sizeof(int), compareInt);
- assert(n == n2);
+ TR_ASSERT(n == n2);
/* remove duplicates */
uniq = tr_new(int, n);
break;
}
- assert(numRead == bytesWritten);
- assert(bytesWritten <= bytesLeft);
+ TR_ASSERT(numRead == bytesWritten);
+ TR_ASSERT(bytesWritten <= bytesLeft);
bytesLeft -= bytesWritten;
}
bool tr_env_key_exists(char const* key)
{
- assert(key != NULL);
+ TR_ASSERT(key != NULL);
#ifdef _WIN32
return GetEnvironmentVariableA(key, NULL, 0) != 0;
char value[16];
- assert(key != NULL);
+ TR_ASSERT(key != NULL);
if (GetEnvironmentVariableA(key, value, TR_N_ELEMENTS(value)) > 1)
{
char const* value;
- assert(key != NULL);
+ TR_ASSERT(key != NULL);
value = getenv(key);
char* value;
- assert(key != NULL);
+ TR_ASSERT(key != NULL);
value = getenv(key);
*
*/
-#include <assert.h>
#include <ctype.h> /* isdigit() */
#include <errno.h>
#include <stdlib.h> /* strtoul() */
*
*/
-#include <assert.h>
#include <ctype.h>
#include <math.h> /* fabs() */
#include <stdio.h>
#include "list.h"
#include "log.h"
#include "ptrarray.h"
+#include "tr-assert.h"
#include "utils.h"
#include "variant.h"
#include "variant-common.h"
unsigned int val = 0;
char const* const end = in + 6;
- assert(in != NULL);
- assert(in[0] == '\\');
- assert(in[1] == 'u');
+ TR_ASSERT(in != NULL);
+ TR_ASSERT(in[0] == '\\');
+ TR_ASSERT(in[1] == 'u');
in += 2;
do
#define _GNU_SOURCE
#endif
-#include <assert.h>
#include <errno.h>
#include <stdlib.h> /* strtod(), realloc(), qsort() */
#include <string.h>
#include "error.h"
#include "file.h"
#include "log.h"
+#include "tr-assert.h"
#include "utils.h" /* tr_new(), tr_free() */
#include "variant.h"
#include "variant-common.h"
static inline char const* getStr(tr_variant const* v)
{
- assert(tr_variantIsString(v));
+ TR_ASSERT(tr_variantIsString(v));
return tr_variant_string_get_string(&v->val.s);
}
{
size_t const needed = v->val.l.count + count;
- assert(tr_variantIsContainer(v));
+ TR_ASSERT(tr_variantIsContainer(v));
if (needed > v->val.l.alloc)
{
void tr_variantListReserve(tr_variant* list, size_t count)
{
- assert(tr_variantIsList(list));
+ TR_ASSERT(tr_variantIsList(list));
containerReserve(list, count);
}
void tr_variantDictReserve(tr_variant* dict, size_t reserve_count)
{
- assert(tr_variantIsDict(dict));
+ TR_ASSERT(tr_variantIsDict(dict));
containerReserve(dict, reserve_count);
}
{
tr_variant* child;
- assert(tr_variantIsList(list));
+ TR_ASSERT(tr_variantIsList(list));
containerReserve(list, 1);
child = &list->val.l.vals[list->val.l.count++];
{
tr_variant* val;
- assert(tr_variantIsDict(dict));
+ TR_ASSERT(tr_variantIsDict(dict));
containerReserve(dict, 1);
{
bool success = 0;
- assert(tr_variantIsDict(dict));
+ TR_ASSERT(tr_variantIsDict(dict));
if (tr_variantIsDict(dict) && n < dict->val.l.count)
{
{
size_t const sourceCount = tr_variantDictSize(source);
- assert(tr_variantIsDict(target));
- assert(tr_variantIsDict(source));
+ TR_ASSERT(tr_variantIsDict(target));
+ TR_ASSERT(tr_variantIsDict(source));
tr_variantDictReserve(target, sourceCount + tr_variantDictSize(target));
#include "log.h"
#include "platform.h" /* tr_lock() */
#include "torrent.h"
+#include "tr-assert.h"
#include "utils.h" /* tr_valloc(), tr_free() */
#include "verify.h"
tr_torrentSetVerifyState(tor, TR_VERIFY_NOW);
changed = verifyTorrent(tor, &stopCurrent);
tr_torrentSetVerifyState(tor, TR_VERIFY_NONE);
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (!stopCurrent && changed)
{
{
struct verify_node* node;
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
tr_logAddTorInfo(tor, "%s", _("Queued for verification"));
node = tr_new(struct verify_node, 1);
tr_lock* lock = getVerifyLock();
tr_lockLock(lock);
- assert(tr_isTorrent(tor));
+ TR_ASSERT(tr_isTorrent(tor));
if (tor == currentNode.torrent)
{
*
*/
-#include <assert.h>
#include <errno.h>
#include <event2/event.h>
#include "transmission.h"
#include "log.h"
#include "ptrarray.h"
+#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
return;
}
- assert(backend->base.free_func == &tr_watchdir_generic_free);
+ TR_ASSERT(backend->base.free_func == &tr_watchdir_generic_free);
if (backend->event != NULL)
{
*
*/
-#include <assert.h>
#include <errno.h>
#include <limits.h> /* NAME_MAX */
#include <stdlib.h> /* realloc() */
#include "transmission.h"
#include "log.h"
+#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
static void tr_watchdir_inotify_on_event(struct bufferevent* event, void* context)
{
- assert(context != NULL);
+ TR_ASSERT(context != NULL);
tr_watchdir_t const handle = context;
tr_watchdir_inotify* const backend = BACKEND_UPCAST(tr_watchdir_get_backend(handle));
break;
}
- assert(ev.wd == backend->inwd);
- assert((ev.mask & INOTIFY_WATCH_MASK) != 0);
- assert(ev.len > 0);
+ TR_ASSERT(ev.wd == backend->inwd);
+ TR_ASSERT((ev.mask & INOTIFY_WATCH_MASK) != 0);
+ TR_ASSERT(ev.len > 0);
if (ev.len > name_size)
{
return;
}
- assert(backend->base.free_func == &tr_watchdir_inotify_free);
+ TR_ASSERT(backend->base.free_func == &tr_watchdir_inotify_free);
if (backend->event != NULL)
{
*
*/
-#include <assert.h>
#include <errno.h>
#include <string.h> /* strcmp() */
#include "transmission.h"
#include "log.h"
#include "ptrarray.h"
+#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
return;
}
- assert(backend->base.free_func == &tr_watchdir_kqueue_free);
+ TR_ASSERT(backend->base.free_func == &tr_watchdir_kqueue_free);
if (backend->event != NULL)
{
*
*/
-#include <assert.h>
#include <errno.h>
#include <stddef.h> /* offsetof */
#include <stdlib.h> /* realloc() */
#include "transmission.h"
#include "log.h"
#include "net.h"
+#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
return FALSE;
}
- assert(wait_result == WAIT_OBJECT_0);
+ TR_ASSERT(wait_result == WAIT_OBJECT_0);
return GetOverlappedResult(handle, overlapped, bytes_transferred, FALSE);
}
size_t const nleft = ev->NextEntryOffset - nread;
- assert(ev->FileNameLength % sizeof(WCHAR) == 0);
- assert(ev->FileNameLength > 0);
- assert(ev->FileNameLength <= nleft);
+ TR_ASSERT(ev->FileNameLength % sizeof(WCHAR) == 0);
+ TR_ASSERT(ev->FileNameLength > 0);
+ TR_ASSERT(ev->FileNameLength <= nleft);
if (nleft > name_size)
{
return;
}
- assert(backend->base.free_func == &tr_watchdir_win32_free);
+ TR_ASSERT(backend->base.free_func == &tr_watchdir_win32_free);
if (backend->fd != INVALID_HANDLE_VALUE)
{
*
*/
-#include <assert.h>
#include <string.h> /* strcmp() */
#include <event2/event.h>
#include "file.h"
#include "log.h"
#include "ptrarray.h"
+#include "tr-assert.h"
#include "utils.h"
#include "watchdir.h"
#include "watchdir-common.h"
tr_watchdir_status const ret = (*handle->callback)(handle, name, handle->callback_user_data);
- assert(ret == TR_WATCHDIR_ACCEPT || ret == TR_WATCHDIR_IGNORE || ret == TR_WATCHDIR_RETRY);
+ TR_ASSERT(ret == TR_WATCHDIR_ACCEPT || ret == TR_WATCHDIR_IGNORE || ret == TR_WATCHDIR_RETRY);
log_debug("Callback decided to %s file \"%s\"", watchdir_status_to_string(ret), name);
static void tr_watchdir_on_retry_timer(evutil_socket_t fd UNUSED, short type UNUSED, void* context)
{
- assert(context != NULL);
+ TR_ASSERT(context != NULL);
tr_watchdir_retry* const retry = context;
tr_watchdir_t const handle = retry->handle;
static void tr_watchdir_retry_restart(tr_watchdir_retry* retry)
{
- assert(retry != NULL);
+ TR_ASSERT(retry != NULL);
evtimer_del(retry->timer);
}
else
{
- assert(handle->backend->free_func != NULL);
+ TR_ASSERT(handle->backend->free_func != NULL);
}
return handle;
char const* tr_watchdir_get_path(tr_watchdir_t handle)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
return handle->path;
}
tr_watchdir_backend* tr_watchdir_get_backend(tr_watchdir_t handle)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
return handle->backend;
}
struct event_base* tr_watchdir_get_event_base(tr_watchdir_t handle)
{
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
return handle->event_base;
}
tr_watchdir_retry const search_key = { .name = (char*)name };
tr_watchdir_retry* existing_retry;
- assert(handle != NULL);
+ TR_ASSERT(handle != NULL);
if ((existing_retry = tr_watchdir_retries_find(&handle->active_retries, &search_key)) != NULL)
{
*
*/
-#include <assert.h>
#include <string.h> /* strlen(), strstr() */
#ifdef _WIN32
#include "torrent.h"
#include "platform.h" /* mutex */
#include "session.h"
+#include "tr-assert.h"
#include "trevent.h" /* tr_runInEventThread() */
#include "utils.h"
#include "version.h" /* User-Agent */
long req_bytes_sent;
CURL* e = msg->easy_handle;
curl_easy_getinfo(e, CURLINFO_PRIVATE, (void*)&task);
- assert(e == task->curl_easy);
+ TR_ASSERT(e == task->curl_easy);
curl_easy_getinfo(e, CURLINFO_RESPONSE_CODE, &task->code);
curl_easy_getinfo(e, CURLINFO_REQUEST_SIZE, &req_bytes_sent);
curl_easy_getinfo(e, CURLINFO_TOTAL_TIME, &total_time);