1 | /* |
---|
2 | * This file Copyright (C) 2007-2008 Charles Kerr <charles@rebelbase.com> |
---|
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-msgs.h 5199 2008-03-04 20:37:24Z charles $ |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef TR_PEER_MSGS_H |
---|
14 | #define TR_PEER_MSGS_H |
---|
15 | |
---|
16 | #include <inttypes.h> |
---|
17 | #include "publish.h" |
---|
18 | |
---|
19 | struct tr_torrent; |
---|
20 | struct tr_peer; |
---|
21 | struct tr_bitfield; |
---|
22 | |
---|
23 | typedef struct tr_peermsgs tr_peermsgs; |
---|
24 | |
---|
25 | tr_peermsgs* tr_peerMsgsNew( struct tr_torrent * torrent, |
---|
26 | struct tr_peer * peer, |
---|
27 | tr_delivery_func func, |
---|
28 | void * user, |
---|
29 | tr_publisher_tag * setme ); |
---|
30 | |
---|
31 | |
---|
32 | void tr_peerMsgsSetChoke( tr_peermsgs *, int doChoke ); |
---|
33 | |
---|
34 | void tr_peerMsgsHave( tr_peermsgs * msgs, |
---|
35 | uint32_t pieceIndex ); |
---|
36 | |
---|
37 | void tr_peerMsgsCancel( tr_peermsgs * msgs, |
---|
38 | uint32_t pieceIndex, |
---|
39 | uint32_t offset, |
---|
40 | uint32_t length ); |
---|
41 | |
---|
42 | void tr_peerMsgsFree( tr_peermsgs* ); |
---|
43 | |
---|
44 | |
---|
45 | enum { |
---|
46 | TR_ADDREQ_OK=0, |
---|
47 | TR_ADDREQ_FULL, |
---|
48 | TR_ADDREQ_DUPLICATE, |
---|
49 | TR_ADDREQ_MISSING, |
---|
50 | TR_ADDREQ_CLIENT_CHOKED |
---|
51 | }; |
---|
52 | |
---|
53 | int tr_peerMsgsAddRequest( tr_peermsgs * peer, |
---|
54 | uint32_t index, |
---|
55 | uint32_t begin, |
---|
56 | uint32_t length ); |
---|
57 | |
---|
58 | /** |
---|
59 | *** PeerMsgs Publish / Subscribe |
---|
60 | **/ |
---|
61 | |
---|
62 | typedef enum |
---|
63 | { |
---|
64 | TR_PEERMSG_CLIENT_HAVE, |
---|
65 | TR_PEERMSG_CLIENT_BLOCK, |
---|
66 | TR_PEERMSG_PIECE_DATA, |
---|
67 | TR_PEERMSG_PEER_PROGRESS, |
---|
68 | TR_PEERMSG_ERROR, |
---|
69 | TR_PEERMSG_CANCEL, |
---|
70 | TR_PEERMSG_NEED_REQ |
---|
71 | } |
---|
72 | PeerMsgsEventType; |
---|
73 | |
---|
74 | typedef struct |
---|
75 | { |
---|
76 | PeerMsgsEventType eventType; |
---|
77 | uint32_t pieceIndex; /* for TR_PEERMSG_GOT_BLOCK, TR_PEERMSG_GOT_HAVE */ |
---|
78 | uint32_t offset; /* for TR_PEERMSG_GOT_BLOCK */ |
---|
79 | uint32_t length; /* for TR_PEERMSG_GOT_BLOCK */ |
---|
80 | float progress; /* for TR_PEERMSG_PEER_PROGRESS */ |
---|
81 | tr_errno err; /* for TR_PEERMSG_GOT_ERROR */ |
---|
82 | } |
---|
83 | tr_peermsgs_event; |
---|
84 | |
---|
85 | tr_publisher_tag tr_peerMsgsSubscribe ( tr_peermsgs * peer, |
---|
86 | tr_delivery_func func, |
---|
87 | void * user ); |
---|
88 | |
---|
89 | void tr_peerMsgsUnsubscribe ( tr_peermsgs * peer, |
---|
90 | tr_publisher_tag tag ); |
---|
91 | |
---|
92 | #endif |
---|