Changeset 7579
- Timestamp:
- Jan 2, 2009, 5:46:22 PM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bandwidth.c
r7576 r7579 27 27 ***/ 28 28 29 enum30 {31 HISTORY_MSEC = 2000,32 INTERVAL_MSEC = HISTORY_MSEC,33 GRANULARITY_MSEC = 50,34 HISTORY_SIZE = ( INTERVAL_MSEC / GRANULARITY_MSEC ),35 MAGIC_NUMBER = 4314336 };37 38 struct bratecontrol39 {40 int newest;41 struct { uint64_t date, size; } transfers[HISTORY_SIZE];42 };43 44 29 static float 45 30 getSpeed( const struct bratecontrol * r, int interval_msec ) … … 83 68 ******/ 84 69 85 struct tr_band86 {87 tr_bool isLimited;88 tr_bool honorParentLimits;89 size_t bytesLeft;90 double desiredSpeed;91 struct bratecontrol raw;92 struct bratecontrol piece;93 };94 95 struct tr_bandwidth96 {97 struct tr_band band[2];98 struct tr_bandwidth * parent;99 int magicNumber;100 tr_session * session;101 tr_ptrArray children; /* struct tr_bandwidth */102 tr_ptrArray peers; /* tr_peerIo */103 };104 105 /***106 ****107 ***/108 109 70 static inline int 110 71 comparePointers( const void * a, const void * b ) … … 114 75 115 76 return 0; 116 }117 118 tr_bool119 tr_isBandwidth( const tr_bandwidth * b )120 {121 return ( b != NULL ) && ( b->magicNumber == MAGIC_NUMBER );122 77 } 123 78 … … 196 151 ***/ 197 152 198 void199 tr_bandwidthSetDesiredSpeed( tr_bandwidth * b,200 tr_direction dir,201 double desiredSpeed )202 {203 assert( tr_isBandwidth( b ) );204 assert( tr_isDirection( dir ) );205 206 b->band[dir].desiredSpeed = desiredSpeed;207 }208 209 double210 tr_bandwidthGetDesiredSpeed( const tr_bandwidth * b,211 tr_direction dir )212 {213 assert( tr_isBandwidth( b ) );214 assert( tr_isDirection( dir ) );215 216 return b->band[dir].desiredSpeed;217 }218 219 void220 tr_bandwidthSetLimited( tr_bandwidth * b,221 tr_direction dir,222 tr_bool isLimited )223 {224 assert( tr_isBandwidth( b ) );225 assert( tr_isDirection( dir ) );226 227 b->band[dir].isLimited = isLimited;228 }229 230 tr_bool231 tr_bandwidthIsLimited( const tr_bandwidth * b,232 tr_direction dir )233 {234 assert( tr_isBandwidth( b ) );235 assert( tr_isDirection( dir ) );236 237 return b->band[dir].isLimited;238 }239 240 153 #if 0 241 154 #warning do not check the code in with this enabled … … 359 272 assert( tr_isPeerIo( peerIo ) ); 360 273 361 tr_ptrArrayInsertSorted( &b->peers, peerIo, comparePointers );362 274 } 363 275 -
trunk/libtransmission/bandwidth.h
r7576 r7579 17 17 #ifndef TR_BANDWIDTH_H 18 18 #define TR_BANDWIDTH_H 19 20 #include "transmission.h" 21 #include "ptrarray.h" 22 23 struct tr_peerIo; 24 25 /* these are PRIVATE IMPLEMENTATION details that should not be touched. 26 * it's included in the header for inlining and composition. */ 27 enum 28 { 29 HISTORY_MSEC = 2000, 30 INTERVAL_MSEC = HISTORY_MSEC, 31 GRANULARITY_MSEC = 50, 32 HISTORY_SIZE = ( INTERVAL_MSEC / GRANULARITY_MSEC ), 33 MAGIC_NUMBER = 43143 34 }; 35 36 /* these are PRIVATE IMPLEMENTATION details that should not be touched. 37 * it's included in the header for inlining and composition. */ 38 struct bratecontrol 39 { 40 int newest; 41 struct { uint64_t date, size; } transfers[HISTORY_SIZE]; 42 }; 43 44 /* these are PRIVATE IMPLEMENTATION details that should not be touched. 45 * it's included in the header for inlining and composition. */ 46 struct tr_band 47 { 48 tr_bool isLimited; 49 tr_bool honorParentLimits; 50 size_t bytesLeft; 51 double desiredSpeed; 52 struct bratecontrol raw; 53 struct bratecontrol piece; 54 }; 19 55 20 56 /** … … 57 93 * bandwidth they can safely use. 58 94 */ 59 60 typedef struct tr_bandwidth tr_bandwidth; 61 62 struct tr_peerIo; 95 typedef struct tr_bandwidth 96 { 97 /* these are PRIVATE IMPLEMENTATION details that should not be touched. 98 * it's included in the header for inlining and composition. */ 99 100 struct tr_band band[2]; 101 struct tr_bandwidth * parent; 102 int magicNumber; 103 tr_session * session; 104 tr_ptrArray children; /* struct tr_bandwidth */ 105 tr_ptrArray peers; /* tr_peerIo */ 106 } 107 tr_bandwidth; 108 63 109 64 110 /** … … 75 121 76 122 /** @brief test to see if the pointer refers to a live bandwidth object */ 77 extern inline tr_bool 78 tr_isBandwidth ( const tr_bandwidth * bandwidth ); 123 static inline tr_bool tr_isBandwidth( const tr_bandwidth * b ) 124 { 125 return ( b != NULL ) && ( b->magicNumber == MAGIC_NUMBER ); 126 } 79 127 80 128 /****** … … 87 135 * @see tr_bandwidthGetDesiredSpeed 88 136 */ 89 extern inline void 90 tr_bandwidthSetDesiredSpeed ( tr_bandwidth * bandwidth, 91 tr_direction direction, 92 double desiredSpeed ); 137 static inline void tr_bandwidthSetDesiredSpeed( tr_bandwidth * bandwidth, 138 tr_direction dir, 139 double desiredSpeed ) 140 { 141 bandwidth->band[dir].desiredSpeed = desiredSpeed; 142 } 93 143 94 144 /** … … 96 146 * @see tr_bandwidthSetDesiredSpeed 97 147 */ 98 extern inline double 99 tr_bandwidthGetDesiredSpeed ( const tr_bandwidth * bandwidth, 100 tr_direction direction ); 148 static inline double 149 tr_bandwidthGetDesiredSpeed( const tr_bandwidth * bandwidth, 150 tr_direction dir ) 151 { 152 return bandwidth->band[dir].desiredSpeed; 153 } 101 154 102 155 /** 103 156 * @brief Set whether or not this bandwidth should throttle its peer-io's speeds 104 157 */ 105 extern inline void 106 tr_bandwidthSetLimited ( tr_bandwidth * bandwidth, 107 tr_direction direction, 108 tr_bool isLimited ); 158 static inline void tr_bandwidthSetLimited( tr_bandwidth * bandwidth, 159 tr_direction dir, 160 tr_bool isLimited ) 161 { 162 bandwidth->band[dir].isLimited = isLimited; 163 } 109 164 110 165 /** 111 166 * @return nonzero if this bandwidth throttles its peer-ios speeds 112 167 */ 113 extern inline tr_bool 114 tr_bandwidthIsLimited ( const tr_bandwidth * bandwidth, 115 tr_direction direction ); 168 static inline tr_bool tr_bandwidthIsLimited( const tr_bandwidth * bandwidth, 169 tr_direction dir ) 170 { 171 return bandwidth->band[dir].isLimited; 172 } 116 173 117 174 /** … … 133 190 ******/ 134 191 135 /** 136 * @brief Get the raw total of bytes read or sent by this bandwidth subtree. 137 */ 138 extern inline double 139 tr_bandwidthGetRawSpeed ( const tr_bandwidth * bandwidth, 140 tr_direction direction ); 141 142 /** 143 * @brief Get the number of piece data bytes read or sent by this bandwidth subtree. 144 */ 145 extern inline double 146 tr_bandwidthGetPieceSpeed ( const tr_bandwidth * bandwidth, 147 tr_direction direction ); 192 /** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */ 193 double tr_bandwidthGetRawSpeed( const tr_bandwidth * bandwidth, 194 tr_direction direction ); 195 196 /** @brief Get the number of piece data bytes read or sent by this bandwidth subtree. */ 197 double tr_bandwidthGetPieceSpeed( const tr_bandwidth * bandwidth, 198 tr_direction direction ); 148 199 149 200 /** … … 181 232 * They will be notified when more bandwidth is made available for them to consume. 182 233 */ 183 extern inline void 184 tr_bandwidthAddPeer ( tr_bandwidth * bandwidth, 185 struct tr_peerIo * peerIo ); 234 void tr_bandwidthAddPeer( tr_bandwidth * bandwidth, 235 struct tr_peerIo * peerIo ); 186 236 187 237 /** 188 238 * @brief remove a peer-io from this bandwidth's list. 189 239 */ 190 extern inline void 191 tr_bandwidthRemovePeer ( tr_bandwidth * bandwidth, 192 struct tr_peerIo * peerIo ); 240 void tr_bandwidthRemovePeer( tr_bandwidth * bandwidth, 241 struct tr_peerIo * peerIo ); 193 242 194 243 #endif -
trunk/libtransmission/peer-io.c
r7576 r7579 79 79 }; 80 80 81 struct tr_peerIo82 {83 tr_bool isEncrypted;84 tr_bool isIncoming;85 tr_bool peerIdIsSet;86 tr_bool extendedProtocolSupported;87 tr_bool fastExtensionSupported;88 89 int magicNumber;90 91 uint8_t encryptionMode;92 tr_port port;93 int socket;94 95 uint8_t peerId[SHA_DIGEST_LENGTH];96 time_t timeCreated;97 98 tr_session * session;99 100 tr_address addr;101 102 tr_can_read_cb canRead;103 tr_did_write_cb didWrite;104 tr_net_error_cb gotError;105 void * userData;106 107 tr_bandwidth * bandwidth;108 tr_crypto * crypto;109 110 struct evbuffer * inbuf;111 struct evbuffer * outbuf;112 struct __tr_list outbuf_datatypes; /* struct tr_datatype */113 114 struct event event_read;115 struct event event_write;116 };117 118 81 /*** 119 82 **** … … 800 763 } 801 764 802 void803 tr_peerIoWriteUint8( tr_peerIo * io,804 struct evbuffer * outbuf,805 uint8_t writeme )806 {807 tr_peerIoWriteBytes( io, outbuf, &writeme, sizeof( uint8_t ) );808 }809 810 void811 tr_peerIoWriteUint16( tr_peerIo * io,812 struct evbuffer * outbuf,813 uint16_t writeme )814 {815 uint16_t tmp = htons( writeme );816 817 tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint16_t ) );818 }819 820 void821 tr_peerIoWriteUint32( tr_peerIo * io,822 struct evbuffer * outbuf,823 uint32_t writeme )824 {825 uint32_t tmp = htonl( writeme );826 827 tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint32_t ) );828 }829 830 765 /*** 831 766 **** … … 858 793 859 794 void 860 tr_peerIoReadUint8( tr_peerIo * io,861 struct evbuffer * inbuf,862 uint8_t * setme )863 {864 tr_peerIoReadBytes( io, inbuf, setme, sizeof( uint8_t ) );865 }866 867 void868 tr_peerIoReadUint16( tr_peerIo * io,869 struct evbuffer * inbuf,870 uint16_t * setme )871 {872 uint16_t tmp;873 tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint16_t ) );874 *setme = ntohs( tmp );875 }876 877 void878 tr_peerIoReadUint32( tr_peerIo * io,879 struct evbuffer * inbuf,880 uint32_t * setme )881 {882 uint32_t tmp;883 tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint32_t ) );884 *setme = ntohl( tmp );885 }886 887 void888 795 tr_peerIoDrain( tr_peerIo * io, 889 796 struct evbuffer * inbuf, … … 898 805 byteCount -= thisPass; 899 806 } 900 }901 902 int903 tr_peerIoGetAge( const tr_peerIo * io )904 {905 return time( NULL ) - io->timeCreated;906 807 } 907 808 … … 982 883 } 983 884 984 struct evbuffer *985 tr_peerIoGetReadBuffer( tr_peerIo * io )986 {987 assert( tr_isPeerIo( io ) );988 989 return io->inbuf;990 }991 992 tr_bool993 tr_peerIoHasBandwidthLeft( const tr_peerIo * io, tr_direction dir )994 {995 assert( tr_isPeerIo( io ) );996 997 return tr_bandwidthClamp( io->bandwidth, dir, 1024 ) > 0;998 }999 1000 885 /*** 1001 886 **** … … 1044 929 event_disable( io, event ); 1045 930 } 931 932 tr_bool 933 tr_peerIoHasBandwidthLeft( const tr_peerIo * io, 934 tr_direction dir ) 935 { 936 assert( tr_isPeerIo( io ) ); 937 938 return tr_bandwidthClamp( io->bandwidth, dir, 1024 ) > 0; 939 } 940 -
trunk/libtransmission/peer-io.h
r7576 r7579 22 22 **/ 23 23 24 #include <assert.h> 25 26 #include <event.h> 27 28 #include "transmission.h" 29 #include "list.h" /* __tr_list */ 30 #include "net.h" /* tr_address */ 31 24 32 struct evbuffer; 25 struct tr_address;26 33 struct tr_bandwidth; 27 34 struct tr_crypto; 28 typedef struct tr_peerIo tr_peerIo; 35 struct tr_peerIo; 36 37 typedef enum 38 { 39 READ_NOW, 40 READ_LATER, 41 READ_ERR 42 } 43 ReadState; 44 45 typedef ReadState ( *tr_can_read_cb )( struct tr_peerIo * io, 46 void * user_data, 47 size_t * setme_piece_byte_count ); 48 49 typedef void ( *tr_did_write_cb )( struct tr_peerIo * io, 50 size_t bytesWritten, 51 int wasPieceData, 52 void * userData ); 53 54 typedef void ( *tr_net_error_cb )( struct tr_peerIo * io, 55 short what, 56 void * userData ); 57 58 typedef struct tr_peerIo 59 { 60 tr_bool isEncrypted; 61 tr_bool isIncoming; 62 tr_bool peerIdIsSet; 63 tr_bool extendedProtocolSupported; 64 tr_bool fastExtensionSupported; 65 66 int magicNumber; 67 68 uint8_t encryptionMode; 69 tr_port port; 70 int socket; 71 72 uint8_t peerId[SHA_DIGEST_LENGTH]; 73 time_t timeCreated; 74 75 tr_session * session; 76 77 tr_address addr; 78 79 tr_can_read_cb canRead; 80 tr_did_write_cb didWrite; 81 tr_net_error_cb gotError; 82 void * userData; 83 84 struct tr_bandwidth * bandwidth; 85 struct tr_crypto * crypto; 86 87 struct evbuffer * inbuf; 88 struct evbuffer * outbuf; 89 struct __tr_list outbuf_datatypes; /* struct tr_datatype */ 90 91 struct event event_read; 92 struct event event_write; 93 } 94 tr_peerIo; 29 95 30 96 /** … … 84 150 tr_bool tr_peerIoIsIncoming( const tr_peerIo * io ); 85 151 86 extern inline int tr_peerIoGetAge( const tr_peerIo * io ); 152 static inline int tr_peerIoGetAge( const tr_peerIo * io ) 153 { 154 return time( NULL ) - io->timeCreated; 155 } 87 156 88 157 … … 99 168 *** 100 169 **/ 101 102 typedef enum103 {104 READ_NOW,105 READ_LATER,106 READ_ERR107 }108 ReadState;109 110 typedef ReadState ( *tr_can_read_cb )( tr_peerIo * io,111 void * user_data,112 size_t * setme_piece_byte_count );113 114 typedef void ( *tr_did_write_cb )( tr_peerIo * io,115 size_t bytesWritten,116 int wasPieceData,117 void * userData );118 119 typedef void ( *tr_net_error_cb )( tr_peerIo * io,120 short what,121 void * userData );122 170 123 171 void tr_peerIoSetIOFuncs ( tr_peerIo * io, … … 164 212 size_t byteCount ); 165 213 166 void tr_peerIoWriteUint8( tr_peerIo * io, 167 struct evbuffer * outbuf, 168 uint8_t writeme ); 169 170 void tr_peerIoWriteUint16( tr_peerIo * io, 171 struct evbuffer * outbuf, 172 uint16_t writeme ); 173 174 void tr_peerIoWriteUint32( tr_peerIo * io, 175 struct evbuffer * outbuf, 176 uint32_t writeme ); 214 static inline void tr_peerIoWriteUint8( tr_peerIo * io, 215 struct evbuffer * outbuf, 216 uint8_t writeme ) 217 { 218 tr_peerIoWriteBytes( io, outbuf, &writeme, sizeof( uint8_t ) ); 219 } 220 221 static inline void tr_peerIoWriteUint16( tr_peerIo * io, 222 struct evbuffer * outbuf, 223 uint16_t writeme ) 224 { 225 const uint16_t tmp = htons( writeme ); 226 tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint16_t ) ); 227 } 228 229 static inline void tr_peerIoWriteUint32( tr_peerIo * io, 230 struct evbuffer * outbuf, 231 uint32_t writeme ) 232 { 233 const uint32_t tmp = htonl( writeme ); 234 tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint32_t ) ); 235 } 177 236 178 237 void tr_peerIoReadBytes( tr_peerIo * io, … … 181 240 size_t byteCount ); 182 241 183 extern inline void 184 tr_peerIoReadUint8( tr_peerIo * io, 185 struct evbuffer * inbuf, 186 uint8_t * setme ); 187 188 extern inline void 189 tr_peerIoReadUint16( tr_peerIo * io, 190 struct evbuffer * inbuf, 191 uint16_t * setme ); 192 193 extern inline void 194 tr_peerIoReadUint32( tr_peerIo * io, 195 struct evbuffer * inbuf, 196 uint32_t * setme ); 242 static inline void tr_peerIoReadUint8( tr_peerIo * io, 243 struct evbuffer * inbuf, 244 uint8_t * setme ) 245 { 246 tr_peerIoReadBytes( io, inbuf, setme, sizeof( uint8_t ) ); 247 } 248 249 static inline void tr_peerIoReadUint16( tr_peerIo * io, 250 struct evbuffer * inbuf, 251 uint16_t * setme ) 252 { 253 uint16_t tmp; 254 tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint16_t ) ); 255 *setme = ntohs( tmp ); 256 } 257 258 static inline void tr_peerIoReadUint32( tr_peerIo * io, 259 struct evbuffer * inbuf, 260 uint32_t * setme ) 261 { 262 uint32_t tmp; 263 tr_peerIoReadBytes( io, inbuf, &tmp, sizeof( uint32_t ) ); 264 *setme = ntohl( tmp ); 265 } 197 266 198 267 void tr_peerIoDrain( tr_peerIo * io, … … 214 283 int isPieceData ); 215 284 216 /** 217 *** 218 **/ 219 220 extern inline tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io, 221 tr_direction direction ); 285 tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io, 286 tr_direction dir ); 287 288 /** 289 *** 290 **/ 222 291 223 292 void tr_peerIoSetEnabled( tr_peerIo * io, … … 229 298 size_t byteLimit ); 230 299 231 extern inline struct evbuffer * tr_peerIoGetReadBuffer( tr_peerIo * io ); 232 233 300 /** 301 *** 302 **/ 303 304 static inline struct evbuffer * tr_peerIoGetReadBuffer( tr_peerIo * io ) 305 { 306 assert( tr_isPeerIo( io ) ); 307 308 return io->inbuf; 309 } 234 310 235 311 -
trunk/libtransmission/peer-msgs.h
r7576 r7579 41 41 uint32_t pieceIndex ); 42 42 43 extern inline void 44 tr_peerMsgsPulse( tr_peermsgs * msgs ); 43 void tr_peerMsgsPulse( tr_peermsgs * msgs ); 45 44 46 45 void tr_peerMsgsCancel( tr_peermsgs * msgs, … … 57 56 uint32_t length ); 58 57 59 extern inline void 60 tr_peerMsgsUnsubscribe( tr_peermsgs * peer, 58 void tr_peerMsgsUnsubscribe( tr_peermsgs * peer, 61 59 tr_publisher_tag tag ); 62 60
Note: See TracChangeset
for help on using the changeset viewer.