98 Commits

Author SHA1 Message Date
fiatjaf
3e1749a01d
fix OK handling. 2023-12-09 13:21:35 -03:00
fiatjaf
f8fa490293
get rid of PublishStatus and always expect relays to answer with an OK for both AUTH and EvENT publishes. 2023-12-07 21:31:40 -03:00
fiatjaf
3adb1cde3c
only store the last AUTH challenge and allow user to perform auth only whenever they want instead of automatically. 2023-11-28 22:30:16 -03:00
fiatjaf
7449f254db
support handling CLOSED messages from relay client. 2023-11-28 18:54:24 -03:00
fiatjaf
93b43ed426
add infolog for when a relay sends an unexpected OK message.
this can be indicative of either us or the relay miscalculating the event id.
2023-11-08 22:22:30 -03:00
fiatjaf
c357e6babe
log event id on bad signature. 2023-11-08 00:07:01 -03:00
fiatjaf
f6df0f3f40
rename .mu -> .closeMutex 2023-11-05 13:39:09 -03:00
Yasuhiro Matsumoto
20d65d4a76 fix race condition in Close 2023-11-05 13:38:32 -03:00
fiatjaf
f8fb9e8c26
fix OKEnvelope always requiring the 4th field. 2023-11-04 17:30:19 -03:00
Isaque Veras
0f66883dc7 feat(kind): using constants 2023-09-07 07:05:01 -03:00
fiatjaf
eef7c40dc7
migrate to xsync v2. 2023-09-04 16:44:36 -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
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