Skip to content

Commit

Permalink
DEVREL-002: Add PingPong Java (#2)
Browse files Browse the repository at this point in the history
* Sample Ping Pong using Next Gen Corda

* Add review comments

---------

Co-authored-by: Divya <[email protected]>
  • Loading branch information
divya-r3 and divya-r3 authored Apr 13, 2023
1 parent 3059de8 commit 19a3ca9
Show file tree
Hide file tree
Showing 44 changed files with 2,458 additions and 0 deletions.
10 changes: 10 additions & 0 deletions java-samples/ping-pong/.ci/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@Library('[email protected]') _

cordaPipeline(
nexusAppId: 'com.corda.CSDE-Java.5.0',
publishRepoPrefix: '',
slimBuild: true,
runUnitTests: false,
dedicatedJobForSnykDelta: false,
slackChannel: '#corda-corda5-dev-ex-build-notifications'
)
5 changes: 5 additions & 0 deletions java-samples/ping-pong/.ci/nightly/JenkinsfileNexusScan
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@Library('[email protected]') _

cordaNexusScanPipeline(
nexusAppId: 'com.corda.CSDE-Java.5.0'
)
6 changes: 6 additions & 0 deletions java-samples/ping-pong/.ci/nightly/JenkinsfileSnykScan
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Library('[email protected]') _

cordaSnykScanPipeline (
snykTokenId: 'r3-snyk-corda5',
snykAdditionalCommands: "--all-sub-projects -d"
)
88 changes: 88 additions & 0 deletions java-samples/ping-pong/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

# Eclipse, ctags, Mac metadata, log files
.classpath
.project
.settings
tags
.DS_Store
*.log
*.orig

# Created by .ignore support plugin (hsz.mobi)

.gradle
local.properties
.gradletasknamecache

# General build files
**/build/*

lib/quasar.jar

**/logs/*

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio

*.iml

## Directory-based project format:
.idea/*.xml
.idea/.name
.idea/copyright
.idea/inspectionProfiles
.idea/libraries
.idea/shelf
.idea/dataSources
.idea/markdown-navigator
.idea/runConfigurations
.idea/dictionaries


# Include the -parameters compiler option by default in IntelliJ required for serialization.
!.idea/codeStyleSettings.xml


## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
**/out/
/classes/



# vim
*.swp
*.swn
*.swo



# Directory generated during Resolve and TestOSGi gradle tasks
bnd/

# Ignore Gradle build output directory
build
/.idea/codeStyles/codeStyleConfig.xml
/.idea/codeStyles/Project.xml



# Ignore Visual studio directory
bin/



*.cpi
*.cpb
*.cpk
workspace/**
#CordaPID.dat
#*.pem
#*.pfx
#CPIFileStatus*.json
#GroupPolicy.json
15 changes: 15 additions & 0 deletions java-samples/ping-pong/.run/runConfigurations/DebugCorDapp.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="DebugCorDapp" type="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
<option name="AUTO_RESTART" value="false" />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="5005" />
<option name="LOCAL" value="false" />
</RunnerSettings>
<method v="2" />
</configuration>
</component>
22 changes: 22 additions & 0 deletions java-samples/ping-pong/.snyk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.25.0
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
ignore:
SNYK-JAVA-ORGJETBRAINSKOTLIN-2393744:
- '*':
reason: >-
This vulnerability relates to information exposure via creation of
temporary files (via Kotlin functions) with insecure permissions.
Corda does not use any of the vulnerable functions so it is not
susceptible to this vulnerability
expires: 2023-06-19T17:15:26.836Z
created: 2023-02-02T17:15:26.839Z
SNYK-JAVA-ORGJETBRAINSKOTLIN-2628385:
- '*':
reason: >-
corda-simulator-runtime is a testRuntimeOnly dependency, as such this
dependency will not be included in any cordaApp produced by the CSDE
project Template
expires: 2023-06-19T17:16:00.009Z
created: 2023-02-02T17:16:00.016Z
patch: {}
62 changes: 62 additions & 0 deletions java-samples/ping-pong/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Ping-Pong CorDapp
This CorDapp allows a node to ping any other node on the network that also has this CorDapp installed.
It demonstrates how to use Corda for messaging and passing data using a [flow](https://docs.r3.com/en/platform/corda/5.0-beta/developing/ledger/flows.html) without saving any states or using any contracts.


### Concepts
The `ping` utility is normally used to send a Send ICMP ECHO_REQUEST packet to network hosts. The idea being that the receiving host will echo the message back.
In this example the Ping flow will send the String "Ping" to a other member in the network.
The otherMember will correspondingly reply with "Pong".

## Flows
You'll notice in our code we call these two classes ping and pong, the flow that sends the `"ping"`, and the flow that returns with a `"pong"`.

Take a look at [Ping.java](./workflows/src/main/java/com/r3/developers/pingpong/workflows/Ping.java).
You'll notice that this flow does what we expect, which is to send an outbound ping, and expect to receive a pong.
If we receive a pong, then our flow is successful.
And of course we see a similar behavior in [Pong.java](./workflows/src/main/java/com/r3/developers/pingpong/workflows/Pong.java).
We expect to receive data from a counterparty that contains a ping, when we receive it, we respond with a pong.

## Pre-Requisites
For development environment setup, please refer to: [Setup Guide](https://docs.r3.com/).


## Running the nodes
1. We will begin our test deployment with clicking the `startCorda`.
`./gradlew startCorda` run this from the Intellij terminal
This task will load up the combined Corda workers in docker.
A successful deployment will allow you to open the REST APIs at: https://localhost:8888/api/v1/swagger#.
You can test out some functions to check connectivity.(GET /cpi function call should return an empty list as for now.)
2. We will now deploy the cordapp with a click of `5-vNodeSetup` task. Upon successful deployment of the CPI,
the GET /cpi function call should now return the meta data of the cpi you just upload


### Running the app
In Corda 5, flows will be triggered via `POST /flow/{holdingidentityshorthash}` and flow result will need to be view at
`GET /flow/{holdingidentityshorthash}/{clientrequestid}`
* holdingidentityshorthash: the id of the network participants, ie Bob, Alice, Charlie. You can view all the short
hashes of the network member with another gradle task called `ListVNodes`
* clientrequestid: the id you specify in the flow requestBody when you trigger a flow.

#### Pinging a node:
Pick a VNode identity to initiate the ping, and get its short hash. Let's pick Alice.

Go to `POST /flow/{holdingidentityshorthash}`, enter the identity short hash(Alice's hash) and request body:
```
{
"clientRequestId": "ping-1",
"flowClassName": "Ping",
"requestBody": {
"otherMember": "CN=Bob, OU=Test Dept, O=R3, L=London, C=GB"
}
}
```

Now hop to `GET /flow/{holdingidentityshorthash}/{clientrequestid}` and enter the short
hash(Alice's hash) and clientrequestid to view the flow result

##Stop corda
To stop the combined worker - run the task `stopCorda` from the terminal.
```
./gradlew stopCorda
```
47 changes: 47 additions & 0 deletions java-samples/ping-pong/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import static org.gradle.api.JavaVersion.VERSION_11

plugins {
id 'org.jetbrains.kotlin.jvm'
id 'net.corda.cordapp.cordapp-configuration'
id 'org.jetbrains.kotlin.plugin.jpa'
id 'java'
id 'maven-publish'
id 'csde'
}

allprojects {
group 'net.corda.samples'
version '1.0-SNAPSHOT'

def javaVersion = VERSION_11

// Declare the set of Java compiler options we need to build a CorDapp.
tasks.withType(JavaCompile) {
// -parameters - Needed for reflection and serialization to work correctly.
options.compilerArgs += [
"-parameters"
]
}

repositories {
// All dependencies are held in Maven Central
mavenCentral()
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
}

}

publishing {
publications {
maven(MavenPublication) {
artifactId "corda-CSDE-java-sample"
groupId project.group
artifact jar
}

}
}

22 changes: 22 additions & 0 deletions java-samples/ping-pong/buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

plugins {
id 'groovy-gradle-plugin'
id 'java'
}

repositories {
mavenCentral()
mavenLocal()
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'

implementation "com.konghq:unirest-java:$unirestVersion"
implementation "com.konghq:unirest-objectmapper-jackson:$unirestVersion"
implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jacksonVersion"

implementation "net.corda:corda-base:$cordaApiVersion"
}
4 changes: 4 additions & 0 deletions java-samples/ping-pong/buildSrc/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jacksonVersion = 2.13.4
unirestVersion=3.13.10

cordaApiVersion=5.0.0.665-Gecko1.0
1 change: 1 addition & 0 deletions java-samples/ping-pong/buildSrc/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// File intentionally left blank
Loading

0 comments on commit 19a3ca9

Please sign in to comment.