Skip to content

Commit

Permalink
fixup! fixup! transport thp
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlesisz committed Jul 30, 2024
1 parent c5c41a6 commit 57e072f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/transport/src/thp/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const readWithExpectedState = async (
throw new Error('Already aborted');
}

console.warn('readWithExpectedState chunk', chunk);
console.warn('readWithExpectedState chunk', protocolState?.expectedResponses, chunk);
// technically this done in send
if (!chunk.success) {
throw new Error(chunk.error);
Expand All @@ -43,6 +43,12 @@ export const readWithExpectedState = async (
return chunk.payload;
}

console.warn(
'readWithExpectedState chunk doesnt match',
chunk.payload.subarray(0, 3),
protocolState?.expectedResponses,
);

// TODO: setTimeout here?, check attempts and retry frequency?
return readWithExpectedState(apiRead, protocolState, signal);
};
Expand All @@ -64,6 +70,7 @@ export const receiveThpMessage = async ({
const isAckExpected = protocolThp.isAckExpected(protocolState?.expectedResponses || []);
if (isAckExpected) {
const ack = protocolThp.encodeAck(decoded.header);
console.warn('Writing Ack', ack);
const ackResult = await apiWrite(ack, signal);

if (!ackResult.success) {
Expand Down
3 changes: 2 additions & 1 deletion packages/transport/src/thp/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ export const sendThpMessage = async ({
const result = await scheduleAction(
async attemptSignal => {
console.warn('---> sendThpMessage attempt start', tries);
// TODO: send should not time out
const sendResult = await sendChunks(chunks, apiWrite);
if (!sendResult.success) {
return sendResult;
}

console.warn('...trying to read', tries);
console.warn('...trying to read ack', tries);

return readWithExpectedState(apiRead, protocolState, attemptSignal);
},
Expand Down

0 comments on commit 57e072f

Please sign in to comment.