static uint64_t parsePeers( tr_torrent * tor, const uint8_t * buf, uint32_t len ) { uint64_t ret = 0; if( !tor->info.isPrivate ) { int i; const int count = len / sizeof( tr_pex ); for( i = 0; i < count; ++i ) { tr_pex pex; readBytes( &pex, &buf, sizeof( tr_pex ) ); tr_peerMgrAddPex( tor->session->peerMgr, tor->info.hash, TR_PEER_FROM_CACHE, &pex ); } tr_tordbg( tor, "Loaded %d peers from resume file", count ); ret = TR_FR_PEERS; } return ret; }
static uint64_t loadPeers( tr_benc * dict, tr_torrent * tor ) { uint64_t ret = 0; const uint8_t * str; size_t len; if( tr_bencDictFindRaw( dict, KEY_PEERS, &str, &len ) ) { int i; const int count = len / sizeof( tr_pex ); for( i = 0; i < count; ++i ) { tr_pex pex; memcpy( &pex, str + ( i * sizeof( tr_pex ) ), sizeof( tr_pex ) ); tr_peerMgrAddPex( tor->session->peerMgr, tor->info.hash, TR_PEER_FROM_CACHE, &pex ); } tr_tordbg( tor, "Loaded %d peers from resume file", count ); ret = TR_FR_PEERS; } return ret; }
static int addPeers(tr_torrent* tor, uint8_t const* buf, int buflen) { int numAdded = 0; int const count = buflen / sizeof(tr_pex); for (int i = 0; i < count && numAdded < MAX_REMEMBERED_PEERS; ++i) { tr_pex pex; memcpy(&pex, buf + i * sizeof(tr_pex), sizeof(tr_pex)); if (tr_isPex(&pex)) { tr_peerMgrAddPex(tor, TR_PEER_FROM_RESUME, &pex, -1); ++numAdded; } } return numAdded; }