Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- '**'

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn lint
- run: yarn prebuild
- run: yarn aegir dep-check
test-node:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [12]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: yarn
- run: yarn prebuild
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
- uses: codecov/codecov-action@v1
test-chrome:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn prebuild
- run: npx aegir test -t browser -t webworker --bail
test-firefox:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn prebuild
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
node_modules/
src/
package-lock.json
dist/
docs/
49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"denque": "^1.4.1",
"err-code": "^2.0.0",
"it-pipe": "^1.0.1",
"libp2p-interfaces": "^0.7.2",
"libp2p-interfaces": "^0.8.0",
"peer-id": "^0.14.0",
"protons": "^2.0.0",
"time-cache": "^0.3.0",
Expand All @@ -51,7 +51,7 @@
"@types/mocha": "^7.0.2",
"@typescript-eslint/eslint-plugin": "^3.0.2",
"@typescript-eslint/parser": "^3.0.2",
"aegir": "^26.0.0",
"aegir": "^28.0.0",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"chai-spies": "^1.0.0",
Expand All @@ -65,8 +65,9 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"it-pair": "^1.0.0",
"libp2p": "^0.29.0",
"libp2p-floodsub": "^0.23.0",
"karma-mocha-webworker": "^1.3.0",
"libp2p": "^0.30.0",
"libp2p-floodsub": "^0.24.1",
"libp2p-mplex": "^0.10.0",
"libp2p-noise": "^2.0.0",
"libp2p-websockets": "^0.14.0",
Expand All @@ -78,10 +79,10 @@
"p-wait-for": "^3.1.0",
"promisify-es6": "^1.0.3",
"sinon": "^9.0.2",
"typescript": "^3.9.3"
"typescript": "4.0.x"
},
"peerDependencies": {
"libp2p": "^0.29.0"
"libp2p": "^0.30.0"
},
"contributors": [
"Cayman <caymannava@gmail.com>",
Expand Down
27 changes: 15 additions & 12 deletions ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { getGossipPeers } from './get-gossip-peers'
import { createGossipRpc, shuffle, hasGossipProtocol, messageIdToString } from './utils'
import { PeerScore, PeerScoreParams, PeerScoreThresholds, createPeerScoreParams, createPeerScoreThresholds } from './score'
import { IWantTracer } from './tracer'
import { AddrInfo, Libp2p, EnvelopeClass, MessageIdFunction } from './interfaces'
import { AddrInfo, MessageIdFunction } from './interfaces'
import { Debugger } from 'debug'
import Libp2p from 'libp2p'

import PeerStreams from 'libp2p-interfaces/src/pubsub/peer-streams'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand All @@ -25,13 +26,14 @@ import Envelope = require('libp2p/src/record/envelope')

interface GossipInputOptions {
emitSelf: boolean
canRelayMessage: boolean
gossipIncoming: boolean
fallbackToFloodsub: boolean
floodPublish: boolean
doPX: boolean
msgIdFn: MessageIdFunction
messageCache: MessageCache
globalSignaturePolicy: string
globalSignaturePolicy: 'StrictSign' | 'StrictNoSign' | undefined
scoreParams: Partial<PeerScoreParams>
scoreThresholds: Partial<PeerScoreThresholds>
directPeers: AddrInfo[]
Expand Down Expand Up @@ -96,21 +98,22 @@ class Gossipsub extends Pubsub {
_directPeerInitial: NodeJS.Timeout
log: Debugger
// eslint-disable-next-line @typescript-eslint/ban-types
emit: (...args: any) => void
emit: (event: string | symbol, ...args: any[]) => boolean

public static multicodec: string = constants.GossipsubIDv11

// TODO: add remaining props
/**
* @param {Libp2p} libp2p
* @param {Object} [options]
* @param {bool} [options.emitSelf] if publish should emit to self, if subscribed, defaults to false
* @param {bool} [options.gossipIncoming] if incoming messages on a subscribed topic should be automatically gossiped, defaults to true
* @param {bool} [options.fallbackToFloodsub] if dial should fallback to floodsub, defaults to true
* @param {bool} [options.floodPublish] if self-published messages should be sent to all peers, defaults to true
* @param {bool} [options.doPX] whether PX is enabled; this should be enabled in bootstrappers and other well connected/trusted nodes. defaults to false
* @param {boolean} [options.emitSelf = false] if publish should emit to self, if subscribed
* @param {boolean} [options.canRelayMessage = false] - if can relay messages not subscribed
* @param {boolean} [options.gossipIncoming = true] if incoming messages on a subscribed topic should be automatically gossiped
* @param {boolean} [options.fallbackToFloodsub = true] if dial should fallback to floodsub
* @param {boolean} [options.floodPublish = true] if self-published messages should be sent to all peers
* @param {boolean} [options.doPX = false] whether PX is enabled; this should be enabled in bootstrappers and other well connected/trusted nodes.
* @param {Object} [options.messageCache] override the default MessageCache
* @param {string} [options.globalSignaturePolicy] signing policy to apply across all messages (default: "StrictSign")
* @param {string} [options.globalSignaturePolicy = "StrictSign"] signing policy to apply across all messages
* @param {Object} [options.scoreParams] peer score parameters
* @param {Object} [options.scoreThresholds] peer score thresholds
* @param {AddrInfo[]} [options.directPeers] peers with which we will maintain direct connections
Expand Down Expand Up @@ -322,9 +325,9 @@ class Gossipsub extends Pubsub {
* Removes a peer from the router
* @override
* @param {PeerId} peer
* @returns {Peer}
* @returns {PeerStreams | undefined}
*/
_removePeer (peerId: PeerId): PeerStreams {
_removePeer (peerId: PeerId): PeerStreams | undefined {
const peerStreams = super._removePeer(peerId)
const id = peerId.toB58String()

Expand Down Expand Up @@ -839,7 +842,7 @@ class Gossipsub extends Pubsub {
// This is not a record from the peer who sent the record, but another peer who is connected with it
// Ensure that it is valid
try {
const envelope = await (Envelope as EnvelopeClass).openAndCertify(pi.signedPeerRecord, 'libp2p-peer-record')
const envelope = await Envelope.openAndCertify(pi.signedPeerRecord, 'libp2p-peer-record')
const eid = envelope.peerId.toB58String()
if (id !== eid) {
this.log(
Expand Down
64 changes: 0 additions & 64 deletions ts/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,9 @@ import { InMessage } from 'libp2p-interfaces/src/pubsub'
import PeerId = require('peer-id')
import Multiaddr = require('multiaddr')

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface DuplexIterableStream<T=any, U=any, V=any> {
sink(source: T): Promise<U>
source(): AsyncIterator<V>
}

export interface Connection {
remoteAddr: Multiaddr
remotePeer: PeerId
stat: {
direction: 'inbound' | 'outbound'
}
registry: Map<string, {protocol: string}>
}

export interface ConnectionManager {
getAll(peerId: PeerId): Connection[]
}

export interface AddrInfo {
id: PeerId
addrs: Multiaddr[]
}

export interface Registrar {
handle (): void
register (): void
unregister (): void
}

export interface Envelope {
peerId: PeerId
payloadType: Uint8Array
payload: Uint8Array
signature: Uint8Array

marshal(): Uint8Array
isEqual(other: Envelope): boolean
validate(domain: string): Promise<boolean>
}

export interface EnvelopeClass {
openAndCertify(data: Uint8Array, domain: string): Promise<Envelope>
}

interface Book<K, V> {
add(k: K, v: V): this
set(k: K, v: V[]): this
get(k: K): V[]
}

export interface AddressBook extends Book<PeerId, Multiaddr[]> {
consumePeerRecord(envelope: Envelope): boolean
getRawEnvelope(peerId: PeerId): Uint8Array | undefined
}

export interface PeerStore {
addressBook: AddressBook
}

export interface Libp2p {
peerId: PeerId
// eslint-disable-next-line @typescript-eslint/ban-types
dialProtocol(peer: PeerId | Multiaddr | string, protocols: string | string[], options?: object): Promise<{stream: DuplexIterableStream, protocol: string}>
connectionManager: ConnectionManager
registrar: Registrar
peerStore: PeerStore
}

export type MessageIdFunction = (msg: InMessage) => Uint8Array;
3 changes: 2 additions & 1 deletion ts/score/peer-score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { PeerScoreParams, validatePeerScoreParams } from './peer-score-params'
import { PeerStats, createPeerStats, ensureTopicStats } from './peer-stats'
import { computeScore } from './compute-score'
import { MessageDeliveries, DeliveryRecordStatus } from './message-deliveries'
import { ConnectionManager, MessageIdFunction } from '../interfaces'
import { MessageIdFunction } from '../interfaces'
import { ERR_TOPIC_VALIDATOR_IGNORE } from '../constants'
import PeerId from 'peer-id'
import ConnectionManager from 'libp2p/src/connection-manager'
import { InMessage } from 'libp2p-interfaces/src/pubsub'
import debug = require('debug')
import pubsubErrors = require('libp2p-interfaces/src/pubsub/errors')
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
"es6", "dom"
],
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"skipLibCheck": true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that typescript@4.1.3 released yesterday broke a type def... Still need to check, we have been experiencing a lot of issues with typescript releases changing outputs of ts declaration files generated.

"esModuleInterop": true,
"outDir": "./src",
"declaration": true,
"types": [
"node"
],
]
},
"include": [
"./ts"
Expand Down