File tree Expand file tree Collapse file tree
src/main/kotlin/network/rpc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import io.javalin.websocket.WsConnectContext
77import io.javalin.websocket.WsContext
88import kotlinx.serialization.encodeToString
99import kotlinx.serialization.json.Json
10+ import logging.Logger
1011import network.kademlia.Kademlia
1112import java.util.concurrent.TimeUnit
1213
@@ -30,6 +31,19 @@ open class RPCManager(configuration: Configuration) : Kademlia(configuration) {
3031 webServer.ws(" /" ) {
3132 it.onConnect(this ::onConnect)
3233 it.onClose(this ::onClose)
34+ it.onMessage { context ->
35+ val message = context.message()
36+ when (message) {
37+ " dht" -> {
38+ context.send(Json .encodeToString(knownNodes.values))
39+ }
40+
41+ else -> {
42+ Logger .debug(" A message of $message is being ignored via WS" )
43+ }
44+ }
45+
46+ }
3347 }
3448 }
3549 }
@@ -47,6 +61,7 @@ open class RPCManager(configuration: Configuration) : Kademlia(configuration) {
4761 .add(webSocket)
4862 }
4963 sendToSubscribed(Topic .Logging , " Hello, this is Nion node!" )
64+ sendToSubscribed(Topic .Logging , Json .encodeToString(knownNodes.values))
5065 }
5166
5267 /* *
You can’t perform that action at this time.
0 commit comments