mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-04-25 09:52:12 +00:00
Allow ws transport (#37)
This commit is contained in:
parent
15e645c2d5
commit
480c8aa850
6
package-lock.json
generated
6
package-lock.json
generated
@ -435,9 +435,9 @@
|
||||
}
|
||||
},
|
||||
"@fluencelabs/aquamarine-interpreter": {
|
||||
"version": "0.7.9",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aquamarine-interpreter/-/aquamarine-interpreter-0.7.9.tgz",
|
||||
"integrity": "sha512-VXbHm0d05XMjTSzOTcb+spVRrIuMcrw8/3dl197wH0jx1C3Wou+vAapQLvGNcKzqDhktPOOzJTE4UARYd0lFMw=="
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aquamarine-interpreter/-/aquamarine-interpreter-0.8.0.tgz",
|
||||
"integrity": "sha512-EoHqReMk6gqcBR8ZJuurXbCyB3t6vrOjsEBX5XgVhdfSYrUvmBvmKy4Elq5ONY2JVec9HCR/n/SfTuxYsnY8PQ=="
|
||||
},
|
||||
"@istanbuljs/load-nyc-config": {
|
||||
"version": "1.1.0",
|
||||
|
@ -5,10 +5,10 @@
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "jest --watch",
|
||||
"test:all": "jest",
|
||||
"test:unit": "jest --testPathPattern=src/__test__/unit",
|
||||
"test:integration": "jest --testPathPattern=src/__test__/integration",
|
||||
"test": "jest --env=jsdom --watch",
|
||||
"test:all": "jest --env=jsdom",
|
||||
"test:unit": "jest --env=jsdom --testPathPattern=src/__test__/unit",
|
||||
"test:integration": "jest --env=jsdom --testPathPattern=src/__test__/integration",
|
||||
"build": "tsc"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
|
27
src/__test__/unit/WsTransport.spec.ts
Normal file
27
src/__test__/unit/WsTransport.spec.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import {FluenceConnection} from "../../internal/FluenceConnection";
|
||||
import Peer from "libp2p";
|
||||
import Multiaddr = require("multiaddr");
|
||||
import {generatePeerId} from "../../internal/peerIdUtils";
|
||||
|
||||
describe('Ws Transport', () => {
|
||||
// TODO: fix this test
|
||||
test.skip('Should work with ws schema', async () => {
|
||||
// arrange
|
||||
let multiaddr = new Multiaddr("/ip4/127.0.0.1/tcp/1234/ws/p2p/12D3KooWMJ78GJrtCxVUpjLEedbPtnLDxkFQJ2wuefEdrxq6zwSs");
|
||||
let peerId = await generatePeerId();
|
||||
const connection = new FluenceConnection(
|
||||
multiaddr,
|
||||
peerId,
|
||||
peerId,
|
||||
_ => {},
|
||||
);
|
||||
await (connection as any).createPeer();
|
||||
let node = (connection as any).node as Peer;
|
||||
|
||||
// act
|
||||
let transport = node.transportManager.transportForMultiaddr(multiaddr);
|
||||
|
||||
// assert
|
||||
expect(transport).not.toBeDefined();
|
||||
});
|
||||
});
|
@ -24,7 +24,7 @@ import { parseParticle, Particle, toPayload } from './particle';
|
||||
import { NOISE } from 'libp2p-noise';
|
||||
import PeerId from 'peer-id';
|
||||
import Multiaddr from 'multiaddr';
|
||||
import { options } from 'libp2p/src/keychain';
|
||||
import { all as allow_all } from 'libp2p-websockets/src/filters';
|
||||
|
||||
export const PROTOCOL_NAME = '/fluence/faas/1.0.0';
|
||||
|
||||
@ -76,20 +76,7 @@ export class FluenceConnection {
|
||||
}
|
||||
|
||||
async connect(options?: FluenceConnectionOptions) {
|
||||
let peerInfo = this.selfPeerId;
|
||||
this.node = await Peer.create({
|
||||
peerId: peerInfo,
|
||||
config: {},
|
||||
modules: {
|
||||
transport: [Websockets],
|
||||
streamMuxer: [Mplex],
|
||||
connEncryption: [NOISE],
|
||||
},
|
||||
dialer: {
|
||||
timeout: options?.dialTimeout,
|
||||
},
|
||||
});
|
||||
|
||||
await this.createPeer(options);
|
||||
await this.startReceiving();
|
||||
}
|
||||
|
||||
@ -100,6 +87,29 @@ export class FluenceConnection {
|
||||
// connection status. If `Disconnected`, it cannot be reconnected
|
||||
private status: Status = Status.Initializing;
|
||||
|
||||
private async createPeer(options?: FluenceConnectionOptions) {
|
||||
const peerInfo = this.selfPeerId;
|
||||
const transportKey = Websockets.prototype[Symbol.toStringTag]
|
||||
this.node = await Peer.create({
|
||||
peerId: peerInfo,
|
||||
modules: {
|
||||
transport: [Websockets],
|
||||
streamMuxer: [Mplex],
|
||||
connEncryption: [NOISE],
|
||||
},
|
||||
config: {
|
||||
transport: {
|
||||
[transportKey]: {
|
||||
filter: allow_all
|
||||
}
|
||||
}
|
||||
},
|
||||
dialer: {
|
||||
timeout: options?.dialTimeout,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private async startReceiving() {
|
||||
if (this.status === Status.Initializing) {
|
||||
await this.node.start();
|
||||
|
Loading…
x
Reference in New Issue
Block a user