67 Commits

Author SHA1 Message Date
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
fiatjaf
02759120ea
Relay.AssumeValid 2023-03-14 17:07:32 -03:00
Jasper Rädisch
74c646fe21 add RequestHeader option for websocket conn 2023-02-25 16:06:46 -03:00
fiatjaf
a0d9f3a392
send notices on a goroutine. 2023-02-14 11:25:49 -03:00
Wayback Archiver
ab2db2dfc5 Fix unblock mutex
- if `receivedEvent.ID` not match `event.ID`, may trigger an error `fatal error: sync: unlock of unlocked mutex`.
- if context cancled, it does not needs mutex.
2023-02-05 17:10:56 -03:00
Wayback Archiver
a16e2a28d5 Update relay.go 2023-02-05 11:19:26 -03:00
Wayback Archiver
d7d4c62602 Fix execution sequence 2023-02-05 11:19:26 -03:00
fiatjaf
92c0143762
make sub.Events a channel of pointers. 2023-01-26 09:04:27 -03:00
Dylan Cant
67813257df stopping data races with sync.mutex to Publish() in relay.go 2023-01-16 11:32:00 -05:00
barkyq
87b6280299
Added some NIP-42 functionality to the client (relay.go) (#38) 2023-01-16 08:27:11 -03:00