mirror of
https://github.com/corda/corda.git
synced 2025-01-02 03:06:45 +00:00
Add in-node network map service
This commit is contained in:
parent
5134dd4bbc
commit
00a2088fa5
@ -11,6 +11,7 @@ import core.node.services.*
|
||||
import core.serialization.deserialize
|
||||
import core.serialization.serialize
|
||||
import core.testing.MockNetworkMapCache
|
||||
import core.utilities.AddOrRemove
|
||||
import core.utilities.AffinityExecutor
|
||||
import org.slf4j.Logger
|
||||
import java.nio.file.FileAlreadyExistsException
|
||||
@ -18,6 +19,7 @@ import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.security.KeyPair
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@ -44,7 +46,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
||||
|
||||
val services = object : ServiceHub {
|
||||
override val networkService: MessagingService get() = net
|
||||
override val networkMapCache: NetworkMapCache = MockNetworkMapCache()
|
||||
override val networkMapCache: NetworkMapCache = InMemoryNetworkMapCache()
|
||||
override val storageService: StorageService get() = storage
|
||||
override val walletService: WalletService get() = wallet
|
||||
override val keyManagementService: KeyManagementService get() = keyManagement
|
||||
@ -63,6 +65,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
||||
lateinit var smm: StateMachineManager
|
||||
lateinit var wallet: WalletService
|
||||
lateinit var keyManagement: E2ETestKeyManagementService
|
||||
var inNodeNetworkMapService: NetworkMapService? = null
|
||||
var inNodeTimestampingService: NodeTimestamperService? = null
|
||||
lateinit var identity: IdentityService
|
||||
lateinit var net: MessagingService
|
||||
@ -78,6 +81,9 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
||||
keyManagement = E2ETestKeyManagementService()
|
||||
makeInterestRatesOracleService()
|
||||
api = APIServerImpl(this)
|
||||
|
||||
// Build services we're advertising
|
||||
if (NetworkMapService.Type in info.advertisedServices) makeNetworkMapService()
|
||||
makeTimestampingService(timestamperAddress)
|
||||
identity = makeIdentityService()
|
||||
|
||||
@ -88,6 +94,12 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
||||
return this
|
||||
}
|
||||
|
||||
open protected fun makeNetworkMapService() {
|
||||
val expires = Instant.now() + NetworkMapService.DEFAULT_EXPIRATION_PERIOD
|
||||
val reg = NodeRegistration(info, Long.MAX_VALUE, AddOrRemove.ADD, expires)
|
||||
inNodeNetworkMapService = InMemoryNetworkMapService(net, reg, services.networkMapCache)
|
||||
}
|
||||
|
||||
private fun makeTimestampingService(timestamperAddress: NodeInfo?) {
|
||||
// Insert a network map entry for the timestamper: this is all temp scaffolding and will go away. If we are
|
||||
// given the details, the timestamping node is somewhere else. Otherwise, we do our own timestamping.
|
||||
@ -103,7 +115,7 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
||||
inNodeTimestampingService = NodeTimestamperService(net, storage.myLegalIdentity, storage.myLegalIdentityKey, platformClock)
|
||||
NodeInfo(net.myAddress, storage.myLegalIdentity, setOf(TimestamperService.Type))
|
||||
}
|
||||
(services.networkMapCache as MockNetworkMapCache).addRegistration(tsid)
|
||||
services.networkMapCache.addNode(tsid)
|
||||
}
|
||||
|
||||
lateinit var interestRatesService: NodeInterestRates.Service
|
||||
|
@ -8,6 +8,7 @@ import core.node.AbstractNode
|
||||
import core.node.NodeConfiguration
|
||||
import core.node.NodeInfo
|
||||
import core.node.PhysicalLocation
|
||||
import core.node.services.NetworkMapService
|
||||
import core.node.services.ServiceType
|
||||
import core.node.services.TimestamperService
|
||||
import core.utilities.AffinityExecutor
|
||||
@ -89,7 +90,7 @@ class MockNetwork(private val threadPerNode: Boolean = false,
|
||||
|
||||
/** Returns a started node, optionally created by the passed factory method */
|
||||
fun createNode(withTimestamper: NodeInfo? = null, forcedID: Int = -1, nodeFactory: Factory = defaultFactory,
|
||||
advertisedServices: Set<ServiceType> = emptySet()): MockNode {
|
||||
vararg advertisedServices: ServiceType): MockNode {
|
||||
val newNode = forcedID == -1
|
||||
val id = if (newNode) counter++ else forcedID
|
||||
|
||||
@ -101,7 +102,7 @@ class MockNetwork(private val threadPerNode: Boolean = false,
|
||||
override val exportJMXto: String = ""
|
||||
override val nearestCity: String = "Atlantis"
|
||||
}
|
||||
val node = nodeFactory.create(path, config, this, withTimestamper, advertisedServices, id).start()
|
||||
val node = nodeFactory.create(path, config, this, withTimestamper, advertisedServices.toSet(), id).start()
|
||||
_nodes.add(node)
|
||||
return node
|
||||
}
|
||||
@ -122,12 +123,13 @@ class MockNetwork(private val threadPerNode: Boolean = false,
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a two node network in which the first node runs a timestamping service and the other doesn't.
|
||||
* Sets up a two node network, in which the first node runs network map and timestamping services and the other
|
||||
* doesn't.
|
||||
*/
|
||||
fun createTwoNodes(nodeFactory: Factory = defaultFactory): Pair<MockNode, MockNode> {
|
||||
require(nodes.isEmpty())
|
||||
return Pair(
|
||||
createNode(null, -1, nodeFactory, setOf(TimestamperService.Type)),
|
||||
createNode(null, -1, nodeFactory, NetworkMapService.Type, TimestamperService.Type),
|
||||
createNode(nodes[0].info, -1, nodeFactory)
|
||||
)
|
||||
}
|
||||
|
@ -98,10 +98,10 @@ fun main(args: Array<String>) {
|
||||
val node = logElapsedTime("Node startup") { Node(dir, myNetAddr, config, timestamperId, advertisedServices, DemoClock()).start() }
|
||||
|
||||
// Add self to network map
|
||||
(node.services.networkMapCache as MockNetworkMapCache).addRegistration(node.info)
|
||||
node.services.networkMapCache.addNode(node.info)
|
||||
|
||||
// Add rates oracle to network map if one has been specified
|
||||
rateOracleId?.let { (node.services.networkMapCache as MockNetworkMapCache).addRegistration(it) }
|
||||
rateOracleId?.let { node.services.networkMapCache.addNode(it) }
|
||||
|
||||
val hostAndPortStrings = options.valuesOf(fakeTradeWithAddr)
|
||||
val identityFiles = options.valuesOf(fakeTradeWithIdentityFile)
|
||||
|
@ -98,7 +98,7 @@ class AttachmentTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
}, advertisedServices = setOf(TimestamperService.Type))
|
||||
}, advertisedServices = TimestamperService.Type)
|
||||
val n1 = network.createNode(n0.info)
|
||||
|
||||
// Insert an attachment into node zero's store directly.
|
||||
|
@ -55,7 +55,7 @@ class TimestamperNodeServiceTest {
|
||||
|
||||
@Test
|
||||
fun successWithNetwork() {
|
||||
val timestamperNode = network.createNode(null, advertisedServices = setOf(TimestamperService.Type))
|
||||
val timestamperNode = network.createNode(null, advertisedServices = TimestamperService.Type)
|
||||
val logName = NodeTimestamperService.TIMESTAMPING_PROTOCOL_TOPIC
|
||||
val psm = TestPSM(timestamperNode.info, clock.instant())
|
||||
val future = timestamperNode.smm.add(logName, psm)
|
||||
@ -66,7 +66,7 @@ class TimestamperNodeServiceTest {
|
||||
|
||||
@Test
|
||||
fun wrongCommands() {
|
||||
val timestamperNode = network.createNode(null, advertisedServices = setOf(TimestamperService.Type))
|
||||
val timestamperNode = network.createNode(null, advertisedServices = TimestamperService.Type)
|
||||
val timestamperKey = timestamperNode.services.storageService.myLegalIdentity.owningKey
|
||||
val service = timestamperNode.inNodeTimestampingService!!
|
||||
|
||||
@ -86,7 +86,7 @@ class TimestamperNodeServiceTest {
|
||||
|
||||
@Test
|
||||
fun tooEarly() {
|
||||
val timestamperNode = network.createNode(null, advertisedServices = setOf(TimestamperService.Type))
|
||||
val timestamperNode = network.createNode(null, advertisedServices = TimestamperService.Type)
|
||||
val timestamperKey = timestamperNode.services.storageService.myLegalIdentity.owningKey
|
||||
val service = timestamperNode.inNodeTimestampingService!!
|
||||
|
||||
@ -100,7 +100,7 @@ class TimestamperNodeServiceTest {
|
||||
|
||||
@Test
|
||||
fun tooLate() {
|
||||
val timestamperNode = network.createNode(null, advertisedServices = setOf(TimestamperService.Type))
|
||||
val timestamperNode = network.createNode(null, advertisedServices = TimestamperService.Type)
|
||||
val timestamperKey = timestamperNode.services.storageService.myLegalIdentity.owningKey
|
||||
val service = timestamperNode.inNodeTimestampingService!!
|
||||
|
||||
@ -114,7 +114,7 @@ class TimestamperNodeServiceTest {
|
||||
|
||||
@Test
|
||||
fun success() {
|
||||
val timestamperNode = network.createNode(null, advertisedServices = setOf(TimestamperService.Type))
|
||||
val timestamperNode = network.createNode(null, advertisedServices = TimestamperService.Type)
|
||||
val timestamperKey = timestamperNode.services.storageService.myLegalIdentity.owningKey
|
||||
val service = timestamperNode.inNodeTimestampingService!!
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user