Handle notices, don't send reqs that have already been closed

This commit is contained in:
Jonathan Staab
2023-08-15 14:21:15 -07:00
parent ee1ac84ab7
commit a909ab6d28
4 changed files with 22 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "paravel",
"version": "0.3.0",
"version": "0.3.1",
"description": "Yet another toolkit for nostr",
"repository": {
"type": "git",
+6 -1
View File
@@ -26,13 +26,18 @@ class SendQueue extends Queue {
}
if (verb === 'REQ') {
return this.cxn.meta.pendingRequests.size < 10
return this.cxn.meta.pendingRequests.size < 8
}
return true
}
handle(message: SocketMessage) {
// If we ended up handling a CLOSE before we handled the REQ, don't send the REQ
if (message[0] === 'CLOSE') {
this.messages = this.messages.filter(m => !(m[0] === 'REQ' && m[1] === message[1]))
}
this.cxn.onSend(message)
}
}
+7 -1
View File
@@ -44,7 +44,7 @@ export class ConnectionMeta {
responseCount = 0
responseTimer = 0
constructor(cxn: Connection) {
constructor(readonly cxn: Connection) {
cxn.on('open', () => {
this.lastOpen = Date.now()
})
@@ -77,6 +77,8 @@ export class ConnectionMeta {
if (verb === 'EVENT') this.onReceiveEvent(...payload)
// @ts-ignore
if (verb === 'EOSE') this.onReceiveEose(...payload)
// @ts-ignore
if (verb === 'NOTICE') this.onReceiveNotice(...payload)
})
}
@@ -133,6 +135,10 @@ export class ConnectionMeta {
}
}
onReceiveNotice(message: string) {
console.warn('NOTICE', this.cxn.url, message)
}
clearPending = () => {
this.pendingPublishes.clear()
this.pendingRequests.clear()
+8 -1
View File
@@ -20,7 +20,14 @@ export class Queue {
}
doWork() {
for (const message of this.messages.splice(0, 10)) {
for (let i = 0; i < 10; i++) {
if (this.messages.length === 0) {
break
}
// Pop the messages one at a time so handle can modify the queue
const [message] = this.messages.splice(0, 1)
if (this.shouldSend(message)) {
this.handle(message)
} else {