Ping / circuit latency, break out commands, add typing function for IM, add thinkingTime and charactersPerSecond parameters to typing functions

This commit is contained in:
Casper Warden
2017-12-13 19:55:08 +00:00
parent af71aa597e
commit 4e8feb181f
96 changed files with 2151 additions and 935 deletions

View File

@@ -29,7 +29,8 @@ export class Circuit
awaitingAck: {
[key: number]: {
packet: Packet,
timeout: number
timeout: number,
sent: number
}
} = {};
receivedPackets: {
@@ -216,7 +217,8 @@ export class Circuit
this.awaitingAck[packet.sequenceNumber] =
{
packet: packet,
timeout: setTimeout(this.resend.bind(this, packet.sequenceNumber), 1000)
timeout: setTimeout(this.resend.bind(this, packet.sequenceNumber), 1000),
sent: new Date().getTime()
};
}
let dataToSend: Buffer = Buffer.allocUnsafe(packet.getSize());
@@ -261,6 +263,26 @@ export class Circuit
this.sendMessage(msg, 0);
}
getOldestUnacked(): number
{
let result = 0;
let oldest = -1;
const keys: string[] = Object.keys(this.awaitingAck);
keys.forEach((seqID: string) =>
{
const nSeq = parseInt(seqID, 10);
if (oldest === -1 || this.awaitingAck[nSeq].sent < oldest)
{
result = nSeq;
oldest = this.awaitingAck[nSeq].sent;
}
});
return result;
}
expireReceivedPacket(sequenceNumber: number)
{
// Enough time has elapsed that we can forget about this packet