Skip to content

Commit e52853e

Browse files
committed
working on debugging singalling issue
1 parent 6ac01c4 commit e52853e

File tree

8 files changed

+61
-33
lines changed

8 files changed

+61
-33
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
},
2121
"devDependencies": {
2222
"@hyper-hyper-space/node-env": "^0.8.0",
23-
"@peculiar/webcrypto": "^1.1.6",
2423
"@types/jest": "^26.0.19",
2524
"@types/node": "^14.0.13",
2625
"@types/ws": "^7.2.6",

src/crypto/ciphers/RSA.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { NodeRSA } from "./NodeRSA";
2-
import { WebCryptoRSA } from "./WebCryptoRSA";
1+
//import { JSEncryptRSA } from './JSEncryptRSA';
2+
import { NodeRSA } from './NodeRSA';
3+
import { WebCryptoRSA } from './WebCryptoRSA';
34

45
interface RSA {
56

@@ -20,7 +21,7 @@ interface RSA {
2021
}
2122

2223
class RSADefaults {
23-
static impl: new () => RSA = globalThis?.crypto?.subtle !== undefined? WebCryptoRSA : NodeRSA;
24+
static impl: new () => RSA = globalThis?.crypto?.subtle !== undefined ? WebCryptoRSA : NodeRSA;
2425
}
2526

2627
export { RSA, RSADefaults };

src/crypto/config/WebCryptoConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class WebCryptoConfig {
88
static overrideImpl: SubtleCrypto | undefined;
99

1010
static getSubtle(): SubtleCrypto {
11-
if (WebCryptoConfig.overrideImpl !== undefined) {
12-
return WebCryptoConfig.overrideImpl;
11+
if ((globalThis as any)?.webCryptoOverrideImpl !== undefined) {
12+
return (globalThis as any)?.webCryptoOverrideImpl as SubtleCrypto;
1313
} else {
1414
return globalThis.crypto.subtle;
1515
}

src/data/model/HashedObject.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,18 +500,18 @@ abstract class HashedObject {
500500
if (obj.author !== undefined) {
501501
if (literal.signature === undefined) {
502502
context.objects.delete(hash);
503-
throw new Error('Missing signature for ' + hash);
503+
throw new Error('Missing signature for ' + hash + ' of type ' + obj.getClassName());
504504
}
505505

506506
if (!await obj.author.verifySignature(hash, literal.signature)) {
507507
context.objects.delete(hash);
508-
throw new Error('Invalid signature for ' + hash);
508+
throw new Error('Invalid signature for ' + hash + ' of type ' + obj.getClassName());
509509
}
510510
}
511511

512512
if (!await obj.validate(context.objects)) {
513513
context.objects.delete(hash);
514-
throw new Error('Validation failed for ' + hash);
514+
throw new Error('Validation failed for ' + hash + ' of type ' + obj.getClassName());
515515
}
516516

517517
return obj;

src/mesh/agents/state/causal/CausalHistorySynchronizer.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,20 @@ class CausalHistorySynchronizer {
150150

151151
checkRequestTimeouts() {
152152

153-
let cancelled = false;
153+
let cancelledSome = false;
154154

155155
for (const reqInfo of this.requests.values()) {
156-
cancelled = cancelled || this.checkRequestRemoval(reqInfo);
156+
157+
const cancelled = this.checkRequestRemoval(reqInfo);
158+
159+
if (cancelled) {
160+
console.log('CANCELLED ' + reqInfo.request.requestId + ' in timeout loop')
161+
}
162+
163+
cancelledSome = cancelledSome || cancelled;
157164
}
158165

159-
if (cancelled) {
166+
if (cancelledSome) {
160167
this.attemptNewRequests();
161168
}
162169
}
@@ -1277,6 +1284,7 @@ class CausalHistorySynchronizer {
12771284
private sendRequest(reqInfo: RequestInfo) {
12781285

12791286
reqInfo.status = 'sent';
1287+
reqInfo.requestSendingTimestamp = Date.now();
12801288

12811289
const reqId = reqInfo.request.requestId;
12821290
this.requests.set(reqId, reqInfo);

src/net/linkup/SignallingServerConnection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { LinkupAddress } from './LinkupAddress';
55

66
class SignallingServerConnection implements LinkupServer {
77

8-
static logger = new Logger(SignallingServerConnection.name, LogLevel.INFO);
8+
static logger = new Logger(SignallingServerConnection.name, LogLevel.ERROR);
99

1010
static WRTC_URL_PREFIX = 'wrtc+';
1111

@@ -256,7 +256,7 @@ class SignallingServerConnection implements LinkupServer {
256256
}
257257

258258
if (!found) {
259-
SignallingServerConnection.logger.warning('Received message for unlistened linkupId: ' + linkupId);
259+
SignallingServerConnection.logger.warning('Received message for unlistened linkupId: ' + linkupId, message);
260260
}
261261
}
262262
} else if (raw !== undefined && raw === 'true') {

test/config.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
import '@hyper-hyper-space/node-env';
2-
import { WebCryptoConfig } from 'crypto/config';
3-
4-
const { Crypto } = require("@peculiar/webcrypto");
5-
6-
const crypto = new Crypto();
7-
8-
WebCryptoConfig.overrideImpl = crypto.subtle;
92

103
let describeProxy = describe;
114

test/mesh/agents/state.test.ts

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Identity } from 'data/identity';
1414
import { describeProxy } from 'config';
1515
import { CausalHistorySyncAgent, TerminalOpsSyncAgent } from 'mesh/agents/state';
1616
import { Logger, LogLevel } from 'util/logging';
17+
import { SlowyString } from '../types/SlowyString';
1718

1819
describeProxy('[SYN] State sync', () => {
1920
test('[SYN01] Gossip agent in small peer group (wrtc)', async (done) => {
@@ -74,6 +75,12 @@ describeProxy('[SYN] State sync', () => {
7475

7576
}, 300000);
7677

78+
test('[SYN11] Causal history agent-based set deep sync in small peer group (wrtc)', async (done) => {
79+
80+
await deepSyncInSmallPeerGroup(done, 'wrtc', undefined, undefined, true);
81+
82+
}, 300000);
83+
7784
});
7885

7986
async function gossipInSmallPeerGroup(done: () => void, network: 'wrtc'|'ws'|'mix' = 'wrtc', basePort?: number) {
@@ -435,7 +442,7 @@ async function stagedSyncInSmallPeerGroup(done: () => void, network: 'wrtc'|'ws'
435442
done();
436443
}
437444

438-
async function deepSyncInSmallPeerGroup(done: () => void, network: 'wrtc'|'ws'|'mix' = 'wrtc', basePort?: number, useRemoting?: boolean) {
445+
async function deepSyncInSmallPeerGroup(done: () => void, network: 'wrtc'|'ws'|'mix' = 'wrtc', basePort?: number, useRemoting?: boolean, useSlowOps?: boolean) {
439446

440447
const size = 3;
441448

@@ -457,14 +464,22 @@ async function deepSyncInSmallPeerGroup(done: () => void, network: 'wrtc'|'ws'|'
457464
let id = await TestIdentity.getFirstTestIdentity();
458465
let kp = await TestIdentity.getFistTestKeyPair();
459466

460-
let s = new MutableSet<HashedObject>();
467+
let s = new MutableSet();
461468

462469
s.setAuthor(id);
463470

471+
472+
473+
464474
await stores[0].save(kp);
465475
await stores[0].save(s);
466476

467-
await s.add(new HashedLiteral('hello'));
477+
if (useSlowOps === true) {
478+
await s.add(new SlowyString('hello'));
479+
} else {
480+
await s.add(new HashedLiteral('hello'));
481+
}
482+
468483

469484
await stores[0].save(s);
470485

@@ -517,16 +532,28 @@ async function deepSyncInSmallPeerGroup(done: () => void, network: 'wrtc'|'ws'|'
517532
}
518533
}
519534

535+
if (useSlowOps === true) {
536+
await s.add(new SlowyString('my'));
537+
await s.add(new SlowyString('dear'));
538+
await s.add(new SlowyString('friends'));
539+
await s.add(new SlowyString('I'));
540+
await s.add(new SlowyString('have'));
541+
await s.add(new SlowyString('very'));
542+
await s.add(new SlowyString('dearly'));
543+
await s.add(new SlowyString('missed'));
544+
await s.add(new SlowyString('you'));
545+
} else {
546+
await s.add(new HashedLiteral('my'));
547+
await s.add(new HashedLiteral('dear'));
548+
await s.add(new HashedLiteral('friends'));
549+
await s.add(new HashedLiteral('I'));
550+
await s.add(new HashedLiteral('have'));
551+
await s.add(new HashedLiteral('very'));
552+
await s.add(new HashedLiteral('dearly'));
553+
await s.add(new HashedLiteral('missed'));
554+
await s.add(new HashedLiteral('you'));
520555

521-
await s.add(new HashedLiteral('my'));
522-
await s.add(new HashedLiteral('dear'));
523-
await s.add(new HashedLiteral('friends'));
524-
await s.add(new HashedLiteral('I'));
525-
await s.add(new HashedLiteral('have'));
526-
await s.add(new HashedLiteral('very'));
527-
await s.add(new HashedLiteral('dearly'));
528-
await s.add(new HashedLiteral('missed'));
529-
await s.add(new HashedLiteral('you'));
556+
}
530557

531558
await stores[0].save(s);
532559

0 commit comments

Comments
 (0)