Skip to content

Commit

Permalink
Use robots suggestion for cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Dec 16, 2024
1 parent 9096665 commit 816b4f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
5 changes: 2 additions & 3 deletions packages/portalnetwork/src/wire/utp/Socket/ContentReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ export class ContentReader {
}

readPacket(payload: Uint8Array) {
this.nextDataNr!++
// Reset to 0 since ackNr and seqNr are 16 bit unsigned integers
if (this.nextDataNr! > 65535) this.nextDataNr! = 0
// Wrap seqNr back to 0 when it exceeds 16-bit max integer
this.nextDataNr! = (this.nextDataNr! + 1) % 65536
this.bytes.push(...payload)
this.logger.extend('BYTES')(
`Current stream: ${this.bytes.length} / ${this.bytesExpected} bytes. ${this.bytesExpected - this.bytes.length} bytes till end of content.`,
Expand Down
12 changes: 3 additions & 9 deletions packages/portalnetwork/src/wire/utp/Socket/ContentWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ export class ContentWriter {
this.logger(
`Sending ST-DATA ${this.sentChunks.length}/${totalChunks} -- SeqNr: ${this.seqNr}`,
)
this.seqNr = this.sentChunks.slice(-1)[0] + 1
// Reset to 0 since ackNr and seqNr are 16 bit unsigned integers
if (this.seqNr > 65535) {
this.seqNr = 0
}
// Wrap seqNr back to 0 when it exceeds 16-bit max integer
this.seqNr = (this.sentChunks[this.sentChunks.length - 1] + 1) % 65536
await this.socket.sendDataPacket(bytes)
return
}
Expand All @@ -62,10 +59,7 @@ export class ContentWriter {
const end = arrayMod.length > 512 ? 512 : undefined
dataChunks[i] = [seqNr, arrayMod.subarray(start, end)]
arrayMod = arrayMod.subarray(end)
seqNr++
if (seqNr > 65535) {
seqNr = 0
} // Reset to 0 if next sequence number > 65535
seqNr = (seqNr + 1) % 65536 // Wrap seqNr back to 0 when it exceeds 16-bit max integer
}
this.logger(`Ready to send ${total} Packets starting at SeqNr: ${this.startingSeqNr}`)
return dataChunks
Expand Down

0 comments on commit 816b4f1

Please sign in to comment.