Commit Graph

126 Commits

Author SHA1 Message Date
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
fiatjaf e84a7936d5 fix some concurrency things. 2023-03-29 14:55:52 -03:00
fiatjaf d3a1624880 ping every 29 seconds.
fixes https://github.com/nbd-wtf/go-nostr/issues/72
2023-03-25 14:59:38 -03:00
fiatjaf 4b1f69ec27 subscriptions receive their context on Prepare(). 2023-03-21 14:50:34 -03:00
fiatjaf e9ad77c822 asynchronous event parsing on received. 2023-03-18 15:09:58 -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 cef5892bce return status from publish when relay loses connectivity. 2023-03-17 16:21:04 -03:00
fiatjaf c982ad0ab1 guard against closed channels in subscriptions. 2023-03-16 15:53:24 -03:00
fiatjaf ec34d4eb10 return error message from Publish() 2023-03-16 14:27:33 -03:00
fiatjaf 0765f7b91b context cancelation for relay connections and subscriptions. 2023-03-16 14:16:46 -03:00