Skip to content

Commit 8632147

Browse files
authored
Merge branch 'main' into dependabot/github_actions/codecov/codecov-action-5.3.1
2 parents 0fd5843 + a32fbeb commit 8632147

File tree

13 files changed

+163
-20
lines changed

13 files changed

+163
-20
lines changed

interop/firefox-version.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
"id": "firefox-js-libp2p-head",
33
"containerImageID": "firefox-js-libp2p-head",
44
"transports": [
5-
{
6-
"name": "webtransport",
7-
"onlyDial": true
8-
},
95
{
106
"name": "webrtc-direct",
117
"onlyDial": true

packages/auto-tls/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ It also requires the Identify protocol.
4343
import { noise } from '@chainsafe/libp2p-noise'
4444
import { yamux } from '@chainsafe/libp2p-yamux'
4545
import { autoTLS } from '@libp2p/auto-tls'
46+
import { autoNAT } from '@libp2p/autonat'
4647
import { identify } from '@libp2p/identify'
4748
import { keychain } from '@libp2p/keychain'
4849
import { webSockets } from '@libp2p/websockets'
@@ -65,6 +66,7 @@ const node = await createLibp2p({
6566
yamux()
6667
],
6768
services: {
69+
autoNAT: autoNAT(),
6870
autoTLS: autoTLS(),
6971
identify: identify(),
7072
keychain: keychain(),
@@ -76,7 +78,7 @@ const node = await createLibp2p({
7678

7779
console.info(node.getMultiaddrs())
7880
// includes public WSS address:
79-
// [ '/ip4/123.123.123.123/tcp/12345/wss ]
81+
// [ '/ip4/123.123.123.123/tcp/12345/tls/ws' ]
8082
```
8183

8284
# Install

packages/auto-tls/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* import { noise } from '@chainsafe/libp2p-noise'
2121
* import { yamux } from '@chainsafe/libp2p-yamux'
2222
* import { autoTLS } from '@libp2p/auto-tls'
23+
* import { autoNAT } from '@libp2p/autonat'
2324
* import { identify } from '@libp2p/identify'
2425
* import { keychain } from '@libp2p/keychain'
2526
* import { webSockets } from '@libp2p/websockets'
@@ -42,6 +43,7 @@
4243
* yamux()
4344
* ],
4445
* services: {
46+
* autoNAT: autoNAT(),
4547
* autoTLS: autoTLS(),
4648
* identify: identify(),
4749
* keychain: keychain(),
@@ -53,7 +55,7 @@
5355
*
5456
* console.info(node.getMultiaddrs())
5557
* // includes public WSS address:
56-
* // [ '/ip4/123.123.123.123/tcp/12345/wss ]
58+
* // [ '/ip4/123.123.123.123/tcp/12345/tls/ws ]
5759
* ```
5860
*/
5961

packages/interface/src/keys/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export interface Ed25519PrivateKey {
193193
readonly publicKey: Ed25519PublicKey
194194

195195
/**
196-
* The raw public key bytes
196+
* The raw private key bytes
197197
*/
198198
readonly raw: Uint8Array
199199

@@ -221,7 +221,7 @@ export interface Secp256k1PrivateKey {
221221
readonly publicKey: Secp256k1PublicKey
222222

223223
/**
224-
* The raw public key bytes
224+
* The raw private key bytes
225225
*/
226226
readonly raw: Uint8Array
227227

packages/metrics-opentelemetry/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
},
4949
"dependencies": {
5050
"@libp2p/interface": "^2.4.0",
51+
"@libp2p/utils": "^6.3.1",
5152
"@opentelemetry/api": "^1.9.0",
5253
"it-foreach": "^2.1.1",
5354
"it-stream-types": "^2.0.2"

packages/metrics-opentelemetry/src/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
*/
3535

3636
import { InvalidParametersError, serviceCapabilities } from '@libp2p/interface'
37+
import { isAsyncGenerator } from '@libp2p/utils/is-async-generator'
38+
import { isGenerator } from '@libp2p/utils/is-generator'
39+
import { isPromise } from '@libp2p/utils/is-promise'
3740
import { trace, metrics, context, SpanStatusCode } from '@opentelemetry/api'
3841
import each from 'it-foreach'
3942
import { OpenTelemetryCounterGroup } from './counter-group.js'
@@ -438,10 +441,6 @@ export function openTelemetryMetrics (init: OpenTelemetryMetricsInit = {}): (com
438441
return (components: OpenTelemetryComponents) => new OpenTelemetryMetrics(components, init)
439442
}
440443

441-
function isPromise <T = any> (obj?: any): obj is Promise<T> {
442-
return typeof obj?.then === 'function'
443-
}
444-
445444
async function wrapPromise (promise: Promise<any>, span: Span, attributes: TraceAttributes, options?: TraceFunctionOptions<any, any>): Promise<any> {
446445
return promise
447446
.then(res => {
@@ -458,10 +457,6 @@ async function wrapPromise (promise: Promise<any>, span: Span, attributes: Trace
458457
})
459458
}
460459

461-
function isGenerator (obj?: any): obj is Generator {
462-
return obj?.[Symbol.iterator] != null
463-
}
464-
465460
function wrapGenerator (gen: Generator, span: Span, attributes: TraceAttributes, options?: TraceGeneratorFunctionOptions<any, any, any>): Generator {
466461
const iter = gen[Symbol.iterator]()
467462
let index = 0
@@ -502,10 +497,6 @@ function wrapGenerator (gen: Generator, span: Span, attributes: TraceAttributes,
502497
return wrapped
503498
}
504499

505-
function isAsyncGenerator (obj?: any): obj is AsyncGenerator {
506-
return obj?.[Symbol.asyncIterator] != null
507-
}
508-
509500
function wrapAsyncGenerator (gen: AsyncGenerator, span: Span, attributes: TraceAttributes, options?: TraceGeneratorFunctionOptions<any, any, any>): AsyncGenerator {
510501
const iter = gen[Symbol.asyncIterator]()
511502
let index = 0

packages/utils/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@
8484
"types": "./dist/src/ip-port-to-multiaddr.d.ts",
8585
"import": "./dist/src/ip-port-to-multiaddr.js"
8686
},
87+
"./is-async-generator": {
88+
"types": "./dist/src/is-async-generator.d.ts",
89+
"import": "./dist/src/is-async-generator.js"
90+
},
91+
"./is-generator": {
92+
"types": "./dist/src/is-generator.d.ts",
93+
"import": "./dist/src/is-generator.js"
94+
},
8795
"./is-promise": {
8896
"types": "./dist/src/is-promise.d.ts",
8997
"import": "./dist/src/is-promise.js"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function isAsyncGenerator (obj: unknown): obj is AsyncGenerator {
2+
if (obj == null) {
3+
return false
4+
}
5+
6+
const asyncIterator = (obj as { [Symbol.asyncIterator]?: unknown })?.[
7+
Symbol.asyncIterator
8+
]
9+
10+
if (typeof asyncIterator !== 'function') {
11+
return false
12+
}
13+
14+
const instance = obj as { next?: unknown }
15+
return typeof instance.next === 'function'
16+
}

packages/utils/src/is-generator.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function isGenerator (obj: unknown): obj is Generator {
2+
if (obj == null) {
3+
return false
4+
}
5+
6+
const iterator = (obj as { [Symbol.iterator]?: unknown })?.[Symbol.iterator]
7+
8+
if (typeof iterator !== 'function') {
9+
return false
10+
}
11+
12+
const instance = obj as { next?: unknown }
13+
14+
return typeof instance.next === 'function'
15+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { expect } from 'aegir/chai'
2+
import { isAsyncGenerator } from '../src/is-async-generator.js'
3+
4+
describe('is-async-generator', () => {
5+
it('should return true if the value is an async generator', () => {
6+
async function * asyncGen (): AsyncGenerator<number> {
7+
yield 1
8+
}
9+
const asyncGenerator = asyncGen()
10+
expect(isAsyncGenerator(asyncGenerator)).to.be.true()
11+
12+
const asyncGenObj = (async function * () {
13+
yield 1
14+
})()
15+
expect(isAsyncGenerator(asyncGenObj)).to.be.true()
16+
})
17+
18+
it('should return false if the value is not an async generator', () => {
19+
expect(isAsyncGenerator(1)).to.be.false()
20+
expect(isAsyncGenerator('string')).to.be.false()
21+
expect(isAsyncGenerator({})).to.be.false()
22+
expect(isAsyncGenerator([])).to.be.false()
23+
expect(isAsyncGenerator(null)).to.be.false()
24+
expect(isAsyncGenerator(undefined)).to.be.false()
25+
expect(isAsyncGenerator(() => {})).to.be.false()
26+
expect(isAsyncGenerator(async () => {})).to.be.false()
27+
expect(
28+
isAsyncGenerator(function * () {
29+
yield 1
30+
})
31+
).to.be.false()
32+
expect(
33+
isAsyncGenerator(async function * () {
34+
yield 1
35+
})
36+
).to.be.false() // async generator function, not generator
37+
expect(isAsyncGenerator(Promise.resolve())).to.be.false()
38+
expect(isAsyncGenerator({ next: async () => {} })).to.be.false()
39+
expect(isAsyncGenerator({ [Symbol.asyncIterator]: () => {} })).to.be.false()
40+
})
41+
})

0 commit comments

Comments
 (0)