diff --git a/src/main/kotlin/core/node/LocationStructures.kt b/src/main/kotlin/core/node/LocationStructures.kt new file mode 100644 index 0000000000..ac0a33d5dc --- /dev/null +++ b/src/main/kotlin/core/node/LocationStructures.kt @@ -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 { + 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() + + 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()] +} \ No newline at end of file diff --git a/src/main/kotlin/core/node/Node.kt b/src/main/kotlin/core/node/Node.kt index 61d15eed0b..8cf16ba761 100644 --- a/src/main/kotlin/core/node/Node.kt +++ b/src/main/kotlin/core/node/Node.kt @@ -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 diff --git a/src/main/kotlin/core/node/NodeInfo.kt b/src/main/kotlin/core/node/NodeInfo.kt new file mode 100644 index 0000000000..d797a54e95 --- /dev/null +++ b/src/main/kotlin/core/node/NodeInfo.kt @@ -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 = emptySet()) diff --git a/src/main/kotlin/core/node/services/NetworkMapCache.kt b/src/main/kotlin/core/node/services/NetworkMapCache.kt index 7463054dd4..3742f84702 100644 --- a/src/main/kotlin/core/node/services/NetworkMapCache.kt +++ b/src/main/kotlin/core/node/services/NetworkMapCache.kt @@ -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 = 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 { - 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() - - 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()] -} \ No newline at end of file diff --git a/src/main/kotlin/core/testing/InMemoryMessagingNetwork.kt b/src/main/kotlin/core/testing/InMemoryMessagingNetwork.kt index e0392edb22..537923be40 100644 --- a/src/main/kotlin/core/testing/InMemoryMessagingNetwork.kt +++ b/src/main/kotlin/core/testing/InMemoryMessagingNetwork.kt @@ -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 diff --git a/src/main/kotlin/core/testing/MockNetworkMapCache.kt b/src/main/kotlin/core/testing/MockNetworkMapCache.kt index 429188e7bb..ef01975e27 100644 --- a/src/main/kotlin/core/testing/MockNetworkMapCache.kt +++ b/src/main/kotlin/core/testing/MockNetworkMapCache.kt @@ -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 { diff --git a/src/main/kotlin/core/testing/MockNode.kt b/src/main/kotlin/core/testing/MockNode.kt index dfa35e810c..5606510b0d 100644 --- a/src/main/kotlin/core/testing/MockNode.kt +++ b/src/main/kotlin/core/testing/MockNode.kt @@ -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 diff --git a/src/main/kotlin/core/testing/Simulation.kt b/src/main/kotlin/core/testing/Simulation.kt index 0c5b2c6a71..9fbe62f17f 100644 --- a/src/main/kotlin/core/testing/Simulation.kt +++ b/src/main/kotlin/core/testing/Simulation.kt @@ -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 diff --git a/src/main/kotlin/demos/IRSDemo.kt b/src/main/kotlin/demos/IRSDemo.kt index 2cf8e04934..687dae0ecd 100644 --- a/src/main/kotlin/demos/IRSDemo.kt +++ b/src/main/kotlin/demos/IRSDemo.kt @@ -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 diff --git a/src/main/kotlin/demos/RateFixDemo.kt b/src/main/kotlin/demos/RateFixDemo.kt index 9fe897cd48..15b80fdae3 100644 --- a/src/main/kotlin/demos/RateFixDemo.kt +++ b/src/main/kotlin/demos/RateFixDemo.kt @@ -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 diff --git a/src/main/kotlin/demos/TraderDemo.kt b/src/main/kotlin/demos/TraderDemo.kt index fe66c6cff7..7e06d7e871 100644 --- a/src/main/kotlin/demos/TraderDemo.kt +++ b/src/main/kotlin/demos/TraderDemo.kt @@ -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 diff --git a/src/main/kotlin/demos/protocols/ExitServerProtocol.kt b/src/main/kotlin/demos/protocols/ExitServerProtocol.kt index 3693f93158..c416d303ea 100644 --- a/src/main/kotlin/demos/protocols/ExitServerProtocol.kt +++ b/src/main/kotlin/demos/protocols/ExitServerProtocol.kt @@ -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 diff --git a/src/main/kotlin/demos/protocols/UpdateBusinessDayProtocol.kt b/src/main/kotlin/demos/protocols/UpdateBusinessDayProtocol.kt index d0718b367a..9f6d63ba4c 100644 --- a/src/main/kotlin/demos/protocols/UpdateBusinessDayProtocol.kt +++ b/src/main/kotlin/demos/protocols/UpdateBusinessDayProtocol.kt @@ -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 diff --git a/src/main/kotlin/protocols/RatesFixProtocol.kt b/src/main/kotlin/protocols/RatesFixProtocol.kt index 7ae6c783c2..b19220e38b 100644 --- a/src/main/kotlin/protocols/RatesFixProtocol.kt +++ b/src/main/kotlin/protocols/RatesFixProtocol.kt @@ -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 diff --git a/src/main/kotlin/protocols/TimestampingProtocol.kt b/src/main/kotlin/protocols/TimestampingProtocol.kt index 5d38cf2f83..e840a75818 100644 --- a/src/main/kotlin/protocols/TimestampingProtocol.kt +++ b/src/main/kotlin/protocols/TimestampingProtocol.kt @@ -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 diff --git a/src/main/kotlin/protocols/TwoPartyDealProtocol.kt b/src/main/kotlin/protocols/TwoPartyDealProtocol.kt index 67fc707999..dfa826263f 100644 --- a/src/main/kotlin/protocols/TwoPartyDealProtocol.kt +++ b/src/main/kotlin/protocols/TwoPartyDealProtocol.kt @@ -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 diff --git a/src/main/kotlin/protocols/TwoPartyTradeProtocol.kt b/src/main/kotlin/protocols/TwoPartyTradeProtocol.kt index 313af6296d..a8c5af6cf0 100644 --- a/src/main/kotlin/protocols/TwoPartyTradeProtocol.kt +++ b/src/main/kotlin/protocols/TwoPartyTradeProtocol.kt @@ -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 diff --git a/src/main/resources/core/node/services/cities.txt b/src/main/resources/core/node/cities.txt similarity index 100% rename from src/main/resources/core/node/services/cities.txt rename to src/main/resources/core/node/cities.txt diff --git a/src/test/kotlin/core/messaging/AttachmentTests.kt b/src/test/kotlin/core/messaging/AttachmentTests.kt index 69b52e55fc..887a9fbbad 100644 --- a/src/test/kotlin/core/messaging/AttachmentTests.kt +++ b/src/test/kotlin/core/messaging/AttachmentTests.kt @@ -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 diff --git a/src/test/kotlin/core/messaging/TwoPartyTradeProtocolTests.kt b/src/test/kotlin/core/messaging/TwoPartyTradeProtocolTests.kt index fef17dc4c0..497d57e828 100644 --- a/src/test/kotlin/core/messaging/TwoPartyTradeProtocolTests.kt +++ b/src/test/kotlin/core/messaging/TwoPartyTradeProtocolTests.kt @@ -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