mleku on Nostr: so i finally have figured out how i'm supposed to do this websocket ...
so i finally have figured out how i'm supposed to do this websocket listener/subscription thing
already wrote most of it, just haven't plugged in the actual handlers to add the filters properly or when events arrive, to scan the events to find the sockets to fire them off to
i think i might manage to get it working tomorrow
it's all in the "listener.go" in relayer, which i remember being much similar in the khatru version except relayer doesn't use the fancy xsync maps
my implementation also just uses a normal mutex, the different feature i'm adding is the filters get fingerprinted so if clients send them repeatedly the filter only has to be tested for matches once and then iterate the listeners to find the matching filter fingerprint for the websocket to send it to
which i think is a bit more efficient when you scale it up and have to deal with dumbass clients that might send out the same stupid filter while it is already active, and even can deduplicate when multiple clients are watching for events from the same npub or whatever, it doesn't match on each of them, just the common one and then just iterate the subscribers list to send em
it's not obvious at small scale but i'm well wary of how dumb clients can be
will be a big smile on my face when the relay actually works with a client tho... right now it just passes all the relay tester tests that don't depend on subscriptions, so that will be first thing to get done
#thoon
Published at
2024-08-29 21:17:24Event JSON
{
"id": "6accec61114f83dc69a7ddedef88f9769af964c6ff0c09067dcdd91bd0153818",
"pubkey": "4c800257a588a82849d049817c2bdaad984b25a45ad9f6dad66e47d3b47e3b2f",
"created_at": 1724966244,
"kind": 1,
"tags": [
[
"t",
"thoon"
],
[
"client",
"Coracle",
"31990:97c70a44366a6535c145b333f973ea86dfdc2d7a99da618c40c64705ad98e322:1685968093690"
]
],
"content": "so i finally have figured out how i'm supposed to do this websocket listener/subscription thing\n\nalready wrote most of it, just haven't plugged in the actual handlers to add the filters properly or when events arrive, to scan the events to find the sockets to fire them off to\n\ni think i might manage to get it working tomorrow\n\nit's all in the \"listener.go\" in relayer, which i remember being much similar in the khatru version except relayer doesn't use the fancy xsync maps\n\nmy implementation also just uses a normal mutex, the different feature i'm adding is the filters get fingerprinted so if clients send them repeatedly the filter only has to be tested for matches once and then iterate the listeners to find the matching filter fingerprint for the websocket to send it to\n\nwhich i think is a bit more efficient when you scale it up and have to deal with dumbass clients that might send out the same stupid filter while it is already active, and even can deduplicate when multiple clients are watching for events from the same npub or whatever, it doesn't match on each of them, just the common one and then just iterate the subscribers list to send em\n\nit's not obvious at small scale but i'm well wary of how dumb clients can be\n\nwill be a big smile on my face when the relay actually works with a client tho... right now it just passes all the relay tester tests that don't depend on subscriptions, so that will be first thing to get done\n\n#thoon",
"sig": "d5c7d68ab4bea8cb570db3941b3245d844f6ec7843f2c3cd9a489cdca33ad8eb4239466867a635c1b7f015425e84782f6721eb07625faa70dfb2e43cb7f21d42"
}