Skip to content

Commit

Permalink
Merge branch 'master' into weboko/fleet-test
Browse files Browse the repository at this point in the history
  • Loading branch information
weboko authored Jul 26, 2023
2 parents be928f7 + 9223813 commit b353f74
Show file tree
Hide file tree
Showing 28 changed files with 651 additions and 182 deletions.
20 changes: 10 additions & 10 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"packages/utils": "0.0.8",
"packages/utils": "0.0.9",
"packages/proto": "0.0.5",
"packages/interfaces": "0.0.15",
"packages/message-hash": "0.1.4",
"packages/enr": "0.0.14",
"packages/peer-exchange": "0.0.13",
"packages/core": "0.0.20",
"packages/dns-discovery": "0.0.14",
"packages/message-encryption": "0.0.18",
"packages/relay": "0.0.3",
"packages/sdk": "0.0.16"
"packages/interfaces": "0.0.16",
"packages/message-hash": "0.1.5",
"packages/enr": "0.0.15",
"packages/peer-exchange": "0.0.14",
"packages/core": "0.0.21",
"packages/dns-discovery": "0.0.15",
"packages/message-encryption": "0.0.19",
"packages/relay": "0.0.4",
"packages/sdk": "0.0.17"
}
25 changes: 12 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
The file is maintained by [Release Please](https://github.com/googleapis/release-please) based on [Conventional Commits](https://www.conventionalcommits.org) specification,
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.21](https://github.com/waku-org/js-waku/compare/core-v0.0.20...core-v0.0.21) (2023-07-26)


### ⚠ BREAKING CHANGES

* remove filter v1 ([#1433](https://github.com/waku-org/js-waku/issues/1433))
* upgrade to [email protected] ([#1400](https://github.com/waku-org/js-waku/issues/1400))

### Features

* Enable event emission for peer discovery/connection in ConnectionManager ([#1438](https://github.com/waku-org/js-waku/issues/1438)) ([6ce898d](https://github.com/waku-org/js-waku/commit/6ce898d77132f30b5d8f33b48c7f6276992a486e))
* Spec test for connection manager ([#1417](https://github.com/waku-org/js-waku/issues/1417)) ([d2f675d](https://github.com/waku-org/js-waku/commit/d2f675d690f4a648dc7294455891f2d66a49ea76))
* Upgrade to [email protected] ([#1400](https://github.com/waku-org/js-waku/issues/1400)) ([420e6c6](https://github.com/waku-org/js-waku/commit/420e6c698dd8f44d40d34e47d876da5d2e1ce85e))


### Miscellaneous Chores

* Remove filter v1 ([#1433](https://github.com/waku-org/js-waku/issues/1433)) ([d483644](https://github.com/waku-org/js-waku/commit/d483644a4bb4350df380719b9bcfbdd0b1439482))


### Dependencies

* The following workspace dependencies were updated
* dependencies
* @waku/interfaces bumped from 0.0.15 to 0.0.16
* @waku/utils bumped from 0.0.8 to 0.0.9

## [0.0.20](https://github.com/waku-org/js-waku/compare/core-v0.0.19...core-v0.0.20) (2023-06-08)


Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@waku/core",
"version": "0.0.20",
"version": "0.0.21",
"description": "TypeScript implementation of the Waku v2 protocol",
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
Expand Down Expand Up @@ -73,9 +73,9 @@
},
"dependencies": {
"@noble/hashes": "^1.3.0",
"@waku/interfaces": "0.0.15",
"@waku/interfaces": "0.0.16",
"@waku/proto": "0.0.5",
"@waku/utils": "0.0.8",
"@waku/utils": "0.0.9",
"debug": "^4.3.4",
"it-all": "^3.0.2",
"it-length-prefixed": "^9.0.1",
Expand Down
99 changes: 97 additions & 2 deletions packages/core/src/lib/connection_manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import type { PeerId } from "@libp2p/interface-peer-id";
import type { PeerInfo } from "@libp2p/interface-peer-info";
import type { ConnectionManagerOptions, IRelay } from "@waku/interfaces";
import type { Peer } from "@libp2p/interface-peer-store";
import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events";
import {
ConnectionManagerOptions,
EPeersByDiscoveryEvents,
IPeersByDiscoveryEvents,
IRelay,
PeersByDiscoveryResult,
} from "@waku/interfaces";
import { Libp2p, Tags } from "@waku/interfaces";
import debug from "debug";

Expand All @@ -12,7 +20,7 @@ export const DEFAULT_MAX_BOOTSTRAP_PEERS_ALLOWED = 1;
export const DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER = 3;
export const DEFAULT_MAX_PARALLEL_DIALS = 3;

export class ConnectionManager {
export class ConnectionManager extends EventEmitter<IPeersByDiscoveryEvents> {
private static instances = new Map<string, ConnectionManager>();
private keepAliveManager: KeepAliveManager;
private options: ConnectionManagerOptions;
Expand Down Expand Up @@ -44,12 +52,57 @@ export class ConnectionManager {
return instance;
}

public async getPeersByDiscovery(): Promise<PeersByDiscoveryResult> {
const peersDiscovered = await this.libp2p.peerStore.all();
const peersConnected = this.libp2p
.getConnections()
.map((conn) => conn.remotePeer);

const peersDiscoveredByBootstrap: Peer[] = [];
const peersDiscoveredByPeerExchange: Peer[] = [];
const peersConnectedByBootstrap: Peer[] = [];
const peersConnectedByPeerExchange: Peer[] = [];

for (const peer of peersDiscovered) {
const tags = await this.getTagNamesForPeer(peer.id);

if (tags.includes(Tags.BOOTSTRAP)) {
peersDiscoveredByBootstrap.push(peer);
} else if (tags.includes(Tags.PEER_EXCHANGE)) {
peersDiscoveredByPeerExchange.push(peer);
}
}

for (const peerId of peersConnected) {
const peer = await this.libp2p.peerStore.get(peerId);
const tags = await this.getTagNamesForPeer(peerId);

if (tags.includes(Tags.BOOTSTRAP)) {
peersConnectedByBootstrap.push(peer);
} else if (tags.includes(Tags.PEER_EXCHANGE)) {
peersConnectedByPeerExchange.push(peer);
}
}

return {
DISCOVERED: {
[Tags.BOOTSTRAP]: peersDiscoveredByBootstrap,
[Tags.PEER_EXCHANGE]: peersDiscoveredByPeerExchange,
},
CONNECTED: {
[Tags.BOOTSTRAP]: peersConnectedByBootstrap,
[Tags.PEER_EXCHANGE]: peersConnectedByPeerExchange,
},
};
}

private constructor(
libp2p: Libp2p,
keepAliveOptions: KeepAliveOptions,
relay?: IRelay,
options?: Partial<ConnectionManagerOptions>
) {
super();
this.libp2p = libp2p;
this.options = {
maxDialAttemptsForPeer: DEFAULT_MAX_DIAL_ATTEMPTS_FOR_PEER,
Expand Down Expand Up @@ -240,6 +293,30 @@ export class ConnectionManager {
void (async () => {
const { id: peerId } = evt.detail;

const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(
Tags.BOOTSTRAP
);

if (isBootstrap) {
this.dispatchEvent(
new CustomEvent<PeerId>(
EPeersByDiscoveryEvents.PEER_DISCOVERY_BOOTSTRAP,
{
detail: peerId,
}
)
);
} else {
this.dispatchEvent(
new CustomEvent<PeerId>(
EPeersByDiscoveryEvents.PEER_DISCOVERY_PEER_EXCHANGE,
{
detail: peerId,
}
)
);
}

try {
await this.attemptDial(peerId);
} catch (error) {
Expand Down Expand Up @@ -267,7 +344,25 @@ export class ConnectionManager {
bootstrapConnections.length > this.options.maxBootstrapPeersAllowed
) {
await this.dropConnection(peerId);
} else {
this.dispatchEvent(
new CustomEvent<PeerId>(
EPeersByDiscoveryEvents.PEER_CONNECT_BOOTSTRAP,
{
detail: peerId,
}
)
);
}
} else {
this.dispatchEvent(
new CustomEvent<PeerId>(
EPeersByDiscoveryEvents.PEER_CONNECT_PEER_EXCHANGE,
{
detail: peerId,
}
)
);
}
})();
},
Expand Down
21 changes: 21 additions & 0 deletions packages/dns-discovery/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* devDependencies
* @waku/interfaces bumped from 0.0.13 to 0.0.14

## [0.0.15](https://github.com/waku-org/js-waku/compare/dns-discovery-v0.0.14...dns-discovery-v0.0.15) (2023-07-26)


### ⚠ BREAKING CHANGES

* upgrade to [email protected] ([#1400](https://github.com/waku-org/js-waku/issues/1400))

### Features

* Upgrade to [email protected] ([#1400](https://github.com/waku-org/js-waku/issues/1400)) ([420e6c6](https://github.com/waku-org/js-waku/commit/420e6c698dd8f44d40d34e47d876da5d2e1ce85e))


### Dependencies

* The following workspace dependencies were updated
* dependencies
* @waku/enr bumped from 0.0.14 to 0.0.15
* @waku/utils bumped from 0.0.8 to 0.0.9
* devDependencies
* @waku/interfaces bumped from 0.0.15 to 0.0.16

## [0.0.14](https://github.com/waku-org/js-waku/compare/dns-discovery-v0.0.13...dns-discovery-v0.0.14) (2023-06-08)


Expand Down
10 changes: 5 additions & 5 deletions packages/dns-discovery/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@waku/dns-discovery",
"version": "0.0.14",
"version": "0.0.15",
"description": "DNS Peer Discovery (EIP-1459)",
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
Expand Down Expand Up @@ -53,12 +53,12 @@
"dependencies": {
"@libp2p/interface-peer-discovery": "^2.0.0",
"@libp2p/interfaces": "^3.3.2",
"@waku/enr": "0.0.14",
"@waku/utils": "0.0.8",
"@waku/enr": "0.0.15",
"@waku/utils": "0.0.9",
"debug": "^4.3.4",
"dns-query": "^0.11.2",
"hi-base32": "^0.5.1",
"uint8arrays": "^4.0.3"
"uint8arrays": "^4.0.4"
},
"devDependencies": {
"@libp2p/interface-peer-info": "^1.0.10",
Expand All @@ -71,7 +71,7 @@
"@rollup/plugin-node-resolve": "^15.0.2",
"@types/chai": "^4.3.4",
"@waku/build-utils": "*",
"@waku/interfaces": "0.0.15",
"@waku/interfaces": "0.0.16",
"chai": "^4.3.7",
"cspell": "^6.31.1",
"karma": "^6.4.1",
Expand Down
20 changes: 20 additions & 0 deletions packages/enr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* devDependencies
* @waku/interfaces bumped from 0.0.14 to 0.0.15

## [0.0.15](https://github.com/waku-org/js-waku/compare/enr-v0.0.14...enr-v0.0.15) (2023-07-26)


### ⚠ BREAKING CHANGES

* upgrade to [email protected] ([#1400](https://github.com/waku-org/js-waku/issues/1400))

### Features

* Upgrade to [email protected] ([#1400](https://github.com/waku-org/js-waku/issues/1400)) ([420e6c6](https://github.com/waku-org/js-waku/commit/420e6c698dd8f44d40d34e47d876da5d2e1ce85e))


### Dependencies

* The following workspace dependencies were updated
* dependencies
* @waku/utils bumped from 0.0.8 to 0.0.9
* devDependencies
* @waku/interfaces bumped from 0.0.15 to 0.0.16

## [0.0.12](https://github.com/waku-org/js-waku/compare/enr-v0.0.11...enr-v0.0.12) (2023-05-18)


Expand Down
Loading

0 comments on commit b353f74

Please sign in to comment.