Minor type adjustments (incomplete, it takes way too much time)

This commit is contained in:
Mike Gelfand 2015-03-15 11:43:32 +00:00
parent 26f68eaada
commit 3f9575fcc8
9 changed files with 67 additions and 67 deletions

View File

@ -123,7 +123,7 @@ typedef enum
tau_action_t; tau_action_t;
static bool static bool
is_tau_response_message (int action, int msglen) is_tau_response_message (tau_action_t action, size_t msglen)
{ {
if (action == TAU_ACTION_CONNECT) return msglen == 16; if (action == TAU_ACTION_CONNECT) return msglen == 16;
if (action == TAU_ACTION_ANNOUNCE) return msglen >= 20; if (action == TAU_ACTION_ANNOUNCE) return msglen >= 20;

View File

@ -72,7 +72,7 @@ struct run_info
time_t last_block_time; time_t last_block_time;
bool is_multi_piece; bool is_multi_piece;
bool is_piece_done; bool is_piece_done;
unsigned len; unsigned int len;
}; };

View File

@ -26,15 +26,15 @@ charint (uint8_t ch)
return 0; return 0;
} }
static int static bool
getShadowInt (uint8_t ch, int * setme) getShadowInt (uint8_t ch, int * setme)
{ {
const char * str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-"; const char * str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-";
const char * pch = strchr (str, ch); const char * pch = strchr (str, ch);
if (!pch) if (!pch)
return 0; return false;
*setme = pch - str; *setme = pch - str;
return 1; return true;
} }
static int static int
@ -97,7 +97,7 @@ mainline_style (char * buf, size_t buflen, const char * name, const uint8_t * id
tr_snprintf (buf, buflen, "%s %c.%c%c.%c", name, id[1], id[3], id[4], id[6]); tr_snprintf (buf, buflen, "%s %c.%c%c.%c", name, id[1], id[3], id[4], id[6]);
} }
static int static bool
isMainlineStyle (const uint8_t * peer_id) isMainlineStyle (const uint8_t * peer_id)
{ {
/** /**
@ -110,7 +110,7 @@ isMainlineStyle (const uint8_t * peer_id)
&& (peer_id[4]=='-' || peer_id[5]=='-'); && (peer_id[4]=='-' || peer_id[5]=='-');
} }
static int static bool
decodeBitCometClient (char * buf, size_t buflen, const uint8_t * id) decodeBitCometClient (char * buf, size_t buflen, const uint8_t * id)
{ {
int is_bitlord; int is_bitlord;

View File

@ -120,7 +120,7 @@ initRC4 (tr_crypto * crypto,
void void
tr_cryptoDecryptInit (tr_crypto * crypto) tr_cryptoDecryptInit (tr_crypto * crypto)
{ {
unsigned char discard[1024]; uint8_t discard[1024];
const char * txt = crypto->isIncoming ? "keyA" : "keyB"; const char * txt = crypto->isIncoming ? "keyA" : "keyB";
initRC4 (crypto, &crypto->dec_key, txt); initRC4 (crypto, &crypto->dec_key, txt);
@ -147,7 +147,7 @@ tr_cryptoDecrypt (tr_crypto * crypto,
void void
tr_cryptoEncryptInit (tr_crypto * crypto) tr_cryptoEncryptInit (tr_crypto * crypto)
{ {
unsigned char discard[1024]; uint8_t discard[1024];
const char * txt = crypto->isIncoming ? "keyB" : "keyA"; const char * txt = crypto->isIncoming ? "keyB" : "keyA";
initRC4 (crypto, &crypto->enc_key, txt); initRC4 (crypto, &crypto->enc_key, txt);

View File

@ -62,26 +62,26 @@ enum
#ifdef ENABLE_LTEP #ifdef ENABLE_LTEP
#define HANDSHAKE_HAS_LTEP(bits)(((bits)[5] & 0x10) ? 1 : 0) #define HANDSHAKE_HAS_LTEP(bits)(((bits)[5] & 0x10) != 0)
#define HANDSHAKE_SET_LTEP(bits)((bits)[5] |= 0x10) #define HANDSHAKE_SET_LTEP(bits)((bits)[5] |= 0x10)
#else #else
#define HANDSHAKE_HAS_LTEP(bits)(0) #define HANDSHAKE_HAS_LTEP(bits)(false)
#define HANDSHAKE_SET_LTEP(bits)((void)0) #define HANDSHAKE_SET_LTEP(bits)((void)0)
#endif #endif
#ifdef ENABLE_FAST #ifdef ENABLE_FAST
#define HANDSHAKE_HAS_FASTEXT(bits)(((bits)[7] & 0x04) ? 1 : 0) #define HANDSHAKE_HAS_FASTEXT(bits)(((bits)[7] & 0x04) != 0)
#define HANDSHAKE_SET_FASTEXT(bits)((bits)[7] |= 0x04) #define HANDSHAKE_SET_FASTEXT(bits)((bits)[7] |= 0x04)
#else #else
#define HANDSHAKE_HAS_FASTEXT(bits)(0) #define HANDSHAKE_HAS_FASTEXT(bits)(false)
#define HANDSHAKE_SET_FASTEXT(bits)((void)0) #define HANDSHAKE_SET_FASTEXT(bits)((void)0)
#endif #endif
#ifdef ENABLE_DHT #ifdef ENABLE_DHT
#define HANDSHAKE_HAS_DHT(bits)(((bits)[7] & 0x01) ? 1 : 0) #define HANDSHAKE_HAS_DHT(bits)(((bits)[7] & 0x01) != 0)
#define HANDSHAKE_SET_DHT(bits)((bits)[7] |= 0x01) #define HANDSHAKE_SET_DHT(bits)((bits)[7] |= 0x01)
#else #else
#define HANDSHAKE_HAS_DHT(bits)(0) #define HANDSHAKE_HAS_DHT(bits)(false)
#define HANDSHAKE_SET_DHT(bits)((void)0) #define HANDSHAKE_SET_DHT(bits)((void)0)
#endif #endif
@ -91,7 +91,31 @@ enum
#define HANDSHAKE_GET_EXTPREF(reserved) ((reserved)[5] & 0x03) #define HANDSHAKE_GET_EXTPREF(reserved) ((reserved)[5] & 0x03)
#define HANDSHAKE_SET_EXTPREF(reserved, val)((reserved)[5] |= 0x03 & (val)) #define HANDSHAKE_SET_EXTPREF(reserved, val)((reserved)[5] |= 0x03 & (val))
typedef uint8_t handshake_state_t; /**
***
**/
typedef enum
{
/* incoming */
AWAITING_HANDSHAKE,
AWAITING_PEER_ID,
AWAITING_YA,
AWAITING_PAD_A,
AWAITING_CRYPTO_PROVIDE,
AWAITING_PAD_C,
AWAITING_IA,
AWAITING_PAYLOAD_STREAM,
/* outgoing */
AWAITING_YB,
AWAITING_VC,
AWAITING_CRYPTO_SELECT,
AWAITING_PAD_D,
N_STATES
}
handshake_state_t;
struct tr_handshake struct tr_handshake
{ {
@ -118,31 +142,6 @@ struct tr_handshake
*** ***
**/ **/
enum
{
/* incoming */
AWAITING_HANDSHAKE,
AWAITING_PEER_ID,
AWAITING_YA,
AWAITING_PAD_A,
AWAITING_CRYPTO_PROVIDE,
AWAITING_PAD_C,
AWAITING_IA,
AWAITING_PAYLOAD_STREAM,
/* outgoing */
AWAITING_YB,
AWAITING_VC,
AWAITING_CRYPTO_SELECT,
AWAITING_PAD_D,
N_STATES
};
/**
***
**/
#define dbgmsg(handshake, ...) \ #define dbgmsg(handshake, ...) \
do { \ do { \
if (tr_logGetDeepEnabled ()) \ if (tr_logGetDeepEnabled ()) \
@ -229,18 +228,19 @@ buildHandshakeMessage (tr_handshake * handshake, uint8_t * buf)
return success; return success;
} }
static int tr_handshakeDone (tr_handshake * handshake, static ReadState tr_handshakeDone (tr_handshake * handshake,
bool isConnected); bool isConnected);
enum typedef enum
{ {
HANDSHAKE_OK, HANDSHAKE_OK,
HANDSHAKE_ENCRYPTION_WRONG, HANDSHAKE_ENCRYPTION_WRONG,
HANDSHAKE_BAD_TORRENT, HANDSHAKE_BAD_TORRENT,
HANDSHAKE_PEER_IS_SELF, HANDSHAKE_PEER_IS_SELF,
}; }
handshake_parse_err_t;
static int static handshake_parse_err_t
parseHandshake (tr_handshake * handshake, parseHandshake (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -254,7 +254,7 @@ parseHandshake (tr_handshake * handshake,
HANDSHAKE_SIZE, evbuffer_get_length (inbuf)); HANDSHAKE_SIZE, evbuffer_get_length (inbuf));
if (evbuffer_get_length (inbuf) < HANDSHAKE_SIZE) if (evbuffer_get_length (inbuf) < HANDSHAKE_SIZE)
return READ_LATER; return HANDSHAKE_ENCRYPTION_WRONG;
/* confirm the protocol */ /* confirm the protocol */
tr_peerIoReadBytes (handshake->io, inbuf, name, HANDSHAKE_NAME_LEN); tr_peerIoReadBytes (handshake->io, inbuf, name, HANDSHAKE_NAME_LEN);
@ -392,10 +392,10 @@ computeRequestHash (const tr_handshake * handshake,
tr_cryptoSecretKeySha1 (handshake->crypto, name, 4, NULL, 0, hash); tr_cryptoSecretKeySha1 (handshake->crypto, name, 4, NULL, 0, hash);
} }
static int static ReadState
readYb (tr_handshake * handshake, struct evbuffer * inbuf) readYb (tr_handshake * handshake, struct evbuffer * inbuf)
{ {
int isEncrypted; bool isEncrypted;
uint8_t yb[KEY_LEN]; uint8_t yb[KEY_LEN];
struct evbuffer * outbuf; struct evbuffer * outbuf;
size_t needlen = HANDSHAKE_NAME_LEN; size_t needlen = HANDSHAKE_NAME_LEN;
@ -403,7 +403,7 @@ readYb (tr_handshake * handshake, struct evbuffer * inbuf)
if (evbuffer_get_length (inbuf) < needlen) if (evbuffer_get_length (inbuf) < needlen)
return READ_LATER; return READ_LATER;
isEncrypted = memcmp (evbuffer_pullup (inbuf, HANDSHAKE_NAME_LEN), HANDSHAKE_NAME, HANDSHAKE_NAME_LEN); isEncrypted = memcmp (evbuffer_pullup (inbuf, HANDSHAKE_NAME_LEN), HANDSHAKE_NAME, HANDSHAKE_NAME_LEN) != 0;
if (isEncrypted) if (isEncrypted)
{ {
needlen = KEY_LEN; needlen = KEY_LEN;
@ -492,7 +492,7 @@ readYb (tr_handshake * handshake, struct evbuffer * inbuf)
return READ_LATER; return READ_LATER;
} }
static int static ReadState
readVC (tr_handshake * handshake, readVC (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -526,7 +526,7 @@ readVC (tr_handshake * handshake,
return READ_NOW; return READ_NOW;
} }
static int static ReadState
readCryptoSelect (tr_handshake * handshake, readCryptoSelect (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -561,7 +561,7 @@ readCryptoSelect (tr_handshake * handshake,
return READ_NOW; return READ_NOW;
} }
static int static ReadState
readPadD (tr_handshake * handshake, readPadD (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -586,7 +586,7 @@ readPadD (tr_handshake * handshake,
**** ****
***/ ***/
static int static ReadState
readHandshake (tr_handshake * handshake, readHandshake (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -699,7 +699,7 @@ readHandshake (tr_handshake * handshake,
return READ_NOW; return READ_NOW;
} }
static int static ReadState
readPeerId (tr_handshake * handshake, readPeerId (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -726,7 +726,7 @@ readPeerId (tr_handshake * handshake,
return tr_handshakeDone (handshake, !connected_to_self); return tr_handshakeDone (handshake, !connected_to_self);
} }
static int static ReadState
readYa (tr_handshake * handshake, readYa (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -760,7 +760,7 @@ readYa (tr_handshake * handshake,
return READ_NOW; return READ_NOW;
} }
static int static ReadState
readPadA (tr_handshake * handshake, struct evbuffer * inbuf) readPadA (tr_handshake * handshake, struct evbuffer * inbuf)
{ {
/* resynchronizing on HASH ('req1',S) */ /* resynchronizing on HASH ('req1',S) */
@ -782,7 +782,7 @@ readPadA (tr_handshake * handshake, struct evbuffer * inbuf)
} }
} }
static int static ReadState
readCryptoProvide (tr_handshake * handshake, readCryptoProvide (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -852,7 +852,7 @@ readCryptoProvide (tr_handshake * handshake,
return READ_NOW; return READ_NOW;
} }
static int static ReadState
readPadC (tr_handshake * handshake, readPadC (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -876,7 +876,7 @@ readPadC (tr_handshake * handshake,
return READ_NOW; return READ_NOW;
} }
static int static ReadState
readIA (tr_handshake * handshake, readIA (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
@ -954,11 +954,11 @@ readIA (tr_handshake * handshake,
return READ_NOW; return READ_NOW;
} }
static int static ReadState
readPayloadStream (tr_handshake * handshake, readPayloadStream (tr_handshake * handshake,
struct evbuffer * inbuf) struct evbuffer * inbuf)
{ {
int i; handshake_parse_err_t i;
const size_t needlen = HANDSHAKE_SIZE; const size_t needlen = HANDSHAKE_SIZE;
dbgmsg (handshake, "reading payload stream... have %"TR_PRIuSIZE", need %"TR_PRIuSIZE, dbgmsg (handshake, "reading payload stream... have %"TR_PRIuSIZE", need %"TR_PRIuSIZE,
@ -1093,7 +1093,7 @@ tr_handshakeFree (tr_handshake * handshake)
tr_free (handshake); tr_free (handshake);
} }
static int static ReadState
tr_handshakeDone (tr_handshake * handshake, bool isOK) tr_handshakeDone (tr_handshake * handshake, bool isOK)
{ {
bool success; bool success;

View File

@ -292,7 +292,7 @@ recalculateHash (tr_torrent * tor, tr_piece_index_t pieceIndex, uint8_t * setme)
while (bytesLeft) while (bytesLeft)
{ {
const int len = MIN (bytesLeft, buflen); const size_t len = MIN (bytesLeft, buflen);
success = !tr_cacheReadBlock (tor->session->cache, tor, pieceIndex, offset, len, buffer); success = !tr_cacheReadBlock (tor->session->cache, tor, pieceIndex, offset, len, buffer);
if (!success) if (!success)
break; break;

View File

@ -139,7 +139,7 @@ tr_logFreeQueue (tr_log_message * list)
**/ **/
char* char*
tr_logGetTimeStr (char * buf, int buflen) tr_logGetTimeStr (char * buf, size_t buflen)
{ {
char tmp[64]; char tmp[64];
struct tm now_tm; struct tm now_tm;

View File

@ -121,7 +121,7 @@ void tr_logAddDeep (const char * file,
...) TR_GNUC_PRINTF (4, 5) TR_GNUC_NONNULL (1,4); ...) TR_GNUC_PRINTF (4, 5) TR_GNUC_NONNULL (1,4);
/** @brief set the buffer with the current time formatted for deep logging. */ /** @brief set the buffer with the current time formatted for deep logging. */
char* tr_logGetTimeStr (char * buf, int buflen) TR_GNUC_NONNULL (1); char* tr_logGetTimeStr (char * buf, size_t buflen) TR_GNUC_NONNULL (1);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1177,7 +1177,7 @@ tr_peerIoReadBytes (tr_peerIo * io, struct evbuffer * inbuf, void * bytes, size_
break; break;
default: default:
assert (0); assert (false);
} }
} }