(libT) peer-mgr doesn't care about non-piece data being transferred, so don't notify it when it happens
This commit is contained in:
parent
a4bbceb483
commit
553bd58681
|
@ -51,7 +51,7 @@ typedef enum
|
|||
{
|
||||
TR_PEER_CLIENT_GOT_BLOCK,
|
||||
TR_PEER_CLIENT_GOT_CHOKE,
|
||||
TR_PEER_CLIENT_GOT_DATA,
|
||||
TR_PEER_CLIENT_GOT_PIECE_DATA,
|
||||
TR_PEER_CLIENT_GOT_ALLOWED_FAST,
|
||||
TR_PEER_CLIENT_GOT_SUGGEST,
|
||||
TR_PEER_CLIENT_GOT_PORT,
|
||||
|
@ -60,7 +60,7 @@ typedef enum
|
|||
TR_PEER_CLIENT_GOT_HAVE,
|
||||
TR_PEER_CLIENT_GOT_HAVE_ALL,
|
||||
TR_PEER_CLIENT_GOT_HAVE_NONE,
|
||||
TR_PEER_PEER_GOT_DATA,
|
||||
TR_PEER_PEER_GOT_PIECE_DATA,
|
||||
TR_PEER_ERROR
|
||||
}
|
||||
PeerEventType;
|
||||
|
@ -72,9 +72,8 @@ typedef struct
|
|||
uint32_t pieceIndex; /* for GOT_BLOCK, GOT_HAVE, CANCEL, ALLOWED, SUGGEST */
|
||||
struct tr_bitfield * bitfield; /* for GOT_BITFIELD */
|
||||
uint32_t offset; /* for GOT_BLOCK */
|
||||
uint32_t length; /* for GOT_BLOCK + GOT_DATA */
|
||||
uint32_t length; /* for GOT_BLOCK + GOT_PIECE_DATA */
|
||||
int err; /* errno for GOT_ERROR */
|
||||
bool wasPieceData; /* for GOT_DATA */
|
||||
tr_port port; /* for GOT_PORT */
|
||||
}
|
||||
tr_peer_event;
|
||||
|
|
|
@ -57,17 +57,17 @@ tr_encryption_type;
|
|||
|
||||
|
||||
typedef ReadState (*tr_can_read_cb)(struct tr_peerIo * io,
|
||||
void * user_data,
|
||||
size_t * setme_piece_byte_count);
|
||||
void * user_data,
|
||||
size_t * setme_piece_byte_count);
|
||||
|
||||
typedef void (*tr_did_write_cb)(struct tr_peerIo * io,
|
||||
size_t bytesWritten,
|
||||
int wasPieceData,
|
||||
void * userData);
|
||||
typedef void (*tr_did_write_cb)(struct tr_peerIo * io,
|
||||
size_t bytesWritten,
|
||||
bool wasPieceData,
|
||||
void * userData);
|
||||
|
||||
typedef void (*tr_net_error_cb)(struct tr_peerIo * io,
|
||||
short what,
|
||||
void * userData);
|
||||
typedef void (*tr_net_error_cb)(struct tr_peerIo * io,
|
||||
short what,
|
||||
void * userData);
|
||||
|
||||
typedef struct tr_peerIo
|
||||
{
|
||||
|
@ -257,26 +257,26 @@ static inline const uint8_t* tr_peerIoGetPeersId (const tr_peerIo * io)
|
|||
***
|
||||
**/
|
||||
|
||||
void tr_peerIoSetIOFuncs (tr_peerIo * io,
|
||||
tr_can_read_cb readcb,
|
||||
tr_did_write_cb writecb,
|
||||
tr_net_error_cb errcb,
|
||||
void * user_data);
|
||||
void tr_peerIoSetIOFuncs (tr_peerIo * io,
|
||||
tr_can_read_cb readcb,
|
||||
tr_did_write_cb writecb,
|
||||
tr_net_error_cb errcb,
|
||||
void * user_data);
|
||||
|
||||
void tr_peerIoClear (tr_peerIo * io);
|
||||
void tr_peerIoClear (tr_peerIo * io);
|
||||
|
||||
/**
|
||||
***
|
||||
**/
|
||||
|
||||
void tr_peerIoWriteBytes (tr_peerIo * io,
|
||||
const void * writeme,
|
||||
size_t writemeLen,
|
||||
bool isPieceData);
|
||||
const void * writeme,
|
||||
size_t writemeLen,
|
||||
bool isPieceData);
|
||||
|
||||
void tr_peerIoWriteBuf (tr_peerIo * io,
|
||||
struct evbuffer * buf,
|
||||
bool isPieceData);
|
||||
struct evbuffer * buf,
|
||||
bool isPieceData);
|
||||
|
||||
/**
|
||||
***
|
||||
|
|
|
@ -101,7 +101,7 @@ enum
|
|||
CANCEL_HISTORY_SEC = 60
|
||||
};
|
||||
|
||||
const tr_peer_event TR_PEER_EVENT_INIT = { 0, 0, NULL, 0, 0, 0, false, 0 };
|
||||
const tr_peer_event TR_PEER_EVENT_INIT = { 0, 0, NULL, 0, 0, 0, 0 };
|
||||
|
||||
/**
|
||||
***
|
||||
|
@ -1697,25 +1697,35 @@ peerCallbackFunc (tr_peer * peer, const tr_peer_event * e, void * vs)
|
|||
|
||||
switch (e->eventType)
|
||||
{
|
||||
case TR_PEER_PEER_GOT_DATA:
|
||||
case TR_PEER_PEER_GOT_PIECE_DATA:
|
||||
{
|
||||
const time_t now = tr_time ();
|
||||
tr_torrent * tor = s->tor;
|
||||
|
||||
if (e->wasPieceData)
|
||||
{
|
||||
tor->uploadedCur += e->length;
|
||||
tr_announcerAddBytes (tor, TR_ANN_UP, e->length);
|
||||
tr_torrentSetActivityDate (tor, now);
|
||||
tr_torrentSetDirty (tor);
|
||||
}
|
||||
tor->uploadedCur += e->length;
|
||||
tr_announcerAddBytes (tor, TR_ANN_UP, e->length);
|
||||
tr_torrentSetActivityDate (tor, now);
|
||||
tr_torrentSetDirty (tor);
|
||||
tr_statsAddUploaded (tor->session, e->length);
|
||||
|
||||
/* update the stats */
|
||||
if (e->wasPieceData)
|
||||
tr_statsAddUploaded (tor->session, e->length);
|
||||
if (peer->atom != NULL)
|
||||
peer->atom->piece_data_time = now;
|
||||
|
||||
/* update our atom */
|
||||
if (peer->atom && e->wasPieceData)
|
||||
break;
|
||||
}
|
||||
|
||||
case TR_PEER_CLIENT_GOT_PIECE_DATA:
|
||||
{
|
||||
const time_t now = tr_time ();
|
||||
tr_torrent * tor = s->tor;
|
||||
|
||||
tor->downloadedCur += e->length;
|
||||
tr_torrentSetActivityDate (tor, now);
|
||||
tr_torrentSetDirty (tor);
|
||||
|
||||
tr_statsAddDownloaded (tor->session, e->length);
|
||||
|
||||
if (peer->atom != NULL)
|
||||
peer->atom->piece_data_time = now;
|
||||
|
||||
break;
|
||||
|
@ -1778,36 +1788,17 @@ peerCallbackFunc (tr_peer * peer, const tr_peer_event * e, void * vs)
|
|||
peerSuggestedPiece (s, peer, e->pieceIndex, true);
|
||||
break;
|
||||
|
||||
case TR_PEER_CLIENT_GOT_DATA:
|
||||
{
|
||||
const time_t now = tr_time ();
|
||||
tr_torrent * tor = s->tor;
|
||||
|
||||
if (e->wasPieceData)
|
||||
{
|
||||
tor->downloadedCur += e->length;
|
||||
tr_torrentSetActivityDate (tor, now);
|
||||
tr_torrentSetDirty (tor);
|
||||
}
|
||||
|
||||
/* update the stats */
|
||||
if (e->wasPieceData)
|
||||
tr_statsAddDownloaded (tor->session, e->length);
|
||||
|
||||
/* update our atom */
|
||||
if (peer->atom && e->wasPieceData)
|
||||
peer->atom->piece_data_time = now;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case TR_PEER_CLIENT_GOT_BLOCK:
|
||||
{
|
||||
const tr_block_index_t block = _tr_block (s->tor, e->pieceIndex, e->offset);
|
||||
tr_torrent * tor = s->tor;
|
||||
const tr_piece_index_t p = e->pieceIndex;
|
||||
const tr_block_index_t block = _tr_block (tor, p, e->offset);
|
||||
if (peer->msgs != NULL) /* webseed downloads don't belong in announce totals */
|
||||
tr_announcerAddBytes (tor, TR_ANN_DOWN, tr_torPieceCountBytes (tor, p));
|
||||
cancelAllRequestsForBlock (s, block, peer);
|
||||
tr_historyAdd (&peer->blocksSentToClient, tr_time(), 1);
|
||||
pieceListResortPiece (s, pieceListLookup (s, e->pieceIndex));
|
||||
tr_torrentGotBlock (s->tor, block);
|
||||
pieceListResortPiece (s, pieceListLookup (s, p));
|
||||
tr_torrentGotBlock (tor, block);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -496,13 +496,20 @@ fireClientGotHaveNone (tr_peermsgs * msgs)
|
|||
}
|
||||
|
||||
static void
|
||||
fireClientGotData (tr_peermsgs * msgs, uint32_t length, int wasPieceData)
|
||||
fireClientGotPieceData (tr_peermsgs * msgs, uint32_t length)
|
||||
{
|
||||
tr_peer_event e = TR_PEER_EVENT_INIT;
|
||||
|
||||
e.length = length;
|
||||
e.eventType = TR_PEER_CLIENT_GOT_DATA;
|
||||
e.wasPieceData = wasPieceData;
|
||||
e.eventType = TR_PEER_CLIENT_GOT_PIECE_DATA;
|
||||
publish (msgs, &e);
|
||||
}
|
||||
|
||||
static void
|
||||
firePeerGotPieceData (tr_peermsgs * msgs, uint32_t length)
|
||||
{
|
||||
tr_peer_event e = TR_PEER_EVENT_INIT;
|
||||
e.length = length;
|
||||
e.eventType = TR_PEER_PEER_GOT_PIECE_DATA;
|
||||
publish (msgs, &e);
|
||||
}
|
||||
|
||||
|
@ -551,17 +558,6 @@ fireClientGotHave (tr_peermsgs * msgs, tr_piece_index_t index)
|
|||
publish (msgs, &e);
|
||||
}
|
||||
|
||||
static void
|
||||
firePeerGotData (tr_peermsgs * msgs, uint32_t length, bool wasPieceData)
|
||||
{
|
||||
tr_peer_event e = TR_PEER_EVENT_INIT;
|
||||
|
||||
e.length = length;
|
||||
e.eventType = TR_PEER_PEER_GOT_DATA;
|
||||
e.wasPieceData = wasPieceData;
|
||||
|
||||
publish (msgs, &e);
|
||||
}
|
||||
|
||||
/**
|
||||
*** ALLOWED FAST SET
|
||||
|
@ -1331,7 +1327,7 @@ readBtPiece (tr_peermsgs * msgs,
|
|||
|
||||
tr_peerIoReadBytesToBuf (msgs->peer->io, inbuf, block_buffer, n);
|
||||
|
||||
fireClientGotData (msgs, n, true);
|
||||
fireClientGotPieceData (msgs, n);
|
||||
*setme_piece_bytes_read += n;
|
||||
dbgmsg (msgs, "got %zu bytes for block %u:%u->%u ... %d remain",
|
||||
n, req->index, req->offset, req->length,
|
||||
|
@ -1603,10 +1599,12 @@ clientGotBlock (tr_peermsgs * msgs,
|
|||
static int peerPulse (void * vmsgs);
|
||||
|
||||
static void
|
||||
didWrite (tr_peerIo * io UNUSED, size_t bytesWritten, int wasPieceData, void * vmsgs)
|
||||
didWrite (tr_peerIo * io UNUSED, size_t bytesWritten, bool wasPieceData, void * vmsgs)
|
||||
{
|
||||
tr_peermsgs * msgs = vmsgs;
|
||||
firePeerGotData (msgs, bytesWritten, wasPieceData);
|
||||
|
||||
if (wasPieceData)
|
||||
firePeerGotPieceData (msgs, bytesWritten);
|
||||
|
||||
if (tr_isPeerIo (io) && io->userData)
|
||||
peerPulse (msgs);
|
||||
|
@ -1648,10 +1646,6 @@ canRead (tr_peerIo * io, void * vmsgs, size_t * piece)
|
|||
|
||||
dbgmsg (msgs, "canRead: ret is %d", (int)ret);
|
||||
|
||||
/* log the raw data that was read */
|
||||
if ((ret != READ_ERR) && (evbuffer_get_length (in) != inlen))
|
||||
fireClientGotData (msgs, inlen - evbuffer_get_length (in), false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,12 +142,11 @@ fire_client_got_blocks (tr_torrent * tor, tr_webseed * w,
|
|||
}
|
||||
|
||||
static void
|
||||
fire_client_got_data (tr_webseed * w, uint32_t length)
|
||||
fire_client_got_piece_data (tr_webseed * w, uint32_t length)
|
||||
{
|
||||
tr_peer_event e = TR_PEER_EVENT_INIT;
|
||||
e.eventType = TR_PEER_CLIENT_GOT_DATA;
|
||||
e.eventType = TR_PEER_CLIENT_GOT_PIECE_DATA;
|
||||
e.length = length;
|
||||
e.wasPieceData = true;
|
||||
publish (w, &e);
|
||||
}
|
||||
|
||||
|
@ -252,7 +251,7 @@ on_content_changed (struct evbuffer * buf,
|
|||
if (!w->is_stopping)
|
||||
{
|
||||
tr_bandwidthUsed (&w->bandwidth, TR_DOWN, n_added, true, tr_time_msec ());
|
||||
fire_client_got_data (w, n_added);
|
||||
fire_client_got_piece_data (w, n_added);
|
||||
}
|
||||
|
||||
len = evbuffer_get_length (buf);
|
||||
|
|
Loading…
Reference in New Issue