Add example to demonstrate Whisper-Waku bridge (#1875)
This commit is contained in:
parent
f335d1cf7e
commit
b33ad8147d
|
@ -0,0 +1,77 @@
|
|||
# List of running node examples
|
||||
|
||||
> All code snippets are run from the root project directory.
|
||||
|
||||
## Whisper-Waku bridge
|
||||
|
||||
This example demonstrates how bridging between Whisper and Waku works.
|
||||
|
||||
First, start a Whisper node and listen to messages:
|
||||
```shell script
|
||||
# start node
|
||||
$ ./build/bin/statusd -c ./_examples/whisper.json -fleet eth.test -dir ./test-bridge-whisper -addr=:30313
|
||||
|
||||
# create a symmetric key
|
||||
$ echo '{"jsonrpc":"2.0","method":"shh_generateSymKeyFromPassword","params":["test-channel"],"id":1}' | \
|
||||
nc -U ./test-bridge-whisper/geth.ipc
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"result": "7d521b2501ec6ed99787ecdec98390f141e6d823c703ad88b73a09d81b07e35e"
|
||||
}
|
||||
|
||||
# create a message filter
|
||||
$ echo '{"jsonrpc":"2.0","method":"shh_newMessageFilter","params":[{"topics": ["0xaabbccdd"], "symKeyID":"7d521b2501ec6ed99787ecdec98390f141e6d823c703ad88b73a09d81b07e35e"}],"id":1}' | \
|
||||
nc -U ./test-bridge-whisper/geth.ipc
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"result": "8fd6c01721a90c6650223f8180afe10c66ea5ab30669797d8b42d09f65a819a6"
|
||||
}
|
||||
```
|
||||
|
||||
In another terminal, start a Waku node and send messages:
|
||||
```shell script
|
||||
$ ./build/bin/statusd -c ./_examples/waku.json -fleet eth.test -dir ./test-bridge-waku -addr=:30303
|
||||
|
||||
# create a symmetric key
|
||||
$ echo '{"jsonrpc":"2.0","method":"waku_generateSymKeyFromPassword","params":["test-channel"],"id":1}' | \
|
||||
nc -U ./test-waku-bridge/geth.ipc
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"result": "1e07adfcb80c9e9853fb2c4cce3d91c17edd17ab6e950387833d64878fe91624"
|
||||
}
|
||||
|
||||
# send a message
|
||||
$ echo '{"jsonrpc":"2.0","method":"waku_post","params":[{"symKeyID":"98999c238e3747b7562674a86d450d531eca616d288a500268878e90848bfe4e", "ttl":100, "topic": "0xaabbccdd", "payload":"0x010203", "powTarget": 5.0, "powTime": 3}],"id":1}' | \
|
||||
nc -U ./test-waku-bridge/geth.ipc
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"result": "0x1832693cdb951b2cf459c9a6e98755407851af401ee1e7859a919ae95f79ef7a"
|
||||
}
|
||||
```
|
||||
|
||||
Finally, check messages in Whisper node:
|
||||
```shell script
|
||||
$ echo '{"jsonrpc":"2.0","method":"shh_getFilterMessages","params":["8fd6c01721a90c6650223f8180afe10c66ea5ab30669797d8b42d09f65a819a6"],"id":1}' | \
|
||||
nc -U ./test-whisper-bridge/geth.ipc | jq .
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"result": [
|
||||
{
|
||||
"ttl": 100,
|
||||
"timestamp": 1582652341,
|
||||
"topic": "0xaabbccdd",
|
||||
"payload": "0xd31d35d36d37",
|
||||
"padding": "0x925591dc6f6b7d01bd687700a222004e133141b7bb8048ac45d90232d8025f02292aa83befe91fe8ec46a47e7bcfb09d8f2d3529afe4e1835315351248b6735a190c9915b021e54de1975ac9d801aff9dec7bfee4cbe9245c3caca70694fa95718e17f8a5b8385bfc3e7196328cdb4fe722e49368c308c35fe73573c639a54b944bc2e35b080b9d36e7d298340bed253be3a26ac609e19df25de90fd9ab4237423772077046805f8dc3d5ad028cc602fd687e98cbb2c4226cba54b7c3e28f6d22bee510db445fe64bfcc996ddcc40423e1fc9e7fd39e2c0b838ded69c451022fe9202b386d9bd17d47d33942c60172f22ab0d38675b0d92c",
|
||||
"pow": 17.418205980066446,
|
||||
"hash": "0x1832693cdb951b2cf459c9a6e98755407851af401ee1e7859a919ae95f79ef7a"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"APIModules": "waku,shh",
|
||||
"HTTPEnabled": true,
|
||||
"WakuConfig": {
|
||||
"Enabled": true
|
||||
},
|
||||
"IPCEnabled": true
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"APIModules": "waku,shh",
|
||||
"HTTPEnabled": true,
|
||||
"WhisperConfig": {
|
||||
"Enabled": true
|
||||
},
|
||||
"IPCEnabled": true
|
||||
}
|
|
@ -82,7 +82,7 @@ func (b *Bridge) Start() {
|
|||
return
|
||||
case env := <-b.whisperIn:
|
||||
wakuEnvelope := (*waku.Envelope)(unsafe.Pointer(env)) // nolint: gosec
|
||||
b.logger.Info("received whisper envelope from waku", zap.Any("envelope", wakuEnvelope))
|
||||
b.logger.Info("received waku envelope from whisper", zap.Any("envelope", wakuEnvelope))
|
||||
b.wakuOut <- wakuEnvelope
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,15 @@ var (
|
|||
params.MainNetworkID, params.RopstenNetworkID, params.RinkebyNetworkID, params.GoerliNetworkID,
|
||||
),
|
||||
)
|
||||
fleet = flag.String(
|
||||
"fleet",
|
||||
params.FleetProd,
|
||||
fmt.Sprintf(
|
||||
"Select fleet: %s (default %s)",
|
||||
[]string{params.FleetProd, params.FleetStaging, params.FleetTest}, params.FleetProd,
|
||||
),
|
||||
)
|
||||
listenAddr = flag.String("addr", ":30303", "address to bind listener to")
|
||||
|
||||
// don't change the name of this flag, https://github.com/ethereum/go-ethereum/blob/master/metrics/metrics.go#L41
|
||||
metricsEnabled = flag.Bool("metrics", false, "Expose ethereum metrics with debug_metrics jsonrpc call")
|
||||
|
@ -87,7 +96,7 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
opts := []params.Option{params.WithFleet(params.FleetProd)}
|
||||
opts := []params.Option{params.WithFleet(*fleet)}
|
||||
if *mailserver {
|
||||
opts = append(opts, params.WithMailserver())
|
||||
}
|
||||
|
@ -104,6 +113,8 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
config.ListenAddr = *listenAddr
|
||||
|
||||
if *register && *mailserver {
|
||||
config.RegisterTopics = append(config.RegisterTopics, params.MailServerDiscv5Topic)
|
||||
} else if *register {
|
||||
|
|
|
@ -226,7 +226,7 @@ func (n *StatusNode) setupRPCClient() (err error) {
|
|||
|
||||
func (n *StatusNode) setupBridge() error {
|
||||
if !n.config.BridgeConfig.Enabled {
|
||||
log.Info("a Whisper-Waku bridge is disabled")
|
||||
log.Info("Whisper-Waku bridge is disabled")
|
||||
return nil
|
||||
}
|
||||
var shh *whisper.Whisper
|
||||
|
|
|
@ -5,6 +5,7 @@ const (
|
|||
FleetUndefined = ""
|
||||
FleetProd = "eth.prod"
|
||||
FleetStaging = "eth.staging"
|
||||
FleetTest = "eth.test"
|
||||
)
|
||||
|
||||
// Cluster defines a list of Ethereum nodes.
|
||||
|
|
Loading…
Reference in New Issue