Use buyer/seller instead of alpha/beta and allow nodes to both be named localhost. Update docs.

This commit is contained in:
Mike Hearn 2016-02-05 15:48:58 +01:00
parent 75a542f79d
commit f705eee312
6 changed files with 18 additions and 22 deletions

View File

@ -1,9 +1,9 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="Node: alpha" type="JetRunConfigurationType" factoryName="Kotlin"> <configuration default="false" name="Node: buyer" type="JetRunConfigurationType" factoryName="Kotlin">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="MAIN_CLASS_NAME" value="core.node.TraderDemoKt" /> <option name="MAIN_CLASS_NAME" value="core.node.TraderDemoKt" />
<option name="VM_PARAMETERS" value="-ea -javaagent:lib/quasar.jar" /> <option name="VM_PARAMETERS" value="-ea -javaagent:lib/quasar.jar" />
<option name="PROGRAM_PARAMETERS" value="--dir=alpha --service-fake-trades --network-address=alpha" /> <option name="PROGRAM_PARAMETERS" value="--dir=buyer --service-fake-trades --network-address=localhost" />
<option name="WORKING_DIRECTORY" value="" /> <option name="WORKING_DIRECTORY" value="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" /> <option name="ALTERNATIVE_JRE_PATH" />

View File

@ -1,9 +1,9 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="Node: beta" type="JetRunConfigurationType" factoryName="Kotlin"> <configuration default="false" name="Node: seller" type="JetRunConfigurationType" factoryName="Kotlin">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" /> <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="MAIN_CLASS_NAME" value="core.node.TraderDemoKt" /> <option name="MAIN_CLASS_NAME" value="core.node.TraderDemoKt" />
<option name="VM_PARAMETERS" value="-ea -javaagent:lib/quasar.jar" /> <option name="VM_PARAMETERS" value="-ea -javaagent:lib/quasar.jar" />
<option name="PROGRAM_PARAMETERS" value="--dir=beta --fake-trade-with=alpha --network-address=beta:31338 --timestamper-identity-file=alpha/identity-public --timestamper-address=alpha:31338" /> <option name="PROGRAM_PARAMETERS" value="--dir=seller --fake-trade-with=localhost --network-address=localhost:31338 --timestamper-identity-file=buyer/identity-public --timestamper-address=localhost" />
<option name="WORKING_DIRECTORY" value="" /> <option name="WORKING_DIRECTORY" value="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" /> <option name="ALTERNATIVE_JRE_PATH" />

View File

@ -106,12 +106,12 @@ mainClassName = 'core.node.TraderDemoKt'
task runDemoBuyer(type: JavaExec, dependsOn: ':classes') { task runDemoBuyer(type: JavaExec, dependsOn: ':classes') {
classpath = sourceSets.main.runtimeClasspath classpath = sourceSets.main.runtimeClasspath
main = 'core.node.TraderDemoKt' main = 'core.node.TraderDemoKt'
args = ['--dir=alpha', '--service-fake-trades', '--network-address=alpha'] args = ['--dir=buyer', '--service-fake-trades', '--network-address=localhost']
} }
task runDemoSeller(type: JavaExec, dependsOn: ':classes') { task runDemoSeller(type: JavaExec, dependsOn: ':classes') {
classpath = sourceSets.main.runtimeClasspath classpath = sourceSets.main.runtimeClasspath
main = 'core.node.TraderDemoKt' main = 'core.node.TraderDemoKt'
args = ['--dir=beta', '--fake-trade-with=alpha', '--network-address=beta:31338', args = ['--dir=seller', '--fake-trade-with=localhost', '--network-address=localhost:31338',
'--timestamper-identity-file=alpha/identity-public', '--timestamper-address=alpha'] '--timestamper-identity-file=buyer/identity-public', '--timestamper-address=localhost']
} }

View File

@ -4,21 +4,15 @@ Running the trading demo
The repository contains a program that implements a demo of two nodes running the two-party trading protocol, which you The repository contains a program that implements a demo of two nodes running the two-party trading protocol, which you
can learn about in :doc:`protocol-state-machines`. can learn about in :doc:`protocol-state-machines`.
The node has only currently been tested on MacOS X. If you have success on other platforms, please let us know. The node has only currently been tested on MacOS X and Ubuntu Linux. If you have success on other platforms, please
let us know.
To run the demo, firstly edit your /etc/hosts file or Windows equivalent to add two aliases for localhost: alpha and
beta. This is necessary for now because parts of the code use the DNS hostname to identify nodes and thus defining two
nodes both called localhost won't work. We might fix this in future to include the port number everywhere, so making
this easier.
You should now be able to run ``ping alpha`` and ``ping beta`` and not see errors.
Now, open two terminals, and in the first run::: Now, open two terminals, and in the first run:::
./gradlew runDemoBuyer ./gradlew runDemoBuyer
It will create a directory named "alpha" and ask you to edit the configuration file inside. Open up ``alpha/config`` It will create a directory named "buyer" and ask you to edit the configuration file inside. Open up ``buyer/config``
in your favourite text editor and give the node a legal identity of "Alpha Corp, Inc" or whatever else you feel like. in your favourite text editor and give the node a legal identity of "Big Buyer Corp, Inc" or whatever else you feel like.
The actual text string is not important. Now run the gradle command again, and it should start up and wait for The actual text string is not important. Now run the gradle command again, and it should start up and wait for
a seller to connect. a seller to connect.

View File

@ -9,7 +9,7 @@
package core.node package core.node
import com.google.common.net.HostAndPort import com.google.common.net.HostAndPort
import com.google.common.util.concurrent.MoreExecutors import core.RunOnCallerThread
import core.ThreadBox import core.ThreadBox
import core.messaging.* import core.messaging.*
import core.utilities.loggerFor import core.utilities.loggerFor
@ -90,7 +90,7 @@ class ArtemisMessagingService(val directory: Path, val myHostPort: HostAndPort)
return mutex.locked { return mutex.locked {
sendClients.getOrPut(addr) { sendClients.getOrPut(addr) {
maybeSetupConnection(addr.hostAndPort) maybeSetupConnection(addr.hostAndPort)
val qName = addr.hostAndPort.hostText val qName = addr.hostAndPort.toString()
session.createProducer(qName) session.createProducer(qName)
} }
} }
@ -124,7 +124,7 @@ class ArtemisMessagingService(val directory: Path, val myHostPort: HostAndPort)
// Create a queue on which to receive messages and set up the handler. // Create a queue on which to receive messages and set up the handler.
session = clientFactory.createSession() session = clientFactory.createSession()
session.createQueue(myHostPort.hostText, "inbound", false) session.createQueue(myHostPort.toString(), "inbound", false)
inboundConsumer = session.createConsumer("inbound").setMessageHandler { message: ClientMessage -> inboundConsumer = session.createConsumer("inbound").setMessageHandler { message: ClientMessage ->
// This code runs for every inbound message. // This code runs for every inbound message.
if (!message.containsProperty(TOPIC_PROPERTY)) { if (!message.containsProperty(TOPIC_PROPERTY)) {
@ -155,7 +155,7 @@ class ArtemisMessagingService(val directory: Path, val myHostPort: HostAndPort)
override fun serialise(): ByteArray = bits override fun serialise(): ByteArray = bits
} }
for (handler in deliverTo) { for (handler in deliverTo) {
(handler.executor ?: MoreExecutors.directExecutor()).execute { (handler.executor ?: RunOnCallerThread).execute {
try { try {
handler.callback(msg, handler) handler.callback(msg, handler)
} catch(e: Exception) { } catch(e: Exception) {
@ -220,7 +220,7 @@ class ArtemisMessagingService(val directory: Path, val myHostPort: HostAndPort)
private enum class ConnectionDirection { INBOUND, OUTBOUND } private enum class ConnectionDirection { INBOUND, OUTBOUND }
private fun maybeSetupConnection(hostAndPort: HostAndPort) { private fun maybeSetupConnection(hostAndPort: HostAndPort) {
val name = hostAndPort.hostText val name = hostAndPort.toString()
// To make ourselves talk to a remote server, we need a "bridge". Bridges are things inside Artemis that know how // To make ourselves talk to a remote server, we need a "bridge". Bridges are things inside Artemis that know how
// to handle remote machines going away temporarily, retry connections, etc. They're the bit that handles // to handle remote machines going away temporarily, retry connections, etc. They're the bit that handles

View File

@ -184,7 +184,9 @@ fun makeFakeCommercialPaper(ownedBy: PublicKey): StateAndRef<CommercialPaper.Sta
private fun loadConfigFile(configFile: Path): NodeConfiguration { private fun loadConfigFile(configFile: Path): NodeConfiguration {
fun askAdminToEditConfig(configFile: Path?) { fun askAdminToEditConfig(configFile: Path?) {
println()
println("This is the first run, so you should edit the config file in $configFile and then start the node again.") println("This is the first run, so you should edit the config file in $configFile and then start the node again.")
println()
System.exit(1) System.exit(1)
} }