Changeset 13936
- Timestamp:
- Feb 2, 2013, 8:17:52 PM (9 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bandwidth.h
r13625 r13936 35 35 enum 36 36 { 37 38 39 40 41 37 HISTORY_MSEC = 2000u, 38 INTERVAL_MSEC = HISTORY_MSEC, 39 GRANULARITY_MSEC = 200, 40 HISTORY_SIZE = (INTERVAL_MSEC / GRANULARITY_MSEC), 41 BANDWIDTH_MAGIC_NUMBER = 43143 42 42 }; 43 43 … … 46 46 struct bratecontrol 47 47 { 48 49 50 51 48 int newest; 49 struct { uint64_t date, size; } transfers[HISTORY_SIZE]; 50 uint64_t cache_time; 51 unsigned int cache_val; 52 52 }; 53 53 … … 56 56 struct tr_band 57 57 { 58 59 60 61 62 63 58 bool isLimited; 59 bool honorParentLimits; 60 unsigned int bytesLeft; 61 unsigned int desiredSpeed_Bps; 62 struct bratecontrol raw; 63 struct bratecontrol piece; 64 64 }; 65 65 … … 105 105 typedef struct tr_bandwidth 106 106 { 107 108 109 110 111 112 113 114 115 116 117 107 /* these are PRIVATE IMPLEMENTATION details that should not be touched. 108 * it's included in the header for inlining and composition. */ 109 110 struct tr_band band[2]; 111 struct tr_bandwidth * parent; 112 tr_priority_t priority; 113 int magicNumber; 114 unsigned int uniqueKey; 115 tr_session * session; 116 tr_ptrArray children; /* struct tr_bandwidth */ 117 struct tr_peerIo * peer; 118 118 } 119 119 tr_bandwidth; … … 131 131 132 132 /** @brief test to see if the pointer refers to a live bandwidth object */ 133 static inline bool tr_isBandwidth (const tr_bandwidth * b) 134 { 135 return (b != NULL) && (b->magicNumber == BANDWIDTH_MAGIC_NUMBER); 133 static inline bool 134 tr_isBandwidth (const tr_bandwidth * b) 135 { 136 return (b != NULL) && (b->magicNumber == BANDWIDTH_MAGIC_NUMBER); 136 137 } 137 138 … … 145 146 * @see tr_bandwidthGetDesiredSpeed 146 147 */ 147 static inline bool tr_bandwidthSetDesiredSpeed_Bps (tr_bandwidth * bandwidth, 148 tr_direction dir, 149 unsigned int desiredSpeed) 150 { 151 unsigned int * value = &bandwidth->band[dir].desiredSpeed_Bps; 152 const bool didChange = desiredSpeed != *value; 153 *value = desiredSpeed; 154 return didChange; 148 static inline bool 149 tr_bandwidthSetDesiredSpeed_Bps (tr_bandwidth * bandwidth, 150 tr_direction dir, 151 unsigned int desiredSpeed) 152 { 153 unsigned int * value = &bandwidth->band[dir].desiredSpeed_Bps; 154 const bool didChange = desiredSpeed != *value; 155 *value = desiredSpeed; 156 return didChange; 155 157 } 156 158 … … 162 164 tr_bandwidthGetDesiredSpeed_Bps (const tr_bandwidth * bandwidth, tr_direction dir) 163 165 { 164 166 return bandwidth->band[dir].desiredSpeed_Bps; 165 167 } 166 168 … … 168 170 * @brief Set whether or not this bandwidth should throttle its peer-io's speeds 169 171 */ 170 static inline bool tr_bandwidthSetLimited (tr_bandwidth * bandwidth, 171 tr_direction dir, 172 bool isLimited) 173 { 174 bool * value = &bandwidth->band[dir].isLimited; 175 const bool didChange = isLimited != *value; 176 *value = isLimited; 177 return didChange; 172 static inline bool 173 tr_bandwidthSetLimited (tr_bandwidth * bandwidth, 174 tr_direction dir, 175 bool isLimited) 176 { 177 bool * value = &bandwidth->band[dir].isLimited; 178 const bool didChange = isLimited != *value; 179 *value = isLimited; 180 return didChange; 178 181 } 179 182 … … 181 184 * @return nonzero if this bandwidth throttles its peer-ios speeds 182 185 */ 183 static inline bool tr_bandwidthIsLimited (const tr_bandwidth * bandwidth, 184 tr_direction dir) 185 { 186 return bandwidth->band[dir].isLimited; 186 static inline bool 187 tr_bandwidthIsLimited (const tr_bandwidth * bandwidth, 188 tr_direction dir) 189 { 190 return bandwidth->band[dir].isLimited; 187 191 } 188 192 … … 190 194 * @brief allocate the next period_msec's worth of bandwidth for the peer-ios to consume 191 195 */ 192 void tr_bandwidthAllocate (tr_bandwidth* bandwidth,193 tr_directiondirection,194 unsigned intperiod_msec);196 void tr_bandwidthAllocate (tr_bandwidth * bandwidth, 197 tr_direction direction, 198 unsigned int period_msec); 195 199 196 200 /** 197 201 * @brief clamps byteCount down to a number that this bandwidth will allow to be consumed 198 202 */ 199 unsigned int tr_bandwidthClamp(const tr_bandwidth * bandwidth,200 201 203 unsigned int tr_bandwidthClamp (const tr_bandwidth * bandwidth, 204 tr_direction direction, 205 unsigned int byteCount); 202 206 203 207 /****** … … 207 211 /** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */ 208 212 unsigned int tr_bandwidthGetRawSpeed_Bps (const tr_bandwidth * bandwidth, 209 210 213 const uint64_t now, 214 const tr_direction direction); 211 215 212 216 /** @brief Get the number of piece data bytes read or sent by this bandwidth subtree. */ … … 219 223 * This is is usually invoked by the peer-io after a read or write. 220 224 */ 221 void tr_bandwidthUsed (tr_bandwidth* bandwidth,222 tr_directiondirection,223 size_tbyteCount,224 boolisPieceData,225 uint64_tnow);226 227 /****** 228 ******* 229 ******/ 230 231 void tr_bandwidthSetParent (tr_bandwidth* bandwidth,232 tr_bandwidth* parent);225 void tr_bandwidthUsed (tr_bandwidth * bandwidth, 226 tr_direction direction, 227 size_t byteCount, 228 bool isPieceData, 229 uint64_t now); 230 231 /****** 232 ******* 233 ******/ 234 235 void tr_bandwidthSetParent (tr_bandwidth * bandwidth, 236 tr_bandwidth * parent); 233 237 234 238 /** … … 238 242 * in that particular case we want to ignore the global speed limit... 239 243 */ 240 static inline bool tr_bandwidthHonorParentLimits (tr_bandwidth * bandwidth, 241 tr_direction direction, 242 bool isEnabled) 243 { 244 bool * value = &bandwidth->band[direction].honorParentLimits; 245 const bool didChange = isEnabled != *value; 246 *value = isEnabled; 247 return didChange; 248 } 249 250 static inline bool tr_bandwidthAreParentLimitsHonored (const tr_bandwidth * bandwidth, 251 tr_direction direction) 252 { 253 assert (tr_isBandwidth (bandwidth)); 254 assert (tr_isDirection (direction)); 255 256 return bandwidth->band[direction].honorParentLimits; 257 } 258 259 /****** 260 ******* 261 ******/ 262 263 void tr_bandwidthSetPeer (tr_bandwidth * bandwidth, 264 struct tr_peerIo * peerIo); 244 static inline bool 245 tr_bandwidthHonorParentLimits (tr_bandwidth * bandwidth, 246 tr_direction direction, 247 bool isEnabled) 248 { 249 bool * value = &bandwidth->band[direction].honorParentLimits; 250 const bool didChange = isEnabled != *value; 251 *value = isEnabled; 252 return didChange; 253 } 254 255 static inline bool 256 tr_bandwidthAreParentLimitsHonored (const tr_bandwidth * bandwidth, 257 tr_direction direction) 258 { 259 assert (tr_isBandwidth (bandwidth)); 260 assert (tr_isDirection (direction)); 261 262 return bandwidth->band[direction].honorParentLimits; 263 } 264 265 /****** 266 ******* 267 ******/ 268 269 void tr_bandwidthSetPeer (tr_bandwidth * bandwidth, 270 struct tr_peerIo * peerIo); 265 271 266 272 /* @} */ -
trunk/libtransmission/peer-common.h
r13900 r13936 33 33 enum 34 34 { 35 /** when we're making requests from another peer,36 37 38 35 /* when we're making requests from another peer, 36 batch them together to send enough requests to 37 meet our bandwidth goals for the next N seconds */ 38 REQUEST_BUF_SECS = 10, 39 39 40 /** this is the maximum size of a block request.41 42 43 40 /* this is the maximum size of a block request. 41 most bittorrent clients will reject requests 42 larger than this size. */ 43 MAX_BLOCK_SIZE = (1024 * 16) 44 44 }; 45 45 … … 50 50 typedef enum 51 51 { 52 53 54 55 56 57 58 59 60 61 62 63 64 52 TR_PEER_CLIENT_GOT_BLOCK, 53 TR_PEER_CLIENT_GOT_CHOKE, 54 TR_PEER_CLIENT_GOT_PIECE_DATA, 55 TR_PEER_CLIENT_GOT_ALLOWED_FAST, 56 TR_PEER_CLIENT_GOT_SUGGEST, 57 TR_PEER_CLIENT_GOT_PORT, 58 TR_PEER_CLIENT_GOT_REJ, 59 TR_PEER_CLIENT_GOT_BITFIELD, 60 TR_PEER_CLIENT_GOT_HAVE, 61 TR_PEER_CLIENT_GOT_HAVE_ALL, 62 TR_PEER_CLIENT_GOT_HAVE_NONE, 63 TR_PEER_PEER_GOT_PIECE_DATA, 64 TR_PEER_ERROR 65 65 } 66 66 PeerEventType; … … 68 68 typedef struct 69 69 { 70 70 PeerEventType eventType; 71 71 72 73 74 75 76 77 72 uint32_t pieceIndex; /* for GOT_BLOCK, GOT_HAVE, CANCEL, ALLOWED, SUGGEST */ 73 struct tr_bitfield * bitfield; /* for GOT_BITFIELD */ 74 uint32_t offset; /* for GOT_BLOCK */ 75 uint32_t length; /* for GOT_BLOCK + GOT_PIECE_DATA */ 76 int err; /* errno for GOT_ERROR */ 77 tr_port port; /* for GOT_PORT */ 78 78 } 79 79 tr_peer_event; -
trunk/libtransmission/peer-mgr.h
r13879 r13936 43 43 enum 44 44 { 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 45 /* true if the peer supports encryption */ 46 ADDED_F_ENCRYPTION_FLAG = 1, 47 48 /* true if the peer is a seed or partial seed */ 49 ADDED_F_SEED_FLAG = 2, 50 51 /* true if the peer supports uTP */ 52 ADDED_F_UTP_FLAGS = 4, 53 54 /* true if the peer has holepunch support */ 55 ADDED_F_HOLEPUNCH = 8, 56 57 /* true if the peer telling us about this peer 58 * initiated the connection (implying that it is connectible) */ 59 ADDED_F_CONNECTABLE = 16 60 60 }; 61 61 62 62 typedef struct tr_pex 63 63 { 64 65 66 64 tr_address addr; 65 tr_port port; /* this field is in network byte order */ 66 uint8_t flags; 67 67 } 68 68 tr_pex; … … 74 74 enum 75 75 { 76 77 78 76 ENCRYPTION_PREFERENCE_UNKNOWN, 77 ENCRYPTION_PREFERENCE_YES, 78 ENCRYPTION_PREFERENCE_NO 79 79 }; 80 80 … … 90 90 typedef struct tr_peer 91 91 { 92 boolpeerIsChoked;93 boolpeerIsInterested;94 boolclientIsChoked;95 boolclientIsInterested;96 booldoPurge;97 98 99 uint8_tstrikes;100 101 uint8_tencryption_preference;102 tr_portdht_port;103 104 105 intpendingReqsToClient;106 107 108 intpendingReqsToPeer;109 110 struct tr_peerIo* io;111 struct peer_atom* atom;112 113 struct tr_bitfieldblame;114 struct tr_bitfieldhave;115 116 117 floatprogress;118 119 120 tr_quarkclient;121 122 time_tchokeChangedAt;123 124 tr_recentHistoryblocksSentToClient;125 tr_recentHistoryblocksSentToPeer;126 127 tr_recentHistorycancelsSentToClient;128 tr_recentHistorycancelsSentToPeer;129 130 struct tr_peermsgs* msgs;92 bool peerIsChoked; 93 bool peerIsInterested; 94 bool clientIsChoked; 95 bool clientIsInterested; 96 bool doPurge; 97 98 /* number of bad pieces they've contributed to */ 99 uint8_t strikes; 100 101 uint8_t encryption_preference; 102 tr_port dht_port; 103 104 /* how many requests the peer has made that we haven't responded to yet */ 105 int pendingReqsToClient; 106 107 /* how many requests we've made and are currently awaiting a response for */ 108 int pendingReqsToPeer; 109 110 struct tr_peerIo * io; 111 struct peer_atom * atom; 112 113 struct tr_bitfield blame; 114 struct tr_bitfield have; 115 116 /** how complete the peer's copy of the torrent is. [0.0...1.0] */ 117 float progress; 118 119 /* the client name from the `v' string in LTEP's handshake dictionary */ 120 tr_quark client; 121 122 time_t chokeChangedAt; 123 124 tr_recentHistory blocksSentToClient; 125 tr_recentHistory blocksSentToPeer; 126 127 tr_recentHistory cancelsSentToClient; 128 tr_recentHistory cancelsSentToPeer; 129 130 struct tr_peermsgs * msgs; 131 131 } 132 132 tr_peer; … … 152 152 153 153 bool tr_peerMgrPeerIsSeed (const tr_torrent * tor, 154 154 const tr_address * addr); 155 155 156 156 void tr_peerMgrSetUtpSupported (tr_torrent * tor, -
trunk/libtransmission/peer-msgs.h
r13625 r13936 33 33 typedef struct tr_peermsgs tr_peermsgs; 34 34 35 tr_peermsgs* tr_peerMsgsNew (struct tr_torrent* torrent,36 struct tr_peer* peer,37 tr_peer_callback* callback,38 void* callback_data);35 tr_peermsgs* tr_peerMsgsNew (struct tr_torrent * torrent, 36 struct tr_peer * peer, 37 tr_peer_callback * callback, 38 void * callback_data); 39 39 40 void tr_peerMsgsSetChoke (tr_peermsgs *, bool peerIsChoked); 40 void tr_peerMsgsSetChoke (tr_peermsgs * msgs, 41 bool peerIsChoked); 41 42 42 int tr_peerMsgsIsReadingBlock (const tr_peermsgs * msgs, tr_block_index_t block); 43 int tr_peerMsgsIsReadingBlock (const tr_peermsgs * msgs, 44 tr_block_index_t block); 43 45 44 void tr_peerMsgsSetInterested (tr_peermsgs *, bool clientIsInterested); 46 void tr_peerMsgsSetInterested (tr_peermsgs * msgs, 47 bool clientIsInterested); 45 48 46 void tr_peerMsgsHave (tr_peermsgs* msgs,47 uint32_tpieceIndex);49 void tr_peerMsgsHave (tr_peermsgs * msgs, 50 uint32_t pieceIndex); 48 51 49 void tr_peerMsgsPulse (tr_peermsgs* msgs);52 void tr_peerMsgsPulse (tr_peermsgs * msgs); 50 53 51 void tr_peerMsgsCancel (tr_peermsgs* msgs,52 tr_block_index_tblock);54 void tr_peerMsgsCancel (tr_peermsgs * msgs, 55 tr_block_index_t block); 53 56 54 void tr_peerMsgsFree (tr_peermsgs*);57 void tr_peerMsgsFree (tr_peermsgs * msgs); 55 58 56 size_t tr_generateAllowedSet (tr_piece_index_t * setmePieces,57 size_t desiredSetSize,58 size_t pieceCount,59 const uint8_t * infohash,60 const struct tr_address * addr);59 size_t tr_generateAllowedSet (tr_piece_index_t * setmePieces, 60 size_t desiredSetSize, 61 size_t pieceCount, 62 const uint8_t * infohash, 63 const struct tr_address * addr); 61 64 62 65 -
trunk/libtransmission/resume.h
r13829 r13936 20 20 enum 21 21 { 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 22 TR_FR_DOWNLOADED = (1 << 0), 23 TR_FR_UPLOADED = (1 << 1), 24 TR_FR_CORRUPT = (1 << 2), 25 TR_FR_PEERS = (1 << 3), 26 TR_FR_PROGRESS = (1 << 4), 27 TR_FR_DND = (1 << 5), 28 TR_FR_FILE_PRIORITIES = (1 << 6), 29 TR_FR_BANDWIDTH_PRIORITY = (1 << 7), 30 TR_FR_SPEEDLIMIT = (1 << 8), 31 TR_FR_RUN = (1 << 9), 32 TR_FR_DOWNLOAD_DIR = (1 << 10), 33 TR_FR_INCOMPLETE_DIR = (1 << 11), 34 TR_FR_MAX_PEERS = (1 << 12), 35 TR_FR_ADDED_DATE = (1 << 13), 36 TR_FR_DONE_DATE = (1 << 14), 37 TR_FR_ACTIVITY_DATE = (1 << 15), 38 TR_FR_RATIOLIMIT = (1 << 16), 39 TR_FR_IDLELIMIT = (1 << 17), 40 TR_FR_TIME_SEEDING = (1 << 18), 41 TR_FR_TIME_DOWNLOADING = (1 << 19), 42 TR_FR_FILENAMES = (1 << 20), 43 TR_FR_NAME = (1 << 21), 44 44 }; 45 45 … … 47 47 * Returns a bitwise-or'ed set of the loaded resume data 48 48 */ 49 uint64_t tr_torrentLoadResume (tr_torrent *tor,50 uint64_tfieldsToLoad,51 const tr_ctor* ctor);49 uint64_t tr_torrentLoadResume (tr_torrent * tor, 50 uint64_t fieldsToLoad, 51 const tr_ctor * ctor); 52 52 53 void tr_torrentSaveResume (tr_torrent* tor);53 void tr_torrentSaveResume (tr_torrent * tor); 54 54 55 void tr_torrentRemoveResume (const tr_torrent * tor);55 void tr_torrentRemoveResume (const tr_torrent * tor); 56 56 57 int tr_torrentRenameResume (const tr_torrent * tor,58 const char * newname);57 int tr_torrentRenameResume (const tr_torrent * tor, 58 const char * newname); 59 59 60 60 #endif
Note: See TracChangeset
for help on using the changeset viewer.