Skip to content

Commit

Permalink
handshake send intro
Browse files Browse the repository at this point in the history
await for handshake before requests
process request queue
  • Loading branch information
Universal Web committed Jul 18, 2023
1 parent 5ebf7cd commit 3a7bf88
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
1 change: 0 additions & 1 deletion udsp/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ export class UDSP {
heapSize = 0;
throttle = false;
debounce = false;
requestQueue = [];
}
16 changes: 16 additions & 0 deletions udsp/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ export class Client extends UDSP {
const { handshake } = message;
console.log('Handshake Finished', handshake);
this.connected = true;
// Trigger the handshake completed event
this.handshakeCompleted();
}
encodePublicKeyHeader(header = {}) {
const key = this.encryptKeypair.publicKey;
Expand All @@ -233,6 +235,20 @@ export class Client extends UDSP {
}
return header;
}
launchHandshake() {
promise((accept) => {
this.handshakeCompleted = accept;
});
this.sendIntro();
}
ensureHandshake() {
if (this.connected === true) {
return true;
} else if (!this.handshakeCompleted) {
this.launchHandshake();
}
return this.handshakeCompleted;
}
send = send;
request = request;
fetch = fetchRequest;
Expand Down
2 changes: 1 addition & 1 deletion udsp/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from '#logs';
import { promise, construct, isString } from '@universalweb/acid';
imported('Request');
export function request(dataArg, options) {
export async function request(dataArg, options) {
const data = (isString(dataArg)) ? {
path: dataArg
} : dataArg;
Expand Down
11 changes: 1 addition & 10 deletions udsp/request/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,7 @@ export class Base {
}
async send() {
const thisSource = this;
if (isFalse(this.handshake)) {
if (this.method !== 'intro') {
if (!this.waitingOnIntro) {
console.log('Handshake not complete.');
this.waitingOnIntro = true;
}
await this.source().intro(this);
this.handshake = this.source().handshake;
}
}
await this.source().ensureHandshake();
if (this.sent) {
return this.accept;
}
Expand Down
1 change: 0 additions & 1 deletion udsp/server/clients/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export class Client {
isServerClient = true;
isServerEnd = true;
pending = false;
requestQueue = construct(Map);
packetIdGenerator = construct(UniqID);
state = 0;
encryptConnectionId = false;
Expand Down

0 comments on commit 3a7bf88

Please sign in to comment.