Corda 3.1 - 发现哪些节点已关闭且未运行
Corda 3.1 - discovering which nodes are down and not operating
我有一个关于 Corda 3.1 的问题,并使用网络映射来查看节点是否已启动 - 为此使用它通常是个好主意吗?
根据这些说明 https://docs.corda.net/network-map.html#http-network-map-protocol 因为有网络地图参与者数据的轮询(以防我们的缓存数据过期),所以技术上应该可以做到这一点。
您能看出以这种方式实施此方法的任何缺点吗?
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.
将网络地图用作活跃度服务不是一个好主意。
网络确实有事件视界参数。如果节点离线的时间超过事件视界参数指定的时间长度,它将被从网络地图中弹出。但是,事件范围通常是几天(例如 30 天)。
相反,您可以使用像 Telnet 这样的工具来 ping 节点的 P2P 端口。如果您 运行 telnet <node host> <P2P port>
并且节点已启动,您将看到类似以下内容:
Trying ::1...
Connected to localhost.
Escape character is '^]'.
如果节点已关闭,您将看到如下内容:
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
或者,如果您想从一个流中自动检查活跃度,您可以定义一个如下所示的子流。此流程将 return 一个布尔值,指示网络上的给定方是否离线。
@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
}
}
}
我有一个关于 Corda 3.1 的问题,并使用网络映射来查看节点是否已启动 - 为此使用它通常是个好主意吗?
根据这些说明 https://docs.corda.net/network-map.html#http-network-map-protocol 因为有网络地图参与者数据的轮询(以防我们的缓存数据过期),所以技术上应该可以做到这一点。 您能看出以这种方式实施此方法的任何缺点吗?
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.
将网络地图用作活跃度服务不是一个好主意。
网络确实有事件视界参数。如果节点离线的时间超过事件视界参数指定的时间长度,它将被从网络地图中弹出。但是,事件范围通常是几天(例如 30 天)。
相反,您可以使用像 Telnet 这样的工具来 ping 节点的 P2P 端口。如果您 运行 telnet <node host> <P2P port>
并且节点已启动,您将看到类似以下内容:
Trying ::1...
Connected to localhost.
Escape character is '^]'.
如果节点已关闭,您将看到如下内容:
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
或者,如果您想从一个流中自动检查活跃度,您可以定义一个如下所示的子流。此流程将 return 一个布尔值,指示网络上的给定方是否离线。
@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
}
}
}