offset = KEY_LEN - len;
memset (crypto->mySecret, 0, offset);
memcpy (crypto->mySecret + offset, secret, len);
- crypto->mySecretIsSet = 1;
+ crypto->mySecretIsSet = true;
}
BN_free (bn);
tr_cryptoSetTorrentHash (tr_crypto * crypto,
const uint8_t * hash)
{
- crypto->torrentHashIsSet = hash ? 1 : 0;
+ crypto->torrentHashIsSet = hash != NULL;
if (hash)
memcpy (crypto->torrentHash, hash, SHA_DIGEST_LENGTH);
return crypto->torrentHashIsSet ? crypto->torrentHash : NULL;
}
-int
+bool
tr_cryptoHasTorrentHash (const tr_crypto * crypto)
{
assert (crypto);
- return crypto->torrentHashIsSet ? 1 : 0;
+ return crypto->torrentHashIsSet;
}
int
const uint8_t* tr_cryptoGetTorrentHash (const tr_crypto * crypto);
-int tr_cryptoHasTorrentHash (const tr_crypto * crypto);
+bool tr_cryptoHasTorrentHash (const tr_crypto * crypto);
const uint8_t* tr_cryptoComputeSecret (tr_crypto * crypto,
const uint8_t * peerPublicKey);
preallocate_file_sparse (tr_sys_file_t fd, uint64_t length)
{
const char zero = '\0';
- bool success = 0;
+ bool success = false;
if (!length)
success = true;
static bool
preallocate_file_full (const char * filename, uint64_t length)
{
- bool success = 0;
+ bool success = false;
tr_sys_file_t fd = tr_sys_file_open (filename, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE, 0666, NULL);
if (fd != TR_BAD_SYS_FILE)
evbuffer_add_uint16 (outbuf, sizeof (msg));
evbuffer_add (outbuf, msg, sizeof (msg));
- handshake->haveSentBitTorrentHandshake = 1;
+ handshake->haveSentBitTorrentHandshake = true;
}
/* send it */
if (!buildHandshakeMessage (handshake, msg))
return tr_handshakeDone (handshake, false);
tr_peerIoWriteBytes (handshake->io, msg, sizeof (msg), false);
- handshake->haveSentBitTorrentHandshake = 1;
+ handshake->haveSentBitTorrentHandshake = true;
}
setReadState (handshake, AWAITING_PEER_ID);
return tr_handshakeDone (handshake, false);
evbuffer_add (outbuf, msg, sizeof (msg));
- handshake->haveSentBitTorrentHandshake = 1;
+ handshake->haveSentBitTorrentHandshake = true;
}
/* send it out */
{
uint8_t msg[HANDSHAKE_SIZE];
buildHandshakeMessage (handshake, msg);
- handshake->haveSentBitTorrentHandshake = 1;
+ handshake->haveSentBitTorrentHandshake = true;
setReadState (handshake, AWAITING_HANDSHAKE);
tr_peerIoWriteBytes (handshake->io, msg, sizeof (msg), false);
}
dbgmsg (handshake, "handshake failed, trying plaintext...");
buildHandshakeMessage (handshake, msg);
- handshake->haveSentBitTorrentHandshake = 1;
+ handshake->haveSentBitTorrentHandshake = true;
setReadState (handshake, AWAITING_HANDSHAKE);
tr_peerIoWriteBytes (handshake->io, msg, sizeof (msg), false);
}
uint8_t msg[HANDSHAKE_SIZE];
buildHandshakeMessage (handshake, msg);
- handshake->haveSentBitTorrentHandshake = 1;
+ handshake->haveSentBitTorrentHandshake = true;
setReadState (handshake, AWAITING_HANDSHAKE);
tr_peerIoWriteBytes (handshake->io, msg, sizeof (msg), false);
}
{
static unsigned char ipv6[16];
static time_t last_time = 0;
- static int have_ipv6 = 0;
+ static bool have_ipv6 = false;
const time_t now = tr_time ();
/* Re-check every half hour */
static void
canReadWrapper (tr_peerIo * io)
{
- bool err = 0;
- bool done = 0;
+ bool err = false;
+ bool done = false;
tr_session * session;
dbgmsg (io, "canRead");
case READ_NOW:
if (evbuffer_get_length (io->inbuf))
continue;
- done = 1;
+ done = true;
break;
case READ_LATER:
- done = 1;
+ done = true;
break;
case READ_ERR:
- err = 1;
+ err = true;
break;
}
return tr_cryptoGetTorrentHash (&io->crypto);
}
-int
+bool
tr_peerIoHasTorrentHash (const tr_peerIo * io)
{
assert (tr_isPeerIo (io));
const uint8_t* tr_peerIoGetTorrentHash (tr_peerIo * io);
-int tr_peerIoHasTorrentHash (const tr_peerIo * io);
+bool tr_peerIoHasTorrentHash (const tr_peerIo * io);
void tr_peerIoSetTorrentHash (tr_peerIo * io,
const uint8_t * hash);
{
struct peer_atom * atom = peer->atom;
atom->flags2 |= MYFLAG_BANNED;
- peer->doPurge = 1;
+ peer->doPurge = true;
tordbg (s, "banning peer %s", tr_atomAddrStr (atom));
}
}
if ((e->err == ERANGE) || (e->err == EMSGSIZE) || (e->err == ENOTCONN))
{
/* some protocol error from the peer */
- peer->doPurge = 1;
+ peer->doPurge = true;
tordbg (s, "setting %s doPurge flag because we got an ERANGE, EMSGSIZE, or ENOTCONN error",
tr_atomAddrStr (peer->atom));
}
/* build the fast set */
msgs->fastsetSize = tr_generateAllowedSet (msgs->fastset, numwant, inf->pieceCount, inf->hash, addr);
- msgs->haveFastSet = 1;
+ msgs->haveFastSet = true;
/* send it to the peer */
for (i=0; i<msgs->fastsetSize; ++i)
version_quark = tr_quark_new (TR_NAME " " USERAGENT_PREFIX, -1);
dbgmsg (msgs, "sending an ltep handshake");
- msgs->clientSentLtepHandshake = 1;
+ msgs->clientSentLtepHandshake = true;
/* decide if we want to advertise metadata xfer support (BEP 9) */
if (tr_torrentIsPrivate (msgs->torrent))
- allow_metadata_xfer = 0;
+ allow_metadata_xfer = false;
else
- allow_metadata_xfer = 1;
+ allow_metadata_xfer = true;
/* decide if we want to advertise pex support */
if (!tr_torrentAllowsPex (msgs->torrent))
- allow_pex = 0;
+ allow_pex = false;
else if (msgs->peerSentLtepHandshake)
- allow_pex = msgs->peerSupportsPex ? 1 : 0;
+ allow_pex = msgs->peerSupportsPex;
else
- allow_pex = 1;
+ allow_pex = true;
tr_variantInitDict (&val, 8);
tr_variantDictAddInt (&val, TR_KEY_e, getSession (msgs)->encryptionMode != TR_CLEAR_PREFERRED);
memset (&pex, 0, sizeof (tr_pex));
tr_peerIoReadBytes (msgs->io, inbuf, tmp, len);
- msgs->peerSentLtepHandshake = 1;
+ msgs->peerSentLtepHandshake = true;
if (tr_variantFromBenc (&val, tmp, len) || !tr_variantIsDict (&val))
{
}
/* check supported messages for utorrent pex */
- msgs->peerSupportsPex = 0;
- msgs->peerSupportsMetadataXfer = 0;
+ msgs->peerSupportsPex = false;
+ msgs->peerSupportsMetadataXfer = false;
if (tr_variantDictFindDict (&val, TR_KEY_m, &sub)) {
if (tr_variantDictFindInt (sub, TR_KEY_ut_pex, &i)) {
else if (ltep_msgid == UT_PEX_ID)
{
dbgmsg (msgs, "got ut pex");
- msgs->peerSupportsPex = 1;
+ msgs->peerSupportsPex = true;
parseUtPex (msgs, msglen, inbuf);
}
else if (ltep_msgid == UT_METADATA_ID)
{
dbgmsg (msgs, "got ut metadata");
- msgs->peerSupportsMetadataXfer = 1;
+ msgs->peerSupportsMetadataXfer = true;
parseUtMetadata (msgs, msglen, inbuf);
}
else
struct remove_data * data;
assert (tr_isTorrent (tor));
- tor->isDeleting = 1;
+ tor->isDeleting = true;
data = tr_new0 (struct remove_data, 1);
data->tor = tor;
tr_logAddNamedInfo (getKey (), _(
"Local Address is \"%s\""), handle->lanaddr);
handle->state = TR_UPNP_IDLE;
- handle->hasDiscovered = 1;
+ handle->hasDiscovered = true;
}
else
{
SHA_CTX sha;
tr_sys_file_t fd = TR_BAD_SYS_FILE;
uint64_t filePos = 0;
- bool changed = 0;
- bool hadPiece = 0;
+ bool changed = false;
+ bool hadPiece = false;
time_t lastSleptAt = 0;
uint32_t piecePos = 0;
tr_file_index_t fileIndex = 0;