-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose relay messages and connection state #54
Conversation
@@ -1,6 +1,6 @@ | |||
[versions] | |||
acinqSecp256 = "0.10.1" | |||
guava = "32.1.1-jre" | |||
guava = "31.1-jre" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My Android builds were hanging on the newer version of guava. (historically, android and guava don't get along very well)
Any appetite for finding a different solution for the cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added #57
private val subscriptions: MutableMap<Subscription, Set<Filter>> = Collections.synchronizedMap(mutableMapOf()) | ||
|
||
private var connectionState = Disconnected | ||
private var _connectionState = MutableStateFlow(Disconnected) | ||
val connectionState : StateFlow<ConnectionState> get() = _connectionState.asStateFlow() // TODO add tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is important so we can show users the current state of the relays
get() = sent.map { event -> | ||
EventMessage(arbSubscriptionId.next(), event) | ||
}.asFlow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way to handle the arb relay messages in this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sent.asSequence()
.zip(arbSubscriptionId.samples())
.map { (event, id) -> EventMessage(id, event) }
.asFlow()
@@ -52,18 +54,21 @@ abstract class Relay { | |||
/** Unsubscribe from a subscription */ | |||
abstract fun unsubscribe(subscription: Subscription) | |||
|
|||
/** All events transmitted by this relay for our active subscriptions */ | |||
/** All messages transmitted by this relay for our active subscriptions */ | |||
abstract val relayMessages : Flow<RelayMessage> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing all messages so we can handle them on the app-side.
It's also important to expose the subscription ID where the message was received so that the correct observer knows the message is for them.
.filterNot { | ||
it is EventMessage && cache.get(it.event.id) | ||
} | ||
.map { | ||
cache.put(it.id, true) | ||
if(it is EventMessage) { | ||
cache.put(it.event.id, true) | ||
} | ||
it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to find a better way to do this.
If multiple subscriptions share the same message, only one of them will receive it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised as #58
a09a960
to
1486398
Compare
I was able to hook up Nostrino relays into Plasma with these changes. It's still a WIP, but I wanted to start some conversations around a few of the changes