Compare commits
No commits in common. "v0.1.0-develop.11" and "v0.1.0-develop.10" have entirely different histories.
v0.1.0-dev
...
v0.1.0-dev
|
@ -1,5 +1,3 @@
|
||||||
# [0.1.0-develop.11](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.10...v0.1.0-develop.11) (2023-08-31)
|
|
||||||
|
|
||||||
# [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.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)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/libs5",
|
"name": "@lumeweb/libs5",
|
||||||
"version": "0.1.0-develop.11",
|
"version": "0.1.0-develop.10",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lumeweb/libs5",
|
"name": "@lumeweb/libs5",
|
||||||
"version": "0.1.0-develop.11",
|
"version": "0.1.0-develop.10",
|
||||||
"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.11",
|
"version": "0.1.0-develop.10",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -319,10 +319,7 @@ export class P2PService {
|
||||||
this.logger.verbose(`[connect] ${connectionUri}`);
|
this.logger.verbose(`[connect] ${connectionUri}`);
|
||||||
|
|
||||||
const socket = await createTransportSocket(protocol, connectionUri);
|
const socket = await createTransportSocket(protocol, connectionUri);
|
||||||
const peer = createTransportPeer(protocol, {
|
const peer = createTransportPeer(protocol, socket, [connectionUri]);
|
||||||
socket,
|
|
||||||
uris: [connectionUri],
|
|
||||||
});
|
|
||||||
|
|
||||||
peer.id = id;
|
peer.id = id;
|
||||||
await this.onNewPeer(peer, true);
|
await this.onNewPeer(peer, true);
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import { Logger, Peer, PeerConstructorOptions } from "#types.js";
|
import { Logger, Peer } from "#types.js";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import NodeId from "#nodeId.js";
|
import NodeId from "#nodeId.js";
|
||||||
|
|
||||||
export abstract class BasePeer implements Peer {
|
export abstract class BasePeer implements Peer {
|
||||||
connectionUris: URL[];
|
connectionUris: Array<URL>;
|
||||||
isConnected: boolean = false;
|
isConnected: boolean = false;
|
||||||
challenge: Uint8Array;
|
challenge: Uint8Array;
|
||||||
protected _socket: any;
|
protected _socket: any;
|
||||||
|
|
||||||
constructor({ socket, uris }: PeerConstructorOptions) {
|
constructor(_socket: any, connectionUris: URL[]) {
|
||||||
this.connectionUris = uris.map((uri) => new URL(uri.toString()));
|
this.connectionUris = connectionUris.map((uri) => new URL(uri.toString()));
|
||||||
this.challenge = new Uint8Array();
|
this.challenge = new Uint8Array();
|
||||||
this._socket = socket;
|
this._socket = _socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _id?: NodeId;
|
private _id?: NodeId;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import { TcpPeer } from "#transports/tcp.js";
|
import { TcpPeer } from "#transports/tcp.js";
|
||||||
import { WebSocketPeer } from "#transports/webSocket.js";
|
import { WebSocketPeer } from "#transports/webSocket.js";
|
||||||
import { PeerConstructorOptions, 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";
|
import { BasePeer } from "#transports/base.js";
|
||||||
const transports = new Map<string, PeerStatic>();
|
const transports = new Map<string, PeerStatic>();
|
||||||
|
@ -26,7 +26,8 @@ export function createTransportSocket(type: string, uri: URL) {
|
||||||
|
|
||||||
export function createTransportPeer(
|
export function createTransportPeer(
|
||||||
type: string,
|
type: string,
|
||||||
params: PeerConstructorOptions,
|
socket: any,
|
||||||
|
connectionUris: URL[] = [],
|
||||||
) {
|
) {
|
||||||
if (!isTransport(type)) {
|
if (!isTransport(type)) {
|
||||||
throw new Error(`transport ${type} does not exist`);
|
throw new Error(`transport ${type} does not exist`);
|
||||||
|
@ -34,7 +35,7 @@ export function createTransportPeer(
|
||||||
|
|
||||||
const transport = transports.get(type) as PeerStatic;
|
const transport = transports.get(type) as PeerStatic;
|
||||||
|
|
||||||
return new transport(params);
|
return new transport(socket, connectionUris);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { BasePeer };
|
export { BasePeer };
|
||||||
|
|
|
@ -30,11 +30,9 @@ export interface Peer {
|
||||||
renderLocationUri(): string;
|
renderLocationUri(): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PeerConstructorOptions = { socket: any; uris: URL[] };
|
|
||||||
|
|
||||||
// Define the static side of the class
|
// Define the static side of the class
|
||||||
export interface PeerStatic {
|
export interface PeerStatic {
|
||||||
new ({ socket, uris }: PeerConstructorOptions): Peer;
|
new (_socket: any, uri: URL[]): Peer;
|
||||||
connect(uri: URL): Promise<any>;
|
connect(uri: URL): Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue