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

Last change on this file since 13948 was 13948, checked in by jordan, 8 years ago

move tr_peer.encryptionPreference to tr_peermsgs.encryptionPreference

  • Property svn:keywords set to Date Rev Author Id
File size: 4.0 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 13948 2013-02-03 22:45:32Z 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#include "bitfield.h"
31#include "history.h"
32#include "quark.h"
33
34enum
35{
36  /* when we're making requests from another peer,
37     batch them together to send enough requests to
38     meet our bandwidth goals for the next N seconds */
39  REQUEST_BUF_SECS = 10,
40
41  /* this is the maximum size of a block request.
42     most bittorrent clients will reject requests
43     larger than this size. */
44  MAX_BLOCK_SIZE = (1024 * 16)
45};
46
47/**
48***  Peer Publish / Subscribe
49**/
50
51typedef enum
52{
53  TR_PEER_CLIENT_GOT_BLOCK,
54  TR_PEER_CLIENT_GOT_CHOKE,
55  TR_PEER_CLIENT_GOT_PIECE_DATA,
56  TR_PEER_CLIENT_GOT_ALLOWED_FAST,
57  TR_PEER_CLIENT_GOT_SUGGEST,
58  TR_PEER_CLIENT_GOT_PORT,
59  TR_PEER_CLIENT_GOT_REJ,
60  TR_PEER_CLIENT_GOT_BITFIELD,
61  TR_PEER_CLIENT_GOT_HAVE,
62  TR_PEER_CLIENT_GOT_HAVE_ALL,
63  TR_PEER_CLIENT_GOT_HAVE_NONE,
64  TR_PEER_PEER_GOT_PIECE_DATA,
65  TR_PEER_ERROR
66}
67PeerEventType;
68
69typedef struct
70{
71  PeerEventType         eventType;
72
73  uint32_t              pieceIndex;   /* for GOT_BLOCK, GOT_HAVE, CANCEL, ALLOWED, SUGGEST */
74  struct tr_bitfield  * bitfield;     /* for GOT_BITFIELD */
75  uint32_t              offset;       /* for GOT_BLOCK */
76  uint32_t              length;       /* for GOT_BLOCK + GOT_PIECE_DATA */
77  int                   err;          /* errno for GOT_ERROR */
78  tr_port               port;         /* for GOT_PORT */
79}
80tr_peer_event;
81
82extern const tr_peer_event TR_PEER_EVENT_INIT;
83
84/**
85 * State information about a connected peer.
86 *
87 * @see struct peer_atom
88 * @see tr_peermsgs
89 */
90typedef struct tr_peer
91{
92  /* whether or not we should free this peer soon.
93     NOTE: private to peer-mgr.c */
94  bool doPurge;
95
96  /* Whether or not we've choked this peer.
97     Only applies to BitTorrent peers */
98  bool peerIsChoked;
99
100  /* whether or not the peer has indicated it will download from us.
101     Only applies to BitTorrent peers */
102  bool peerIsInterested;
103
104  /* whether or the peer is choking us.
105     Only applies to BitTorrent peers */
106  bool clientIsChoked;
107
108  /* whether or not we've indicated to the peer that we would download from them if unchoked.
109     Only applies to BitTorrent peers */
110  bool clientIsInterested;
111
112  /* number of bad pieces they've contributed to */
113  uint8_t strikes;
114
115  /* how many requests the peer has made that we haven't responded to yet */
116  int pendingReqsToClient;
117
118  /* how many requests we've made and are currently awaiting a response for */
119  int pendingReqsToPeer;
120
121  struct tr_peerIo * io;
122
123  /* Hook to private peer-mgr information */
124  struct peer_atom * atom;
125
126  /** how complete the peer's copy of the torrent is. [0.0...1.0] */
127  float progress;
128
129  struct tr_bitfield blame;
130  struct tr_bitfield have;
131
132  /* the client name.
133     For BitTorrent peers, this is the app name derived from the `v' string in LTEP's handshake dictionary */
134  tr_quark client;
135
136  time_t chokeChangedAt;
137
138  tr_recentHistory blocksSentToClient;
139  tr_recentHistory blocksSentToPeer;
140
141  tr_recentHistory cancelsSentToClient;
142  tr_recentHistory cancelsSentToPeer;
143
144  struct tr_peermsgs * msgs;
145}
146tr_peer;
147
148typedef void tr_peer_callback (struct tr_peer       * peer,
149                               const tr_peer_event  * event,
150                               void                 * client_data);
151
152/** Update the tr_peer.progress field based on the 'have' bitset. */
153void tr_peerUpdateProgress (tr_torrent * tor, struct tr_peer *);
154
155
156#ifdef WIN32
157 #define EMSGSIZE WSAEMSGSIZE
158#endif
159
160/** @} */
161
162#endif
Note: See TracBrowser for help on using the repository browser.