This commit is contained in:
Pavel Murygin 2022-05-13 12:52:56 +03:00
parent 3a88fd9177
commit bf7b523660
5 changed files with 1017 additions and 3757 deletions

4721
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,31 +24,30 @@
"copy-marine": "dist/tools/copyMarine.js" "copy-marine": "dist/tools/copyMarine.js"
}, },
"dependencies": { "dependencies": {
"@chainsafe/libp2p-noise": "^4.1.1", "@chainsafe/libp2p-noise": "6.1.1",
"@fluencelabs/avm": "0.24.2", "@fluencelabs/avm": "0.24.2",
"@fluencelabs/marine-js": "0.2.5", "@fluencelabs/marine-js": "0.2.5",
"async": "3.2.0", "async": "3.2.0",
"browser-or-node": "^2.0.0", "browser-or-node": "^2.0.0",
"bs58": "4.0.1", "bs58": "4.0.1",
"buffer": "^6.0.3", "buffer": "^6.0.3",
"cids": "0.8.1", "cids": "1.1.9",
"it-length-prefixed": "3.0.1", "it-length-prefixed": "7.0.1",
"it-pipe": "1.1.0", "it-pipe": "2.0.3",
"libp2p": "=0.33.0", "libp2p": "0.36.2",
"libp2p-crypto": "=0.20.0", "libp2p-crypto": "0.21.2",
"libp2p-mplex": "=0.10.2", "libp2p-mplex": "0.10.7",
"libp2p-websockets": "^0.16.2", "libp2p-websockets": "0.16.2",
"loglevel": "1.7.0", "loglevel": "1.7.0",
"multiaddr": "^10.0.1", "multiaddr": "10.0.1",
"multiformats": "^9.6.4", "multiformats": "9.6.5",
"peer-id": "=0.15.4", "peer-id": "0.16.0",
"platform": "^1.3.6", "platform": "^1.3.6",
"rxjs": "^7.3.0", "rxjs": "^7.3.0",
"ts-pattern": "^3.3.3", "ts-pattern": "^3.3.3",
"uuid": "8.3.0" "uuid": "8.3.0"
}, },
"devDependencies": { "devDependencies": {
"@fluencelabs/aqua": "^0.7.0-285",
"@fluencelabs/aqua-lib": "^0.4.3", "@fluencelabs/aqua-lib": "^0.4.3",
"@fluencelabs/fluence-network-environment": "^1.0.13", "@fluencelabs/fluence-network-environment": "^1.0.13",
"@types/jest": "^26.0.22", "@types/jest": "^26.0.22",

View File

@ -16,19 +16,16 @@
import Websockets from 'libp2p-websockets'; import Websockets from 'libp2p-websockets';
import Mplex from 'libp2p-mplex'; import Mplex from 'libp2p-mplex';
import Lib2p2Peer, { MuxedStream } from 'libp2p'; import Lib2p2Peer from 'libp2p';
import { decode, encode } from 'it-length-prefixed'; import { decode, encode } from 'it-length-prefixed';
import pipe from 'it-pipe'; import { pipe } from 'it-pipe';
import * as log from 'loglevel'; import * as log from 'loglevel';
import { Particle } from './Particle'; import { Particle } from './Particle';
import { NOISE } from '@chainsafe/libp2p-noise'; import { NOISE } from '@chainsafe/libp2p-noise';
import PeerId from 'peer-id';
import { Multiaddr } from 'multiaddr'; import { Multiaddr } from 'multiaddr';
import { all as allow_all } from 'libp2p-websockets/src/filters'; import { all as allow_all } from 'libp2p-websockets/src/filters';
import { Connection } from 'libp2p-interfaces/src/topology'; import { Connection } from 'libp2p-interfaces/src/topology';
import Buffer from './Buffer'; import Buffer from './Buffer';
import ConnectionManager from 'libp2p/src/connection-manager';
import { single } from 'rxjs';
export const PROTOCOL_NAME = '/fluence/particle/2.0.0'; export const PROTOCOL_NAME = '/fluence/particle/2.0.0';
@ -39,7 +36,7 @@ export interface FluenceConnectionOptions {
/** /**
* Peer id of the Fluence Peer * Peer id of the Fluence Peer
*/ */
peerId: PeerId; peerId: any;
/** /**
* Multiaddress of the relay to make connection to * Multiaddress of the relay to make connection to
@ -69,7 +66,7 @@ export class FluenceConnection {
modules: { modules: {
transport: [Websockets], transport: [Websockets],
streamMuxer: [Mplex], streamMuxer: [Mplex],
connEncryption: [NOISE], connEncryption: [NOISE as any],
}, },
config: { config: {
transport: { transport: {
@ -90,6 +87,7 @@ export class FluenceConnection {
pipe( pipe(
// force new line // force new line
stream.source, stream.source,
// @ts-ignore
decode(), decode(),
async (source: AsyncIterable<string>) => { async (source: AsyncIterable<string>) => {
try { try {
@ -177,10 +175,11 @@ export class FluenceConnection {
const { stream } = await this._connection.newStream(PROTOCOL_NAME); const { stream } = await this._connection.newStream(PROTOCOL_NAME);
const sink = stream.sink; const sink = stream.sink;
stream.pipe( pipe(
// force new line // force new line
[Buffer.from(particle.toString(), 'utf8')], [Buffer.from(particle.toString(), 'utf8')],
encode(), encode(),
// @ts-ignore
sink, sink,
); );
@ -212,7 +211,7 @@ export class FluenceConnection {
} }
} }
private _outStream: MuxedStream; // private _outStream: MuxedStream;
private _lib2p2Peer: Lib2p2Peer; private _lib2p2Peer: Lib2p2Peer;
private _connection: Connection; private _connection: Connection;
private _relayAddress: Multiaddr; private _relayAddress: Multiaddr;

View File

@ -14,16 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
import * as PeerId from 'peer-id'; import PeerId from 'peer-id';
import { keys } from 'libp2p-crypto'; import { keys } from 'libp2p-crypto';
export class KeyPair { export class KeyPair {
/** /**
* Key pair in libp2p format. Used for backward compatibility with the current FluencePeer implementation * Key pair in libp2p format. Used for backward compatibility with the current FluencePeer implementation
*/ */
public Libp2pPeerId: PeerId; public Libp2pPeerId: any;
constructor(libp2pPeerId: PeerId) { constructor(libp2pPeerId: any) {
this.Libp2pPeerId = libp2pPeerId; this.Libp2pPeerId = libp2pPeerId;
} }

View File

@ -1,9 +1,5 @@
{ {
"compilerOptions": { "compilerOptions": {
"typeRoots": [
"./node_modules/@types",
"./node_modules/libp2p-ts/types",
],
"outDir": "./dist/", "outDir": "./dist/",
"baseUrl": ".", "baseUrl": ".",
"downlevelIteration": true, "downlevelIteration": true,
@ -13,7 +9,7 @@
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"pretty": true, "pretty": true,
"target": "ES5", "target": "ES6",
"module": "commonjs", "module": "commonjs",
"moduleResolution": "node", "moduleResolution": "node",
"declaration": true, "declaration": true,
@ -23,6 +19,7 @@
"noImplicitAny": false, "noImplicitAny": false,
"alwaysStrict": true, "alwaysStrict": true,
"noImplicitThis": true, "noImplicitThis": true,
"skipLibCheck": true,
"strictNullChecks": false "strictNullChecks": false
}, },
"exclude": [ "exclude": [