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 12204 2011-03-22 15:19:54Z 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 46/** 47*** Peer Publish / Subscribe 48**/ 49 50typedef enum 51{ 52 TR_PEER_CLIENT_GOT_BLOCK, 53 TR_PEER_CLIENT_GOT_CHOKE, 54 TR_PEER_CLIENT_GOT_DATA, 55 TR_PEER_CLIENT_GOT_ALLOWED_FAST, 56 TR_PEER_CLIENT_GOT_SUGGEST, 57 TR_PEER_CLIENT_GOT_PORT, 58 TR_PEER_CLIENT_GOT_REJ, 59 TR_PEER_CLIENT_GOT_BITFIELD, 60 TR_PEER_CLIENT_GOT_HAVE, 61 TR_PEER_CLIENT_GOT_HAVE_ALL, 62 TR_PEER_CLIENT_GOT_HAVE_NONE, 63 TR_PEER_PEER_GOT_DATA, 64 TR_PEER_ERROR 65} 66PeerEventType; 67 68typedef struct 69{ 70 PeerEventType eventType; 71 72 uint32_t pieceIndex; /* for GOT_BLOCK, GOT_HAVE, CANCEL, ALLOWED, SUGGEST */ 73 struct tr_bitfield * bitfield; /* for GOT_BITFIELD */ 74 uint32_t offset; /* for GOT_BLOCK */ 75 uint32_t length; /* for GOT_BLOCK + GOT_DATA */ 76 int err; /* errno for GOT_ERROR */ 77 bool wasPieceData; /* for GOT_DATA */ 78 tr_port port; /* for GOT_PORT */ 79} 80tr_peer_event; 81 82extern const tr_peer_event TR_PEER_EVENT_INIT; 83 84struct tr_peer; 85 86typedef void tr_peer_callback( struct tr_peer * peer, 87 const tr_peer_event * event, 88 void * client_data ); 89 90/** Update the tr_peer.progress field based on the 'have' bitset. */ 91void tr_peerUpdateProgress( tr_torrent * tor, struct tr_peer * ); 92 93 94#ifdef WIN32 95 #define EMSGSIZE WSAEMSGSIZE 96#endif 97 98/** @} */ 99 100#endif 101