Skip to content

fix: use scoped logger #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions src/noise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { NoiseComponents } from './index.js'
import type { MetricsRegistry } from './metrics.js'
import type { HandshakeResult, ICrypto, INoiseConnection, KeyPair } from './types.js'
import type { MultiaddrConnection, SecuredConnection, PrivateKey, PublicKey, StreamMuxerFactory, SecureConnectionOptions } from '@libp2p/interface'
import type { MultiaddrConnection, SecuredConnection, PrivateKey, PublicKey, StreamMuxerFactory, SecureConnectionOptions, SecurableStream, Logger } from '@libp2p/interface'

Check failure on line 20 in src/noise.ts

View workflow job for this annotation

GitHub Actions / js-test-and-release / build

Module '"@libp2p/interface"' has no exported member 'SecurableStream'.
import type { LengthPrefixedStream } from 'it-length-prefixed-stream'
import type { Duplex } from 'it-stream-types'
import type { Uint8ArrayList } from 'uint8arraylist'
Expand Down Expand Up @@ -45,12 +45,14 @@
private readonly extensions?: NoiseExtensions
private readonly metrics?: MetricsRegistry
private readonly components: NoiseComponents
private readonly log: Logger

constructor (components: NoiseComponents, init: NoiseInit = {}) {
const { staticNoiseKey, extensions, crypto, prologueBytes } = init
const { metrics } = components

this.components = components
this.log = components.logger.forComponent('libp2p:noise')
const _crypto = crypto ?? defaultCrypto
this.crypto = wrapCrypto(_crypto)
this.extensions = {
Expand Down Expand Up @@ -83,7 +85,8 @@
* @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer
* @param options.signal - Used to abort the operation
*/
public async secureOutbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, NoiseExtensions>> {
public async secureOutbound <Stream extends SecurableStream = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, NoiseExtensions>> {
const log = connection.log?.newScope('noise') ?? this.log
const wrappedConnection = lpStream(
connection,
{
Expand All @@ -96,6 +99,7 @@
const handshake = await this.performHandshakeInitiator(
wrappedConnection,
this.components.privateKey,
log,
options?.remotePeer?.publicKey,
options
)
Expand Down Expand Up @@ -144,7 +148,8 @@
* @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer
* @param options.signal - Used to abort the operation
*/
public async secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, NoiseExtensions>> {
public async secureInbound <Stream extends SecurableStream = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, NoiseExtensions>> {
const log = connection.log?.newScope('noise') ?? this.log
const wrappedConnection = lpStream(
connection,
{
Expand All @@ -157,6 +162,7 @@
const handshake = await this.performHandshakeResponder(
wrappedConnection,
this.components.privateKey,
log,
options?.remotePeer?.publicKey,
options
)
Expand All @@ -182,6 +188,7 @@
connection: LengthPrefixedStream,
// TODO: pass private key in noise constructor via Components
privateKey: PrivateKey,
log: Logger,
remoteIdentityKey?: PublicKey,
options?: SecureConnectionOptions
): Promise<HandshakeResult> {
Expand All @@ -193,7 +200,7 @@
connection,
privateKey,
remoteIdentityKey,
log: this.components.logger.forComponent('libp2p:noise:xxhandshake'),
log: log.newScope('xxhandshake'),

Check failure on line 203 in src/noise.ts

View workflow job for this annotation

GitHub Actions / js-test-and-release / build

Property 'newScope' does not exist on type 'Logger'.
crypto: this.crypto,
prologue: this.prologue,
s: this.staticKey,
Expand All @@ -218,6 +225,7 @@
private async performHandshakeResponder (
connection: LengthPrefixedStream,
privateKey: PrivateKey,
log: Logger,
remoteIdentityKey?: PublicKey,
options?: SecureConnectionOptions
): Promise<HandshakeResult> {
Expand All @@ -229,7 +237,7 @@
connection,
privateKey,
remoteIdentityKey,
log: this.components.logger.forComponent('libp2p:noise:xxhandshake'),
log: log.newScope('xxhandshake'),

Check failure on line 240 in src/noise.ts

View workflow job for this annotation

GitHub Actions / js-test-and-release / build

Property 'newScope' does not exist on type 'Logger'.
crypto: this.crypto,
prologue: this.prologue,
s: this.staticKey,
Expand Down
Loading