Compare commits
No commits in common. "2b12150d71509447eb8968ee875bc205e1855353" and "a003da1606c104a7aa0fd3cfe9018557a4ff1e24" have entirely different histories.
2b12150d71
...
a003da1606
|
@ -7,24 +7,16 @@ import { errorExit } from "../lib/error.js";
|
||||||
import stringify from "json-stable-stringify";
|
import stringify from "json-stable-stringify";
|
||||||
import {
|
import {
|
||||||
getRpcServer,
|
getRpcServer,
|
||||||
RPC_PROTOCOL_ID,
|
|
||||||
RPC_PROTOCOL_SYMBOL,
|
RPC_PROTOCOL_SYMBOL,
|
||||||
setupStream,
|
setupStream,
|
||||||
} from "./rpc/server.js";
|
} from "./rpc/server.js";
|
||||||
import { get as getSwarm, SecretStream } from "./swarm.js";
|
import { get as getSwarm, SecretStream } from "./swarm.js";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
// @ts-ignore
|
|
||||||
import Protomux from "protomux";
|
|
||||||
|
|
||||||
export async function start() {
|
export async function start() {
|
||||||
getSwarm().on("connection", (stream: SecretStream) => {
|
getSwarm().on("connection", (stream: SecretStream) =>
|
||||||
Protomux.from(stream).pair(
|
getRpcServer().setup(stream)
|
||||||
{ protocol: "protomux-rpc", id: RPC_PROTOCOL_ID },
|
|
||||||
async () => {
|
|
||||||
getRpcServer().setup(stream);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getRpcByPeer(peer: Buffer | string) {
|
export async function getRpcByPeer(peer: Buffer | string) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ import config from "../../config";
|
||||||
const sodium = require("sodium-universal");
|
const sodium = require("sodium-universal");
|
||||||
let server: RPCServer;
|
let server: RPCServer;
|
||||||
|
|
||||||
export const RPC_PROTOCOL_ID = b4a.from("lumeweb");
|
const RPC_PROTOCOL_ID = b4a.from("lumeweb");
|
||||||
export const RPC_PROTOCOL_SYMBOL = Symbol.for(RPC_PROTOCOL_ID.toString());
|
export const RPC_PROTOCOL_SYMBOL = Symbol.for(RPC_PROTOCOL_ID.toString());
|
||||||
|
|
||||||
export function getRpcServer(): RPCServer {
|
export function getRpcServer(): RPCServer {
|
||||||
|
|
|
@ -69,9 +69,6 @@ export class ProtocolManager {
|
||||||
this._swarm = swarm;
|
this._swarm = swarm;
|
||||||
|
|
||||||
this._swarm.on("connection", (peer: any) => {
|
this._swarm.on("connection", (peer: any) => {
|
||||||
if (!peer.userData) {
|
|
||||||
peer.userData = null;
|
|
||||||
}
|
|
||||||
for (const protocol of this._protocols) {
|
for (const protocol of this._protocols) {
|
||||||
Protomux.from(peer).pair(
|
Protomux.from(peer).pair(
|
||||||
{ protocol: protocol[0] },
|
{ protocol: protocol[0] },
|
||||||
|
|
Loading…
Reference in New Issue