Compare commits
No commits in common. "v0.1.0-develop.4" and "v0.1.0-develop.3" have entirely different histories.
v0.1.0-dev
...
v0.1.0-dev
|
@ -1,5 +1,3 @@
|
||||||
# [0.1.0-develop.4](https://git.lumeweb.com/LumeWeb/relay-plugin-s5/compare/v0.1.0-develop.3...v0.1.0-develop.4) (2023-08-31)
|
|
||||||
|
|
||||||
# [0.1.0-develop.3](https://git.lumeweb.com/LumeWeb/relay-plugin-s5/compare/v0.1.0-develop.2...v0.1.0-develop.3) (2023-08-31)
|
# [0.1.0-develop.3](https://git.lumeweb.com/LumeWeb/relay-plugin-s5/compare/v0.1.0-develop.2...v0.1.0-develop.3) (2023-08-31)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/relay-plugin-s5",
|
"name": "@lumeweb/relay-plugin-s5",
|
||||||
"version": "0.1.0-develop.4",
|
"version": "0.1.0-develop.3",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lumeweb/relay-plugin-s5",
|
"name": "@lumeweb/relay-plugin-s5",
|
||||||
"version": "0.1.0-develop.4",
|
"version": "0.1.0-develop.3",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/interface-relay": "^0.0.2-develop.3",
|
"@lumeweb/interface-relay": "^0.0.2-develop.3",
|
||||||
"@lumeweb/libs5": "^0.1.0-develop.14",
|
"@lumeweb/libs5": "^0.1.0-develop.9",
|
||||||
"@lumeweb/libs5-transport-hyper": "^0.1.0-develop.5",
|
|
||||||
"@types/streamx": "^2.9.1",
|
"@types/streamx": "^2.9.1",
|
||||||
"streamx": "^2.15.1"
|
"streamx": "^2.15.1"
|
||||||
},
|
},
|
||||||
|
@ -1818,9 +1817,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lumeweb/libs5": {
|
"node_modules/@lumeweb/libs5": {
|
||||||
"version": "0.1.0-develop.14",
|
"version": "0.1.0-develop.9",
|
||||||
"resolved": "https://registry.npmjs.org/@lumeweb/libs5/-/libs5-0.1.0-develop.14.tgz",
|
"resolved": "https://registry.npmjs.org/@lumeweb/libs5/-/libs5-0.1.0-develop.9.tgz",
|
||||||
"integrity": "sha512-nLRaDl3c355iDIUU40ES9P5FZvgPtpRJNnAymaJeOxQVjI9TlO+4aGiACB8Wv0uywjSfy6CHvYMS32UZNLhIHA==",
|
"integrity": "sha512-t4Lo9g6xmzCTCaxtva6R4klk3z4TEh+TDVUCkt7MrP0WLqRamEqckQkPn99xDgio1epgOQGnXz/rHrfGmqSsiQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/curves": "^1.1.0",
|
"@noble/curves": "^1.1.0",
|
||||||
"@noble/hashes": "^1.3.1",
|
"@noble/hashes": "^1.3.1",
|
||||||
|
@ -1831,15 +1830,6 @@
|
||||||
"ws": "^8.13.0"
|
"ws": "^8.13.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lumeweb/libs5-transport-hyper": {
|
|
||||||
"version": "0.1.0-develop.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/@lumeweb/libs5-transport-hyper/-/libs5-transport-hyper-0.1.0-develop.5.tgz",
|
|
||||||
"integrity": "sha512-xLc7MhL9dIR7WkaLntkpU56XLNeko3FElB29Rm9q/IEG7xBiwD807ikjxPrBb8R/a/H7c7w1aUAlZVu4U26xxQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"@lumeweb/libs5": "^0.1.0-develop.13",
|
|
||||||
"streamx": "^2.15.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@lumeweb/node-library-preset": {
|
"node_modules/@lumeweb/node-library-preset": {
|
||||||
"version": "0.2.7",
|
"version": "0.2.7",
|
||||||
"resolved": "https://registry.npmjs.org/@lumeweb/node-library-preset/-/node-library-preset-0.2.7.tgz",
|
"resolved": "https://registry.npmjs.org/@lumeweb/node-library-preset/-/node-library-preset-0.2.7.tgz",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/relay-plugin-s5",
|
"name": "@lumeweb/relay-plugin-s5",
|
||||||
"version": "0.1.0-develop.4",
|
"version": "0.1.0-develop.3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -19,8 +19,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/interface-relay": "^0.0.2-develop.3",
|
"@lumeweb/interface-relay": "^0.0.2-develop.3",
|
||||||
"@lumeweb/libs5": "^0.1.0-develop.14",
|
"@lumeweb/libs5": "^0.1.0-develop.9",
|
||||||
"@lumeweb/libs5-transport-hyper": "^0.1.0-develop.5",
|
|
||||||
"@types/streamx": "^2.9.1",
|
"@types/streamx": "^2.9.1",
|
||||||
"streamx": "^2.15.1"
|
"streamx": "^2.15.1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
import { Logger, Peer, PeerStatic } from "@lumeweb/libs5";
|
||||||
|
import { URL } from "url";
|
||||||
|
import NodeId from "@lumeweb/libs5/lib/nodeId.js";
|
||||||
|
import { Buffer } from "buffer";
|
||||||
|
import { PROTOCOL } from "./constants.js";
|
||||||
|
import { Readable } from "streamx";
|
||||||
|
|
||||||
|
export default class HyperTransportPeer implements Peer {
|
||||||
|
challenge: Uint8Array;
|
||||||
|
connectionUris: Array<URL>;
|
||||||
|
isConnected: boolean = false;
|
||||||
|
private _peer: any;
|
||||||
|
private _muxer: any;
|
||||||
|
private _socket = new Readable();
|
||||||
|
private _pipe?: any;
|
||||||
|
|
||||||
|
constructor(peer: any, connectionUris: URL[], muxer: any) {
|
||||||
|
this.connectionUris = connectionUris.map((uri) => new URL(uri.toString()));
|
||||||
|
this.challenge = new Uint8Array();
|
||||||
|
this._peer = peer;
|
||||||
|
this._muxer = muxer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _id?: NodeId;
|
||||||
|
|
||||||
|
get id(): NodeId {
|
||||||
|
return this._id as NodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
set id(value: NodeId) {
|
||||||
|
this._id = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async init() {
|
||||||
|
const channel = await this._muxer.createChannel({
|
||||||
|
protocol: PROTOCOL,
|
||||||
|
});
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
this._pipe = await channel.addMessage({
|
||||||
|
async onmessage(m) {
|
||||||
|
if (m instanceof Uint8Array) {
|
||||||
|
m = Buffer.from(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
self._socket.push(m);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await channel.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async connect(uri: URL): Promise<any> {
|
||||||
|
return Promise.reject("not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
listenForMessages(
|
||||||
|
callback: (event: any) => Promise<void>,
|
||||||
|
{
|
||||||
|
onDone,
|
||||||
|
onError,
|
||||||
|
logger,
|
||||||
|
}: {
|
||||||
|
onDone?: any;
|
||||||
|
onError?: (...args: any[]) => void;
|
||||||
|
logger: Logger;
|
||||||
|
},
|
||||||
|
): void {
|
||||||
|
this._socket.on("data", async (data: Buffer) => {
|
||||||
|
await callback(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (onDone) {
|
||||||
|
this._socket.on("end", onDone);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onError) {
|
||||||
|
this._socket.on("error", onError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderLocationUri(): string {
|
||||||
|
return "Hypercore client";
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage(message: Uint8Array): void {
|
||||||
|
this._pipe.write(message);
|
||||||
|
}
|
||||||
|
}
|
17
src/index.ts
17
src/index.ts
|
@ -1,14 +1,9 @@
|
||||||
import type { PluginAPI } from "@lumeweb/interface-relay";
|
import type { PluginAPI } from "@lumeweb/interface-relay";
|
||||||
import {
|
import { createKeyPair, createNode, S5NodeConfig } from "@lumeweb/libs5";
|
||||||
S5NodeConfig,
|
|
||||||
createKeyPair,
|
|
||||||
createNode,
|
|
||||||
NodeId,
|
|
||||||
} from "@lumeweb/libs5";
|
|
||||||
import HyperTransportPeer from "@lumeweb/libs5-transport-hyper";
|
|
||||||
import { Level } from "level";
|
import { Level } from "level";
|
||||||
|
|
||||||
import { PROTOCOL } from "./constants.js";
|
import { PROTOCOL } from "./constants.js";
|
||||||
|
import HyperTransportPeer from "./hyperTransport.js";
|
||||||
|
import { NodeId } from "@lumeweb/libs5";
|
||||||
import * as fs from "fs/promises";
|
import * as fs from "fs/promises";
|
||||||
|
|
||||||
const plugin = {
|
const plugin = {
|
||||||
|
@ -40,11 +35,7 @@ const plugin = {
|
||||||
|
|
||||||
api.swarm.join(api.util.crypto.createHash(PROTOCOL));
|
api.swarm.join(api.util.crypto.createHash(PROTOCOL));
|
||||||
api.protocols.register(PROTOCOL, async (peer: any, muxer: any) => {
|
api.protocols.register(PROTOCOL, async (peer: any, muxer: any) => {
|
||||||
const s5peer = new HyperTransportPeer({
|
const s5peer = new HyperTransportPeer(peer, [], muxer);
|
||||||
muxer,
|
|
||||||
peer,
|
|
||||||
protocol: PROTOCOL,
|
|
||||||
});
|
|
||||||
|
|
||||||
s5peer.id = new NodeId(peer.remotePublicKey);
|
s5peer.id = new NodeId(peer.remotePublicKey);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue