Skip to content

Commit

Permalink
Merge pull request #34 from xash/currently_send_entry
Browse files Browse the repository at this point in the history
Make DataChannel handler independent of currentlyReceivedEntry
  • Loading branch information
sgwilym authored Nov 22, 2024
2 parents 624a601 + ce479a0 commit 6c22c02
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/wgps/wgps_messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export class WgpsMessenger<
private currentlySentEntry: Entry<NamespaceId, SubspaceId, PayloadDigest>;
private currentlyReceivedEntry: Entry<NamespaceId, SubspaceId, PayloadDigest>;
private currentlyReceivedOffset = 0n;
private currentlyReceivedLimit = 0n;

private handlesPayloadRequestsOurs = new HandleStore<{
offset: bigint;
Expand Down Expand Up @@ -743,7 +744,6 @@ export class WgpsMessenger<

if (msg.kind === MsgKind.DataSendEntry) {
this.currentlyReceivedEntry = msg.entry;
this.currentlyReceivedOffset = msg.offset;
} else if (msg.kind === MsgKind.DataReplyPayload) {
const request = this.handlesPayloadRequestsOurs.get(msg.handle);

Expand All @@ -754,7 +754,6 @@ export class WgpsMessenger<
}

this.currentlyReceivedEntry = request.entry;
this.currentlyReceivedOffset = request.offset;
}

switch (msg.kind) {
Expand Down Expand Up @@ -1489,6 +1488,9 @@ export class WgpsMessenger<
) {
switch (message.kind) {
case MsgKind.DataSendEntry: {
this.currentlyReceivedLimit = message.entry.payloadLength;
this.currentlyReceivedOffset = message.offset;

const staticToken = await this.handlesStaticTokensTheirs.getEventually(
message.staticTokenHandle,
);
Expand All @@ -1513,15 +1515,15 @@ export class WgpsMessenger<
case MsgKind.DataSendPayload: {
if (
message.amount + this.currentlyReceivedOffset >
this.currentlyReceivedEntry.payloadLength
this.currentlyReceivedLimit
) {
throw new WgpsMessageValidationError("Partner sent too many bytes.");
}

this.currentlyReceivedOffset += message.amount;

const endHere = this.currentlyReceivedOffset ===
this.currentlyReceivedEntry.payloadLength;
this.currentlyReceivedLimit;

this.dataPayloadIngester.push(message.bytes, endHere);

Expand All @@ -1536,6 +1538,8 @@ export class WgpsMessenger<
);
}

this.currentlyReceivedLimit = result.entry.payloadLength;
this.currentlyReceivedOffset = result.offset;
this.dataPayloadIngester.target(result.entry);

break;
Expand Down

0 comments on commit 6c22c02

Please sign in to comment.