Skip to content

Commit

Permalink
Allow peer endpoints to be autodetected
Browse files Browse the repository at this point in the history
The current code generally specifies a default address of the peer
as 0.0.0.0:xxxx (e.g. 0.0.0.0:7051).  This works as both the
listener binding address and (oddly) as the client connect()
address for the cases where the peer is running in certain
environments (such as devenv).  However, in other environments,
0.0.0.0 is not sufficient for properly connecting to an endpoint.
This is a critical operation for chaincode since it will require
the formation of a connection to the CORE_PEER_ADDRESS in order
to function.

Part of the problem is that the unit tests employ custom setup
logic which does not flow through the common code for
establishing the CORE_PEER_ADDRESS.  Therefore, these unit-tests
do not respect the ADDRESSAUTODETECT feature and are unable to
present a valid endpoint in all circumstances.  This will become
a problem later in the series when we introduce the notion
of running the unit-tests within a dockerized environment.

The fix here is to mutate the unit-test setup logic to utilize
the library operations that process the ADDRESSAUTODETECT
feature.

A few cases were not easily adaptable, so they were denoted
with a FIXME label and left for a future task.

Change-Id: Ib5cffb9847be6c9f4125cde9b108709e95d99e71
Signed-off-by: Greg Haskins <gregory.haskins@gmail.com>
  • Loading branch information
ghaskins committed Nov 7, 2016
1 parent 26d78ea commit db404bd
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/chaincode/chaincodetest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ peer:
address: 0.0.0.0:21212
# Whether the Peer should programmatically determine the address to bind to.
# This case is useful for docker containers.
addressAutoDetect: false
addressAutoDetect: true

# Peer port to accept connections on
port: 21212
Expand Down
6 changes: 5 additions & 1 deletion core/chaincode/exectransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/hyperledger/fabric/core/crypto"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos"
putils "github.com/hyperledger/fabric/protos/utils"
Expand Down Expand Up @@ -70,7 +71,10 @@ func initPeer() (net.Listener, error) {

kvledger.Initialize(ledgerPath)

peerAddress := viper.GetString("peer.address")
peerAddress, err := peer.GetLocalAddress()
if err != nil {
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
}
lis, err := net.Listen("tcp", peerAddress)
if err != nil {
return nil, fmt.Errorf("Error starting peer listener %s", err)
Expand Down
1 change: 1 addition & 0 deletions core/chaincode/lccc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func constructDeploymentSpec(name string, path string, initArgs [][]byte) (*pb.C
func initialize() {
//use a different address than what we usually use for "peer"
//we override the peerAddress set in chaincode_support.go
// FIXME: Use peer.GetLocalAddress()
peerAddress := "0.0.0.0:21212"

var opts []grpc.ServerOption
Expand Down
1 change: 1 addition & 0 deletions core/chaincode/systemchaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestExecuteDeploySysChaincode(t *testing.T) {

//use a different address than what we usually use for "peer"
//we override the peerAddress set in chaincode_support.go
// FIXME: Use peer.GetLocalAddress()
peerAddress := "0.0.0.0:21726"
lis, err := net.Listen("tcp", peerAddress)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions core/endorser/endorser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ peer:
address: 0.0.0.0:21212
# Whether the Peer should programmatically determine the address to bind to.
# This case is useful for docker containers.
addressAutoDetect: false
addressAutoDetect: true

# Peer port to accept connections on
port: 21212
Expand Down Expand Up @@ -406,13 +406,13 @@ chaincode:
# A value <= 0 turns keepalive off
keepalive: 0

# system chaincodes whitelist. To add system chaincode "myscc" to the
# system chaincodes whitelist. To add system chaincode "myscc" to the
# whitelist, add "myscc: enable" to the list
system:
lccc: enable
escc: enable
vscc: enable

###############################################################################
#
# Ledger section - ledger configuration encompases both the blockchain
Expand Down
6 changes: 5 additions & 1 deletion core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/hyperledger/fabric/core/crypto"
"github.com/hyperledger/fabric/core/db"
"github.com/hyperledger/fabric/core/ledger/kvledger"
"github.com/hyperledger/fabric/core/peer"
pb "github.com/hyperledger/fabric/protos"
pbutils "github.com/hyperledger/fabric/protos/utils"
"github.com/spf13/viper"
Expand Down Expand Up @@ -58,7 +59,10 @@ func initPeer() (net.Listener, error) {

viper.Set("peer.fileSystemPath", filepath.Join(os.TempDir(), "hyperledger", "production"))

peerAddress := viper.GetString("peer.address")
peerAddress, err := peer.GetLocalAddress()
if err != nil {
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
}
lis, err := net.Listen("tcp", peerAddress)
if err != nil {
return nil, fmt.Errorf("Error starting peer listener %s", err)
Expand Down
2 changes: 1 addition & 1 deletion core/rest/rest_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ peer:
address: 0.0.0.0:7051
# Whether the Peer should programmatically determine the address to bind to.
# This case is useful for docker containers.
addressAutoDetect: false
addressAutoDetect: true

# Setting for runtime.GOMAXPROCS(n). If n < 1, it does not change the current setting
gomaxprocs: -1
Expand Down
2 changes: 1 addition & 1 deletion examples/chaincode/go/asset_management02/asset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ peer:
address: 0.0.0.0:40404
# Whether the Peer should programmatically determine the address to bind to.
# This case is useful for docker containers.
addressAutoDetect: false
addressAutoDetect: true

# Peer port to accept connections on
port: 40404
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/hyperledger/fabric/core/crypto"
"github.com/hyperledger/fabric/core/db"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/membersrvc/ca"
pb "github.com/hyperledger/fabric/protos"
Expand Down Expand Up @@ -585,7 +586,10 @@ func initVP() {

//use a different address than what we usually use for "peer"
//we override the peerAddress set in chaincode_support.go
peerAddress := "0.0.0.0:40404"
peerAddress, err := peer.GetLocalAddress()
if err != nil {
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
}
var err error
lis, err = net.Listen("tcp", peerAddress)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ peer:
address: 0.0.0.0:40404
# Whether the Peer should programmatically determine the address to bind to.
# This case is useful for docker containers.
addressAutoDetect: false
addressAutoDetect: true

# Peer port to accept connections on
port: 40404
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/hyperledger/fabric/core/crypto"
"github.com/hyperledger/fabric/core/db"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/membersrvc/ca"
pb "github.com/hyperledger/fabric/protos"
Expand Down Expand Up @@ -420,7 +421,10 @@ func initVP() {

//use a different address than what we usually use for "peer"
//we override the peerAddress set in chaincode_support.go
peerAddress := "0.0.0.0:40404"
peerAddress, err := peer.GetLocalAddress()
if err != nil {
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
}
var err error
lis, err = net.Listen("tcp", peerAddress)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions examples/chaincode/go/rbac_tcerts_no_attrs/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ func initVP() {

//use a different address than what we usually use for "peer"
//we override the peerAddress set in chaincode_support.go
// FIXME: Use peer.GetLocalAddress()
peerAddress := "0.0.0.0:40404"
var err error
lis, err = net.Listen("tcp", peerAddress)
Expand Down

0 comments on commit db404bd

Please sign in to comment.