137 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
4c50cce79c add the same warnings in Subscribe and PrepareSubscription help comments. 2023-08-31 09:27:20 -03:00
fiatjaf
446b104990 simplify subscription closing. 2023-08-22 10:58:34 -03:00
Kay
ac2350c722 style: using effective go and refactoring 2023-08-21 15:50:05 -03:00
fiatjaf
35faff858a reuse buffer when reading messages from websocket. 2023-07-30 17:12:30 -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
c03c028142 fix: don't stop reading the websocket for no reason! 2023-07-11 15:23:48 -03:00
fiatjaf
6e79f72174 prevent halting in some other places. 2023-07-11 11:04:48 -03:00
fiatjaf
6b625f7896 handle OK callbacks properly when there is not a "reason" (which is the expected behavior). 2023-06-26 21:00:39 -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
f78270765d prevent halting when a relay gets disconnected. 2023-06-22 10:45:45 -03:00
fiatjaf
fd409f6c35 add closure queue channel that was missing. 2023-06-22 09:32:12 -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
fiatjaf
ee8f58360f print all filters when doesn't match. 2023-06-09 16:11:16 -03:00
fiatjaf
a80965425b comment out info log for when we get an event outside of a subscription.
relays will often keep sending stored events even though we've closed a subscription already.
2023-06-09 13:49:29 -03:00
fiatjaf
bc783a3a24 fix atomicity of subscription ids. 2023-06-09 11:01:42 -03:00
fiatjaf
9cafea7e2a ensure relay context and subscriptions are closed when we lose connectivity. 2023-05-30 17:44:25 -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
39f09e6bb9 replace generic-sync-map with xsync. 2023-05-30 13:52:14 -03:00
fiatjaf
ad0f73fa9c ensure subscription dies if the relay connection dies. 2023-05-30 13:47:47 -03:00
fiatjaf
5cead32fbe remove extra subscription after publishing an event to check if it is there.
just assume all relays will return OK.
2023-05-30 13:45:45 -03:00
fiatjaf
0c06788672 oops: stop replacing connectionContext with Connect(ctx). 2023-05-10 09:09:49 -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
d36fbb95b9 ParseMessage() returns an Envelope, use that on the main relay handler loop. 2023-05-09 16:55:21 -03:00
Marc Tarnutzer
c86e907142 enable compression by default 2023-05-05 22:00:25 +02:00
Marc Tarnutzer
9c01ead91f switch to gobwas/ws, add compression 2023-05-04 23:51:15 +02:00
fiatjaf
32ca737acf remove unused ping handler (it is done automatically).
fixes https://github.com/nbd-wtf/go-nostr/pull/74, thanks @patdz
2023-04-26 08:12:50 -03:00
fiatjaf
3838ed7e91 guard ping writes with the mutex.
fixes https://github.com/nbd-wtf/go-nostr/issues/76#issuecomment-1521170395
2023-04-26 08:04:51 -03:00
Patrick Bennett
b077a41f83 Fix race condition on status in Relay.Publish method and failure to send
A race-condition exists between setting of the (unprotected) status and the callback which sets the status upon receiving an OK.
The message is sent which can receive an OK in separate goroutine (setting status) prior to the status being set to 'sent.'
The OK can be received prior to the status being set.

This fix also sets the status to PublishStatusFailed if the WriteJSON call fails.
2023-04-21 07:48:08 -03:00
fiatjaf
9b89a49e5e cancel relay context when calling .Close().
fixing https://github.com/nbd-wtf/go-nostr/issues/76#issuecomment-1517251898
2023-04-21 07:45:28 -03:00
fiatjaf
af52f8d490 debug log events received. 2023-04-14 10:07:10 -03:00
fiatjaf
326d2790de rename interface{} to any. 2023-04-12 12:14:24 -03:00
fiatjaf
2314db57a1 tweak timeouts on Publish() 2023-04-11 15:33:29 -03:00
fiatjaf
32768b1a5b improve debug logging, fix stringer interface, debuglog events sent, fix debuglogging affecting the actual values. 2023-04-11 11:02:35 -03:00
fiatjaf
7f64f2f65e improve logic for subscribing to just-published events. 2023-04-11 10:38:30 -03:00
fiatjaf
df7abe72fa fix: return PublishStatusFailed if connection can't be established etc. 2023-04-11 09:52:01 -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
4c9db5928a log relay url too when filter doesn't match. 2023-04-06 12:57:15 -03:00
fiatjaf
abfb7de394 add a mutex lock around Challenges and Notices channel. 2023-03-31 22:09:01 -03:00
fiatjaf
30e0e1040a use context passed to .Connect() for the live of the relay. 2023-03-30 18:26:43 -03:00