github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/integration/configtx/host_port.go (about)

     1  /*
     2  Copyright IBM Corp All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package configtx
     8  
     9  import (
    10  	"net"
    11  	"strconv"
    12  
    13  	"github.com/osdi23p228/fabric/integration/nwo"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  // PeerHostPort returns the host name and port number for the specified peer.
    18  func PeerHostPort(n *nwo.Network, p *nwo.Peer) (string, int) {
    19  	return splitHostPort(n.PeerAddress(p, nwo.ListenPort))
    20  }
    21  
    22  // OrdererHostPort returns the host name and port number for the specified
    23  // orderer.
    24  func OrdererHostPort(n *nwo.Network, o *nwo.Orderer) (string, int) {
    25  	return splitHostPort(n.OrdererAddress(o, nwo.ListenPort))
    26  }
    27  
    28  // OrdererClusterHostPort returns the host name and cluster port number for the
    29  // specified orderer.
    30  func OrdererClusterHostPort(n *nwo.Network, o *nwo.Orderer) (string, int) {
    31  	return splitHostPort(n.OrdererAddress(o, nwo.ClusterPort))
    32  }
    33  
    34  func splitHostPort(address string) (string, int) {
    35  	host, port, err := net.SplitHostPort(address)
    36  	Expect(err).NotTo(HaveOccurred())
    37  	portInt, err := strconv.Atoi(port)
    38  	Expect(err).NotTo(HaveOccurred())
    39  	return host, portInt
    40  }