Skip to content

Commit c1747c7

Browse files
author
Nao Nishijima
committed
[FAB-4921] Can't run Block-listener/e2e w/o tls
This patch set improves block-listener sample to enable TLS. Change-Id: I31b36bf6fac1eb7e7567e6891e6cb27f8114fa93 Signed-off-by: Nao Nishijima <nao.nishijima@hal.hitachi.com>
1 parent 6d817cd commit c1747c7

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

examples/events/block-listener/README.md

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# What is block-listener
22
block-listener.go connects to a peer in order to receive block and chaincode
3-
events (if there are chaincode events being sent). Currently, this example only
4-
works with TLS disabled in the environment.
3+
events (if there are chaincode events being sent).
54

65
# To Run
76
```sh
@@ -13,10 +12,17 @@ Please note that the default MSP under fabric/sampleconfig will be used if no
1312
MSP parameters are provided.
1413

1514
# Example with the e2e_cli example
16-
In order to use the block listener with the e2e_cli example, make sure that TLS
17-
has been disabled by setting CORE_PEER_TLS_ENABLED=***false*** in
18-
``docker-compose-cli.yaml``, ``base/docker-compose-base.yaml`` and
19-
``base/peer-base.yaml``.
15+
The block listener can be used with TLS enabled or disabled. By default,
16+
the e2e_cli example will have TLS enabled. In order to allow the
17+
block-listener sample to connect to peers on e2e_cli example with a TLS
18+
enabled, the easiest way would be to map 127.0.0.1 to the hostname of peer
19+
that you are connecting to, such as peer0.org1.example.com. For example on
20+
\*nix based systems this would be an entry in /etc/hosts file.
21+
22+
If you would prefer to disable TLS, you may do so by setting
23+
CORE_PEER_TLS_ENABLED=***false*** in ``docker-compose-cli.yaml`` and
24+
``base/peer-base.yaml`` as well as
25+
ORDERER_GENERAL_TLS_ENABLED=***false*** in``base/docker-compose-base.yaml``.
2026

2127
Next, run the [e2e_cli example](https://github.com/hyperledger/fabric/tree/master/examples/e2e_cli).
2228

@@ -25,30 +31,48 @@ Once the "All in one" command:
2531
./network_setup.sh up
2632
```
2733
has completed, attach the event client to peer peer0.org1.example.com by doing
28-
the following (assuming you are running block-listener in the host environment):
34+
the following (assuming you are running block-listener in the host environment)
35+
if TLS is enabled:
36+
```sh
37+
CORE_PEER_TLS_ENABLED=true CORE_PEER_TLS_ROOTCERT_FILE=$GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt ./block-listener -events-address=peer0.org1.example.com:7053 -events-mspdir=$GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp -events-mspid=Org1MSP
38+
```
39+
40+
If TLS is disabled, you can simply run:
2941
```sh
30-
./block-listener -events-address=127.0.0.1:7053 -events-mspdir=$GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp -events-mspid=Org1MSP
42+
./block-listener -events-address=peer0.org1.example.com:7053 -events-mspdir=$GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp -events-mspid=Org1MSP
3143
```
3244

33-
The event client should output "Event Address: 127.0.0.1:7053" and wait for
34-
events.
45+
The event client should output "Event Address: peer0.org1.example.com:7053"
46+
and wait for events.
3547

3648
Exec into the cli container:
3749

3850
```sh
3951
docker exec -it cli bash
4052
```
41-
Setup the environment variables for peer0.org1.example.com
53+
54+
Next, setup the environment variables for peer0.org1.example.com.
55+
If TLS is enabled:
56+
```sh
57+
CORE_PEER_MSPCONFIGPATH=$GOPATH/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
58+
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
59+
CORE_PEER_LOCALMSPID="Org1MSP"
60+
ORDERER_CA=$GOPATH/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
61+
```
62+
If TLS is disabled:
4263
```sh
4364
CORE_PEER_MSPCONFIGPATH=$GOPATH/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
4465
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
4566
CORE_PEER_LOCALMSPID="Org1MSP"
4667
```
4768

48-
Create an invoke transaction:
49-
69+
Create an invoke transaction. If TLS is enabled:
70+
```sh
71+
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
72+
```
73+
If TLS is disabled:
5074
```sh
51-
peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
75+
peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
5276
```
5377
Now you should see the block content displayed in the terminal running the block
5478
listener.

examples/events/block-listener/block-listener.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"flag"
2222
"fmt"
2323
"os"
24+
"strings"
2425

2526
"github.com/hyperledger/fabric/core/ledger/util"
2627
"github.com/hyperledger/fabric/events/consumer"
@@ -29,6 +30,7 @@ import (
2930
"github.com/hyperledger/fabric/protos/common"
3031
pb "github.com/hyperledger/fabric/protos/peer"
3132
"github.com/hyperledger/fabric/protos/utils"
33+
"github.com/spf13/viper"
3234
)
3335

3436
type adapter struct {
@@ -135,6 +137,12 @@ func getChainCodeEvents(tdata []byte) (*pb.ChaincodeEvent, error) {
135137
}
136138

137139
func main() {
140+
// For environment variables
141+
viper.SetEnvPrefix("core")
142+
viper.AutomaticEnv()
143+
replacer := strings.NewReplacer(".", "_")
144+
viper.SetEnvKeyReplacer(replacer)
145+
138146
var eventAddress string
139147
var chaincodeID string
140148
var mspDir string

0 commit comments

Comments
 (0)