make tr_bencDictFindType() private.
This commit is contained in:
parent
2ed1e6ee9d
commit
3b7499a79b
|
@ -380,7 +380,7 @@ tr_bencDictFind( tr_benc * val, const char * key )
|
|||
return i<0 ? NULL : &val->val.l.vals[i+1];
|
||||
}
|
||||
|
||||
tr_benc*
|
||||
static tr_benc*
|
||||
tr_bencDictFindType( tr_benc * val, const char * key, int type )
|
||||
{
|
||||
tr_benc * ret = tr_bencDictFind( val, key );
|
||||
|
|
|
@ -76,7 +76,6 @@ int tr_bencDictFindRaw( tr_benc * dict, const char * key, const uint8_t **
|
|||
int tr_bencDictFindList( tr_benc * dict, const char * key, tr_benc ** setme );
|
||||
int tr_bencDictFindDict( tr_benc * dict, const char * key, tr_benc ** setme );
|
||||
tr_benc * tr_bencDictFind( tr_benc * dict, const char * key );
|
||||
tr_benc * tr_bencDictFindType( tr_benc * dict, const char * key, int type );
|
||||
tr_benc * tr_bencDictFindFirst( tr_benc * dict, ... );
|
||||
|
||||
/* convenience functions for building tr_benc structures */
|
||||
|
|
|
@ -320,7 +320,7 @@ tr_metainfoParse( const tr_handle * handle,
|
|||
/* info_hash: urlencoded 20-byte SHA1 hash of the value of the info key
|
||||
* from the Metainfo file. Note that the value will be a bencoded
|
||||
* dictionary, given the definition of the info key above. */
|
||||
if(( beInfo = tr_bencDictFindType( meta, "info", TYPE_DICT )))
|
||||
if( tr_bencDictFindDict( meta, "info", &beInfo ) )
|
||||
{
|
||||
int len;
|
||||
char * str = tr_bencSave( beInfo, &len );
|
||||
|
|
|
@ -980,6 +980,7 @@ sendLtepHandshake( tr_peermsgs * msgs )
|
|||
static void
|
||||
parseLtepHandshake( tr_peermsgs * msgs, int len, struct evbuffer * inbuf )
|
||||
{
|
||||
int64_t i;
|
||||
tr_benc val, * sub;
|
||||
uint8_t * tmp = tr_new( uint8_t, len );
|
||||
|
||||
|
@ -995,24 +996,23 @@ parseLtepHandshake( tr_peermsgs * msgs, int len, struct evbuffer * inbuf )
|
|||
dbgmsg( msgs, "here is the ltep handshake we got [%*.*s]", len, len, tmp );
|
||||
|
||||
/* does the peer prefer encrypted connections? */
|
||||
if(( sub = tr_bencDictFindType( &val, "e", TYPE_INT )))
|
||||
msgs->info->encryption_preference = sub->val.i
|
||||
? ENCRYPTION_PREFERENCE_YES
|
||||
: ENCRYPTION_PREFERENCE_NO;
|
||||
if( tr_bencDictFindInt( &val, "e", &i ) )
|
||||
msgs->info->encryption_preference = i ? ENCRYPTION_PREFERENCE_YES
|
||||
: ENCRYPTION_PREFERENCE_NO;
|
||||
|
||||
/* check supported messages for utorrent pex */
|
||||
msgs->peerSupportsPex = 0;
|
||||
if(( sub = tr_bencDictFindType( &val, "m", TYPE_DICT ))) {
|
||||
if(( sub = tr_bencDictFindType( sub, "ut_pex", TYPE_INT ))) {
|
||||
msgs->ut_pex_id = (uint8_t) sub->val.i;
|
||||
if( tr_bencDictFindDict( &val, "m", &sub ) ) {
|
||||
if( tr_bencDictFindInt( sub, "ut_pex", &i ) ) {
|
||||
msgs->ut_pex_id = (uint8_t) i;
|
||||
msgs->peerSupportsPex = msgs->ut_pex_id == 0 ? 0 : 1;
|
||||
dbgmsg( msgs, "msgs->ut_pex is %d", (int)msgs->ut_pex_id );
|
||||
}
|
||||
}
|
||||
|
||||
/* get peer's listening port */
|
||||
if(( sub = tr_bencDictFindType( &val, "p", TYPE_INT ))) {
|
||||
msgs->info->port = htons( (uint16_t)sub->val.i );
|
||||
if( tr_bencDictFindInt( &val, "p", &i ) ) {
|
||||
msgs->info->port = htons( (uint16_t)i );
|
||||
dbgmsg( msgs, "msgs->port is now %hu", msgs->info->port );
|
||||
}
|
||||
|
||||
|
@ -1025,20 +1025,23 @@ parseUtPex( tr_peermsgs * msgs, int msglen, struct evbuffer * inbuf )
|
|||
{
|
||||
int loaded = 0;
|
||||
uint8_t * tmp = tr_new( uint8_t, msglen );
|
||||
tr_benc val, *added;
|
||||
tr_benc val;
|
||||
const tr_torrent * tor = msgs->torrent;
|
||||
const uint8_t * added;
|
||||
size_t added_len;
|
||||
|
||||
tr_peerIoReadBytes( msgs->io, inbuf, tmp, msglen );
|
||||
|
||||
if( tr_torrentAllowsPex( tor )
|
||||
&& (( loaded = !tr_bencLoad( tmp, msglen, &val, NULL )))
|
||||
&& (( added = tr_bencDictFindType( &val, "added", TYPE_STR ))))
|
||||
&& tr_bencDictFindRaw( &val, "added", &added, &added_len ) )
|
||||
{
|
||||
const uint8_t * added_f = NULL;
|
||||
tr_pex * pex;
|
||||
size_t i, n;
|
||||
size_t added_f_len = 0;
|
||||
tr_bencDictFindRaw( &val, "added.f", &added_f, &added_f_len );
|
||||
pex = tr_peerMgrCompactToPex( added->val.s.s, added->val.s.i, added_f, added_f_len, &n );
|
||||
pex = tr_peerMgrCompactToPex( added, added_len, added_f, added_f_len, &n );
|
||||
for( i=0; i<n; ++i )
|
||||
tr_peerMgrAddPex( msgs->session->peerMgr, tor->info.hash,
|
||||
TR_PEER_FROM_PEX, pex+i );
|
||||
|
|
|
@ -77,13 +77,12 @@ static uint64_t
|
|||
loadPeers( tr_benc * dict, tr_torrent * tor )
|
||||
{
|
||||
uint64_t ret = 0;
|
||||
tr_benc * p;
|
||||
const uint8_t * str;
|
||||
size_t len;
|
||||
|
||||
if(( p = tr_bencDictFindType( dict, KEY_PEERS, TYPE_STR )))
|
||||
if( tr_bencDictFindRaw( dict, KEY_PEERS, &str, &len ) )
|
||||
{
|
||||
int i;
|
||||
const char * str = p->val.s.s;
|
||||
const size_t len = p->val.s.i;
|
||||
const int count = len / sizeof( tr_pex );
|
||||
for( i=0; i<count; ++i ) {
|
||||
tr_pex pex;
|
||||
|
@ -283,8 +282,9 @@ loadProgress( tr_benc * dict, tr_torrent * tor )
|
|||
|
||||
if( tr_bencDictFindDict( dict, KEY_PROGRESS, &p ) )
|
||||
{
|
||||
const uint8_t * raw;
|
||||
size_t rawlen;
|
||||
tr_benc * m;
|
||||
tr_benc * b;
|
||||
int n;
|
||||
time_t * curMTimes = tr_torrentGetMTimes( tor, &n );
|
||||
|
||||
|
@ -316,12 +316,12 @@ loadProgress( tr_benc * dict, tr_torrent * tor )
|
|||
tr_tordbg( tor, "Torrent needs to be verified - unable to find mtimes" );
|
||||
}
|
||||
|
||||
if(( b = tr_bencDictFindType( p, KEY_PROGRESS_BITFIELD, TYPE_STR )))
|
||||
if( tr_bencDictFindRaw( p, KEY_PROGRESS_BITFIELD, &raw, &rawlen ) )
|
||||
{
|
||||
tr_bitfield tmp;
|
||||
tmp.byteCount = b->val.s.i;
|
||||
tmp.byteCount = rawlen;
|
||||
tmp.bitCount = tmp.byteCount * 8;
|
||||
tmp.bits = (uint8_t*) b->val.s.s;
|
||||
tmp.bits = (uint8_t*) raw;
|
||||
if( tr_cpBlockBitfieldSet( tor->completion, &tmp ) ) {
|
||||
tr_torrentUncheck( tor );
|
||||
tr_tordbg( tor, "Torrent needs to be verified - error loading bitfield" );
|
||||
|
|
|
@ -106,8 +106,8 @@ tr_ctorSetMetainfoFromFile( tr_ctor * ctor,
|
|||
|
||||
/* if no `name' field was set, then set it from the filename */
|
||||
if( ctor->isSet_metainfo ) {
|
||||
tr_benc * info = tr_bencDictFindType( &ctor->metainfo, "info", TYPE_DICT );
|
||||
if( info ) {
|
||||
tr_benc * info;
|
||||
if( tr_bencDictFindDict( &ctor->metainfo, "info", &info ) ) {
|
||||
tr_benc * name = tr_bencDictFindFirst( info, "name.utf-8", "name", NULL );
|
||||
if( name == NULL )
|
||||
name = tr_bencDictAdd( info, "name" );
|
||||
|
|
Loading…
Reference in New Issue