-
Notifications
You must be signed in to change notification settings - Fork 0
/
discover.go
46 lines (39 loc) · 1.36 KB
/
discover.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package nwo
import (
"encoding/json"
"github.com/hyperledger/fabric/integration/nwo/commands"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
// DiscoveredPeer defines a struct for discovering peers using discovery service.
// each peer in the result will have these fields
type DiscoveredPeer struct {
MSPID string `yaml:"mspid,omitempty"`
Endpoint string `yaml:"endpoint,omitempty"`
Identity string `yaml:"identity,omitempty"`
Chaincodes []string `yaml:"chaincodes,omitempty"`
}
// running discovery service command discover peers against peer using channel name and user as specified in the
// function arguments. return a slice of the discovered peers
func DiscoverPeers(n *Network, p *Peer, user, channelName string) func() []DiscoveredPeer {
return func() []DiscoveredPeer {
peers := commands.Peers{
UserCert: n.PeerUserCert(p, user),
UserKey: n.PeerUserKey(p, user),
MSPID: n.Organization(p.Organization).MSPID,
Server: n.PeerAddress(p, ListenPort),
Channel: channelName,
}
sess, err := n.Discover(peers)
Expect(err).NotTo(HaveOccurred())
Eventually(sess).Should(gexec.Exit(0))
var discovered []DiscoveredPeer
err = json.Unmarshal(sess.Out.Contents(), &discovered)
Expect(err).NotTo(HaveOccurred())
return discovered
}
}