blob: 66d5512077896248c54a5f6613b7e270291cf6ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#ifndef BTPD_TORRENT_H
#define BTPD_TORRENT_H
struct piece {
uint32_t index;
unsigned nblocks;
unsigned ngot;
unsigned nbusy;
uint8_t *have_field;
uint8_t *down_field;
TAILQ_ENTRY(piece) entry;
};
TAILQ_HEAD(piece_tq, piece);
struct torrent {
const char *relpath;
struct metainfo meta;
TAILQ_ENTRY(torrent) entry;
void *imem;
size_t isiz;
uint8_t *piece_field;
uint8_t *block_field;
uint32_t have_npieces;
unsigned long *piece_count;
uint64_t uploaded, downloaded;
unsigned long choke_time;
unsigned long opt_time;
unsigned long tracker_time;
short ndown;
struct peer *optimistic;
unsigned npeers;
struct peer_tq peers;
int endgame;
struct piece_tq getlst;
};
TAILQ_HEAD(torrent_tq, torrent);
off_t torrent_bytes_left(struct torrent *tp);
char *torrent_get_bytes(struct torrent *tp, off_t start, size_t len);
void torrent_put_bytes(struct torrent *tp, const char *buf,
off_t start, size_t len);
int torrent_load(const char *metafile);
void torrent_unload(struct torrent *tp);
int torrent_has_peer(struct torrent *tp, const uint8_t *id);
struct torrent *torrent_get_by_hash(const uint8_t *hash);
#endif
|