before it's considered too old and needs to be rebuilt */
PIECE_LIST_SHELF_LIFE_SECS = 60,
- /* use for bitwise operations w/peer_atom.myflags */
+ /* use for bitwise operations w/peer_atom.flags2 */
MYFLAG_BANNED = 1,
- /* use for bitwise operations w/peer_atom.myflags */
+ /* use for bitwise operations w/peer_atom.flags2 */
/* unreachable for now... but not banned.
* if they try to connect to us it's okay */
MYFLAG_UNREACHABLE = 2,
{
uint8_t from;
uint8_t flags; /* these match the added_f flags */
- uint8_t myflags; /* flags that aren't defined in added_f */
+ uint8_t flags2; /* flags that aren't defined in added_f */
uint8_t uploadOnly; /* UPLOAD_ONLY_ */
int8_t seedProbability; /* how likely is this to be a seed... [0..100] or -1 for unknown */
int8_t blocklisted; /* -1 for unknown, TRUE for blocklisted, FALSE for not blocklisted */
if( ++peer->strikes >= MAX_BAD_PIECES_PER_PEER )
{
struct peer_atom * atom = peer->atom;
- atom->myflags |= MYFLAG_BANNED;
+ atom->flags2 |= MYFLAG_BANNED;
peer->doPurge = 1;
tordbg( t, "banning peer %s", tr_atomAddrStr( atom ) );
}
if( !readAnythingFromPeer )
{
tordbg( t, "marking peer %s as unreachable... numFails is %d", tr_atomAddrStr( atom ), (int)atom->numFails );
- atom->myflags |= MYFLAG_UNREACHABLE;
+ atom->flags2 |= MYFLAG_UNREACHABLE;
}
}
}
atom->time = tr_time( );
atom->piece_data_time = 0;
atom->lastConnectionAt = tr_time( );
- atom->myflags &= ~MYFLAG_UNREACHABLE;
- if( atom->myflags & MYFLAG_BANNED )
+ if( !tr_peerIoIsIncoming( io ) )
+ {
+ atom->flags |= ADDED_F_CONNECTABLE;
+ atom->flags2 &= ~MYFLAG_UNREACHABLE;
+ }
+
+ if( atom->flags2 & MYFLAG_BANNED )
{
tordbg( t, "banned peer %s tried to reconnect",
tr_atomAddrStr( atom ) );
}
/* penalize peers that were unreachable the last time we tried */
- if( atom->myflags & MYFLAG_UNREACHABLE )
+ if( atom->flags2 & MYFLAG_UNREACHABLE )
sec += sec;
dbgmsg( "reconnect interval for %s is %d seconds", tr_atomAddrStr( atom ), sec );
return FALSE;
/* not if they're banned... */
- if( atom->myflags & MYFLAG_BANNED )
+ if( atom->flags2 & MYFLAG_BANNED )
return FALSE;
return TRUE;
i = tr_torrentIsSeed( tor ) ? 1 : 0;
score = addValToKey( score, 1, i );
+ /* prefer peers that are known to be connectible */
+ i = ( atom->flags & ADDED_F_CONNECTABLE ) ? 0 : 1;
+ score = addValToKey( score, 1, i );
+
/* prefer peers that we might have a chance of uploading to...
so lower seed probability is better */
if( atom->seedProbability == 100 ) i = 101;
{
tordbg( t, "peerIo not created; marking peer %s as unreachable",
tr_atomAddrStr( atom ) );
- atom->myflags |= MYFLAG_UNREACHABLE;
+ atom->flags2 |= MYFLAG_UNREACHABLE;
atom->numFails++;
}
else
struct tr_torrent;
typedef struct tr_peerMgr tr_peerMgr;
+/* added_f's bitwise-or'ed flags */
enum
{
- /* corresponds to ut_pex's added.f flags */
+ /* true if the peer supports encryption */
ADDED_F_ENCRYPTION_FLAG = 1,
- /* corresponds to ut_pex's added.f flags */
+ /* true if the peer is a seed or partial seed */
ADDED_F_SEED_FLAG = 2,
+
+ /* true if the peer supports uTP */
+ ADDED_F_UTP_FLAGS = 4,
+
+ /* true if the peer has holepunch support */
+ ADDED_F_HOLEPUNCH = 8,
+
+ /* true if the peer telling us about this peer
+ * initiated the connection (implying that it is connectible) */
+ ADDED_F_CONNECTABLE = 16
};
typedef struct tr_pex