Compare commits
No commits in common. "v0.1.0-develop.10" and "v0.1.0-develop.9" have entirely different histories.
v0.1.0-dev
...
v0.1.0-dev
|
@ -1,5 +1,3 @@
|
||||||
# [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-08-31)
|
|
||||||
|
|
||||||
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-08-31)
|
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-08-31)
|
||||||
|
|
||||||
# [0.1.0-develop.8](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.7...v0.1.0-develop.8) (2023-08-31)
|
# [0.1.0-develop.8](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.7...v0.1.0-develop.8) (2023-08-31)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/libs5",
|
"name": "@lumeweb/libs5",
|
||||||
"version": "0.1.0-develop.10",
|
"version": "0.1.0-develop.9",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lumeweb/libs5",
|
"name": "@lumeweb/libs5",
|
||||||
"version": "0.1.0-develop.10",
|
"version": "0.1.0-develop.9",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/curves": "^1.1.0",
|
"@noble/curves": "^1.1.0",
|
||||||
"@noble/hashes": "^1.3.1",
|
"@noble/hashes": "^1.3.1",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/libs5",
|
"name": "@lumeweb/libs5",
|
||||||
"version": "0.1.0-develop.10",
|
"version": "0.1.0-develop.9",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -10,7 +10,6 @@ export {
|
||||||
createTransportSocket,
|
createTransportSocket,
|
||||||
isTransport,
|
isTransport,
|
||||||
createTransportPeer,
|
createTransportPeer,
|
||||||
BasePeer,
|
|
||||||
} from "./transports/index.js";
|
} from "./transports/index.js";
|
||||||
export type { SignedRegistryEntry };
|
export type { SignedRegistryEntry };
|
||||||
export { NodeId };
|
export { NodeId };
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { Logger, Peer } from "#types.js";
|
|
||||||
import { URL } from "url";
|
|
||||||
import NodeId from "#nodeId.js";
|
|
||||||
|
|
||||||
export abstract class BasePeer implements Peer {
|
|
||||||
connectionUris: Array<URL>;
|
|
||||||
isConnected: boolean = false;
|
|
||||||
challenge: Uint8Array;
|
|
||||||
protected _socket: any;
|
|
||||||
|
|
||||||
constructor(_socket: any, connectionUris: URL[]) {
|
|
||||||
this.connectionUris = connectionUris.map((uri) => new URL(uri.toString()));
|
|
||||||
this.challenge = new Uint8Array();
|
|
||||||
this._socket = _socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _id?: NodeId;
|
|
||||||
|
|
||||||
get id(): NodeId {
|
|
||||||
return this._id as NodeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
set id(value: NodeId) {
|
|
||||||
this._id = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract sendMessage(message: Uint8Array);
|
|
||||||
|
|
||||||
abstract renderLocationUri(): string;
|
|
||||||
|
|
||||||
abstract listenForMessages(
|
|
||||||
callback: (event: any) => Promise<void>,
|
|
||||||
{
|
|
||||||
onDone,
|
|
||||||
onError,
|
|
||||||
logger,
|
|
||||||
}: { onDone?: any; onError?: (...args: any[]) => void; logger: Logger },
|
|
||||||
): void;
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@ import { TcpPeer } from "#transports/tcp.js";
|
||||||
import { WebSocketPeer } from "#transports/webSocket.js";
|
import { WebSocketPeer } from "#transports/webSocket.js";
|
||||||
import { PeerStatic } from "#types.js";
|
import { PeerStatic } from "#types.js";
|
||||||
import isNode from "detect-node";
|
import isNode from "detect-node";
|
||||||
import { BasePeer } from "#transports/base.js";
|
|
||||||
const transports = new Map<string, PeerStatic>();
|
const transports = new Map<string, PeerStatic>();
|
||||||
|
|
||||||
export function registerTransport(type: string, transport: PeerStatic) {
|
export function registerTransport(type: string, transport: PeerStatic) {
|
||||||
|
@ -38,8 +37,6 @@ export function createTransportPeer(
|
||||||
return new transport(socket, connectionUris);
|
return new transport(socket, connectionUris);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { BasePeer };
|
|
||||||
|
|
||||||
if (isNode) {
|
if (isNode) {
|
||||||
registerTransport("tcp", TcpPeer);
|
registerTransport("tcp", TcpPeer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,32 @@
|
||||||
import { Logger, Peer } from "../types.js";
|
import { Logger, Peer } from "../types.js";
|
||||||
|
import NodeId from "../nodeId.js";
|
||||||
import * as net from "net";
|
import * as net from "net";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import { decodeEndian } from "../util.js";
|
import { decodeEndian } from "../util.js";
|
||||||
import * as console from "console";
|
import * as console from "console";
|
||||||
import { BasePeer } from "#transports/base.js";
|
|
||||||
|
|
||||||
export class TcpPeer extends BasePeer implements Peer {
|
export class TcpPeer implements Peer {
|
||||||
|
connectionUris: Array<URL>;
|
||||||
|
isConnected: boolean = false;
|
||||||
|
challenge: Uint8Array;
|
||||||
|
private _socket: net.Socket;
|
||||||
|
|
||||||
|
constructor(_socket: net.Socket, connectionUris: URL[]) {
|
||||||
|
this.connectionUris = connectionUris.map((uri) => new URL(uri.toString()));
|
||||||
|
this.challenge = new Uint8Array();
|
||||||
|
this._socket = _socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _id?: NodeId;
|
||||||
|
|
||||||
|
get id(): NodeId {
|
||||||
|
return this._id as NodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(value: NodeId) {
|
||||||
|
this._id = value;
|
||||||
|
}
|
||||||
|
|
||||||
sendMessage(message: Uint8Array): void {
|
sendMessage(message: Uint8Array): void {
|
||||||
this._socket.write(message);
|
this._socket.write(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,29 @@ import { Logger, Peer } from "../types.js";
|
||||||
import NodeId from "../nodeId.js";
|
import NodeId from "../nodeId.js";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import { WebSocket } from "ws";
|
import { WebSocket } from "ws";
|
||||||
import { BasePeer } from "#transports/base.js";
|
|
||||||
|
|
||||||
export class WebSocketPeer extends BasePeer implements Peer {
|
export class WebSocketPeer implements Peer {
|
||||||
|
connectionUris: Array<URL>;
|
||||||
|
isConnected: boolean = false;
|
||||||
|
challenge: Uint8Array;
|
||||||
|
private _socket: WebSocket;
|
||||||
|
|
||||||
|
constructor(_socket: WebSocket, connectionUris: URL[]) {
|
||||||
|
this.connectionUris = connectionUris.map((uri) => new URL(uri.toString()));
|
||||||
|
this.challenge = new Uint8Array(); // Initialize as needed
|
||||||
|
this._socket = _socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _id?: NodeId;
|
||||||
|
|
||||||
|
get id(): NodeId {
|
||||||
|
return this._id as NodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(value: NodeId) {
|
||||||
|
this._id = value;
|
||||||
|
}
|
||||||
|
|
||||||
sendMessage(message: Uint8Array): void {
|
sendMessage(message: Uint8Array): void {
|
||||||
this._socket.send(message);
|
this._socket.send(message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue