Commit Graph

50 Commits

Author SHA1 Message Date
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
fiatjaf
329b8d44d2 move stuff back from nostr package to top level.
because otherwise the path must be specified as github.com/fiatjaf/go-nostr/nostr, which is annoying.
2022-11-04 08:22:13 -03:00
BitcoinCoderBob
9549c3624a nostr package, readme updates accordingly, matching example program (#14) 2022-10-12 17:24:30 -03:00
fiatjaf
cea3004867 update to go1.18 and use generic sync maps instead of normal maps.
fixes https://github.com/fiatjaf/go-nostr/issues/12
2022-08-22 08:45:39 -03:00
fiatjaf
1f1d3cfe7f some changes and fixes related to sub.Sub(). 2022-05-04 12:39:10 -03:00
fiatjaf
86853004ef change parsing so NIP12 can work, rename types. 2022-02-08 16:27:33 -03:00
fiatjaf
ef1f548212 avoid sending to closed Events/UniqueEvents channels. 2022-02-07 11:33:45 -03:00
Honza Pokorny
a3df2cb893 Add mutexes around websockets
We replace the bare websocket.Conn type with a new Connection type which
implements `WriteJSON`, `WriteMessage`, and `Close`.  The Connection
type adds mutexes around writes since gorilla doesn't support concurrent
writes to websockets.

Signed-off-by: Honza Pokorny <honza@pokorny.ca>
2022-01-12 12:19:33 -03:00
Honza Pokorny
26c3b4aac9 Remove unnecessary argument to subscription.Sub
The `Sub()` function retrieves the list of filters from the
`Subscripton` object itself, and therefore it's unnecessary to pass it
in.  The argument is unused.

Here, we remove the function argument from the definition, and from the
single call site.  We then pass the filters to the initializer.

This makes it so that filters are in fact passed to the relay on the wire.
2022-01-04 12:24:05 -03:00
fiatjaf
d131e8460e move everything to the same directory. 2022-01-02 08:44:18 -03:00