Commit Graph

59 Commits

Author SHA1 Message Date
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
fiatjaf
85fc74fd22 fixing subscription labels and ids. 2023-03-18 15:09:49 -03:00
fiatjaf
3f66c60b5f subscription labels: GetID() and SetLabel(). 2023-03-18 08:40:12 -03:00
fiatjaf
fdc99d61b6 subscription ids as sequential numbers and sub.GetID() 2023-03-17 16:43:48 -03:00
fiatjaf
0765f7b91b context cancelation for relay connections and subscriptions. 2023-03-16 14:16:46 -03:00
fiatjaf
92c0143762 make sub.Events a channel of pointers. 2023-01-26 09:04:27 -03:00
barkyq
87b6280299 Added some NIP-42 functionality to the client (relay.go) (#38) 2023-01-16 08:27:11 -03:00
barkyq
a37ffacc74 added sub.mutex handling in the relay Connect() function (#37) 2023-01-15 09:19:00 -03:00
fiatjaf
4a62a753e6 contexts everywhere. 2023-01-01 20:58:43 -03:00
fiatjaf
2d01aa8630 prevent sending on closed channel for subscription. 2022-11-26 09:25:51 -03:00
fiatjaf
b0ae497656 allow more fine-grained control over subscription filters. 2022-11-19 14:00:29 -03:00
fiatjaf
8bc91a894c sub.GetFilters() 2022-11-19 07:19:36 -03:00
fiatjaf
69ccfbaa08 protect against faulty relays that send more than one EOSE halting us
using sync.Once{} to only emit to the EndOfStoredEvents channel once
(it has capacity 1 so anything over that would halt).
2022-11-16 10:07:37 -03:00
fiatjaf
2641327c28 support for EOSE and OK messages on relay/subscription. 2022-11-12 21:49:57 -03:00
fiatjaf
c4d52e516f change relaypool and subscription such that a Relay can have an independent existence. 2022-11-06 21:15:42 -03:00