Compare commits

...

4 Commits

9 changed files with 23 additions and 3 deletions

View File

@ -1,3 +1,5 @@
# [0.1.0-develop.32](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.31...v0.1.0-develop.32) (2023-09-02)
# [0.1.0-develop.31](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.30...v0.1.0-develop.31) (2023-09-02)

4
npm-shrinkwrap.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@lumeweb/libs5",
"version": "0.1.0-develop.31",
"version": "0.1.0-develop.32",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@lumeweb/libs5",
"version": "0.1.0-develop.31",
"version": "0.1.0-develop.32",
"dependencies": {
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",

View File

@ -1,6 +1,6 @@
{
"name": "@lumeweb/libs5",
"version": "0.1.0-develop.31",
"version": "0.1.0-develop.32",
"type": "module",
"main": "lib/index.js",
"repository": {

View File

@ -69,6 +69,10 @@ export class S5Node {
await p2p.start();
}
public async stop() {
await this.services.p2p.stop();
}
async readStorageLocationsFromDB(
hash: Multihash,
): Promise<Map<number, Map<string, Map<number, any>>>> {

View File

@ -97,6 +97,9 @@ export class P2PService extends EventEmitter {
this.connectToNode([new URL(p)]);
}
}
async stop() {
[...this.node.services.p2p.peers.values()].forEach((peer) => peer.end());
}
async onNewPeer(peer: Peer, verifyId: boolean): Promise<void> {
peer.challenge = crypto.randomBytes(32);

View File

@ -38,4 +38,6 @@ export abstract class BasePeer implements Peer {
logger,
}: { onDone?: any; onError?: (...args: any[]) => void; logger: Logger },
): void;
abstract end(): void;
}

View File

@ -6,6 +6,8 @@ import * as console from "console";
import { BasePeer } from "#transports/base.js";
export class TcpPeer extends BasePeer implements Peer {
declare _socket: net.Socket;
sendMessage(message: Uint8Array): void {
this._socket.write(message);
}
@ -59,6 +61,9 @@ export class TcpPeer extends BasePeer implements Peer {
this._socket.on("error", onError);
}
}
end(): void {
this._socket.end();
}
public static async connect(uri: URL): Promise<net.Socket> {
const host = uri.hostname;

View File

@ -42,6 +42,9 @@ export class WebSocketPeer extends BasePeer implements Peer {
this._socket.addEventListener("error", onError);
}
}
end(): void {
this._socket.end();
}
public static async connect(uri: URL): Promise<WebSocket> {
return new Promise((resolve, reject) => {

View File

@ -28,6 +28,7 @@ export interface Peer {
): void;
renderLocationUri(): string;
end(): void;
}
export type PeerConstructorOptions = { socket: any; uris?: URL[] };