source: trunk/libtransmission/peer-common.h @ 11897

Last change on this file since 11897 was 11897, checked in by jordan, 11 years ago

(trunk libT) #3767 "rarest first policy" -- fixed.

This commit, started by a patch from athy, implements a rarest first policy when deciding which pieces to request from peers. It keeps a count of how many peers have each piece, and updates the count when getting bitfields, have, have all, and have none messages, as well as decrementing the counts when peers disconnect.

This running total is generated only for downloading torrents. Seeds don't have this overhead.

  • Property svn:keywords set to Date Rev Author Id
File size: 2.5 KB
Line 
1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
4 * This file is licensed by the GPL version 2. Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: peer-common.h 11897 2011-02-17 05:14:53Z jordan $
11 */
12
13#ifndef __TRANSMISSION__
14 #error only libtransmission should #include this header.
15#endif
16
17#ifndef TR_PEER_H
18#define TR_PEER_H
19
20/**
21 * @addtogroup peers Peers
22 * @{
23 */
24
25/**
26*** Fields common to webseed and bittorrent peers
27**/
28
29#include "transmission.h"
30
31struct tr_bitfield;
32
33enum
34{
35    /** when we're making requests from another peer,
36        batch them together to send enough requests to
37        meet our bandwidth goals for the next N seconds */
38    REQUEST_BUF_SECS = 10,
39
40    /** this is the maximum size of a block request.
41        most bittorrent clients will reject requests
42        larger than this size. */
43    MAX_BLOCK_SIZE = ( 1024 * 16 )
44};
45
46typedef enum
47{
48    TR_ADDREQ_OK = 0,
49    TR_ADDREQ_FULL,
50    TR_ADDREQ_DUPLICATE,
51    TR_ADDREQ_MISSING,
52    TR_ADDREQ_CLIENT_CHOKED
53}
54tr_addreq_t;
55
56/**
57***  Peer Publish / Subscribe
58**/
59
60typedef enum
61{
62    TR_PEER_CLIENT_GOT_BLOCK,
63    TR_PEER_CLIENT_GOT_CHOKE,
64    TR_PEER_CLIENT_GOT_DATA,
65    TR_PEER_CLIENT_GOT_ALLOWED_FAST,
66    TR_PEER_CLIENT_GOT_SUGGEST,
67    TR_PEER_CLIENT_GOT_PORT,
68    TR_PEER_CLIENT_GOT_REJ,
69    TR_PEER_CLIENT_GOT_BITFIELD,
70    TR_PEER_CLIENT_GOT_HAVE,
71    TR_PEER_CLIENT_GOT_HAVE_ALL,
72    TR_PEER_CLIENT_GOT_HAVE_NONE,
73    TR_PEER_PEER_GOT_DATA,
74    TR_PEER_PEER_PROGRESS,
75    TR_PEER_ERROR
76}
77PeerEventType;
78
79typedef struct
80{
81    PeerEventType         eventType;
82
83    uint32_t              pieceIndex;   /* for GOT_BLOCK, GOT_HAVE, CANCEL, ALLOWED, SUGGEST */
84    struct tr_bitfield  * bitfield;     /* for GOT_BITFIELD */
85    uint32_t              offset;       /* for GOT_BLOCK */
86    uint32_t              length;       /* for GOT_BLOCK + GOT_DATA */
87    float                 progress;     /* for PEER_PROGRESS */
88    int                   err;          /* errno for GOT_ERROR */
89    tr_bool               wasPieceData; /* for GOT_DATA */
90    tr_port               port;         /* for GOT_PORT */
91}
92tr_peer_event;
93
94extern const tr_peer_event TR_PEER_EVENT_INIT;
95
96struct tr_peer;
97
98typedef void tr_peer_callback( struct tr_peer       * peer,
99                               const tr_peer_event  * event,
100                               void                 * client_data );
101
102#ifdef WIN32
103 #define EMSGSIZE WSAEMSGSIZE
104#endif
105
106/** @} */
107
108#endif
Note: See TracBrowser for help on using the repository browser.