Corda 3.1 - discovering which nodes are down and not operating

蹲街弑〆低调 提交于 2021-02-08 10:01:35

问题


I have a question regarding Corda 3.1 and using the network map for the purpose of seeing if node is up - is it generally a good idea to use it for that ?

From these notes https://docs.corda.net/network-map.html#http-network-map-protocol as there is a polling of the network map participants data (in case that our cached data expired) it should be technically possible to do that. Could you see any drawbacks of implementing this in that way ?

If the node is configured with the compatibilityZoneURL config then it first uploads its own signed NodeInfo to the server (and each time it changes on startup) and then proceeds to download the entire network map. The network map consists of a list of NodeInfo hashes. The node periodically polls for the network map (based on the HTTP cache expiry header) and any new entries are downloaded and cached. Entries which no longer exist are deleted from the node’s cache.


回答1:


It is not a good idea to use the network map as a liveness service.

The network does have an event horizon parameter. If the node is offline for longer than the length of time specified by the event horizon parameter, it is ejected from the network map. However, the event horizon would usually be days (e.g. 30 days).

Instead, you can just ping the node's P2P port using a tool like Telnet. If you run telnet <node host> <P2P port> and the node is up, you'll see something like:

Trying ::1...
Connected to localhost.
Escape character is '^]'.

If the node is down, you'll see something like:

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host

Alternatively, if you want to check liveness automatically from within a flow, you can define a subflow like the one below. This flow will return a boolean indicating whether a given party on the network is offline.

@InitiatingFlow
class IsLiveFlow(val otherPartyName: CordaX500Name) : FlowLogic<Boolean>() {

    @Suspendable
    override fun call(): Boolean {
        val otherPartyInfo = serviceHub.networkMapCache.getNodeByLegalName(otherPartyName)!!
        val otherPartyP2PAddress = otherPartyInfo.addresses.single()
        return try {
            Socket().use { socket ->
                socket.connect(InetSocketAddress(otherPartyP2PAddress.host, otherPartyP2PAddress.port), 1000)
                true
            }
        } catch (e: IOException) {
            false
        }
    }
}


来源:https://stackoverflow.com/questions/51383429/corda-3-1-discovering-which-nodes-are-down-and-not-operating

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!