Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions notNeededPackages.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,6 @@
"libraryName": "bitcoinjs-lib",
"asOfVersion": "5.0.0"
},
"bittorrent-protocol": {
"libraryName": "bittorrent-protocol",
"asOfVersion": "3.5.4"
},
"bitwise": {
"libraryName": "bitwise",
"asOfVersion": "2.0.0"
Expand Down Expand Up @@ -1136,10 +1132,6 @@
"libraryName": "create-html-element",
"asOfVersion": "2.1.0"
},
"create-torrent": {
"libraryName": "create-torrent",
"asOfVersion": "6.0.0"
},
"credit-card-type": {
"libraryName": "credit-card-type",
"asOfVersion": "9.0.0"
Expand Down Expand Up @@ -4133,10 +4125,6 @@
"libraryName": "parse-ms",
"asOfVersion": "2.1.0"
},
"parse-torrent": {
"libraryName": "parse-torrent",
"asOfVersion": "11.0.0"
},
"parse5": {
"libraryName": "parse5",
"asOfVersion": "7.0.0"
Expand Down Expand Up @@ -6507,10 +6495,6 @@
"libraryName": "webpack-virtual-modules",
"asOfVersion": "0.4.2"
},
"webtorrent": {
"libraryName": "webtorrent",
"asOfVersion": "2.0.0"
},
"whatwg-streams": {
"libraryName": "typescript",
"asOfVersion": "3.2.1"
Expand Down Expand Up @@ -6880,4 +6864,4 @@
"asOfVersion": "4.6.0"
}
}
}
}
5 changes: 5 additions & 0 deletions types/bittorrent-protocol/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"@definitelytyped/no-any-union": "off"
}
}
5 changes: 5 additions & 0 deletions types/bittorrent-protocol/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
33 changes: 33 additions & 0 deletions types/bittorrent-protocol/bittorrent-protocol-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Protocol = require("bittorrent-protocol");
import * as net from "net";

class TestExtension implements Protocol.Extension {
constructor(protected wire: Protocol.Wire) {}
name = "extname";
}

net.createServer(socket => {
const wire = new Protocol();

wire.use(TestExtension);

// pipe to and from the protocol
socket.pipe(wire).pipe(socket);

wire.on("handshake", (infoHash, peerId) => {
// receive a handshake (infoHash and peerId are hex strings)

// lets emit a handshake of our own as well
wire.handshake("my info hash (hex)", "my peer id (hex)");
});

wire.on("unchoke", () => {
console.log("peer is no longer choking us: " + wire.peerChoking);
});

// Extend wire using the test extension
wire.extended("extname", {});

// Confirm extension has been added to Wire instance.
console.log(wire.extname.name);
}).listen(6881);
101 changes: 101 additions & 0 deletions types/bittorrent-protocol/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/// <reference types="node" />

import * as stream from "stream";

declare const BittorrentProtocol: BittorrentProtocol.BittorrentProtocol;

declare namespace BittorrentProtocol {
interface BittorrentProtocol {
new(): Wire;
(): Wire;
}

interface ExtensionConstructor {
new(wire: Wire): Extension;
}

interface Extension {
onHandshake?(infoHash: string, peerId: string, extensions: { [name: string]: boolean }): void;
onExtendedHandshake?(handshake: { [key: string]: any }): void;
onMessage?(buf: Buffer): void;
name: string;
}

interface Request {
piece: number;
offset: number;
length: number;
callback(): void;
}

interface Wire extends stream.Duplex {
readonly peerId: string; // remote peer id (hex string)
readonly peerIdBuffer: Buffer; // remote peer id (Buffer)
readonly type: "webrtc" | "tcpIncoming" | "tcpOutgoing" | "webSeed"; // connection type
readonly amChoking: boolean; // are we choking the peer?
readonly amInterested: boolean; // are we interested in the peer?
readonly peerChoking: boolean; // is the peer choking us?
readonly peerInterested: boolean; // is the peer interested in us?
readonly requests: Request[];
readonly peerRequests: Request[];
readonly extendedMapping: { [key: number]: string };
readonly peerExtendedMapping: { [key: string]: number };

setKeepAlive(enable: boolean): void;

setTimeout(ms: number, unref?: boolean): void;

destroy(): any;
end(): any;

use(ext: ExtensionConstructor): void;

[key: string]: any;

handshake(infoHash: string | Buffer, peerId: string | Buffer, extensions?: any): void;

choke(): void;

unchoke(): void;

interested(): void;

uninterested(): void;

have(index: number): void;

// TODO: bitfield can be also a bitfield instance
bitfield(bitfield: Buffer | any): void;

// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
request<T extends any>(index: number, offset: number, length: number, cb?: (err: Error) => T): T | void;

piece(index: number, offset: number, buffer: Buffer): void;

cancel(index: number, offset: number, length: number): void;

port(port: number): void;

extended(ext: number | string, obj: any): void;

// TODO: bitfield is a bitfield instance
on(event: "bitfield", listener: (bitfield: any) => void): this;
on(
event: "keep-alive" | "choke" | "unchoke" | "interested" | "uninterested" | "timeout",
listener: () => void,
): this;
on(event: "upload" | "have" | "download" | "port", listener: (length: number) => void): this;
on(event: "handshake", listener: (infoHash: string, peerId: string, extensions: Extension[]) => void): this;
on(
event: "request",
listener: (index: number, offset: number, length: number, respond: () => void) => void,
): this;
on(event: "piece", listener: (index: number, offset: number, buffer: Buffer) => void): this;
on(event: "cancel", listener: (index: number, offset: number, length: number) => void): this;
on(event: "extended", listener: (ext: "handshake" | string, buf: any) => void): void;
on(event: "unknownmessage", listener: (buffer: Buffer) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
}
}

export = BittorrentProtocol;
28 changes: 28 additions & 0 deletions types/bittorrent-protocol/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"private": true,
"name": "@types/bittorrent-protocol",
"version": "3.1.9999",
"projects": [
"https://github.com/webtorrent/bittorrent-protocol"
],
"dependencies": {
"@types/node": "*"
},
"devDependencies": {
"@types/bittorrent-protocol": "workspace:."
},
"owners": [
{
"name": "Feross Aboukhadijeh",
"githubUsername": "feross"
},
{
"name": "Tomasz Łaziuk",
"githubUsername": "tlaziuk"
},
{
"name": "H1b9b",
"githubUsername": "h1b9b"
}
]
}
19 changes: 19 additions & 0 deletions types/bittorrent-protocol/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "node16",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"bittorrent-protocol-tests.ts"
]
}
5 changes: 5 additions & 0 deletions types/create-torrent/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
38 changes: 38 additions & 0 deletions types/create-torrent/create-torrent-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import createTorrent = require("create-torrent");
import fs = require("fs");

createTorrent("test", (err, torrent) => {
if (err) {
return;
}

fs.writeFileSync("test.torrent", torrent);
});

createTorrent(
"test",
{
name: "test",
comment: "test",
createdBy: "test",
creationDate: Date.now(),
private: true,
pieceLength: 100,
announceList: [["test"]],
urlList: ["test"],
info: {
test: "test",
},
onProgress: (b1, b2) => {
const percent = Math.round(b1 / b2 * 100);
console.info(`${percent} % ${b1} B - ${b2} B`);
},
},
(err, torrent) => {
if (err) {
return;
}

fs.writeFileSync("test.torrent", torrent);
},
);
55 changes: 55 additions & 0 deletions types/create-torrent/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/// <reference types="node" />

interface CreateTorrentOptions {
// name of the torrent (default = basename of `path`, or 1st file's name)
name?: string | undefined;
// free-form textual comments of the author
comment?: string | undefined;
// name and version of program used to create torrent
createdBy?: string | undefined;
// creation time in UNIX epoch format (default = now)
creationDate?: number | undefined;
// is this a private .torrent? (default = false)
private?: boolean | undefined;
// force a custom piece length (number of bytes)
pieceLength?: number | undefined;
// custom trackers (array of arrays of strings) (see [bep12](http://www.bittorrent.org/beps/bep_0012.html))
announceList?: string[][] | undefined;
// web seed urls (see [bep19](http://www.bittorrent.org/beps/bep_0019.html))
urlList?: string[] | undefined;
// add non-standard info dict entries, e.g. info.source, a convention for cross-seeding
info?: Record<string, string> | undefined;
// called with the number of bytes hashed and estimated total size after every piece
onProgress?(hashedLength: number, estimatedTorrentLength: number): void;
}

declare function createTorrent(
input:
| string
| string[]
| File
| File[]
| FileList
| Buffer
| Buffer[]
| NodeJS.ReadableStream
| NodeJS.ReadableStream[],
cb: (err: Error | null, torrent: Buffer) => any,
): void;

declare function createTorrent(
input:
| string
| string[]
| File
| File[]
| FileList
| Buffer
| Buffer[]
| NodeJS.ReadableStream
| NodeJS.ReadableStream[],
opts: CreateTorrentOptions,
cb: (err: Error | null, torrent: Buffer) => any,
): void;

export = createTorrent;
20 changes: 20 additions & 0 deletions types/create-torrent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"private": true,
"name": "@types/create-torrent",
"version": "5.0.9999",
"projects": [
"https://github.com/webtorrent/create-torrent#readme"
],
"dependencies": {
"@types/node": "*"
},
"devDependencies": {
"@types/create-torrent": "workspace:."
},
"owners": [
{
"name": "Jesse Chan",
"githubUsername": "jesec"
}
]
}
20 changes: 20 additions & 0 deletions types/create-torrent/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "node16",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"create-torrent-tests.ts"
]
}
5 changes: 5 additions & 0 deletions types/parse-torrent/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
Loading