2023-03-17 10:13:08 +00:00
|
|
|
import type { Plugin, PluginAPI } from "@lumeweb/relay-types";
|
2023-04-17 00:52:56 +00:00
|
|
|
import { MultiSocketProxy } from "@lumeweb/libhyperproxy";
|
2022-08-29 22:45:01 +00:00
|
|
|
|
2023-03-17 10:13:08 +00:00
|
|
|
const PROTOCOL = "lumeweb.proxy.ipfs";
|
2022-08-29 22:45:01 +00:00
|
|
|
|
2023-03-17 10:13:08 +00:00
|
|
|
interface PeerInfoResult {
|
|
|
|
publicKey: Uint8Array;
|
|
|
|
libp2pPublicKey: Uint8Array;
|
2022-08-29 22:45:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const plugin: Plugin = {
|
|
|
|
name: "ipfs",
|
|
|
|
async plugin(api: PluginAPI): Promise<void> {
|
2023-04-17 00:52:56 +00:00
|
|
|
const proxy = new MultiSocketProxy({
|
2023-03-17 10:13:08 +00:00
|
|
|
swarm: api.swarm,
|
|
|
|
protocol: PROTOCOL,
|
2023-04-17 00:52:56 +00:00
|
|
|
allowedPorts: [5001, 5002],
|
|
|
|
server: true,
|
2022-08-29 22:45:01 +00:00
|
|
|
});
|
2023-04-17 00:52:56 +00:00
|
|
|
api.swarm.join(api.util.crypto.createHash(PROTOCOL));
|
2023-03-17 10:13:08 +00:00
|
|
|
api.protocols.register(PROTOCOL, (peer: any, muxer: any) => {
|
|
|
|
proxy.handlePeer({
|
|
|
|
peer,
|
|
|
|
muxer,
|
|
|
|
});
|
2022-08-29 22:45:01 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default plugin;
|