Skip to content

Commit

Permalink
New Chunking & completion half in
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal Web committed Jun 21, 2023
1 parent ff91535 commit 2348a75
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 319 deletions.
2 changes: 1 addition & 1 deletion packetsizecalc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Ether=14
IPv4=40
UDP=8
QUIC=1330
connectionID Encrypted max 56
connectionID size
Binary file modified profiles/default-Ephemeral.cert
Binary file not shown.
Binary file modified profiles/default-EphemeralPublic.cert
Binary file not shown.
Binary file modified profiles/default-Master.cert
Binary file not shown.
Binary file modified profiles/default-MasterPublic.cert
Binary file not shown.
Binary file modified profiles/default-Profile.cert
Binary file not shown.
6 changes: 4 additions & 2 deletions scripts/certificates.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ const domainProfile = await createProfile({
encryptClientConnectionId: 'sealedbox',
encryptServerConnectionId: 'sealedbox',
connectionIdKeypair: true,
// Max connection id size in bytes
connectionIdSize: 56,
// Encrypt public key sent in the packet
encryptClientKey: 'sealedbox',
encryptServerKey: 'sealedbox',
encryptKeypair: true
},
// Max connection id size in bytes
connectionIdSize: 56,
// Max Payload size
maxPayloadSize: 900,
ip: '::1',
port: 8888,
domain: 'universal.web',
Expand Down
Binary file modified services/universal.web-Ephemeral.cert
Binary file not shown.
Binary file modified services/universal.web-EphemeralPublic.cert
Binary file not shown.
Binary file modified services/universal.web-Master.cert
Binary file not shown.
Binary file modified services/universal.web-MasterPublic.cert
Binary file not shown.
Binary file modified services/universal.web-Profile.cert
Binary file not shown.
44 changes: 35 additions & 9 deletions udsp/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { decode, encode } from 'msgpackr';
import {
failed, info, msgReceived, msgSent
} from '#logs';
const chunkSize = 700;
const dataEncodingTypesChunked = /stream|file|image|string/;
const dataEncodingTypesStructured = /json|Packetpack|struct|/;
/**
Expand All @@ -36,7 +35,8 @@ export class Ask {
const thisAsk = this;
const {
queue,
packetIdGenerator
packetIdGenerator,
maxPacketSize
} = client;
let request;
if (message) {
Expand Down Expand Up @@ -74,6 +74,7 @@ export class Ask {
this.on({
onData,
});
this.maxPacketSize = maxPacketSize;
queue.set(streamId, thisAsk);
return thisAsk;
}
Expand Down Expand Up @@ -101,7 +102,11 @@ export class Ask {
this.completed = Date.now();
}
// Flush All body and remove this reply from the map
destroy() {
destroy(err) {
this.state = 2;
if (err) {
this.err = err;
}
console.log(`Destroying Ask ${this.id}`);
this.flush();
this.client().queue.delete(this.id);
Expand Down Expand Up @@ -144,8 +149,9 @@ export class Ask {
async chunk(body) {
const chunks = [];
const packetLength = body.length;
for (let index = 0; index < packetLength;index += chunkSize) {
const chunk = body.subarray(index, index + chunkSize);
const { maxPacketSize } = this;
for (let index = 0; index < packetLength;index += maxPacketSize) {
const chunk = body.subarray(index, index + maxPacketSize);
chunks.push(chunk);
}
return chunks;
Expand Down Expand Up @@ -212,6 +218,7 @@ export class Ask {
}
async onPacket(packet) {
const thisAsk = this;
thisAsk.lastPacketTime = Date.now();
const { message } = packet;
const {
body,
Expand All @@ -224,6 +231,8 @@ export class Ask {
act,
// Packet total
pt: totalIncomingUniquePackets,
// Dat payload size
tps: totalIncomingPayloadSize,
// Data Encoding
de: incomingDataEncoding,
// Complete
Expand All @@ -233,12 +242,16 @@ export class Ask {
// Acknowledgement
ack,
// Negative Acknowledgement
nack
nack,
err
} = message;
console.log(`Stream Id ${streamId}`);
if (hasValue(totalIncomingUniquePackets)) {
thisAsk.totalIncomingUniquePackets = totalIncomingUniquePackets;
}
if (hasValue(totalIncomingPayloadSize)) {
thisAsk.totalIncomingPayloadSize = totalIncomingPayloadSize;
}
if (incomingDataEncoding) {
thisAsk.incomingDataEncoding = incomingDataEncoding;
}
Expand All @@ -256,9 +269,12 @@ export class Ask {
thisAsk.totalReceivedUniquePackets = 1;
thisAsk.totalIncomingUniquePackets = 1;
}
if (thisAsk.totalIncomingUniquePackets === thisAsk.totalReceivedUniquePackets) {
if (cmplt) {
thisAsk.state = 2;
}
if (err) {
return this.destroy(err);
}
if (thisAsk.state === 2 || cmplt) {
thisAsk.assemble();
}
Expand All @@ -271,6 +287,11 @@ export class Ask {
body
} = message;
this.data[pid] = body;
this.currentPayloadSize += body.length;
if (this.totalIncomingPayloadSize) {
this.progress = this.totalIncomingPayloadSize / this.currentPayloadSize;
console.log('Progress', this.progress);
}
if (this.events.data) {
this.events.data(body, pid);
}
Expand All @@ -281,7 +302,11 @@ export class Ask {
const { incomingDataEncoding } = thisAsk;
thisAsk.response.body = Buffer.concat(thisAsk.data);
if (incomingDataEncoding === 'struct' || !incomingDataEncoding) {
thisAsk.response.body = decode(thisAsk.response.body);
try {
thisAsk.response.body = decode(thisAsk.response.body);
} catch (err) {
return this.destroy('Failed to decode incoming data');
}
}
}
console.log('Assemble', thisAsk.response.body);
Expand All @@ -304,6 +329,8 @@ export class Ask {
});
return awaitingResult;
}
currentPayloadSize = 0;
progress = 0;
isAsk = true;
request = {};
response = {};
Expand All @@ -325,7 +352,6 @@ export class Ask {
totalOutgoingPayloadSize = 0;
// Must be checked for uniqueness
totalSentConfirmedPackets = 0;
totalIncomingUniquePackets = 1;
totalIncomingPayloadSize = 0;
// Must be checked for uniqueness
totalReceivedPackets = 0;
Expand Down
Loading

0 comments on commit 2348a75

Please sign in to comment.