func (n *Network) OrdererLocalMSPDir(o *topology.Orderer) string {
	return n.OrdererLocalCryptoDir(o, "msp")
}
OrdererLocalMSPDir returns the path to the local MSP directory for the
Orderer.
package network
import (
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"sort"
	"strconv"
	"strings"
	"syscall"
	"text/template"
	"time"
	"github.com/hyperledger/fabric/integration/runner"
	"github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
	. "github.com/onsi/gomega/gstruct"
	"github.com/onsi/gomega/matchers"
	"github.com/onsi/gomega/types"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/ginkgomon"
	"github.com/tedsuo/ifrit/grouper"
	"gopkg.in/yaml.v2"
	"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api"
	"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
	"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/commands"
	"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/fabricconfig"
	"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/opts"
	"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/topology"
	"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc"
)
func (n *Network) LogSpec() string {
	if len(n.Logging.Spec) == 0 {
		return "info:fscnode=debug"
	}
	return n.Logging.Spec
}
func (n *Network) LogFormat() string {
	if len(n.Logging.Format) == 0 {
		return "'%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'"
	}
	return n.Logging.Format
}
func (n *Network) AddOrg(o *topology.Organization, peers ...*topology.Peer) {
	for _, p := range peers {
		ports := api.Ports{}
		for _, portName := range PeerPortNames() {
			ports[portName] = n.Context.ReservePort()
		}
		n.Context.SetPortsByPeerID(n.Prefix, p.ID(), ports)
		n.Peers = append(n.Peers, p)
	}
	n.Organizations = append(n.Organizations, o)
	n.Consortiums[0].Organizations = append(n.Consortiums[0].Organizations, o.Name)
}
func (n *Network) ConfigTxConfigPath() string {
	return filepath.Join(n.Context.RootDir(), n.Prefix, "configtx.yaml")
}
func (n *Network) CryptoPath() string {
	return filepath.Join(n.Context.RootDir(), n.Prefix, "crypto")
}
func (n *Network) CryptoConfigPath() string {
	return filepath.Join(n.Context.RootDir(), n.Prefix, "crypto-config.yaml")
}
func (n *Network) OutputBlockPath(channelName string) string {
	return filepath.Join(n.Context.RootDir(), n.Prefix, fmt.Sprintf("%s_block.pb", channelName))
}
func (n *Network) CreateChannelTxPath(channelName string) string {
	return filepath.Join(n.Context.RootDir(), n.Prefix, fmt.Sprintf("%s_tx.pb", channelName))
}
func (n *Network) OrdererDir(o *topology.Orderer) string {
	return filepath.Join(n.Context.RootDir(), n.Prefix, "orderers", o.ID())
}
func (n *Network) OrdererConfigPath(o *topology.Orderer) string {
	return filepath.Join(n.OrdererDir(o), "orderer.yaml")
}
func (n *Network) ReadOrdererConfig(o *topology.Orderer) *fabricconfig.Orderer {
	var orderer fabricconfig.Orderer
	ordererBytes, err := ioutil.ReadFile(n.OrdererConfigPath(o))
	Expect(err).NotTo(HaveOccurred())
	err = yaml.Unmarshal(ordererBytes, &orderer)
	Expect(err).NotTo(HaveOccurred())
	return &orderer
}
func (n *Network) WriteOrdererConfig(o *topology.Orderer, config *fabricconfig.Orderer) {
	ordererBytes, err := yaml.Marshal(config)
	Expect(err).NotTo(HaveOccurred())
	err = ioutil.WriteFile(n.OrdererConfigPath(o), ordererBytes, 0644)
	Expect(err).NotTo(HaveOccurred())
}
func (n *Network) ReadConfigTxConfig() *fabricconfig.ConfigTx {
	var configtx fabricconfig.ConfigTx
	configtxBytes, err := ioutil.ReadFile(n.ConfigTxConfigPath())
	Expect(err).NotTo(HaveOccurred())
	err = yaml.Unmarshal(configtxBytes, &configtx)
	Expect(err).NotTo(HaveOccurred())
	return &configtx
}
func (n *Network) WriteConfigTxConfig(config *fabricconfig.ConfigTx) {
	configtxBytes, err := yaml.Marshal(config)
	Expect(err).NotTo(HaveOccurred())
	err = ioutil.WriteFile(n.ConfigTxConfigPath(), configtxBytes, 0644)
	Expect(err).NotTo(HaveOccurred())
}
func (n *Network) PeerDir(p *topology.Peer) string {
	return filepath.Join(n.Context.RootDir(), n.Prefix, "peers", p.ID())
}
func (n *Network) PeerConfigPath(p *topology.Peer) string {
	return filepath.Join(n.PeerDir(p), "core.yaml")
}
func (n *Network) PeerLedgerDir(p *topology.Peer) string {
	return filepath.Join(n.PeerDir(p), "filesystem/ledgersData")
}
func (n *Network) ReadPeerConfig(p *topology.Peer) *fabricconfig.Core {
	var core fabricconfig.Core
	coreBytes, err := ioutil.ReadFile(n.PeerConfigPath(p))
	Expect(err).NotTo(HaveOccurred())
	err = yaml.Unmarshal(coreBytes, &core)
	Expect(err).NotTo(HaveOccurred())
	return &core
}
func (n *Network) WritePeerConfig(p *topology.Peer, config *fabricconfig.Core) {
	coreBytes, err := yaml.Marshal(config)
	Expect(err).NotTo(HaveOccurred())
	err = ioutil.WriteFile(n.PeerConfigPath(p), coreBytes, 0644)
	Expect(err).NotTo(HaveOccurred())
}
func (n *Network) peerUserCryptoDir(p *topology.Peer, user, cryptoMaterialType string) string {
	org := n.Organization(p.Organization)
	Expect(org).NotTo(BeNil())
	return n.userCryptoDir(org, "peerOrganizations", user, cryptoMaterialType)
}
func (n *Network) ordererUserCryptoDir(o *topology.Orderer, user, cryptoMaterialType string) string {
	org := n.Organization(o.Organization)
	Expect(org).NotTo(BeNil())
	return n.userCryptoDir(org, "ordererOrganizations", user, cryptoMaterialType)
}
func (n *Network) userCryptoDir(org *topology.Organization, nodeOrganizationType, user, cryptoMaterialType string) string {
	return filepath.Join(
		n.Context.RootDir(),
		n.Prefix,
		"crypto",
		nodeOrganizationType,
		org.Domain,
		"users",
		fmt.Sprintf("%s@%s", user, org.Domain),
		cryptoMaterialType,
	)
}
func (n *Network) OrgPeerCACertificatePath(org *topology.Organization) string {
	return n.orgCACertificatePath(org, "peerOrganizations")
}
func (n *Network) orgCACertificatePath(org *topology.Organization, nodeOrganizationType string) string {
	return filepath.Join(
		n.Context.RootDir(),
		n.Prefix,
		"crypto",
		nodeOrganizationType,
		org.Domain,
		"ca",
		fmt.Sprintf("ca.%s-cert.pem", org.Domain),
	)
}
func (n *Network) PeerUserMSPDir(p *topology.Peer, user string) string {
	return n.peerUserCryptoDir(p, user, "msp")
}
func (n *Network) ViewNodeMSPDir(p *topology.Peer) string {
	switch {
	case n.topology.NodeOUs:
		switch p.Role {
		case "":
			return n.PeerUserMSPDir(p, p.Name)
		case "client":
			return n.PeerUserMSPDir(p, p.Name)
		default:
			return n.PeerLocalMSPDir(p)
		}
	default:
		return n.PeerLocalMSPDir(p)
	}
}
func (n *Network) FSCNodeLocalTLSDir(p *topology.Peer) string {
	switch {
	case n.topology.NodeOUs:
		switch p.Role {
		case "":
			return n.peerUserCryptoDir(p, p.Name, "tls")
		case "client":
			return n.peerUserCryptoDir(p, p.Name, "tls")
		default:
			return n.peerLocalCryptoDir(p, "tls")
		}
	default:
		return n.peerLocalCryptoDir(p, "tls")
	}
}
func (n *Network) IdemixUserMSPDir(o *topology.Organization, user string) string {
	return n.userCryptoDir(o, "peerOrganizations", user, "")
}
func (n *Network) OrdererUserMSPDir(o *topology.Orderer, user string) string {
	return n.ordererUserCryptoDir(o, user, "msp")
}
func (n *Network) PeerUserTLSDir(p *topology.Peer, user string) string {
	return n.peerUserCryptoDir(p, user, "tls")
}
func (n *Network) PeerUserCert(p *topology.Peer, user string) string {
	org := n.Organization(p.Organization)
	Expect(org).NotTo(BeNil())
	return filepath.Join(
		n.PeerUserMSPDir(p, user),
		"signcerts",
		fmt.Sprintf("%s@%s-cert.pem", user, org.Domain),
	)
}
func (n *Network) OrdererUserCert(o *topology.Orderer, user string) string {
	org := n.Organization(o.Organization)
	Expect(org).NotTo(BeNil())
	return filepath.Join(
		n.OrdererUserMSPDir(o, user),
		"signcerts",
		fmt.Sprintf("%s@%s-cert.pem", user, org.Domain),
	)
}
func (n *Network) PeerUserKey(p *topology.Peer, user string) string {
	org := n.Organization(p.Organization)
	Expect(org).NotTo(BeNil())
	return filepath.Join(
		n.PeerUserMSPDir(p, user),
		"keystore",
		"priv_sk",
	)
}
func (n *Network) PeerKey(p *topology.Peer) string {
	org := n.Organization(p.Organization)
	Expect(org).NotTo(BeNil())
	return filepath.Join(
		n.PeerLocalMSPDir(p),
		"keystore",
		"priv_sk",
	)
}
func (n *Network) OrdererUserKey(o *topology.Orderer, user string) string {
	org := n.Organization(o.Organization)
	Expect(org).NotTo(BeNil())
	return filepath.Join(
		n.OrdererUserMSPDir(o, user),
		"keystore",
		"priv_sk",
	)
}
func (n *Network) peerLocalCryptoDir(p *topology.Peer, cryptoType string) string {
	org := n.Organization(p.Organization)
	Expect(org).NotTo(BeNil())
	return filepath.Join(
		n.Context.RootDir(),
		n.Prefix,
		"crypto",
		"peerOrganizations",
		org.Domain,
		"peers",
		fmt.Sprintf("%s.%s", p.Name, org.Domain),
		cryptoType,
	)
}
func (n *Network) peerUserLocalCryptoDir(p *topology.Peer, user, cryptoType string) string {
	org := n.Organization(p.Organization)
	Expect(org).NotTo(BeNil())
	return filepath.Join(
		n.Context.RootDir(),
		n.Prefix,
		"crypto",
		"peerOrganizations",
		org.Domain,
		"users",
		fmt.Sprintf("%s@%s", user, org.Domain),
		cryptoType,
	)
}
func (n *Network) PeerLocalMSPDir(p *topology.Peer) string {
	return n.peerLocalCryptoDir(p, "msp")
}
func (n *Network) PeerLocalMSPIdentityCert(p *topology.Peer) string {
	return filepath.Join(
		n.peerLocalCryptoDir(p, "msp"),
		"signcerts",
		p.Name+"."+n.Organization(p.Organization).Domain+"-cert.pem",
	)
}
func (n *Network) PeerUserLocalMSPIdentityCert(p *topology.Peer, user string) string {
	return filepath.Join(
		n.peerUserLocalCryptoDir(p, user, "msp"),
		"signcerts",
		p.Name+"@"+n.Organization(p.Organization).Domain+"-cert.pem",
	)
}
func (n *Network) PeerLocalIdemixExtraIdentitiesDir(p *topology.Peer) string {
	return n.peerLocalCryptoDir(p, "extraids")
}
func (n *Network) PeerLocalExtraIdentityDir(p *topology.Peer, id string) string {
	index := 1
	for _, identity := range p.ExtraIdentities {
		if identity.ID == id {
			switch identity.MSPType {
			case "idemix":
				return n.peerLocalCryptoDir(p, filepath.Join("extraids", id))
			case "bccsp":
				return n.peerUserCryptoDir(p, identity.ID, "msp")
			}
		}
		if identity.MSPType == "bccsp" {
			index++
		}
	}
	panic("id not found")
}
func (n *Network) PeerLocalTLSDir(p *topology.Peer) string {
	return n.peerLocalCryptoDir(p, "tls")
}
func (n *Network) PeerCert(p *topology.Peer) string {
	org := n.Organization(p.Organization)
	Expect(org).NotTo(BeNil())
	return filepath.Join(
		n.PeerLocalMSPDir(p),
		"signcerts",
		fmt.Sprintf("%s.%s-cert.pem", p.Name, org.Domain),
	)
}
func (n *Network) PeerOrgMSPDir(org *topology.Organization) string {
	return filepath.Join(
		n.Context.RootDir(),
		n.Prefix,
		"crypto",
		"peerOrganizations",
		org.Domain,
		"msp",
	)
}
func (n *Network) Topology() *topology.Topology {
	return n.topology
}
func (n *Network) DefaultIdemixOrgMSPDir() string {
	for _, organization := range n.Organizations {
		if organization.MSPType == "idemix" {
			return filepath.Join(
				n.Context.RootDir(),
				n.Prefix,
				"crypto",
				"peerOrganizations",
				organization.Domain,
			)
		}
	}
	return ""
}
func (n *Network) IdemixOrgMSPDir(org *topology.Organization) string {
	return filepath.Join(
		n.Context.RootDir(),
		n.Prefix,
		"crypto",
		"peerOrganizations",
		org.Domain,
	)
}
func (n *Network) OrdererOrgMSPDir(o *topology.Organization) string {
	return filepath.Join(
		n.Context.RootDir(),
		n.Prefix,
		"crypto",
		"ordererOrganizations",
		o.Domain,
		"msp",
	)
}
func (n *Network) OrdererLocalCryptoDir(o *topology.Orderer, cryptoType string) string {
	org := n.Organization(o.Organization)
	Expect(org).NotTo(BeNil())
	return filepath.Join(
		n.Context.RootDir(),
		n.Prefix,
		"crypto",
		"ordererOrganizations",
		org.Domain,
		"orderers",
		fmt.Sprintf("%s.%s", o.Name, org.Domain),
		cryptoType,
	)
}