tlibeech.h - libeech - bittorrent library
(HTM) git clone git://z3bra.org/libeech.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
tlibeech.h (1385B)
---
1 /* See LICENSE file for copyright and license details. */
2 #include <limits.h>
3
4 #include "be.h"
5
6 #define PCESIZ 1048576
7 #define BLKSIZ 16384
8 #define MSGSIZ ((BLKSIZ) + 13)
9
10 #define PCENUM 65535
11 #define BLKNUM ((PCESIZ)/(BLKSIZ)+!!((PCESIZ)%(BLKSIZ)))
12
13 enum {
14 CONNECTED = 1 << 0,
15 HANDSHAKESENT = 1 << 1,
16 HANDSHAKERCVD = 1 << 2,
17 SEEDING = 1 << 3,
18 LEECHING = 1 << 4,
19 AMCHOKING = 1 << 5,
20 AMINTERESTED = 1 << 6,
21 ISCHOKING = 1 << 7,
22 ISINTERESTED = 1 << 8,
23 };
24
25 struct piece {
26 int n;
27 ssize_t sz;
28 char blks[PCESIZ];
29 char rq[BLKNUM / 8 + !!(BLKNUM % 8)];
30 char bl[BLKNUM / 8 + !!(BLKNUM % 8)];
31 };
32
33 struct peer {
34 int fd;
35 int state;
36 int port;
37 char host[HOST_NAME_MAX];
38 char rxbuf[MSGSIZ];
39 long rxbufsz;
40 char bf[PCENUM / 8 + !!(PCENUM % 8)];
41 char view[PCENUM / 8 + !!(PCENUM % 8)];
42 struct piece piece;
43 struct peer *next;
44 };
45
46 struct file {
47 size_t sz;
48 char path[PATH_MAX];
49 };
50
51 struct torrent {
52 char id[21];
53 char ih[20];
54 char tr[PATH_MAX];
55 char bf[PCENUM];
56 char ph[PCENUM];
57 struct be be;
58 struct be info;
59 struct peer *peers;
60 struct file *files;
61 long npiece;
62 long nfile;
63 long psz;
64 long sz;
65 long dl;
66 long ul;
67 };
68
69 int glch_loadtorrent(struct torrent *, char *, size_t);
70 int glch_addpeer(struct torrent *, struct peer *, char *, int);
71 int glch_bind(char *, int);
72 int glch_leech(struct torrent *, int);
73 long glch_piececount(struct torrent *);