nwo

package
v0.0.0-...-bef689d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigTxTemplate = `` /* 2925-byte string literal not displayed */
View Source
const CoreTemplate = `` /* 4528-byte string literal not displayed */

CoreTemplate is a basic core configuration. It serves as the template for all core.yaml documents.

View Source
const CryptoTemplate = `` /* 793-byte string literal not displayed */
View Source
const OrdererTemplate = `` /* 1748-byte string literal not displayed */

Variables

View Source
var RequiredImages = []string{
	"hyperledger/fabric-ccenv:latest",
	runner.CouchDBDefaultImage,
	runner.KafkaDefaultImage,
	runner.ZooKeeperDefaultImage,
}

Functions

func DeployChaincode

func DeployChaincode(n *Network, channel string, orderer *Orderer, chaincode Chaincode)

DeployChaincode is a helper that will install chaincode to all peers that are connected to the specified channel, instantiate the chaincode on one of the peers, and wait for the instantiation to complete on all of the peers.

func NewCommand

func NewCommand(path string, command Command) *exec.Cmd

Types

type CA

type CA struct {
	Hostname string `yaml:"hostname,omitempty"`
}

type Chaincode

type Chaincode struct {
	Name    string
	Version string
	Path    string
	Ctor    string
	Policy  string
}

type Channel

type Channel struct {
	Name    string `yaml:"name,omitempty"`
	Profile string `yaml:"profile,omitempty"`
}

Channel associates a channel name with a configtxgen profile name.

type Command

type Command interface {
	Args() []string
	SessionName() string
}

type Components

type Components struct {
	Paths map[string]string
}

func (*Components) Build

func (c *Components) Build(args ...string)

func (*Components) Cleanup

func (c *Components) Cleanup()

func (*Components) ConfigTxGen

func (c *Components) ConfigTxGen() string

func (*Components) Cryptogen

func (c *Components) Cryptogen() string

func (*Components) Idemixgen

func (c *Components) Idemixgen() string

func (*Components) Orderer

func (c *Components) Orderer() string

func (*Components) Peer

func (c *Components) Peer() string

type Config

type Config struct {
	Organizations []*Organization `yaml:"organizations,omitempty"`
	Consortiums   []*Consortium   `yaml:"consortiums,omitempty"`
	SystemChannel *SystemChannel  `yaml:"system_channel,omitempty"`
	Channels      []*Channel      `yaml:"channels,omitempty"`
	Consensus     *Consensus      `yaml:"consensus,omitempty"`
	Orderers      []*Orderer      `yaml:"orderers,omitempty"`
	Peers         []*Peer         `yaml:"peers,omitempty"`
	Profiles      []*Profile      `yaml:"profiles,omitempty"`
}

Config holds the basic information needed to generate fabric configuration files.

func BasicKafka

func BasicKafka() *Config

func BasicSolo

func BasicSolo() *Config

func (*Config) RemovePeer

func (c *Config) RemovePeer(orgName, peerName string)

type Consensus

type Consensus struct {
	Type       string `yaml:"type,omitempty"`
	Brokers    int    `yaml:"brokers,omitempty"`
	ZooKeepers int    `yaml:"zookeepers,omitempty"`
}

Consensus indicates the orderer types and how many broker and zookeeper instances.

type Consortium

type Consortium struct {
	Name          string   `yaml:"name,omitempty"`
	Organizations []string `yaml:"organizations,omitempty"`
}

A Consortium is a named collection of Organizations. It is used to populate the Orderer geneesis block profile.

type Enver

type Enver interface {
	Env() []string
}

type Network

type Network struct {
	RootDir      string
	StartPort    uint16
	NetworkID    string
	Components   *Components
	DockerClient *docker.Client

	PortsByBrokerID  map[string]Ports
	PortsByOrdererID map[string]Ports
	PortsByPeerID    map[string]Ports
	Organizations    []*Organization
	SystemChannel    *SystemChannel
	Channels         []*Channel
	Consensus        *Consensus
	Orderers         []*Orderer
	Peers            []*Peer
	Profiles         []*Profile
	Consortiums      []*Consortium
	// contains filtered or unexported fields
}

Network holds information about a fabric network.

func New

func New(c *Config, rootDir string, client *docker.Client, startPort int, components *Components) *Network

New creates a Network from a simple configuration. All generated or managed artifacts for the network will be located under rootDir. Ports will be allocated sequentially from the specified startPort.

func (*Network) AnchorsForChannel

func (n *Network) AnchorsForChannel(chanName string) []*Peer

AnchorsForChannel returns all Peer instances that are anchors for the named channel.

func (*Network) AnchorsInOrg

func (n *Network) AnchorsInOrg(orgName string) []*Peer

AnchorsInOrg returns all peers that are an anchor for at least one channel in the named organization.

func (*Network) Bootstrap

func (n *Network) Bootstrap()

Bootstrap generates the cryptographic material, orderer system channel genesis block, and create channel transactions needed to run a fabric network.

The cryptogen tool is used to create crypto material from the contents of ${rootDir}/crypto-config.yaml. The generated artifacts will be placed in ${rootDir}/crypto/...

The gensis block is generated from the profile referenced by the SystemChannel.Profile attribute. The block is written to ${rootDir}/${SystemChannel.Name}_block.pb.

The create channel transactions are generated for each Channel referenced by the Network using the channel's Profile attribute. The transactions are written to ${rootDir}/${Channel.Name}_tx.pb.

func (*Network) BrokerAddresses

func (n *Network) BrokerAddresses(portName PortName) []string

BrokerAddresses returns the list of broker addresses for the network.

func (*Network) BrokerGroupRunner

func (n *Network) BrokerGroupRunner() ifrit.Runner

BrokerGroupRunner returns a runner that manages the processes that make up the kafka broker network for fabric.

func (*Network) BrokerRunner

func (n *Network) BrokerRunner(id int, zookeepers []string) *runner.Kafka

BrokerRunner returns a runner for an kafka broker instance.

func (*Network) Cleanup

func (n *Network) Cleanup()

Cleanup attempts to cleanup docker related artifacts that may have been created by the network.

func (*Network) ConfigTxConfigPath

func (n *Network) ConfigTxConfigPath() string

ConfigTxPath returns the path to the generated configtxgen configuration file.

func (*Network) ConfigTxGen

func (n *Network) ConfigTxGen(command Command) (*gexec.Session, error)

ConfigTxGen starts a gexec.Session for the provided configtxgen command.

func (*Network) Consortium

func (n *Network) Consortium(name string) *Consortium

Consortium returns information about the named Consortium.

func (*Network) CreateAndJoinChannel

func (n *Network) CreateAndJoinChannel(o *Orderer, channelName string)

CreateAndJoinChannel will create the specified channel. The referencing peers will then be joined to the channel.

The network must be running before this is called.

func (*Network) CreateAndJoinChannels

func (n *Network) CreateAndJoinChannels(o *Orderer)

CreateAndJoinChannels will create all channels specified in the config that are referenced by peers. The referencing peers will then be joined to the channel(s).

The network must be running before this is called.

func (*Network) CreateChannel

func (n *Network) CreateChannel(name string, o *Orderer, p *Peer)

CreateChannel will submit an existing create channel transaction to the specified orderer. The channel transaction must exist at the location returned by CreateChannelTxPath.

The orderer must be running when this is called.

func (*Network) CreateChannelTxPath

func (n *Network) CreateChannelTxPath(name string) string

CreateChannelTxPath returns the path to the create channel transaction for the named channel.

func (*Network) CryptoConfigPath

func (n *Network) CryptoConfigPath() string

CryptoConfigPath returns the path to the generated cryptogen configuration file.

func (*Network) CryptoPath

func (n *Network) CryptoPath() string

CryptoPath returns the path to the directory where cryptogen will place its generated artifacts.

func (*Network) Cryptogen

func (n *Network) Cryptogen(command Command) (*gexec.Session, error)

Cryptogen starts a gexec.Session for the provided cryptogen command.

func (*Network) GenerateConfigTree

func (n *Network) GenerateConfigTree()

GenerateConfigTree generates the configuration documents required to bootstrap a fabric network. A configuration file will be generated for cryptogen, configtxgen, and for each peer and orderer. The contents of the documents will be based on the Config used to create the Network.

When this method completes, the resulting tree will look something like this:

${rootDir}/configtx.yaml ${rootDir}/crypto-config.yaml ${rootDir}/orderers/orderer0.orderer-org/orderer.yaml ${rootDir}/peers/peer0.org1/core.yaml ${rootDir}/peers/peer0.org2/core.yaml ${rootDir}/peers/peer1.org1/core.yaml ${rootDir}/peers/peer1.org2/core.yaml

func (*Network) GenerateConfigTxConfig

func (n *Network) GenerateConfigTxConfig()

func (*Network) GenerateCoreConfig

func (n *Network) GenerateCoreConfig(p *Peer)

func (*Network) GenerateCryptoConfig

func (n *Network) GenerateCryptoConfig()

func (*Network) GenerateOrdererConfig

func (n *Network) GenerateOrdererConfig(o *Orderer)

func (*Network) InstallChaincode

func (n *Network) InstallChaincode(peers []*Peer, install commands.ChaincodeInstall)

InstallChaincode installs chaincode to the listed peers and verifies that the install has completed.

func (*Network) InstantiateChaincode

func (n *Network) InstantiateChaincode(peer *Peer, instantiate commands.ChaincodeInstantiate)

InstantiateChaincode instantiates chaincode at the specified peer and verifies that the instantiation is complete before returning.

func (*Network) JoinChannel

func (n *Network) JoinChannel(name string, o *Orderer, peers ...*Peer)

JoinChannel will join peers to the specified channel. The orderer is used to obtain the current configuration block for the channel.

The orderer and listed peers must be running before this is called.

func (*Network) NetworkGroupRunner

func (n *Network) NetworkGroupRunner() ifrit.Runner

NetworkGroupRunner returns a runner that can be used to start and stop an entire fabric network.

func (*Network) Orderer

func (n *Network) Orderer(name string) *Orderer

Orderer returns the information about the named Orderer.

func (*Network) OrdererAddress

func (n *Network) OrdererAddress(o *Orderer, portName PortName) string

OrdererAddress returns the address (host and port) exposed by the Orderer for the named port. Command line tools should use the returned address when connecting to the orderer.

This assumes that the orderer is listening on 0.0.0.0 or 127.0.0.1 and is available on the loopback address.

func (*Network) OrdererConfigPath

func (n *Network) OrdererConfigPath(o *Orderer) string

OrdererConfigPath returns the path to the orderer configuration document for the specified Orderer.

func (*Network) OrdererDir

func (n *Network) OrdererDir(o *Orderer) string

OrdererDir returns the path to the configuration directory for the specified Orderer.

func (*Network) OrdererGroupRunner

func (n *Network) OrdererGroupRunner() ifrit.Runner

OrdererGroupRunner returns a runner that can be used to start and stop all orderers in a network.

func (*Network) OrdererLocalMSPDir

func (n *Network) OrdererLocalMSPDir(o *Orderer) string

OrdererLocalMSPDir returns the path to the local MSP directory for the Orderer.

func (*Network) OrdererOrgMSPDir

func (n *Network) OrdererOrgMSPDir(o *Organization) string

OrdererOrgMSPDir returns the path to the MSP directory of the Orderer organization.

func (*Network) OrdererOrgs

func (n *Network) OrdererOrgs() []*Organization

OrdererOrgs returns all Organization instances that own at least one orderer.

func (*Network) OrdererPort

func (n *Network) OrdererPort(o *Orderer, portName PortName) uint16

OrdererPort returns the named port reserved for the Orderer instance.

func (*Network) OrdererRunner

func (n *Network) OrdererRunner(o *Orderer) ifrit.Runner

OrdererRunner returns an ifrit.Runner for the specified orderer. The runner can be used to start and manage an orderer process.

func (*Network) OrderersInOrg

func (n *Network) OrderersInOrg(orgName string) []*Orderer

OrderersInOrg returns all Orderer instances owned by the named organaiztion.

func (*Network) Organization

func (n *Network) Organization(orgName string) *Organization

Organization returns the information about the named Organization.

func (*Network) OrgsForOrderers

func (n *Network) OrgsForOrderers(ordererNames []string) []*Organization

OrgsForOrderers returns all Organization instances that own at least one of the named orderers.

func (*Network) OutputBlockPath

func (n *Network) OutputBlockPath(name string) string

OutputBlockPath returns the path to the genesis block for the named system channel.

func (*Network) Peer

func (n *Network) Peer(orgName, peerName string) *Peer

Peer returns the information about the named Peer in the named organization.

func (*Network) PeerAddress

func (n *Network) PeerAddress(p *Peer, portName PortName) string

PeerAddress returns the address (host and port) exposed by the Peer for the named port. Command line tools should use the returned address when connecting to a peer.

This assumes that the peer is listening on 0.0.0.0 and is available on the loopback address.

func (*Network) PeerAdminSession

func (n *Network) PeerAdminSession(p *Peer, command Command) (*gexec.Session, error)

PeerAdminSession starts a gexec.Session as a peer admin for the provided peer command. This is intended to be used by short running peer cli commands that execute in the context of a peer configuration.

func (*Network) PeerConfigPath

func (n *Network) PeerConfigPath(p *Peer) string

PeerConfigPath returns the path to the peer configuration document for the specified peer.

func (*Network) PeerDir

func (n *Network) PeerDir(p *Peer) string

PeerDir returns the path to the configuration directory for the specified Peer.

func (*Network) PeerGroupRunner

func (n *Network) PeerGroupRunner() ifrit.Runner

PeerGroupRunner returns a runner that can be used to start and stop all peers in a network.

func (*Network) PeerLocalMSPDir

func (n *Network) PeerLocalMSPDir(p *Peer) string

PeerLocalMSPDir returns the path to the local MSP directory for the peer.

func (*Network) PeerOrgMSPDir

func (n *Network) PeerOrgMSPDir(org *Organization) string

PeerOrgMSPDir returns the path to the MSP directory of the Peer organization.

func (*Network) PeerOrgs

func (n *Network) PeerOrgs() []*Organization

PeerOrgs returns all Organizations associated with at least one Peer.

func (*Network) PeerPort

func (n *Network) PeerPort(p *Peer, portName PortName) uint16

PeerPort returns the named port reserved for the Peer instance.

func (*Network) PeerRunner

func (n *Network) PeerRunner(p *Peer) ifrit.Runner

PeerRunner returns an ifrit.Runner for the specified peer. The runner can be used to start and manage a peer process.

func (*Network) PeerUserMSPDir

func (n *Network) PeerUserMSPDir(p *Peer, user string) string

PeerUserMSPDir returns the path to the MSP directory containing the certificates and keys for the specified user of the peer.

func (*Network) PeerUserSession

func (n *Network) PeerUserSession(p *Peer, user string, command Command) (*gexec.Session, error)

PeerUserSession starts a gexec.Session as a peer user for the provided peer command. This is intended to be used by short running peer cli commands that execute in the context of a peer configuration.

func (*Network) PeersInOrg

func (n *Network) PeersInOrg(orgName string) []*Peer

PeersInOrg returns all Peer instances that are owned by the named organization.

func (*Network) PeersWithChannel

func (n *Network) PeersWithChannel(chanName string) []*Peer

PeersWithChannel returns all Peer instances that have joined the named channel.

func (*Network) ReservePort

func (n *Network) ReservePort() uint16

ReservePort allocates the next available port.

func (*Network) StartSession

func (n *Network) StartSession(cmd *exec.Cmd, name string) (*gexec.Session, error)

StartSession executes a command session. This should be used to launch command line tools that are expected to run to completion.

func (*Network) ZooKeeperRunner

func (n *Network) ZooKeeperRunner(idx int) *runner.ZooKeeper

ZooKeeperRunner returns a runner for a ZooKeeper instance.

type Orderer

type Orderer struct {
	Name         string `yaml:"name,omitempty"`
	Organization string `yaml:"organization,omitempty"`
}

Orderer defines an orderer instance and its owning organization.

func (Orderer) ID

func (o Orderer) ID() string

ID provides a unique identifier for an orderer instance.

type Organization

type Organization struct {
	MSPID         string `yaml:"msp_id,omitempty"`
	Name          string `yaml:"name,omitempty"`
	Domain        string `yaml:"domain,omitempty"`
	EnableNodeOUs bool   `yaml:"enable_node_organizational_units"`
	Users         int    `yaml:"users,omitempty"`
	CA            *CA    `yaml:"ca,omitempty"`
}

Organization models information about an Organization. It includes the information needed to populate an MSP with cryptogen.

type Peer

type Peer struct {
	Name         string         `yaml:"name,omitempty"`
	Organization string         `yaml:"organization,omitempty"`
	Channels     []*PeerChannel `yaml:"channels,omitempty"`
}

Peer defines a peer instance, it's owning organization, and the list of channels that the peer shoudl be joined to.

func (*Peer) Anchor

func (p *Peer) Anchor() bool

Anchor returns true if this peer is an anchor for any channel it has joined.

func (*Peer) ID

func (p *Peer) ID() string

ID provides a unique identifier for a peer instance.

type PeerChannel

type PeerChannel struct {
	Name   string `yaml:"name,omitempty"`
	Anchor bool   `yaml:"anchor"`
}

PeerChannel names of the channel a peer should be joined to and whether or not the peer should be an anchor for the channel.

type PortName

type PortName string
const (
	ChaincodePort PortName = "Chaincode"
	EventsPort    PortName = "Events"
	HostPort      PortName = "HostPort"
	ListenPort    PortName = "Listen"
	ProfilePort   PortName = "Profile"
)

func BrokerPortNames

func BrokerPortNames() []PortName

BrokerPortNames returns the list of ports that need to be reserved for a Kafka broker.

func OrdererPortNames

func OrdererPortNames() []PortName

OrdererPortNames returns the list of ports that need to be reserved for an Orderer.

func PeerPortNames

func PeerPortNames() []PortName

PeerPortNames returns the list of ports that need to be reserved for a Peer.

type Ports

type Ports map[PortName]uint16

type Profile

type Profile struct {
	Name          string   `yaml:"name,omitempty"`
	Orderers      []string `yaml:"orderers,omitempty"`
	Consortium    string   `yaml:"consortium,omitempty"`
	Organizations []string `yaml:"organizations,omitempty"`
}

A profile encapsulates basic information for a configtxgen profile.

type SystemChannel

type SystemChannel struct {
	Name    string `yaml:"name,omitempty"`
	Profile string `yaml:"profile,omitempty"`
}

The SystemChannel declares the name of the network system channel and its associated configtxgen profile name.

type WorkingDirer

type WorkingDirer interface {
	WorkingDir() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL