This is an automated email from the ASF dual-hosted git repository.
toulmean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git
The following commit(s) were added to refs/heads/master by this push:
new 963b16b Add READMEs for hobbits-relayer and gossip. Add more output
to the relayer
963b16b is described below
commit 963b16b3c379da9dba84eff7ce28181f5deac136
Author: Antoine Toulme <[email protected]>
AuthorDate: Fri Jun 14 00:01:52 2019 -0700
Add READMEs for hobbits-relayer and gossip. Add more output to the relayer
---
dist/build.gradle | 14 +++-
gossip/README.md | 91 ++++++++++++++++++++++
hobbits-relayer/README.md | 66 ++++++++++++++++
.../kotlin/org/apache/tuweni/relayer/RelayerApp.kt | 9 ++-
.../org/apache/tuweni/hobbits/HobbitsTransport.kt | 32 ++++++--
.../kotlin/org/apache/tuweni/hobbits/Relayer.kt | 2 +-
6 files changed, 204 insertions(+), 10 deletions(-)
diff --git a/dist/build.gradle b/dist/build.gradle
index cbb8ca9..9b04b3c 100644
--- a/dist/build.gradle
+++ b/dist/build.gradle
@@ -21,7 +21,6 @@ jar { enabled = false }
static def mandatoryFiles(CopySpec spec) {
spec.into('') {
from ".."
- include 'README.md'
include 'DISCLAIMER'
include 'LICENSE'
include 'NOTICE'
@@ -34,6 +33,10 @@ distributions {
baseName = 'tuweni-bin'
contents {
mandatoryFiles(it)
+ into('') {
+ from ".."
+ include 'README.md'
+ }
def docs = []
def libs = []
def sources = []
@@ -69,6 +72,7 @@ distributions {
mandatoryFiles(it)
into('') {
from ".."
+ include 'README.md'
include '*.md'
include '*.gradle'
include 'dependency-versions.gradle'
@@ -85,6 +89,10 @@ distributions {
baseName = 'tuweni-gossip'
contents {
mandatoryFiles(it)
+ into('') {
+ from ".."
+ include 'gossip/README.md'
+ }
into('bin') {
from { project(':gossip').startScripts.outputs.files }
fileMode = 0755
@@ -101,6 +109,10 @@ distributions {
baseName = 'tuweni-relayer'
contents {
mandatoryFiles(it)
+ into('') {
+ from ".."
+ include 'hobbits-relayer/README.md'
+ }
into('bin') {
from { project(':hobbits-relayer').startScripts.outputs.files }
fileMode = 0755
diff --git a/gossip/README.md b/gossip/README.md
new file mode 100644
index 0000000..a1e7827
--- /dev/null
+++ b/gossip/README.md
@@ -0,0 +1,91 @@
+# Gossip application
+
+This application creates a sample standalone application applying the Plumtree
gossip library.
+
+```bash
+$>bin/gossip --help
+ Usage: <main class> [-h] [--sending] [--numberOfMessages=<numberOfMessages>]
+ [--payloadSize=<payloadSize>]
+ [--sendInterval=<sendInterval>] [-c=<configPath>]
+ [-l=<port>] [-m=<messageLog>] [-n=<networkInterface>]
+ [-r=<rpcPort>] [-p[=<peers>...]]...
+ --numberOfMessages=<numberOfMessages>
+ Number of messages to publish (load testing)
+ --payloadSize=<payloadSize>
+ Size of the random payload to send to other peers
(load
+ testing)
+ --sending Whether this peer sends random messages to all
other
+ peers (load testing)
+ --sendInterval=<sendInterval>
+ Interval to wait in between sending messages in
+ milliseconds (load testing)
+ -c, --config=<configPath> Configuration file.
+ -h, --help Prints usage prompt
+ -l, --listen=<port> Port to listen on
+ -m, --messageLog=<messageLog>
+ Log file where messages are stored
+ -n, --networkInterface=<networkInterface>
+ Network interface to bind to
+ -p, --peer[=<peers>...] Static peers list
+ -r, --rpc=<rpcPort> RPC port to listen on
+```
+
+Example usage:
+```bash
+$>bin/gossip --sending --payloadSize 512 --sendInterval 200 -l 2000 -r 4000 -n
0.0.0.0 -p tcp://127.0.0.1:3000 -p tcp://127.0.0.1:3001
+```
+
+You can configure this application to send random messages to other peers.
+The application can also open up a RPC port accepting messages to propagate:
+
+```bash
+$>curl -X POST http://localhost:4000/publish -d "hello"
+```
+
+The application optionally takes a config file (with the `-c` flag).
+
+Default configuration:
+```toml
+listenPort = 0
+rpcPort = 0
+networkInterface = "0.0.0.0"
+peers = []
+messagelog = "messages.log"
+sending = false
+sendInterval = 1000
+numberOfMessages=100
+payloadSize = 200
+```
+
+Sample sender configuration:
+```toml
+listenPort = 2000
+rpcPort = 4000
+networkInterface = "0.0.0.0"
+peers = [ "tcp://127.0.0.1:3000", "tcp://127.0.0.1:3001"]
+messagelog = "messages.log"
+sending = true
+sendInterval = 1000
+numberOfMessages=100
+payloadSize = 200
+```
+
+Peers are encoded as URIs using the TCP scheme: `tcp://127.0.0.1:3000`
+
+## More information
+
+- [Official website](https://tuweni.apache.org)
+- [GitHub project](https://github.com/apache/incubator-tuweni)
+
+# License
+
+Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE
+file distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file
+to You under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the
+License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on
+an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the
+specific language governing permissions and limitations under the License.
diff --git a/hobbits-relayer/README.md b/hobbits-relayer/README.md
new file mode 100644
index 0000000..257fe29
--- /dev/null
+++ b/hobbits-relayer/README.md
@@ -0,0 +1,66 @@
+# Relayer application
+
+This application relays two hobbits endpoints.
+
+Usage:
+```bash
+$> bin/hobbits-relayer --help
+Usage: <main class> [-h] [-b=<bind>] [-t=<to>]
+ -b, --bind=<bind> Endpoint to bind to
+ -h, --help Prints usage prompt
+ -t, --to=<to> Endpoint to relay to
+```
+
+The application prints out messages to STDOUT.
+
+Sample use:
+
+Listen to a port
+```bash
+$> netcat -l -p 18000
+```
+
+Set up the relayer:
+```bash
+$> bin/hobbits-relayer -b tcp://localhost:10000 -t tcp://localhost:18000
+```
+
+Send a message:
+```bash
+$> cat message
+EWP 0.2 RPC 5 5
+hellohello
+$> cat message | netcat localhost 10000
+```
+
+The relayer will show the message:
+```bash
+EWP 0.2 RPC 5 5
+0x68656C6C6F
+0x68656C6C6F
+```
+
+The listener will show the message, received:
+```bash
+$> netcat -l -p 18000
+EWP 0.2 RPC 5 5
+hellohello
+```
+
+## More information
+
+- [Official website](https://tuweni.apache.org)
+- [GitHub project](https://github.com/apache/incubator-tuweni)
+
+# License
+
+Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE
+file distributed with this work for additional information regarding copyright
ownership. The ASF licenses this file
+to You under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the
+License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on
+an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the
+specific language governing permissions and limitations under the License.
diff --git
a/hobbits-relayer/src/main/kotlin/org/apache/tuweni/relayer/RelayerApp.kt
b/hobbits-relayer/src/main/kotlin/org/apache/tuweni/relayer/RelayerApp.kt
index 6ba2d6b..5b8c5c4 100644
--- a/hobbits-relayer/src/main/kotlin/org/apache/tuweni/relayer/RelayerApp.kt
+++ b/hobbits-relayer/src/main/kotlin/org/apache/tuweni/relayer/RelayerApp.kt
@@ -45,10 +45,15 @@ class RelayerApp {
val relayer = Relayer(vertx, opts.bind, opts.to, {
System.out.println(it)
})
- Runtime.getRuntime().addShutdownHook(Thread { relayer.stop()
- vertx.close() })
+ Runtime.getRuntime().addShutdownHook(Thread {
+ println("Relayer stopping")
+ relayer.stop()
+ vertx.close()
+ println("Relayer stopped")
+ })
runBlocking {
relayer.start()
+ println("Relayer started, bound to ${opts.bind} and targeting
${opts.to}")
}
}
}
diff --git
a/hobbits/src/main/kotlin/org/apache/tuweni/hobbits/HobbitsTransport.kt
b/hobbits/src/main/kotlin/org/apache/tuweni/hobbits/HobbitsTransport.kt
index 185ce5c..f31999c 100644
--- a/hobbits/src/main/kotlin/org/apache/tuweni/hobbits/HobbitsTransport.kt
+++ b/hobbits/src/main/kotlin/org/apache/tuweni/hobbits/HobbitsTransport.kt
@@ -44,9 +44,13 @@ import kotlin.coroutines.CoroutineContext
*
* It can be used to contact other Hobbits endpoints, or to expose endpoints
to the network.
*
+ * @param vertx Vert.x instance
+ * @param incompleteMessageHandler a handler to manage incomplete or invalid
messages
+ * @param coroutineContext the co-routine context for the transport
*/
class HobbitsTransport(
private val vertx: Vertx,
+ private val incompleteMessageHandler: (Bytes) -> Unit = {},
override val coroutineContext: CoroutineContext = Dispatchers.Default
) : CoroutineScope {
@@ -256,7 +260,15 @@ class HobbitsTransport(
httpServer.requestHandler {
if (endpoint.requestURI == null ||
it.path().startsWith(endpoint.requestURI)) {
- it.bodyHandler {
endpoint.handler(Message.readMessage(Bytes.wrapBuffer(it))!!) }
+ it.bodyHandler {
+ val bytes = Bytes.wrapBuffer(it)
+ val message = Message.readMessage(bytes)
+ if (message == null) {
+ incompleteMessageHandler(bytes)
+ } else {
+ endpoint.handler(message)
+ }
+ }
it.response().statusCode = 200
it.response().end()
} else {
@@ -277,9 +289,10 @@ class HobbitsTransport(
val tcpServer = vertx.createNetServer()
tcpServers[id] = tcpServer
tcpServer.connectHandler { connectHandler -> connectHandler.handler {
buffer ->
- val message = Message.readMessage(Bytes.wrapBuffer(buffer))
+ val bytes = Bytes.wrapBuffer(buffer)
+ val message = Message.readMessage(bytes)
if (message == null) {
- TODO("Buffer not implemented yet")
+ incompleteMessageHandler(bytes)
} else {
endpoint.handler(message)
}
@@ -300,9 +313,10 @@ class HobbitsTransport(
udpServers[id] = udpServer
udpServer.handler { packet ->
- val message = Message.readMessage(Bytes.wrapBuffer(packet.data()))
+ val bytes = Bytes.wrapBuffer(packet.data())
+ val message = Message.readMessage(bytes)
if (message == null) {
- TODO("Buffer not implemented yet")
+ incompleteMessageHandler(bytes)
} else {
endpoint.handler(message)
}
@@ -326,7 +340,13 @@ class HobbitsTransport(
it.binaryMessageHandler { buffer ->
try {
-
endpoint.handler(Message.readMessage(Bytes.wrapBuffer(buffer))!!)
+ val bytes = Bytes.wrapBuffer(buffer)
+ val message = Message.readMessage(bytes)
+ if (message == null) {
+ incompleteMessageHandler(bytes)
+ } else {
+ endpoint.handler(message)
+ }
} finally {
it.end()
}
diff --git a/hobbits/src/main/kotlin/org/apache/tuweni/hobbits/Relayer.kt
b/hobbits/src/main/kotlin/org/apache/tuweni/hobbits/Relayer.kt
index e5d2ff3..398f873 100644
--- a/hobbits/src/main/kotlin/org/apache/tuweni/hobbits/Relayer.kt
+++ b/hobbits/src/main/kotlin/org/apache/tuweni/hobbits/Relayer.kt
@@ -40,7 +40,7 @@ class Relayer(
override val coroutineContext: CoroutineContext = Dispatchers.Default
) : CoroutineScope {
- private val transport = HobbitsTransport(vertx, coroutineContext)
+ private val transport = HobbitsTransport(vertx, { println("Invalid message:
$it") }, coroutineContext)
init {
val toURI = URI.create(to)
val uri = URI.create(bind)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]