source: trunk/libtransmission/peer-common.h

Last change on this file was 14724, checked in by jordan, 5 years ago

use '#pragma once' instead of #ifndef..#define..#endif guards

  • Property svn:keywords set to Date Rev Author Id
File size: 4.1 KB
Line 
1/*
2 * This file Copyright (C) 2008-2014 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: peer-common.h 14724 2016-03-29 16:37:21Z mikedld $
8 */
9
10#ifndef __TRANSMISSION__
11 #error only libtransmission should #include this header.
12#endif
13
14#pragma once
15
16#include "transmission.h"
17#include "bitfield.h"
18#include "history.h"
19#include "quark.h"
20
21/**
22 * @addtogroup peers Peers
23 * @{
24 */
25
26struct tr_peer;
27struct tr_swarm;
28
29enum
30{
31  /* this is the maximum size of a block request.
32     most bittorrent clients will reject requests
33     larger than this size. */
34  MAX_BLOCK_SIZE = (1024 * 16)
35};
36
37/**
38***  Peer Publish / Subscribe
39**/
40
41typedef enum
42{
43  TR_PEER_CLIENT_GOT_BLOCK,
44  TR_PEER_CLIENT_GOT_CHOKE,
45  TR_PEER_CLIENT_GOT_PIECE_DATA,
46  TR_PEER_CLIENT_GOT_ALLOWED_FAST,
47  TR_PEER_CLIENT_GOT_SUGGEST,
48  TR_PEER_CLIENT_GOT_PORT,
49  TR_PEER_CLIENT_GOT_REJ,
50  TR_PEER_CLIENT_GOT_BITFIELD,
51  TR_PEER_CLIENT_GOT_HAVE,
52  TR_PEER_CLIENT_GOT_HAVE_ALL,
53  TR_PEER_CLIENT_GOT_HAVE_NONE,
54  TR_PEER_PEER_GOT_PIECE_DATA,
55  TR_PEER_ERROR
56}
57PeerEventType;
58
59typedef struct
60{
61  PeerEventType         eventType;
62
63  uint32_t              pieceIndex;   /* for GOT_BLOCK, GOT_HAVE, CANCEL, ALLOWED, SUGGEST */
64  struct tr_bitfield  * bitfield;     /* for GOT_BITFIELD */
65  uint32_t              offset;       /* for GOT_BLOCK */
66  uint32_t              length;       /* for GOT_BLOCK + GOT_PIECE_DATA */
67  int                   err;          /* errno for GOT_ERROR */
68  tr_port               port;         /* for GOT_PORT */
69}
70tr_peer_event;
71
72extern const tr_peer_event TR_PEER_EVENT_INIT;
73
74typedef void (*tr_peer_callback) (struct tr_peer       * peer,
75                                  const tr_peer_event  * event,
76                                  void                 * client_data);
77
78/***
79****
80***/
81
82typedef void (*tr_peer_destruct_func)(struct tr_peer * peer);
83typedef bool (*tr_peer_is_transferring_pieces_func)(const struct tr_peer * peer,
84                                                    uint64_t now,
85                                                    tr_direction direction,
86                                                    unsigned int * Bps);
87struct tr_peer_virtual_funcs
88{
89  tr_peer_destruct_func destruct;
90  tr_peer_is_transferring_pieces_func is_transferring_pieces;
91};
92
93/**
94 * State information about a connected peer.
95 *
96 * @see struct peer_atom
97 * @see tr_peerMsgs
98 */
99typedef struct tr_peer
100{
101  /* whether or not we should free this peer soon.
102     NOTE: private to peer-mgr.c */
103  bool doPurge;
104
105  /* number of bad pieces they've contributed to */
106  uint8_t strikes;
107
108  /* how many requests the peer has made that we haven't responded to yet */
109  int pendingReqsToClient;
110
111  /* how many requests we've made and are currently awaiting a response for */
112  int pendingReqsToPeer;
113
114  /* Hook to private peer-mgr information */
115  struct peer_atom * atom;
116
117  struct tr_swarm * swarm;
118
119  /** how complete the peer's copy of the torrent is. [0.0...1.0] */
120  float progress;
121
122  struct tr_bitfield blame;
123  struct tr_bitfield have;
124
125  /* the client name.
126     For BitTorrent peers, this is the app name derived from the `v' string in LTEP's handshake dictionary */
127  tr_quark client;
128
129  tr_recentHistory blocksSentToClient;
130  tr_recentHistory blocksSentToPeer;
131
132  tr_recentHistory cancelsSentToClient;
133  tr_recentHistory cancelsSentToPeer;
134
135  const struct tr_peer_virtual_funcs * funcs;
136}
137tr_peer;
138
139
140void tr_peerConstruct (struct tr_peer * peer, const tr_torrent * tor);
141
142void tr_peerDestruct  (struct tr_peer * peer);
143
144
145/** Update the tr_peer.progress field based on the 'have' bitset. */
146void tr_peerUpdateProgress (tr_torrent * tor, struct tr_peer *);
147
148bool tr_peerIsSeed (const struct tr_peer * peer);
149
150/***
151****
152***/
153
154typedef struct tr_swarm_stats
155{
156  int activePeerCount[2];
157  int activeWebseedCount;
158  int peerCount;
159  int peerFromCount[TR_PEER_FROM__MAX];
160}
161tr_swarm_stats;
162
163extern const tr_swarm_stats TR_SWARM_STATS_INIT;
164
165void tr_swarmGetStats (const struct tr_swarm * swarm, tr_swarm_stats * setme);
166
167void tr_swarmIncrementActivePeers (struct tr_swarm * swarm, tr_direction direction, bool is_active);
168
169
170/***
171****
172***/
173
174
175#ifdef _WIN32
176 #undef  EMSGSIZE
177 #define EMSGSIZE WSAEMSGSIZE
178#endif
179
180/** @} */
181
Note: See TracBrowser for help on using the repository browser.