Changeset 7397 for trunk/libtransmission/peer-msgs.c
- Timestamp:
- Dec 15, 2008, 12:17:08 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-msgs.c
r7361 r7397 283 283 uint8_t ut_pex_id; 284 284 uint16_t pexCount; 285 uint16_t pexCount6; 285 286 uint16_t minActiveRequests; 286 287 uint16_t maxActiveRequests; … … 309 310 tr_timer * pexTimer; 310 311 tr_pex * pex; 312 tr_pex * pex6; 311 313 312 314 time_t clientSentPexAt; … … 1182 1184 1183 1185 if( tr_torrentAllowsPex( tor ) 1184 && (( loaded = !tr_bencLoad( tmp, msglen, &val, NULL ))) 1185 && tr_bencDictFindRaw( &val, "added", &added, &added_len )) 1186 { 1187 const uint8_t * added_f = NULL; 1188 tr_pex * pex; 1189 size_t i, n; 1190 size_t added_f_len = 0; 1191 tr_bencDictFindRaw( &val, "added.f", &added_f, &added_f_len ); 1192 pex = tr_peerMgrCompactToPex( added, added_len, added_f, added_f_len, &n ); 1193 for( i=0; i<n; ++i ) 1194 tr_peerMgrAddPex( msgs->session->peerMgr, tor->info.hash, 1195 TR_PEER_FROM_PEX, pex + i ); 1196 tr_free( pex ); 1186 && ( ( loaded = !tr_bencLoad( tmp, msglen, &val, NULL ) ) ) ) 1187 { 1188 if( tr_bencDictFindRaw( &val, "added", &added, &added_len ) ) 1189 { 1190 const uint8_t * added_f = NULL; 1191 tr_pex * pex; 1192 size_t i, n; 1193 size_t added_f_len = 0; 1194 tr_bencDictFindRaw( &val, "added.f", &added_f, &added_f_len ); 1195 pex = 1196 tr_peerMgrCompactToPex( added, added_len, added_f, added_f_len, 1197 &n ); 1198 for( i = 0; i < n; ++i ) 1199 tr_peerMgrAddPex( msgs->session->peerMgr, tor->info.hash, 1200 TR_PEER_FROM_PEX, pex + i ); 1201 tr_free( pex ); 1202 } 1203 1204 if( tr_bencDictFindRaw( &val, "added6", &added, &added_len ) ) 1205 { 1206 const uint8_t * added_f = NULL; 1207 tr_pex * pex; 1208 size_t i, n; 1209 size_t added_f_len = 0; 1210 tr_bencDictFindRaw( &val, "added6.f", &added_f, &added_f_len ); 1211 pex = 1212 tr_peerMgrCompact6ToPex( added, added_len, added_f, added_f_len, 1213 &n ); 1214 for( i = 0; i < n; ++i ) 1215 tr_peerMgrAddPex( msgs->session->peerMgr, tor->info.hash, 1216 TR_PEER_FROM_PEX, pex + i ); 1217 tr_free( pex ); 1218 } 1219 1197 1220 } 1198 1221 … … 2006 2029 } 2007 2030 2008 /* TODO: ipv6 pex */2009 2031 static void 2010 2032 sendPex( tr_peermsgs * msgs ) … … 2013 2035 { 2014 2036 PexDiffs diffs; 2037 PexDiffs diffs6; 2015 2038 tr_pex * newPex = NULL; 2039 tr_pex * newPex6 = NULL; 2016 2040 const int newCount = tr_peerMgrGetPeers( msgs->session->peerMgr, 2017 2041 msgs->torrent->info.hash, 2018 &newPex ); 2042 &newPex, TR_AF_INET ); 2043 const int newCount6 = tr_peerMgrGetPeers( msgs->session->peerMgr, 2044 msgs->torrent->info.hash, 2045 &newPex6, TR_AF_INET6 ); 2019 2046 2020 2047 /* build the diffs */ … … 2029 2056 tr_pexCompare, sizeof( tr_pex ), 2030 2057 pexDroppedCb, pexAddedCb, pexElementCb, &diffs ); 2058 diffs6.added = tr_new( tr_pex, newCount6 ); 2059 diffs6.addedCount = 0; 2060 diffs6.dropped = tr_new( tr_pex, msgs->pexCount6 ); 2061 diffs6.droppedCount = 0; 2062 diffs6.elements = tr_new( tr_pex, newCount6 + msgs->pexCount6 ); 2063 diffs6.elementCount = 0; 2064 tr_set_compare( msgs->pex6, msgs->pexCount6, 2065 newPex6, newCount6, 2066 tr_pexCompare, sizeof( tr_pex ), 2067 pexDroppedCb, pexAddedCb, pexElementCb, &diffs6 ); 2031 2068 dbgmsg( 2032 2069 msgs, 2033 2070 "pex: old peer count %d, new peer count %d, added %d, removed %d", 2034 msgs->pexCount, newCount, diffs.addedCount, diffs.droppedCount ); 2035 2036 if( !diffs.addedCount && !diffs.droppedCount ) 2071 msgs->pexCount, newCount + newCount6, 2072 diffs.addedCount + diffs6.addedCount, 2073 diffs.droppedCount + diffs6.droppedCount ); 2074 2075 if( !diffs.addedCount && !diffs.droppedCount && !diffs6.addedCount && 2076 !diffs6.droppedCount ) 2037 2077 { 2038 2078 tr_free( diffs.elements ); 2079 tr_free( diffs6.elements ); 2039 2080 } 2040 2081 else … … 2051 2092 msgs->pex = diffs.elements; 2052 2093 msgs->pexCount = diffs.elementCount; 2094 tr_free( msgs->pex6 ); 2095 msgs->pex6 = diffs6.elements; 2096 msgs->pexCount6 = diffs6.elementCount; 2053 2097 2054 2098 /* build the pex payload */ 2055 tr_bencInitDict( &val, 3 ); 2099 tr_bencInitDict( &val, 3 ); /* ipv6 support: left as 3: 2100 * speed vs. likelihood? */ 2056 2101 2057 2102 /* "added" */ 2058 2103 tmp = walk = tr_new( uint8_t, diffs.addedCount * 6 ); 2059 for( i = 0; i < diffs.addedCount; ++i ) { 2104 for( i = 0; i < diffs.addedCount; ++i ) 2105 { 2060 2106 memcpy( walk, &diffs.added[i].addr.addr, 4 ); walk += 4; 2061 2107 memcpy( walk, &diffs.added[i].port, 2 ); walk += 2; … … 2075 2121 /* "dropped" */ 2076 2122 tmp = walk = tr_new( uint8_t, diffs.droppedCount * 6 ); 2077 for( i = 0; i < diffs.droppedCount; ++i ) { 2123 for( i = 0; i < diffs.droppedCount; ++i ) 2124 { 2078 2125 memcpy( walk, &diffs.dropped[i].addr.addr, 4 ); walk += 4; 2079 2126 memcpy( walk, &diffs.dropped[i].port, 2 ); walk += 2; … … 2081 2128 assert( ( walk - tmp ) == diffs.droppedCount * 6 ); 2082 2129 tr_bencDictAddRaw( &val, "dropped", tmp, walk - tmp ); 2130 tr_free( tmp ); 2131 2132 /* "added6" */ 2133 tmp = walk = tr_new( uint8_t, diffs6.addedCount * 18 ); 2134 for( i = 0; i < diffs6.addedCount; ++i ) 2135 { 2136 memcpy( walk, &diffs6.added[i].addr.addr.addr6.s6_addr, 16 ); 2137 walk += 16; 2138 memcpy( walk, &diffs6.added[i].port, 2 ); 2139 walk += 2; 2140 } 2141 assert( ( walk - tmp ) == diffs6.addedCount * 18 ); 2142 tr_bencDictAddRaw( &val, "added6", tmp, walk - tmp ); 2143 tr_free( tmp ); 2144 2145 /* "added6.f" */ 2146 tmp = walk = tr_new( uint8_t, diffs6.addedCount ); 2147 for( i = 0; i < diffs6.addedCount; ++i ) 2148 *walk++ = diffs6.added[i].flags; 2149 assert( ( walk - tmp ) == diffs6.addedCount ); 2150 tr_bencDictAddRaw( &val, "added6.f", tmp, walk - tmp ); 2151 tr_free( tmp ); 2152 2153 /* "dropped6" */ 2154 tmp = walk = tr_new( uint8_t, diffs6.droppedCount * 18 ); 2155 for( i = 0; i < diffs6.droppedCount; ++i ) 2156 { 2157 memcpy( walk, &diffs6.dropped[i].addr.addr.addr6.s6_addr, 16 ); 2158 walk += 16; 2159 memcpy( walk, &diffs6.dropped[i].port, 2 ); 2160 walk += 2; 2161 } 2162 assert( ( walk - tmp ) == diffs6.droppedCount * 18); 2163 tr_bencDictAddRaw( &val, "dropped6", tmp, walk - tmp ); 2083 2164 tr_free( tmp ); 2084 2165 … … 2100 2181 tr_free( diffs.dropped ); 2101 2182 tr_free( newPex ); 2183 tr_free( diffs6.added ); 2184 tr_free( diffs6.dropped ); 2185 tr_free( newPex6 ); 2102 2186 2103 2187 msgs->clientSentPexAt = time( NULL ); … … 2176 2260 evbuffer_free( msgs->incoming.block ); 2177 2261 evbuffer_free( msgs->outMessages ); 2262 tr_free( msgs->pex6 ); 2178 2263 tr_free( msgs->pex ); 2179 2264
Note: See TracChangeset
for help on using the changeset viewer.