about summary refs log tree commit diff
path: root/btpd/torrent.h
blob: 273b32f0b023b310e0066d8db720bd3c22bb7e4a (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
#ifndef BTPD_TORRENT_H
#define BTPD_TORRENT_H

#define PIECE_BLOCKLEN (1 << 14)
#define RELPATH_SIZE SHAHEXSIZE

enum torrent_state {
    T_STARTING,
    T_LEECH,
    T_SEED,
    T_STOPPING,
    T_GHOST
};

struct torrent {
    struct tlib *tl;

    enum torrent_state state;
    int delete;

    struct content *cm;
    struct trackers *tr;
    struct net *net;

    off_t total_length;
    off_t piece_length;
    uint32_t npieces;
    unsigned nfiles;
    struct mi_file *files;
    size_t pieces_off;

    BTPDQ_ENTRY(torrent) entry;
};

BTPDQ_HEAD(torrent_tq, torrent);

unsigned torrent_count(void);
unsigned torrent_ghosts(void);
const struct torrent_tq *torrent_get_all(void);
struct torrent *torrent_by_num(unsigned num);
struct torrent *torrent_by_hash(const uint8_t *hash);

enum ipc_err torrent_start(struct tlib *tl);
void torrent_stop(struct torrent *tp, int delete);

int torrent_active(struct tlib *tl);
int torrent_haunting(struct tlib *tl);
int torrent_startable(struct tlib *tl);

off_t torrent_piece_size(struct torrent *tp, uint32_t piece);
uint32_t torrent_piece_blocks(struct torrent *tp, uint32_t piece);
uint32_t torrent_block_size(struct torrent *tp, uint32_t piece,
    uint32_t nblocks, uint32_t block);
const char *torrent_name(struct torrent *tp);

void torrent_on_tick_all(void);

#endif