Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

how can i exit the program after the relays send an EOSE? #28

Open
jeremyd opened this issue Dec 24, 2022 · 5 comments
Open

how can i exit the program after the relays send an EOSE? #28

jeremyd opened this issue Dec 24, 2022 · 5 comments

Comments

@jeremyd
Copy link

jeremyd commented Dec 24, 2022

I was attempting to add a get-contacts to synchronize my noscl contact list with the contact events I've sent from other clients.. I'd like the program to detect an EOSE from all relays and then save the config and exit, but I'm having a hard time figuring out how I might do that. Anyway, feel free to ignore this, but, if it's easy maybe we can document it or etc.. Thanks!

master...jeremyd:noscl:master

@fiatjaf
Copy link
Owner

fiatjaf commented Dec 24, 2022

This needs to be implemented.

@jeremyd jeremyd closed this as completed Jan 23, 2023
@fiatjaf fiatjaf reopened this Jan 23, 2023
@honza
Copy link
Collaborator

honza commented Feb 9, 2023

When you first subscribe to a relay, you'll be flooded with messages, and then it will stop, and the channel will wait for new messages. You can create a loop with a timeout, and once the timeout is reached, you can break from it.

Something like this would work:

	timeout := time.After(5 * time.Second)
	tick := time.Tick(1 * time.Millisecond)

	_, all := pool.Sub(nostr.Filters{})
	unique := nostr.Unique(all)

	for {
		select {
		case <-timeout:
			fmt.Println("timeout")
			break
		case <-tick:
                        timeout = time.After(5 * time.Second)
			event := <-unique
			handleEvent(event)

		}
	}

I wonder if it might be useful to have a reusable function that does the book-keeping for you.

@honza
Copy link
Collaborator

honza commented Feb 9, 2023

I implemented the helper in 7a5acc0

@honza
Copy link
Collaborator

honza commented Feb 10, 2023

Actually, what we really need is to upgrade the go-nostr library. The EOSE stuff is already implemented there. The problem is though that we need to figure out our own way of doing relay pooling.

@jeremyd
Copy link
Author

jeremyd commented Feb 11, 2023

Actually, what we really need is to upgrade the go-nostr library. The EOSE stuff is already implemented there. The problem is though that we need to figure out our own way of doing relay pooling.

yes, it is straight forward do do with go-nostr. here is one way I implemented this https://github.com/jeremyd/nostr-contacts/blob/main/cmd/backup.go#L130

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants