Skip to content

Commit

Permalink
Add websocket and TCP transport.
Browse files Browse the repository at this point in the history
  • Loading branch information
farhoud committed May 1, 2022
1 parent eca064a commit b28d859
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion apps/box/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"listen": [
"/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star",
"/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star",
"/ip4/0.0.0.0/tcp/4001"
"/ip4/0.0.0.0/tcp/4002",
"/ip4/0.0.0.0/tcp/4003/ws"
]
},
"ipfs": {
Expand Down
8 changes: 3 additions & 5 deletions apps/box/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as fs from "fs"
import peerId from "peer-id"
import {LIBP2P_PATH, FULA_NODES, IPFS_HTTP} from "./const";
import TCP from 'libp2p-tcp'
import WS from 'libp2p-websockets'

const getPeerId = async () => {
if (fs.existsSync(LIBP2P_PATH + '/identity.json')) {
Expand Down Expand Up @@ -42,7 +43,7 @@ export const libConfig = async (config: Partial<Libp2pOptions>): Promise<Libp2pO
listen
},
modules: {
transport: [WebRTCStar, TCP],
transport: [WebRTCStar, TCP, WS],
streamMuxer: [Mplex],
connEncryption: [NOISE],
peerDiscovery: [Bootstrap],
Expand Down Expand Up @@ -79,10 +80,7 @@ export const libConfig = async (config: Partial<Libp2pOptions>): Promise<Libp2pO

export const ipfsConfig = () => ({
Addresses: {
Swarm: [
'/ip4/0.0.0.0/tcp/4002',
'/ip4/127.0.0.1/tcp/4003/ws'
],
Swarm: listen,
Announce: [],
NoAnnounce: [],
API: '/ip4/127.0.0.1/tcp/5002',
Expand Down
2 changes: 2 additions & 0 deletions libraries/fula-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"libp2p": "~0.36.2",
"libp2p-mplex": "~0.10.7",
"libp2p-webrtc-star": "~0.25.0",
"libp2p-tcp": "^0.17.2",
"libp2p-websockets": "~0.16.2",
"@chainsafe/libp2p-noise": "~5.0.2",
"events": "~3.3.0"
},
Expand Down
6 changes: 4 additions & 2 deletions libraries/fula-client/scripts/build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ await build({
'libp2p-webrtc-star',
'libp2p-bootstrap',
'libp2p-mplex',
'libp2p-websockets'
'libp2p-websockets',
'libp2p-tcp'
]
});

Expand Down Expand Up @@ -66,7 +67,8 @@ await build({
'libp2p-bootstrap',
'libp2p-mplex',
'libp2p-websockets',
'wrtc'
'wrtc',
'libp2p-tcp'
]
});

2 changes: 1 addition & 1 deletion libraries/fula-client/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ await build({
bundle: true,
sourcemap: false,
outfile: 'dist/node/index.cjs',
external: ['wrtc','libp2p-webrtc-star','libp2p-mplex','libp2p','@chainsafe/libp2p-noise']
external: ['wrtc','libp2p-webrtc-star','libp2p-mplex','libp2p','@chainsafe/libp2p-noise','libp2p-tcp','libp2p-websockets']
});


Expand Down
5 changes: 4 additions & 1 deletion libraries/fula-client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { NOISE, Noise } from '@chainsafe/libp2p-noise';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import Mplex from 'libp2p-mplex';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import WS from 'libp2p-websockets'
import { constructorOptions, Libp2pOptions } from 'libp2p';
import { SIG_SERVER } from './constant';
import Protector from "libp2p/src/pnet/index.js"
Expand All @@ -26,7 +29,7 @@ export async function configure(option?:Option): Promise<Libp2pOptions & Partial
listen: SIG_SERVER
},
modules: {
transport: [WebRTCStar],
transport: [WebRTCStar,WS],
streamMuxer: [Mplex],
connEncryption: [NOISE],
connProtector: option?.netSecret?new Protector(option.netSecret):undefined
Expand Down
2 changes: 1 addition & 1 deletion libraries/fula-client/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Multiaddr } from 'multiaddr';

export const SIG_SERVER = [
'/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
];

export const SIG_MULTIADDRS = SIG_SERVER.map((item) => {
Expand Down
2 changes: 1 addition & 1 deletion libraries/fula-client/tests/fula.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {createClient} from '../src';
import {Status} from "../src/connection";
import {File} from '@web-std/file'

const serverIds = ['12D3KooWPRpVw8od6xtsGTjzoKkQMN2xdEnAssQi8mQeK1VTizKa'];
const serverIds = ['12D3KooWQnEmxzocejZTHHSP2VxWs9z93rzAjkiWo2xhXgaWcBbK'];

const testFile = new File(['test'], 'test', {
lastModified: 1639579330347,
Expand Down

0 comments on commit b28d859

Please sign in to comment.