Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

fix: use trace logging for happy paths #59

Merged
merged 1 commit into from
Apr 17, 2023
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
8 changes: 4 additions & 4 deletions src/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ export async function handle (stream: Duplex<any>, protocols: string | string[],

while (true) {
const protocol = await multistream.readString(reader, options)
log('read "%s"', protocol)
log.trace('read "%s"', protocol)

if (protocol === PROTOCOL_ID) {
log('respond with "%s" for "%s"', PROTOCOL_ID, protocol)
log.trace('respond with "%s" for "%s"', PROTOCOL_ID, protocol)
multistream.write(writer, uint8ArrayFromString(PROTOCOL_ID), options)
continue
}

if (protocols.includes(protocol)) {
multistream.write(writer, uint8ArrayFromString(protocol), options)
log('respond with "%s" for "%s"', protocol, protocol)
log.trace('respond with "%s" for "%s"', protocol, protocol)
rest()
return { stream: shakeStream, protocol }
}
Expand All @@ -82,7 +82,7 @@ export async function handle (stream: Duplex<any>, protocols: string | string[],
// <varint-msg-len><varint-proto-name-len><proto-name>\n<varint-proto-name-len><proto-name>\n\n
multistream.write(writer, new Uint8ArrayList(...protocols.map(p => multistream.encode(uint8ArrayFromString(p)))), options)
// multistream.writeAll(writer, protocols.map(p => uint8ArrayFromString(p)))
log('respond with "%s" for %s', protocols, protocol)
log.trace('respond with "%s" for %s', protocols, protocol)
continue
}

Expand Down
10 changes: 5 additions & 5 deletions src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ export async function select (stream: Duplex<any>, protocols: string | string[],
throw new Error('At least one protocol must be specified')
}

log('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
log.trace('select: write ["%s", "%s"]', PROTOCOL_ID, protocol)
const p1 = uint8ArrayFromString(PROTOCOL_ID)
const p2 = uint8ArrayFromString(protocol)
multistream.writeAll(writer, [p1, p2], options)

let response = await multistream.readString(reader, options)
log('select: read "%s"', response)
log.trace('select: read "%s"', response)

// Read the protocol response if we got the protocolId in return
if (response === PROTOCOL_ID) {
response = await multistream.readString(reader, options)
log('select: read "%s"', response)
log.trace('select: read "%s"', response)
}

// We're done
Expand All @@ -90,10 +90,10 @@ export async function select (stream: Duplex<any>, protocols: string | string[],

// We haven't gotten a valid ack, try the other protocols
for (const protocol of protocols) {
log('select: write "%s"', protocol)
log.trace('select: write "%s"', protocol)
multistream.write(writer, uint8ArrayFromString(protocol), options)
const response = await multistream.readString(reader, options)
log('select: read "%s" for "%s"', response, protocol)
log.trace('select: read "%s" for "%s"', response, protocol)

if (response === protocol) {
rest() // End our writer so others can start writing to stream
Expand Down