#define DEBUG if(!debug){}else fprint #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) >= (b) ? (a) : (b)) #define GET32(buf) (ulong)((uchar)(buf)[0]<<24|(uchar)(buf)[1]<<16|(uchar)(buf)[2]<<8|(uchar)(buf)[3]) #define PUT32(buf, i) do{ (buf)[0] = (i)>>24; (buf)[1] = (i)>>16; (buf)[2] = (i)>>8; (buf)[3] = (i); }while(0) #define IsInterested(p) ((p)->status & Interested) #define IsChoking(p) ((p)->status & Choked) #define IsInteresting(p) ((p)->status & (Interested<<2)) #define IsChoked(p) ((p)->status & (Choked<<2)) #define Stable(p) ((p)->lastchange + Stablesecs < time(0)) #define setisinterested(p, v) peersetstatus((p), Interested, (v)) #define setischoking(p, v) peersetstatus((p), Choked, (v)) #define setisinteresting(p, v) peersetstatus((p), Interested<<2, (v)) #define setischoked(p, v) peersetstatus((p), Choked<<2, (v)) /* bee.c */ void beefree(Bee *); void beeprint(int, int, Bee *); char *beeunpickle(Biobuf *, Bee *); void beepickle(Bee *, char **, int *); Bee *beedictget(Bee *, char *, int); void ebeedictget(Bee *, char *, int, void *, void*); /* bite.c */ Bite *bitenew(int, int, int, int); void bitefree(Bite *); void biteappend(Bite **, Bite *); Bite *bitepop(Bite **); void biteprepend(Bite **, Bite *); Bite *bitefind(Bite *, int, int, int); int biteremove(Bite **, Bite *); int bitehave(Torrent *, Bite *); int bitelen(Bite *); /* bits.c */ Bits* bitnew(int, uchar *); void bitset(Bits *, int); void bitunset(Bits *, int); int bitget(Bits *, int); int bitlen(Bits *); int bitnbytes(Bits *); void bitfree(Bits *); int bithaveall(Bits *); double bithave(Bits *); int bitnhave(Bits *); void bitcopy(Bits *, Bits *, int); void bitclear(Bits *); Bits *bitand(Bits *, Bits *); void bitinvert(Bits *); Bits *bitinvertand(Bits *, Bits *); int bitinvertandlen(Bits *, Bits *); /* file.c */ void fileinit(Torrent *, Bee *, int, int); int filepiecehashokay(Torrent *, Piece *); vlong filebytesinpiece(Torrent *, File *, Piece *); void filewrite(Torrent *, vlong, vlong, char *); void fileread(Torrent *, vlong, vlong, char *); int filelen(File *); File *filelast(File *); /* msg.c */ void msgfree(Msg *); void msgappend(Msg **, Msg *); void msgprepend(Msg **, Msg *); char *msgparse(char *, int, Msg *, int); int msgremove(Msg **, Msg *); int msglen(Msg *); int msgmaxlen(int); Msg *msgnew(int, int); char *msgwrite(int, Msg *); char *peerreadstart(int, uchar *, uchar *); char *peerwritestart(int, uchar *, uchar *); /* peer.c */ Peer *peernew(int); void peerfree(Peer *); int peerlen(Peer *); void peeradd(Peer **, Peer *); Peer *peerpop(Peer **); Peer *peerfind(Peer *, int); Peer *peermatch(Peer *, Peer *); Peer *peermatchbyip(Peer *, Peer *); void peersetstatus(Peer *, uint, uint); void peerremove(Peer **, Peer *); /* piece.c */ void pieceinit(Piece *, int, uchar *, ulong); void pieceaddpeer(Piece *, int); void pieceaddpeerhaves(Torrent *, Peer *); void pieceremoveid(Piece *, int); /* rate.c */ Rate *ratenew(int); void rateadd(Rate *, vlong, vlong); void ratetick(Rate *); vlong ratesum(Rate *, int, int); double ratecurrent(Rate *, int, int); void ratefree(Rate *); /* sched.c */ void piecepeerschedule(Torrent *, Peer *); void strategy(Torrent *t); /* subr.c */ char *estrdup(char *); void *emalloc(ulong); void *erealloc(void *, ulong); void *emallocz(ulong, int); char *ememdup(char *, ulong); #pragma varargck type "L" vlong #pragma varargck type "H" uchar * #pragma varargck type "M" Msg * #pragma varargck type "B" Bits * #pragma varargck type "P" Peer * #pragma varargck type "C" Piece * #pragma varargck type "I" Bite * #pragma varargck type "F" File * #pragma varargck type "R" Rate * #pragma varargck type "T" Torrent * int Hfmt(Fmt *); int Lfmt(Fmt *); int Mfmt(Fmt *); int Bfmt(Fmt *); int Pfmt(Fmt *); int Cfmt(Fmt *); int Ifmt(Fmt *); int Ffmt(Fmt *); int Rfmt(Fmt *); int Tfmt(Fmt *); /* torrent.c */ void torrentinit(Torrent *, Bee *, int, int); void torrentverify(Torrent *); void torrentprep(Torrent *t); void torrentdo(Torrent *t); void request(Torrent *, Peer *, Bite *); void trackrequest(Torrent *, char *); /* tracker.c */ char *trackerget(Bee *, char *, char *, uchar *, uchar *, vlong, vlong, vlong, char *);