Improve relay tracking with thunks, add/rename some kinds
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {AUTH_JOIN} from "@welshman/util"
|
||||
import {RELAY_JOIN} from "@welshman/util"
|
||||
import {describe, expect, it, vi, beforeEach, afterEach} from "vitest"
|
||||
import {Socket, SocketStatus, SocketEvent} from "../src/socket"
|
||||
import {AuthStatus, AuthStateEvent} from "../src/auth"
|
||||
@@ -56,7 +56,7 @@ describe("policy", () => {
|
||||
expect(sendSpy).toHaveBeenCalledWith(authEvent)
|
||||
|
||||
// Auth join event should not be buffered
|
||||
const joinEvent: ClientMessage = ["EVENT", {id: "789", kind: AUTH_JOIN}]
|
||||
const joinEvent: ClientMessage = ["EVENT", {id: "789", kind: RELAY_JOIN}]
|
||||
socket.send(joinEvent)
|
||||
expect(sendSpy).toHaveBeenCalledWith(joinEvent)
|
||||
|
||||
@@ -159,21 +159,21 @@ describe("policy", () => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
it("should not retry AUTH_JOIN events", () => {
|
||||
it("should not retry RELAY_JOIN events", () => {
|
||||
const cleanup = socketPolicyAuthBuffer(socket)
|
||||
const sendSpy = vi.spyOn(socket, "send")
|
||||
|
||||
// Send an AUTH_JOIN event
|
||||
// Send an RELAY_JOIN event
|
||||
const event: ClientMessage = [
|
||||
"EVENT",
|
||||
{id: "123", kind: AUTH_JOIN, content: "", tags: [], pubkey: "", sig: ""},
|
||||
{id: "123", kind: RELAY_JOIN, content: "", tags: [], pubkey: "", sig: ""},
|
||||
]
|
||||
socket.emit(SocketEvent.Send, event)
|
||||
|
||||
// Receive auth-required rejection
|
||||
socket.emit(SocketEvent.Receive, ["OK", "123", false, "auth-required: need to auth first"])
|
||||
|
||||
// Should not retry AUTH_JOIN events
|
||||
// Should not retry RELAY_JOIN events
|
||||
expect(sendSpy).not.toHaveBeenCalled()
|
||||
|
||||
cleanup()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {on, ms, nthNe, always, call, sleep, ago, now} from "@welshman/lib"
|
||||
import {AUTH_JOIN, StampedEvent, SignedEvent} from "@welshman/util"
|
||||
import {RELAY_JOIN, StampedEvent, SignedEvent} from "@welshman/util"
|
||||
import {
|
||||
ClientMessage,
|
||||
isClientAuth,
|
||||
@@ -42,7 +42,7 @@ export const socketPolicyAuthBuffer = (socket: Socket) => {
|
||||
if (isClientAuth(message)) return
|
||||
|
||||
// Always allow sending join requests
|
||||
if (isClientEvent(message) && message[1].kind === AUTH_JOIN) return
|
||||
if (isClientEvent(message) && message[1].kind === RELAY_JOIN) return
|
||||
|
||||
// If the auth flow is complete, no need to buffer anymore
|
||||
if (terminalStatuses.includes(socket.auth.status)) return
|
||||
|
||||
Reference in New Issue
Block a user