@kumiai/hub-server 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/handlers.js +27 -1
- package/package.json +5 -5
package/lib/handlers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HandlerError } from '@enkaku/server';
|
|
2
2
|
import { HUB_ERROR_CODES, hubErrorCodeOf, InvalidPayloadError, KeyPackageFetchLimitError, keyPackageDigest, wakeRecipientKeyProblem } from '@kumiai/hub-protocol';
|
|
3
3
|
import { fromB64, toB64 } from '@sozai/codec';
|
|
4
|
-
import { getReporter } from '@sozai/log';
|
|
4
|
+
import { getLogger, getReporter } from '@sozai/log';
|
|
5
5
|
import { createRateLimiter } from './rateLimit.js';
|
|
6
6
|
function normalizeAuthorizeDecision(decision) {
|
|
7
7
|
return typeof decision === 'boolean' ? {
|
|
@@ -29,6 +29,11 @@ const reportStoreError = getReporter([
|
|
|
29
29
|
'kumiai',
|
|
30
30
|
'hub-server'
|
|
31
31
|
], '@kumiai/hub-server');
|
|
32
|
+
const receiveLogger = getLogger([
|
|
33
|
+
'kumiai',
|
|
34
|
+
'hub-server',
|
|
35
|
+
'receive'
|
|
36
|
+
]);
|
|
32
37
|
/** What the failed operation was about, for the default log line: a DID for the per-recipient
|
|
33
38
|
* methods, a topic for fan-out, nothing for a store-wide purge. */ function subjectOf(event) {
|
|
34
39
|
switch(event.method){
|
|
@@ -550,11 +555,22 @@ export function createHandlers(params) {
|
|
|
550
555
|
// backpressure stalls `writer.write` until `receiveBufferLimit` tears the channel down.
|
|
551
556
|
function waitForRoom(bytes) {
|
|
552
557
|
if (tornDown || hasRoom(bytes)) return Promise.resolve();
|
|
558
|
+
receiveLogger.debug('receive window full for {recipientDID}: paused with {frames} frames ({bytes} bytes) unacked', {
|
|
559
|
+
recipientDID: clientDID,
|
|
560
|
+
frames: inFlight.size,
|
|
561
|
+
bytes: inFlightBytes
|
|
562
|
+
});
|
|
553
563
|
return new Promise((resolve)=>{
|
|
554
564
|
let timer;
|
|
555
565
|
const arm = ()=>{
|
|
556
566
|
clearTimeout(timer);
|
|
557
567
|
timer = setTimeout(()=>{
|
|
568
|
+
receiveLogger.warn('receive ack timeout for {recipientDID}: released {frames} frames ({bytes} bytes) after {timeoutMs} ms', {
|
|
569
|
+
recipientDID: clientDID,
|
|
570
|
+
frames: inFlight.size,
|
|
571
|
+
bytes: inFlightBytes,
|
|
572
|
+
timeoutMs: receiveAckTimeout
|
|
573
|
+
});
|
|
558
574
|
releaseAll();
|
|
559
575
|
notifyWindow();
|
|
560
576
|
}, receiveAckTimeout);
|
|
@@ -593,10 +609,19 @@ export function createHandlers(params) {
|
|
|
593
609
|
const done = new Promise((resolve)=>{
|
|
594
610
|
resolveDone = resolve;
|
|
595
611
|
});
|
|
612
|
+
function logUnackedFrames() {
|
|
613
|
+
if (inFlight.size === 0) return;
|
|
614
|
+
receiveLogger.debug('receive stream ended for {recipientDID} with {frames} frames ({bytes} bytes) unacked', {
|
|
615
|
+
recipientDID: clientDID,
|
|
616
|
+
frames: inFlight.size,
|
|
617
|
+
bytes: inFlightBytes
|
|
618
|
+
});
|
|
619
|
+
}
|
|
596
620
|
// Idempotent teardown, shared by every failure and end path. Frames stay pending in the store
|
|
597
621
|
// and redeliver on the next connect (store-and-forward).
|
|
598
622
|
function finish() {
|
|
599
623
|
if (tornDown) return;
|
|
624
|
+
logUnackedFrames();
|
|
600
625
|
tornDown = true;
|
|
601
626
|
notifyWindow();
|
|
602
627
|
if (receiveToken != null) registry.releaseReceiveWriter(clientDID, receiveToken);
|
|
@@ -742,6 +767,7 @@ export function createHandlers(params) {
|
|
|
742
767
|
}
|
|
743
768
|
} catch (error) {
|
|
744
769
|
// A synchronous drain error (e.g. store.fetch threw): clean up and reject the handler.
|
|
770
|
+
if (!tornDown) logUnackedFrames();
|
|
745
771
|
tornDown = true;
|
|
746
772
|
notifyWindow();
|
|
747
773
|
if (receiveToken != null) registry.releaseReceiveWriter(clientDID, receiveToken);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/hub-server",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Hub server for Enkaku E2EE group message routing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hub",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"lib/*"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@enkaku/protocol": "^0.22.
|
|
29
|
-
"@enkaku/server": "^0.22.
|
|
28
|
+
"@enkaku/protocol": "^0.22.5",
|
|
29
|
+
"@enkaku/server": "^0.22.5",
|
|
30
30
|
"@kokuin/capability": "^0.5.2",
|
|
31
31
|
"@kokuin/token": "^0.6.4",
|
|
32
32
|
"@kumiai/hub-protocol": "^0.12.0",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@sozai/log": "^0.4.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@enkaku/client": "^0.22.
|
|
39
|
-
"@enkaku/transport": "^0.22.
|
|
38
|
+
"@enkaku/client": "^0.22.5",
|
|
39
|
+
"@enkaku/transport": "^0.22.5",
|
|
40
40
|
"@kumiai/hub-conformance": "^0.12.0",
|
|
41
41
|
"@kumiai/hub-wake": "^0.12.0"
|
|
42
42
|
},
|