]> granicus.if.org Git - transmission/commitdiff
Minor type adjustments (incomplete, it takes way too much time)
authorMike Gelfand <mikedld@mikedld.com>
Sun, 15 Mar 2015 11:43:32 +0000 (11:43 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Sun, 15 Mar 2015 11:43:32 +0000 (11:43 +0000)
libtransmission/announcer-udp.c
libtransmission/cache.c
libtransmission/clients.c
libtransmission/crypto.c
libtransmission/handshake.c
libtransmission/inout.c
libtransmission/log.c
libtransmission/log.h
libtransmission/peer-io.c

index 47f825a98aa7b682abbd47d8e38ecfacc0197951..43ef63d6b76933c781c85b62639e003f115c347d 100644 (file)
@@ -123,7 +123,7 @@ typedef enum
 tau_action_t;
 
 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_ANNOUNCE) return msglen >= 20;
index 933adfac956c4f754cb52f1d9d10fa3b6d364620..909cffd1d538055f0c4f88595c50b8462a81af9c 100644 (file)
@@ -72,7 +72,7 @@ struct run_info
   time_t last_block_time;
   bool is_multi_piece;
   bool is_piece_done;
-  unsigned len;
+  unsigned int len;
 };
 
 
index a45ee103eb7c1284329b3f4573f0f49290523683..defc49f80015b81befe7021393184d8fa8864e4e 100644 (file)
@@ -26,15 +26,15 @@ charint (uint8_t ch)
     return 0;
 }
 
-static int
+static bool
 getShadowInt (uint8_t ch, int * setme)
 {
     const char * str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-";
     const char * pch = strchr (str, ch);
     if (!pch)
-        return 0;
+        return false;
     *setme = pch - str;
-    return 1;
+    return true;
 }
 
 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]);
 }
 
-static int
+static bool
 isMainlineStyle (const uint8_t * peer_id)
 {
     /**
@@ -110,7 +110,7 @@ isMainlineStyle (const uint8_t * peer_id)
         && (peer_id[4]=='-' || peer_id[5]=='-');
 }
 
-static int
+static bool
 decodeBitCometClient (char * buf, size_t buflen, const uint8_t * id)
 {
     int is_bitlord;
index 1997ceed673ddce550d3fb5131ccfe351650e743..0321c25235a35fa388e22cf738f44bd4cd4b5f11 100644 (file)
@@ -120,7 +120,7 @@ initRC4 (tr_crypto    * crypto,
 void
 tr_cryptoDecryptInit (tr_crypto * crypto)
 {
-  unsigned char discard[1024];
+  uint8_t discard[1024];
   const char * txt = crypto->isIncoming ? "keyA" : "keyB";
 
   initRC4 (crypto, &crypto->dec_key, txt);
@@ -147,7 +147,7 @@ tr_cryptoDecrypt (tr_crypto  * crypto,
 void
 tr_cryptoEncryptInit (tr_crypto * crypto)
 {
-  unsigned char discard[1024];
+  uint8_t discard[1024];
   const char * txt = crypto->isIncoming ? "keyB" : "keyA";
 
   initRC4 (crypto, &crypto->enc_key, txt);
index c307f2f3d0d0224764aeae14307a829ce0ea632c..169952ccba85e88f723f11e1afb7c8b69bfa34ef 100644 (file)
@@ -62,26 +62,26 @@ enum
 
 
 #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)
 #else
- #define HANDSHAKE_HAS_LTEP(bits)(0)
+ #define HANDSHAKE_HAS_LTEP(bits)(false)
  #define HANDSHAKE_SET_LTEP(bits)((void)0)
 #endif
 
 #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)
 #else
- #define HANDSHAKE_HAS_FASTEXT(bits)(0)
+ #define HANDSHAKE_HAS_FASTEXT(bits)(false)
  #define HANDSHAKE_SET_FASTEXT(bits)((void)0)
 #endif
 
 #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)
 #else
- #define HANDSHAKE_HAS_DHT(bits)(0)
+ #define HANDSHAKE_HAS_DHT(bits)(false)
  #define HANDSHAKE_SET_DHT(bits)((void)0)
 #endif
 
@@ -91,34 +91,11 @@ enum
 #define HANDSHAKE_GET_EXTPREF(reserved)    ((reserved)[5] & 0x03)
 #define HANDSHAKE_SET_EXTPREF(reserved, val)((reserved)[5] |= 0x03 & (val))
 
-typedef uint8_t handshake_state_t;
-
-struct tr_handshake
-{
-  bool                  haveReadAnythingFromPeer;
-  bool                  havePeerID;
-  bool                  haveSentBitTorrentHandshake;
-  tr_peerIo *           io;
-  tr_crypto *           crypto;
-  tr_session *          session;
-  handshake_state_t     state;
-  tr_encryption_mode    encryptionMode;
-  uint16_t              pad_c_len;
-  uint16_t              pad_d_len;
-  uint16_t              ia_len;
-  uint32_t              crypto_select;
-  uint32_t              crypto_provide;
-  uint8_t               myReq1[SHA_DIGEST_LENGTH];
-  handshakeDoneCB       doneCB;
-  void *                doneUserData;
-  struct event        * timeout_timer;
-};
-
 /**
 ***
 **/
 
-enum
+typedef enum
 {
   /* incoming */
   AWAITING_HANDSHAKE,
@@ -137,6 +114,28 @@ enum
   AWAITING_PAD_D,
 
   N_STATES
+}
+handshake_state_t;
+
+struct tr_handshake
+{
+  bool                  haveReadAnythingFromPeer;
+  bool                  havePeerID;
+  bool                  haveSentBitTorrentHandshake;
+  tr_peerIo *           io;
+  tr_crypto *           crypto;
+  tr_session *          session;
+  handshake_state_t     state;
+  tr_encryption_mode    encryptionMode;
+  uint16_t              pad_c_len;
+  uint16_t              pad_d_len;
+  uint16_t              ia_len;
+  uint32_t              crypto_select;
+  uint32_t              crypto_provide;
+  uint8_t               myReq1[SHA_DIGEST_LENGTH];
+  handshakeDoneCB       doneCB;
+  void *                doneUserData;
+  struct event        * timeout_timer;
 };
 
 /**
@@ -229,18 +228,19 @@ buildHandshakeMessage (tr_handshake * handshake, uint8_t * buf)
   return success;
 }
 
-static int tr_handshakeDone (tr_handshake * handshake,
-                             bool           isConnected);
+static ReadState tr_handshakeDone (tr_handshake * handshake,
+                                   bool           isConnected);
 
-enum
+typedef enum
 {
   HANDSHAKE_OK,
   HANDSHAKE_ENCRYPTION_WRONG,
   HANDSHAKE_BAD_TORRENT,
   HANDSHAKE_PEER_IS_SELF,
-};
+}
+handshake_parse_err_t;
 
-static int
+static handshake_parse_err_t
 parseHandshake (tr_handshake *    handshake,
                 struct evbuffer * inbuf)
 {
@@ -254,7 +254,7 @@ parseHandshake (tr_handshake *    handshake,
           HANDSHAKE_SIZE, evbuffer_get_length (inbuf));
 
   if (evbuffer_get_length (inbuf) < HANDSHAKE_SIZE)
-    return READ_LATER;
+    return HANDSHAKE_ENCRYPTION_WRONG;
 
   /* confirm the protocol */
   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);
 }
 
-static int
+static ReadState
 readYb (tr_handshake * handshake, struct evbuffer * inbuf)
 {
-  int isEncrypted;
+  bool isEncrypted;
   uint8_t yb[KEY_LEN];
   struct evbuffer * outbuf;
   size_t needlen = HANDSHAKE_NAME_LEN;
@@ -403,7 +403,7 @@ readYb (tr_handshake * handshake, struct evbuffer * inbuf)
   if (evbuffer_get_length (inbuf) < needlen)
     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)
     {
       needlen = KEY_LEN;
@@ -492,7 +492,7 @@ readYb (tr_handshake * handshake, struct evbuffer * inbuf)
   return READ_LATER;
 }
 
-static int
+static ReadState
 readVC (tr_handshake    * handshake,
         struct evbuffer * inbuf)
 {
@@ -526,7 +526,7 @@ readVC (tr_handshake    * handshake,
   return READ_NOW;
 }
 
-static int
+static ReadState
 readCryptoSelect (tr_handshake    * handshake,
                   struct evbuffer * inbuf)
 {
@@ -561,7 +561,7 @@ readCryptoSelect (tr_handshake    * handshake,
   return READ_NOW;
 }
 
-static int
+static ReadState
 readPadD (tr_handshake    * handshake,
           struct evbuffer * inbuf)
 {
@@ -586,7 +586,7 @@ readPadD (tr_handshake    * handshake,
 ****
 ***/
 
-static int
+static ReadState
 readHandshake (tr_handshake    * handshake,
                struct evbuffer * inbuf)
 {
@@ -699,7 +699,7 @@ readHandshake (tr_handshake    * handshake,
   return READ_NOW;
 }
 
-static int
+static ReadState
 readPeerId (tr_handshake    * handshake,
             struct evbuffer * inbuf)
 {
@@ -726,7 +726,7 @@ readPeerId (tr_handshake    * handshake,
   return tr_handshakeDone (handshake, !connected_to_self);
 }
 
-static int
+static ReadState
 readYa (tr_handshake    * handshake,
         struct evbuffer * inbuf)
 {
@@ -760,7 +760,7 @@ readYa (tr_handshake    * handshake,
   return READ_NOW;
 }
 
-static int
+static ReadState
 readPadA (tr_handshake * handshake, struct evbuffer * inbuf)
 {
   /* resynchronizing on HASH ('req1',S) */
@@ -782,7 +782,7 @@ readPadA (tr_handshake * handshake, struct evbuffer * inbuf)
     }
 }
 
-static int
+static ReadState
 readCryptoProvide (tr_handshake    * handshake,
                    struct evbuffer * inbuf)
 {
@@ -852,7 +852,7 @@ readCryptoProvide (tr_handshake    * handshake,
   return READ_NOW;
 }
 
-static int
+static ReadState
 readPadC (tr_handshake    * handshake,
           struct evbuffer * inbuf)
 {
@@ -876,7 +876,7 @@ readPadC (tr_handshake    * handshake,
   return READ_NOW;
 }
 
-static int
+static ReadState
 readIA (tr_handshake    * handshake,
         struct evbuffer * inbuf)
 {
@@ -954,11 +954,11 @@ readIA (tr_handshake    * handshake,
   return READ_NOW;
 }
 
-static int
+static ReadState
 readPayloadStream (tr_handshake    * handshake,
                    struct evbuffer * inbuf)
 {
-  int i;
+  handshake_parse_err_t i;
   const size_t needlen = HANDSHAKE_SIZE;
 
   dbgmsg (handshake, "reading payload stream... have %"TR_PRIuSIZE", need %"TR_PRIuSIZE,
@@ -1093,7 +1093,7 @@ tr_handshakeFree (tr_handshake * handshake)
   tr_free (handshake);
 }
 
-static int
+static ReadState
 tr_handshakeDone (tr_handshake * handshake, bool isOK)
 {
   bool success;
index 82a769380ae0a342b5d1a3a2c18c333128420d0c..5f580f5da905e00238a07872ee599a23b8418f73 100644 (file)
@@ -292,7 +292,7 @@ recalculateHash (tr_torrent * tor, tr_piece_index_t pieceIndex, uint8_t * setme)
 
   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);
       if (!success)
         break;
index c50bbacb700579c8c5386ae7d0ddaabe62bf921b..16120def37a10889c0644d3755fb7385d2786b8b 100644 (file)
@@ -139,7 +139,7 @@ tr_logFreeQueue (tr_log_message * list)
 **/
 
 char*
-tr_logGetTimeStr (char * buf, int buflen)
+tr_logGetTimeStr (char * buf, size_t buflen)
 {
   char tmp[64];
   struct tm now_tm;
index 9684801720890c4c8553bf0b9072083e5770abe7..71d8b2e3c119f19ec1597d4d4b79bbcf56b2593e 100644 (file)
@@ -121,7 +121,7 @@ void tr_logAddDeep (const char * file,
                     ...) TR_GNUC_PRINTF (4, 5) TR_GNUC_NONNULL (1,4);
 
 /** @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
 }
index 8e8a619f1aa36b6156b05aa471bdfbd61fcd10ce..cae762197ad760eb0fa0724066def920f9fdd301 100644 (file)
@@ -1177,7 +1177,7 @@ tr_peerIoReadBytes (tr_peerIo * io, struct evbuffer * inbuf, void * bytes, size_
             break;
 
         default:
-            assert (0);
+            assert (false);
     }
 }