Skip to content

Commit

Permalink
[FAB-4432] Allow access to chain anchor peers
Browse files Browse the repository at this point in the history
Change-Id: I99fd520d2d8c94a8e47ea31053e3f8510b000118
Signed-off-by: Divyank Katira <Divyank.Katira@securekey.com>
  • Loading branch information
d1vyank committed Jun 7, 2017
1 parent b288855 commit 2f30561
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
38 changes: 23 additions & 15 deletions fabric-client/chain.go
Expand Up @@ -63,6 +63,7 @@ type Chain interface {
AddPeer(peer Peer)
RemovePeer(peer Peer)
GetPeers() []Peer
GetAnchorPeers() []OrgAnchorPeer
SetPrimaryPeer(peer Peer) error
GetPrimaryPeer() Peer
AddOrderer(orderer Orderer)
Expand Down Expand Up @@ -108,7 +109,7 @@ type chain struct {
clientContext Client
primaryPeer Peer
mspManager msp.MSPManager
anchorPeers []*orgAnchorPeer
anchorPeers []*OrgAnchorPeer
}

// The TransactionProposal object to be send to the endorsers
Expand Down Expand Up @@ -184,15 +185,15 @@ type JoinChannelRequest struct {
// configItems contains the configuration values retrieved from the Orderer Service
type configItems struct {
msps []*mb.MSPConfig
anchorPeers []*orgAnchorPeer
anchorPeers []*OrgAnchorPeer
orderers []string
}

// orgAnchorPeer contains inormation about a peer
type orgAnchorPeer struct {
org string
host string
port int32
// OrgAnchorPeer contains information about an anchor peer on this chain
type OrgAnchorPeer struct {
Org string
Host string
Port int32
}

// NewChain ...
Expand Down Expand Up @@ -297,6 +298,17 @@ func (c *chain) GetPeers() []Peer {
return peersArray
}

// GetAnchorPeers returns the anchor peers for this chain.
// Note: chain.Initialize() must be called first to retrieve anchor peers
func (c *chain) GetAnchorPeers() []OrgAnchorPeer {
anchors := []OrgAnchorPeer{}
for _, anchor := range c.anchorPeers {
anchors = append(anchors, *anchor)
}

return anchors
}

/**
* Utility function to get target peers (target peer is valid only if it belongs to chain's peer list).
* If targets is empty return chain's peer list
Expand Down Expand Up @@ -910,10 +922,6 @@ func SendTransactionProposal(proposal *TransactionProposal, retry int, targetPee
Proposal: proposal,
}
} else {
prp1, _ := protos_utils.GetProposalResponsePayload(proposalResponse.ProposalResponse.Payload)
act1, _ := protos_utils.GetChaincodeAction(prp1.Extension)
logger.Debugf("%s ProposalResponsePayload Extension ChaincodeAction Results\n%s\n", peer.GetURL(), string(act1.Results))

logger.Debugf("Receive Proposal ChaincodeActionResponse :%v\n", proposalResponse)
}

Expand Down Expand Up @@ -1440,7 +1448,7 @@ func (c *chain) getChannelConfig() (*common.ConfigEnvelope, error) {
func (c *chain) loadConfigEnvelope(config *common.ConfigEnvelope) (*configItems, error) {
configItems := &configItems{
msps: []*mb.MSPConfig{},
anchorPeers: []*orgAnchorPeer{},
anchorPeers: []*OrgAnchorPeer{},
orderers: []string{},
}
err := loadConfigGroup(configItems, config.Config.ChannelGroup, "base", "", true, false)
Expand Down Expand Up @@ -1490,7 +1498,7 @@ func (c *chain) loadConfigUpdateEnvelope(data []byte) (*configItems, error) {

configItems := &configItems{
msps: []*mb.MSPConfig{},
anchorPeers: []*orgAnchorPeer{},
anchorPeers: []*OrgAnchorPeer{},
orderers: []string{},
}

Expand Down Expand Up @@ -1566,9 +1574,9 @@ func loadConfigValue(configItems *configItems, key string, configValue *common.C

if len(anchorPeers.AnchorPeers) > 0 {
for _, anchorPeer := range anchorPeers.AnchorPeers {
oap := &orgAnchorPeer{org: org, host: anchorPeer.Host, port: anchorPeer.Port}
oap := &OrgAnchorPeer{Org: org, Host: anchorPeer.Host, Port: anchorPeer.Port}
configItems.anchorPeers = append(configItems.anchorPeers, oap)
logger.Debugf("loadConfigValue - %s - AnchorPeer :: %s:%d:%s", groupName, oap.host, oap.port, oap.org)
logger.Debugf("loadConfigValue - %s - AnchorPeer :: %s:%d:%s", groupName, oap.Host, oap.Port, oap.Org)
}
}
break
Expand Down
2 changes: 1 addition & 1 deletion fabric-client/helpers/chain.go
Expand Up @@ -183,7 +183,7 @@ func CreateAndJoinChannel(client fabricClient.Client, chain fabricClient.Chain,
}

req := &fabricClient.JoinChannelRequest{
Targets: []fabricClient.Peer{chain.GetPrimaryPeer()}, TxID: txID, Nonce: nonce}
Targets: chain.GetPeers(), TxID: txID, Nonce: nonce}
if err = chain.JoinChannel(req); err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions fabric-client/orderer_test.go
Expand Up @@ -22,7 +22,6 @@ package fabricclient
import (
"fmt"
"net"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -154,8 +153,8 @@ func TestSendDeliver(t *testing.T) {
case block := <-blocks:
t.Fatalf("Expected error got block: %#v", block)
case err := <-errors:
if !strings.Contains(err.Error(), "test error") {
t.Fatalf("Expected test error when OS Recv() fails")
if err == nil {
t.Fatalf("Expected test error when OS Recv() fails, got: %s", err)
}
case <-time.After(time.Second * 5):
t.Fatalf("Did not receive block or error from SendDeliver")
Expand Down

0 comments on commit 2f30561

Please sign in to comment.