mirror of
https://github.com/corda/corda.git
synced 2025-06-14 13:18:18 +00:00
Remove advertised services from NodeInfo (#1521)
* Remove advertisedServices from NodeInfo. Introduce notaryIdentities in NetworkMapCache, that will be filled in later from NetworkParameters. Clean up NetworkMapCache API. Expose notaryIdentities through RPC. For now we assume as temporary solution that notaries in NetworkMap have to contain "notary" in name. * Further clean up of NetworkMapCache API Remve partyNodes. Introduce getAllNodeInfos function * Remove notaryIdentity from ServiceHub * Address Shams review comments * Address Andrius review comments * Add comments, cleanup * Fixes * Address comments * Yet another commit with comments addressed * Move ServiceType and ServiceInfo to node-api Add changelog entry. Address rest of comments. * Minor comments
This commit is contained in:
committed by
josecoll
parent
6887947a4d
commit
fd57cf1c0c
27
node-api/src/main/kotlin/net/corda/nodeapi/ServiceInfo.kt
Normal file
27
node-api/src/main/kotlin/net/corda/nodeapi/ServiceInfo.kt
Normal file
@ -0,0 +1,27 @@
|
||||
package net.corda.nodeapi
|
||||
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
|
||||
/**
|
||||
* A container for additional information for an advertised service.
|
||||
*
|
||||
* @param type the ServiceType identifier
|
||||
* @param name the service name, used for differentiating multiple services of the same type. Can also be used as a
|
||||
* grouping identifier for nodes collectively running a distributed service.
|
||||
*/
|
||||
@CordaSerializable
|
||||
data class ServiceInfo(val type: ServiceType, val name: CordaX500Name? = null) {
|
||||
companion object {
|
||||
fun parse(encoded: String): ServiceInfo {
|
||||
val parts = encoded.split("|")
|
||||
require(parts.size in 1..2) { "Invalid number of elements found" }
|
||||
val type = ServiceType.parse(parts[0])
|
||||
val name = parts.getOrNull(1)
|
||||
val principal = name?.let { CordaX500Name.parse(it) }
|
||||
return ServiceInfo(type, principal)
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString() = if (name != null) "$type|$name" else type.toString()
|
||||
}
|
45
node-api/src/main/kotlin/net/corda/nodeapi/ServiceType.kt
Normal file
45
node-api/src/main/kotlin/net/corda/nodeapi/ServiceType.kt
Normal file
@ -0,0 +1,45 @@
|
||||
package net.corda.nodeapi
|
||||
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
|
||||
/**
|
||||
* Identifier for service types a node can expose over the network to other peers. These types are placed into network
|
||||
* map advertisements. Services that are purely local and are not providing functionality to other parts of the network
|
||||
* don't need a declared service type.
|
||||
*/
|
||||
@CordaSerializable
|
||||
class ServiceType private constructor(val id: String) {
|
||||
init {
|
||||
// Enforce:
|
||||
//
|
||||
// * IDs must start with a lower case letter
|
||||
// * IDs can only contain alphanumeric, full stop and underscore ASCII characters
|
||||
require(id.matches(Regex("[a-z][a-zA-Z0-9._]+"))) { id }
|
||||
}
|
||||
|
||||
companion object {
|
||||
val corda: ServiceType
|
||||
get() {
|
||||
val stack = Throwable().stackTrace
|
||||
val caller = stack.first().className
|
||||
require(caller.startsWith("net.corda.")) { "Corda ServiceType namespace is reserved for Corda core components" }
|
||||
return ServiceType("corda")
|
||||
}
|
||||
|
||||
val notary: ServiceType = corda.getSubType("notary")
|
||||
val networkMap: ServiceType = corda.getSubType("network_map")
|
||||
|
||||
fun parse(id: String): ServiceType = ServiceType(id)
|
||||
|
||||
private fun baseWithSubType(baseId: String, subTypeId: String) = ServiceType("$baseId.$subTypeId")
|
||||
}
|
||||
|
||||
fun getSubType(subTypeId: String): ServiceType = baseWithSubType(id, subTypeId)
|
||||
|
||||
fun isSubTypeOf(superType: ServiceType) = (id == superType.id) || id.startsWith(superType.id + ".")
|
||||
fun isNotary() = isSubTypeOf(notary)
|
||||
|
||||
override fun equals(other: Any?): Boolean = other === this || other is ServiceType && other.id == this.id
|
||||
override fun hashCode(): Int = id.hashCode()
|
||||
override fun toString(): String = id
|
||||
}
|
Reference in New Issue
Block a user