-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
99 lines (90 loc) · 2.61 KB
/
types.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (C) 2020-2022 Russell Clarey. All rights reserved. MIT license.
export enum AnnounceEvent {
/** Indicates the announce request is one performed at regular intervals */
empty = "empty",
/** Must be sent with the first request to the tracker */
started = "started",
/**
* Must be sent to the tracker when the download completes, but not if the download was
* already complete when the client started
*/
completed = "completed",
/** Must be sent if the client is shutting down gracefully */
stopped = "stopped",
}
// Mapping from AnnounceEvent to int
export const UDP_EVENT_MAP = [
AnnounceEvent.empty,
AnnounceEvent.completed,
AnnounceEvent.started,
AnnounceEvent.stopped,
];
export enum CompactValue {
/** Compact peer list is accepted */
compact = "1",
/** Compact peer list is not accepted */
full = "0",
}
export interface AnnouncePeer {
/** IP address of the peer */
ip: string;
/** TCP port of the peer */
port: number;
/** Peer's self-selected ID */
id?: Uint8Array;
}
export interface AnnounceInfo {
/** SHA1 hash of the bencoded info dictionary */
infoHash: Uint8Array;
/** Self-selected ID */
peerId: Uint8Array;
/** The IP address at which the client is listening */
ip: string;
/** The port at which the client is listening */
port: number;
/** Number of bytes uploaded */
uploaded: number;
/** Number of bytes downloaded */
downloaded: number;
/** Number of bytes the client still has to download */
left: number;
/** Indicates the purpose of the request */
event: AnnounceEvent;
/** Number of peers that the client would like to receive from the tracker */
numWant?: number;
/** Indicates whether or not the client accepts a compact response */
compact?: CompactValue;
/**
* An addition ID meant to allow a client to prove their identity should their IP
* address change
*/
key?: Uint8Array;
}
export type ScrapeData = {
/** Number of peers who have the whole file */
complete: number;
/** Number of completed downloads */
downloaded: number;
/** Number of peers who do not yet have the whole file */
incomplete: number;
/** Info hash for the file */
infoHash: Uint8Array;
};
export enum AnnouncePeerState {
/** The peer has the whole file */
seeder = "seeder",
/** The peer does not have the whole file */
leecher = "leecher",
}
export interface AnnouncePeerInfo extends AnnouncePeer {
/** Peer's self-selected ID */
id: Uint8Array;
/** Whether this peer is a leecher or seeder */
state: AnnouncePeerState;
}
export enum UdpTrackerAction {
connect = 0,
announce = 1,
scrape = 2,
error = 3,
}