Move node identity structures into core.node package

While node identity is used by services, it is not intrinsically part of services,
so moved it to the core.node package instead.
This commit is contained in:
Ross Nicoll 2016-04-07 18:18:06 +01:00
parent 81b2935285
commit ca1db997ab
20 changed files with 107 additions and 82 deletions

View File

@ -0,0 +1,68 @@
/*
* Copyright 2015 Distributed Ledger Group LLC. Distributed as Licensed Company IP to DLG Group Members
* pursuant to the August 7, 2015 Advisory Services Agreement and subject to the Company IP License terms
* set forth therein.
*
* All other rights reserved.
*/
package core.node
import java.util.*
/** A latitude/longitude pair. */
data class WorldCoordinate(val latitude: Double, val longitude: Double) {
init {
require(latitude in -90..90)
require(longitude in -180..180)
}
/**
* Convert to screen coordinates using the Mercator projection. You should have a world map image that
* you know the precise extents of for this function to work.
*
* Note that no world map ever has latitude extents of -90 to 90 because at these extremes the mapping tends
* to infinity. Google Maps, for example, uses a square map image, and square maps yield latitude extents
* of 85.0511 to -85.0511 = arctan(sinh(π)).
*/
fun project(screenWidth: Double, screenHeight: Double, topLatitude: Double, bottomLatitude: Double,
leftLongitude: Double, rightLongitude: Double): Pair<Double, Double> {
require(latitude in bottomLatitude..topLatitude)
require(longitude in leftLongitude..rightLongitude)
fun deg2rad(deg: Double) = deg * Math.PI / 180.0
val leftLngRad = deg2rad(leftLongitude)
val rightLngRad = deg2rad(rightLongitude)
fun longitudeToScreenX(lng: Double) = screenWidth * (deg2rad(lng) - leftLngRad) / (rightLngRad - leftLngRad)
fun screenYRelative(latDeg: Double) = Math.log(Math.tan(latDeg / 360.0 * Math.PI + Math.PI / 4))
val topLatRel = screenYRelative(topLatitude)
val bottomLatRel = screenYRelative(bottomLatitude)
fun latitudeToScreenY(lat: Double) = screenHeight * (screenYRelative(lat) - topLatRel) / (bottomLatRel - topLatRel)
return Pair(longitudeToScreenX(longitude), latitudeToScreenY(latitude))
}
}
/**
* A labelled [WorldCoordinate], where the label is human meaningful. For example, the name of the nearest city.
* Labels should not refer to non-landmarks, for example, they should not contain the names of organisations.
*/
data class PhysicalLocation(val coordinate: WorldCoordinate, val description: String)
/**
* A simple lookup table of city names to their coordinates. Lookups are case insensitive.
*/
object CityDatabase {
private val cityMap = HashMap<String, PhysicalLocation>()
init {
javaClass.getResourceAsStream("cities.txt").bufferedReader().useLines { lines ->
for (line in lines) {
if (line.startsWith("#")) continue
val (name, lng, lat) = line.split('\t')
cityMap[name.toLowerCase()] = PhysicalLocation(WorldCoordinate(lat.toDouble(), lng.toDouble()), name)
}
}
}
operator fun get(name: String) = cityMap[name.toLowerCase()]
}

View File

@ -7,7 +7,6 @@ import com.codahale.metrics.JmxReporter
import com.google.common.net.HostAndPort
import core.messaging.MessagingService
import core.node.services.ArtemisMessagingService
import core.node.services.NodeInfo
import core.node.servlets.AttachmentDownloadServlet
import core.node.servlets.DataUploadServlet
import core.utilities.loggerFor

View File

@ -0,0 +1,19 @@
/*
* Copyright 2015 Distributed Ledger Group LLC. Distributed as Licensed Company IP to DLG Group Members
* pursuant to the August 7, 2015 Advisory Services Agreement and subject to the Company IP License terms
* set forth therein.
*
* All other rights reserved.
*/
package core.node
import core.Party
import core.messaging.SingleMessageRecipient
import core.node.services.ServiceType
/**
* Info about a network node that acts on behalf of some sort of verified identity.
*/
data class NodeInfo(val address: SingleMessageRecipient, val identity: Party,
val physicalLocation: PhysicalLocation? = null,
var advertisedServices: Set<ServiceType> = emptySet())

View File

@ -3,15 +3,10 @@ package core.node.services
import core.Party
import core.crypto.DummyPublicKey
import core.messaging.SingleMessageRecipient
import core.node.NodeInfo
import core.node.PhysicalLocation
import java.util.*
/**
* Info about a network node that acts on behalf of some sort of verified identity.
*/
data class NodeInfo(val address: SingleMessageRecipient, val identity: Party,
val physicalLocation: PhysicalLocation? = null,
var advertisedServices: Set<ServiceType> = emptySet())
/**
* A network map contains lists of nodes on the network along with information about their identity keys, services
* they provide and host names or IP addresses where they can be connected to. A reasonable architecture for the
@ -30,59 +25,3 @@ interface NetworkMapCache {
fun nodeForPartyName(name: String): NodeInfo? = partyNodes.singleOrNull { it.identity.name == name }
}
/** A latitude/longitude pair. */
data class WorldCoordinate(val latitude: Double, val longitude: Double) {
init {
require(latitude in -90..90)
require(longitude in -180..180)
}
/**
* Convert to screen coordinates using the Mercator projection. You should have a world map image that
* you know the precise extents of for this function to work.
*
* Note that no world map ever has latitude extents of -90 to 90 because at these extremes the mapping tends
* to infinity. Google Maps, for example, uses a square map image, and square maps yield latitude extents
* of 85.0511 to -85.0511 = arctan(sinh(π)).
*/
fun project(screenWidth: Double, screenHeight: Double, topLatitude: Double, bottomLatitude: Double,
leftLongitude: Double, rightLongitude: Double): Pair<Double, Double> {
require(latitude in bottomLatitude..topLatitude)
require(longitude in leftLongitude..rightLongitude)
fun deg2rad(deg: Double) = deg * Math.PI / 180.0
val leftLngRad = deg2rad(leftLongitude)
val rightLngRad = deg2rad(rightLongitude)
fun longitudeToScreenX(lng: Double) = screenWidth * (deg2rad(lng) - leftLngRad) / (rightLngRad - leftLngRad)
fun screenYRelative(latDeg: Double) = Math.log(Math.tan(latDeg / 360.0 * Math.PI + Math.PI / 4))
val topLatRel = screenYRelative(topLatitude)
val bottomLatRel = screenYRelative(bottomLatitude)
fun latitudeToScreenY(lat: Double) = screenHeight * (screenYRelative(lat) - topLatRel) / (bottomLatRel - topLatRel)
return Pair(longitudeToScreenX(longitude), latitudeToScreenY(latitude))
}
}
/**
* A labelled [WorldCoordinate], where the label is human meaningful. For example, the name of the nearest city.
* Labels should not refer to non-landmarks, for example, they should not contain the names of organisations.
*/
data class PhysicalLocation(val coordinate: WorldCoordinate, val description: String)
/**
* A simple lookup table of city names to their coordinates. Lookups are case insensitive.
*/
object CityDatabase {
private val cityMap = HashMap<String, PhysicalLocation>()
init {
javaClass.getResourceAsStream("cities.txt").bufferedReader().useLines { lines ->
for (line in lines) {
if (line.startsWith("#")) continue
val (name, lng, lat) = line.split('\t')
cityMap[name.toLowerCase()] = PhysicalLocation(WorldCoordinate(lat.toDouble(), lng.toDouble()), name)
}
}
}
operator fun get(name: String) = cityMap[name.toLowerCase()]
}

View File

@ -6,8 +6,8 @@ import com.google.common.util.concurrent.MoreExecutors
import core.ThreadBox
import core.crypto.sha256
import core.messaging.*
import core.node.NodeInfo
import core.node.services.DummyTimestampingAuthority
import core.node.services.NodeInfo
import core.node.services.NodeTimestamperService
import core.node.services.ServiceType
import core.utilities.loggerFor

View File

@ -11,7 +11,7 @@ import core.Party
import core.crypto.DummyPublicKey
import core.messaging.SingleMessageRecipient
import core.node.services.NetworkMapCache
import core.node.services.NodeInfo
import core.node.NodeInfo
import java.util.*
class MockNetworkMapCache : NetworkMapCache {

View File

@ -7,9 +7,9 @@ import core.messaging.MessagingService
import core.messaging.SingleMessageRecipient
import core.node.AbstractNode
import core.node.NodeConfiguration
import core.node.NodeInfo
import core.node.PhysicalLocation
import core.node.services.FixedIdentityService
import core.node.services.NodeInfo
import core.node.services.PhysicalLocation
import core.node.services.ServiceType
import core.utilities.loggerFor
import org.slf4j.Logger

View File

@ -1,12 +1,11 @@
package core.testing
import com.google.common.util.concurrent.ListenableFuture
import core.node.CityDatabase
import core.node.NodeConfiguration
import core.node.services.CityDatabase
import core.node.services.NodeInfo
import core.node.services.PhysicalLocation
import core.node.NodeInfo
import core.node.PhysicalLocation
import core.protocols.ProtocolLogic
import core.testing.MockNetworkMapCache
import core.then
import core.utilities.ProgressTracker
import rx.Observable

View File

@ -7,8 +7,8 @@ import core.logElapsedTime
import core.node.Node
import core.node.NodeConfiguration
import core.node.NodeConfigurationFromConfig
import core.node.NodeInfo
import core.node.services.ArtemisMessagingService
import core.node.services.NodeInfo
import core.node.services.ServiceType
import core.testing.MockNetworkMapCache
import core.serialization.deserialize

View File

@ -5,7 +5,7 @@ import core.*
import core.node.Node
import core.node.NodeConfiguration
import core.node.services.ArtemisMessagingService
import core.node.services.NodeInfo
import core.node.NodeInfo
import core.node.services.NodeInterestRates
import core.serialization.deserialize
import core.utilities.ANSIProgressRenderer

View File

@ -12,8 +12,8 @@ import core.node.Node
import core.node.NodeConfiguration
import core.node.NodeConfigurationFromConfig
import core.node.services.ArtemisMessagingService
import core.node.NodeInfo
import core.node.services.NodeAttachmentService
import core.node.services.NodeInfo
import core.node.services.NodeWalletService
import core.protocols.ProtocolLogic
import core.serialization.deserialize

View File

@ -3,7 +3,7 @@ package demos.protocols
import co.paralleluniverse.fibers.Suspendable
import co.paralleluniverse.strands.Strand
import core.node.Node
import core.node.services.NodeInfo
import core.node.NodeInfo
import core.protocols.ProtocolLogic
import core.serialization.deserialize
import core.testing.MockNetworkMapCache

View File

@ -6,8 +6,8 @@ import contracts.DealState
import contracts.InterestRateSwap
import core.StateAndRef
import core.node.Node
import core.node.NodeInfo
import core.node.services.linearHeadsOfType
import core.node.services.NodeInfo
import core.protocols.ProtocolLogic
import core.random63BitValue
import core.serialization.deserialize

View File

@ -4,7 +4,7 @@ import co.paralleluniverse.fibers.Suspendable
import core.*
import core.crypto.DigitalSignature
import core.messaging.SingleMessageRecipient
import core.node.services.NodeInfo
import core.node.NodeInfo
import core.protocols.ProtocolLogic
import core.utilities.ProgressTracker
import java.math.BigDecimal

View File

@ -6,7 +6,7 @@ import core.WireTransaction
import core.crypto.DigitalSignature
import core.messaging.MessageRecipients
import core.messaging.StateMachineManager
import core.node.services.NodeInfo
import core.node.NodeInfo
import core.node.services.NodeTimestamperService
import core.node.services.TimestamperService
import core.protocols.ProtocolLogic

View File

@ -7,7 +7,7 @@ import core.*
import core.crypto.DigitalSignature
import core.crypto.signWithECDSA
import core.messaging.SingleMessageRecipient
import core.node.services.NodeInfo
import core.node.NodeInfo
import core.protocols.ProtocolLogic
import core.utilities.ProgressTracker
import core.utilities.UntrustworthyData

View File

@ -9,7 +9,7 @@ import core.crypto.DigitalSignature
import core.crypto.signWithECDSA
import core.messaging.SingleMessageRecipient
import core.messaging.StateMachineManager
import core.node.services.NodeInfo
import core.node.NodeInfo
import core.protocols.ProtocolLogic
import core.utilities.ProgressTracker
import core.utilities.trace

View File

@ -4,8 +4,8 @@ import core.Attachment
import core.crypto.SecureHash
import core.crypto.sha256
import core.node.NodeConfiguration
import core.node.NodeInfo
import core.node.services.NodeAttachmentService
import core.node.services.NodeInfo
import core.node.services.ServiceType
import core.serialization.OpaqueBytes
import core.testing.MockNetwork

View File

@ -5,6 +5,7 @@ import contracts.CommercialPaper
import core.*
import core.crypto.SecureHash
import core.node.NodeConfiguration
import core.node.NodeInfo
import core.node.services.*
import core.testing.InMemoryMessagingNetwork
import core.testing.MockNetwork