-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
custom ws subscriptions for vara (#334)
- Loading branch information
Showing
14 changed files
with
155 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
src/main/kotlin/io/emeraldpay/dshackle/upstream/HasEgressSubscription.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...main/kotlin/io/emeraldpay/dshackle/upstream/generic/subscribe/GenericPersistentConnect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) 2022 EmeraldPay, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.emeraldpay.dshackle.upstream.generic.subscribe | ||
|
||
import io.emeraldpay.dshackle.commons.DurableFlux | ||
import io.emeraldpay.dshackle.commons.SharedFluxHolder | ||
import io.emeraldpay.dshackle.upstream.Selector | ||
import io.emeraldpay.dshackle.upstream.SubscriptionConnect | ||
import reactor.core.publisher.Flux | ||
import java.time.Duration | ||
|
||
abstract class GenericPersistentConnect : SubscriptionConnect<Any> { | ||
|
||
private val connectionSource = DurableFlux | ||
.newBuilder() | ||
.using(::createConnection) | ||
.backoffOnError(Duration.ofMillis(100), 1.5, Duration.ofSeconds(60)) | ||
.build() | ||
private val holder = SharedFluxHolder( | ||
connectionSource::connect, | ||
) | ||
|
||
override fun connect(matcher: Selector.Matcher): Flux<Any> { | ||
return holder.get() | ||
} | ||
|
||
abstract fun createConnection(): Flux<Any> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/io/emeraldpay/dshackle/upstream/polkadot/PolkadotEgressSubscription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.emeraldpay.dshackle.upstream.polkadot | ||
|
||
import io.emeraldpay.dshackle.upstream.EgressSubscription | ||
import io.emeraldpay.dshackle.upstream.Multistream | ||
import io.emeraldpay.dshackle.upstream.Selector.Matcher | ||
import io.emeraldpay.dshackle.upstream.calls.DefaultPolkadotMethods | ||
import io.emeraldpay.dshackle.upstream.generic.GenericUpstream | ||
import reactor.core.publisher.Flux | ||
import reactor.core.scheduler.Scheduler | ||
|
||
class PolkadotEgressSubscription( | ||
val upstream: Multistream, | ||
val scheduler: Scheduler, | ||
) : EgressSubscription { | ||
override fun getAvailableTopics(): List<String> { | ||
return DefaultPolkadotMethods.subs.map { it.first } | ||
} | ||
|
||
override fun subscribe(topic: String, params: Any?, matcher: Matcher): Flux<ByteArray> { | ||
val up = upstream.getUpstreams().shuffled().first { matcher.matches(it) } as GenericUpstream | ||
return up.getIngressSubscription().get<ByteArray>(topic)?.connect(matcher) ?: Flux.empty() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/io/emeraldpay/dshackle/upstream/polkadot/PolkadotIngressSubscription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.emeraldpay.dshackle.upstream.polkadot | ||
|
||
import io.emeraldpay.dshackle.upstream.IngressSubscription | ||
import io.emeraldpay.dshackle.upstream.SubscriptionConnect | ||
import io.emeraldpay.dshackle.upstream.ethereum.WsSubscriptions | ||
import io.emeraldpay.dshackle.upstream.generic.subscribe.GenericPersistentConnect | ||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest | ||
import reactor.core.publisher.Flux | ||
import reactor.core.publisher.Mono | ||
import java.time.Duration | ||
|
||
class PolkadotIngressSubscription(val conn: WsSubscriptions) : IngressSubscription { | ||
override fun getAvailableTopics(): List<String> { | ||
return emptyList() // not used now | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun <T> get(topic: String): SubscriptionConnect<T> { | ||
return PolkaConnect(conn, topic) as SubscriptionConnect<T> | ||
} | ||
} | ||
|
||
class PolkaConnect( | ||
val conn: WsSubscriptions, | ||
val topic: String, | ||
) : GenericPersistentConnect() { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun createConnection(): Flux<Any> { | ||
return conn.subscribe(JsonRpcRequest(topic, listOf())) | ||
.data | ||
.timeout(Duration.ofSeconds(60), Mono.empty()) | ||
.onErrorResume { Mono.empty() } as Flux<Any> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.