Commit Graph

73 Commits

Author SHA1 Message Date
fiatjaf 80d0546ce6 we should be doing this since years ago: force an EOSE if the relay refuses to give us one. 2025-08-25 22:42:05 -03:00
fiatjaf c2635c1f20 eliminate ID option that was being ignored. 2025-08-23 09:16:25 -03:00
fiatjaf 7289da9c72 improve/refactor websocket connections hoping this will fix the undetected disconnections we're seeing.
this commit also remove all the sonic envelope parsing and reintroduces filters in REQ as a slice instead of as a singleton.

why? well, the sonic stuff wasn't really that fast, it was a little bit but only got fast enough once I introduced unsafe conversions between []byte and string and did weird unsafe reuse of []byte in order to save the values of tags, which would definitely cause issues in the future if the caller wasn't aware of it (and even if they were, like myself).

and the filters stuff is because we abandoned the idea of changing NIP-01 to only accept one filter per REQ.
2025-07-10 22:58:37 -03:00
fiatjaf b81a6382d9 allow dangerously setting an absolute subscription id. 2025-05-03 11:56:37 -03:00
fiatjaf 2b5b646a62 a big bundle of conversions and other changes. 2025-04-15 17:13:57 -03:00
fiatjaf b4268d649c a bunch of [32]byte conversions. still more needed. 2025-04-14 17:47:53 -03:00
fiatjaf cc23d81e80 pool's .FetchManyReplaceable() and amends to previous commit. 2025-03-12 00:49:58 -03:00
fiatjaf 441f94563f WithCheckDuplicateReplaceable() and helper functions for efficient replaceable event matching. 2025-03-12 00:19:41 -03:00
fiatjaf c9411a3c5b depressing sonic json decoder implementation, breakingly force COUNT to use a single filter, reorganize envelope tests. 2025-03-06 19:34:36 -03:00
fiatjaf 5bfaed2740 docstrings for many functions. 2025-03-04 11:42:44 -03:00
fiatjaf 06a15fdaab follow list fetching test and related changes and fixes.
- make BatchedSubManyEose() use a single duplicate id index and use it for replaceable loaders;
- fixes parsing follow entry from kind:3 events (and others);
- adds a "cause" to most cancelation errors in relay/pool;
- remove the inherent cache from dataloader (we have our own hopefully);
- increase max frame size we can read from any websocket to 2**18 (262k), which gives over 2000 item lists.
2025-01-17 13:44:51 -03:00
fiatjaf febf022124 add some basic sdk tests, fix saving hints (normalize urls), checkduplicates arg order, kvdb stuff and other things. 2025-01-16 17:39:16 -03:00
fiatjaf e1971d12c0 WithCheckDuplicate(), let's see if this works. 2025-01-15 14:29:38 -03:00
fiatjaf 795f9516ae use @mmalmi json string preparsing speedup for duplicate events
- get rid of "nonUnique" variants of subMany as we can now relay on CheckDuplicate to track relays.
- add global pool tracker duplicateMiddleware.
2025-01-15 14:29:38 -03:00
fiatjaf 0d40b40c9c pool: support CountMany() using hyperloglog. 2024-11-16 17:47:42 -03:00
fiatjaf 9c692af624 I think this handles CLOSED messages better. 2024-10-16 16:27:50 -03:00
fiatjaf 9e0a86d48e subscription must be deemed closed when receiving a CLOSED. 2024-10-15 18:27:19 -03:00
fiatjaf ad14daec9f allocate subscription id only once on creation. 2024-09-29 16:44:31 -03:00
fiatjaf 24343dbbef reduce allocations at subscription.GetID() because why not. 2024-09-29 07:55:06 -03:00
fiatjaf 7503643e80 stop debuglogging duplicate "sending" messages, that has confused me absurdly. 2024-09-26 21:12:19 -03:00
fiatjaf f57d93ac78 after getting an EOSE we should stop checking since/until. 2024-09-06 19:37:34 -03:00
fiatjaf 5938a71146 replace close() with actually sending a value to .EndOfStoredEvents and .Closed channels.
I thought `close()` would be nice because it would be cheap and not lock the goroutine while waiting for the receiver to acknowledge the thing, but turns out it introduces the serious risk of users putting <- sub.EndOfStoredEvents in the same for { select {} } statement as sub.Events, for example, and they they get into an infinite loop.

we had this same problem here inside this same library, and what is fixed in 242af0bf76 by @mattn.
2024-01-01 10:18:16 -03:00
fiatjaf 7449f254db support handling CLOSED messages from relay client. 2023-11-28 18:54:24 -03:00
fiatjaf 1f605f3629 remove intermediary .events channel and hacky ms sleep. 2023-09-04 08:57:53 -03:00
fiatjaf 6d1875de46 ensure eose channel closes after events have been emitted. 2023-09-04 08:33:31 -03:00
fiatjaf 446b104990 simplify subscription closing. 2023-08-22 10:58:34 -03:00
fiatjaf c5bf5892c3 release sub.Events lock when subscription is canceled. 2023-08-21 15:53:27 -03:00
Kay ac2350c722 style: using effective go and refactoring 2023-08-21 15:50:05 -03:00
fiatjaf 53b9dde6e0 relay.Count() 2023-07-18 16:17:00 -03:00
fiatjaf 6cee628149 rename debugLog->debugLogf 2023-07-11 15:25:02 -03:00
fiatjaf 71f4594033 wait when CLOSEing. 2023-06-25 12:56:17 -03:00
fiatjaf 54d3de4908 refactor some things, add back one mutex for each subscription for dispatching events, but in a cleaner way. 2023-06-25 00:17:39 -03:00
fiatjaf ac0c0769fe disentangle things a little more.
having a single loop for everything was too much. goroutines things were getting stuck.
2023-06-23 16:23:00 -03:00
fiatjaf f0a35d7ab2 Write returns an error in a channel (why? I think it makes no difference.) 2023-06-22 10:46:31 -03:00
fiatjaf 68648a16b9 remove conn field from subscription. 2023-06-22 09:12:35 -03:00
fiatjaf 030c1d1898 get rid of mutexes and use a single loop to prevent races.
in the meantime change the API to makes a little less error-prone.
2023-06-21 19:55:43 -03:00
Isaque Veras 58d56abe05 fix: removing redundancy 2023-06-12 08:18:29 -03:00
fiatjaf bc783a3a24 fix atomicity of subscription ids. 2023-06-09 11:01:42 -03:00
fiatjaf a2941876e3 expose subscriptions from relay and keep that updated. 2023-05-30 14:55:44 -03:00
fiatjaf 0f7a3f01f2 use an atomic counter. 2023-05-30 14:01:07 -03:00
fiatjaf 9dc674bc02 use different contexts for the relay connection lifetime and the Connect() call.
fixes https://github.com/nbd-wtf/go-nostr/pull/86
2023-05-09 17:08:08 -03:00
fiatjaf ccbb44989f get rid of WriteJSON() and replace calls with manually marshaled envelopes. 2023-05-09 17:02:22 -03:00
fiatjaf 326d2790de rename interface{} to any. 2023-04-12 12:14:24 -03:00
fiatjaf ec3f1287c4 debug log CLOSE messages. 2023-04-12 12:14:16 -03:00
fiatjaf 6f74d284c4 improved logging thing with the "debug" build tag. 2023-04-11 09:35:37 -03:00
fiatjaf 4507477486 slight improvements to debug logging. 2023-04-11 07:10:05 -03:00
fiatjaf e103c99bb8 a pluggable logging interface and more debug logging. 2023-04-11 00:32:32 -03:00
fiatjaf ef428ff39f Subscription.Fire() can error, so Relay.Subscribe() must also. 2023-04-06 16:21:25 -03:00
fiatjaf 4b1f69ec27 subscriptions receive their context on Prepare(). 2023-03-21 14:50:34 -03:00
fiatjaf 46e724b8d5 dry sub.unsub() on context cancelation. 2023-03-18 16:07:19 -03:00