Переглянути джерело

libnetwork: return concrete-typed *Endpoint

libnetwork.Endpoint is an interface with a single implementation.

https://github.com/golang/go/wiki/CodeReviewComments#interfaces

Signed-off-by: Cory Snider <csnider@mirantis.com>
Cory Snider 2 роки тому
батько
коміт
c71555f030

+ 1 - 1
builder/builder-next/executor_unix.go

@@ -83,7 +83,7 @@ func (p *bridgeProvider) New() (network.Namespace, error) {
 }
 
 type lnInterface struct {
-	ep  libnetwork.Endpoint
+	ep  *libnetwork.Endpoint
 	sbx *libnetwork.Sandbox
 	sync.Once
 	err      error

+ 4 - 4
daemon/container_operations.go

@@ -291,7 +291,7 @@ func (daemon *Daemon) updateNetworkSettings(container *container.Container, n li
 	return nil
 }
 
-func (daemon *Daemon) updateEndpointNetworkSettings(container *container.Container, n libnetwork.Network, ep libnetwork.Endpoint) error {
+func (daemon *Daemon) updateEndpointNetworkSettings(container *container.Container, n libnetwork.Network, ep *libnetwork.Endpoint) error {
 	if err := buildEndpointInfo(container.NetworkSettings, n, ep); err != nil {
 		return err
 	}
@@ -834,7 +834,7 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
 	return nil
 }
 
-func updateJoinInfo(networkSettings *network.Settings, n libnetwork.Network, ep libnetwork.Endpoint) error {
+func updateJoinInfo(networkSettings *network.Settings, n libnetwork.Network, ep *libnetwork.Endpoint) error {
 	if ep == nil {
 		return errors.New("invalid enppoint whhile building portmap info")
 	}
@@ -881,11 +881,11 @@ func (daemon *Daemon) ForceEndpointDelete(name string, networkName string) error
 
 func (daemon *Daemon) disconnectFromNetwork(container *container.Container, n libnetwork.Network, force bool) error {
 	var (
-		ep   libnetwork.Endpoint
+		ep   *libnetwork.Endpoint
 		sbox *libnetwork.Sandbox
 	)
 
-	s := func(current libnetwork.Endpoint) bool {
+	s := func(current *libnetwork.Endpoint) bool {
 		epInfo := current.Info()
 		if epInfo == nil {
 			return false

+ 2 - 2
daemon/network.go

@@ -969,7 +969,7 @@ func getPortMapInfo(sb *libnetwork.Sandbox) nat.PortMap {
 	return pm
 }
 
-func getEndpointPortMapInfo(ep libnetwork.Endpoint) (nat.PortMap, error) {
+func getEndpointPortMapInfo(ep *libnetwork.Endpoint) (nat.PortMap, error) {
 	pm := nat.PortMap{}
 	driverInfo, err := ep.DriverInfo()
 	if err != nil {
@@ -1013,7 +1013,7 @@ func getEndpointPortMapInfo(ep libnetwork.Endpoint) (nat.PortMap, error) {
 }
 
 // buildEndpointInfo sets endpoint-related fields on container.NetworkSettings based on the provided network and endpoint.
-func buildEndpointInfo(networkSettings *internalnetwork.Settings, n libnetwork.Network, ep libnetwork.Endpoint) error {
+func buildEndpointInfo(networkSettings *internalnetwork.Settings, n libnetwork.Network, ep *libnetwork.Endpoint) error {
 	if ep == nil {
 		return errors.New("endpoint cannot be nil")
 	}

+ 1 - 1
daemon/network_windows.go

@@ -7,7 +7,7 @@ import (
 )
 
 // getEndpointInNetwork returns the container's endpoint to the provided network.
-func getEndpointInNetwork(name string, n libnetwork.Network) (libnetwork.Endpoint, error) {
+func getEndpointInNetwork(name string, n libnetwork.Network) (*libnetwork.Endpoint, error) {
 	endpointName := strings.TrimPrefix(name, "/")
 	return n.EndpointByName(endpointName)
 }

+ 5 - 5
libnetwork/agent.go

@@ -551,7 +551,7 @@ func (n *network) leaveCluster() error {
 	return agent.networkDB.LeaveNetwork(n.ID())
 }
 
-func (ep *endpoint) addDriverInfoToCluster() error {
+func (ep *Endpoint) addDriverInfoToCluster() error {
 	n := ep.getNetwork()
 	if !n.isClusterEligible() {
 		return nil
@@ -573,7 +573,7 @@ func (ep *endpoint) addDriverInfoToCluster() error {
 	return nil
 }
 
-func (ep *endpoint) deleteDriverInfoFromCluster() error {
+func (ep *Endpoint) deleteDriverInfoFromCluster() error {
 	n := ep.getNetwork()
 	if !n.isClusterEligible() {
 		return nil
@@ -595,7 +595,7 @@ func (ep *endpoint) deleteDriverInfoFromCluster() error {
 	return nil
 }
 
-func (ep *endpoint) addServiceInfoToCluster(sb *Sandbox) error {
+func (ep *Endpoint) addServiceInfoToCluster(sb *Sandbox) error {
 	if ep.isAnonymous() && len(ep.myAliases) == 0 || ep.Iface() == nil || ep.Iface().Address() == nil {
 		return nil
 	}
@@ -677,7 +677,7 @@ func (ep *endpoint) addServiceInfoToCluster(sb *Sandbox) error {
 	return nil
 }
 
-func (ep *endpoint) deleteServiceInfoFromCluster(sb *Sandbox, fullRemove bool, method string) error {
+func (ep *Endpoint) deleteServiceInfoFromCluster(sb *Sandbox, fullRemove bool, method string) error {
 	if ep.isAnonymous() && len(ep.myAliases) == 0 {
 		return nil
 	}
@@ -742,7 +742,7 @@ func (ep *endpoint) deleteServiceInfoFromCluster(sb *Sandbox, fullRemove bool, m
 	return nil
 }
 
-func disableServiceInNetworkDB(a *agent, n *network, ep *endpoint) {
+func disableServiceInNetworkDB(a *agent, n *network, ep *Endpoint) {
 	var epRec EndpointRecord
 
 	logrus.Debugf("disableServiceInNetworkDB for %s %s", ep.svcName, ep.ID())

+ 3 - 3
libnetwork/controller.go

@@ -90,8 +90,8 @@ type Controller struct {
 	cfg              *config.Config
 	stores           []datastore.DataStore
 	extKeyListener   net.Listener
-	watchCh          chan *endpoint
-	unWatchCh        chan *endpoint
+	watchCh          chan *Endpoint
+	unWatchCh        chan *Endpoint
 	svcRecords       map[string]svcInfo
 	nmap             map[string]*netWatch
 	serviceBindings  map[serviceKey]*service
@@ -959,7 +959,7 @@ func (c *Controller) NewSandbox(containerID string, options ...SandboxOption) (*
 		sb = &Sandbox{
 			id:                 sandboxID,
 			containerID:        containerID,
-			endpoints:          []*endpoint{},
+			endpoints:          []*Endpoint{},
 			epPriority:         map[string]int{},
 			populatedEndpoints: map[string]struct{}{},
 			config:             containerConfig{},

+ 8 - 10
libnetwork/default_gateway.go

@@ -84,9 +84,7 @@ func (sb *Sandbox) setupDefaultGW() error {
 		}
 	}()
 
-	epLocal := newEp.(*endpoint)
-
-	if err = epLocal.sbJoin(sb); err != nil {
+	if err = newEp.sbJoin(sb); err != nil {
 		return fmt.Errorf("container %s: endpoint join on GW Network failed: %v", sb.containerID, err)
 	}
 
@@ -95,7 +93,7 @@ func (sb *Sandbox) setupDefaultGW() error {
 
 // If present, detach and remove the endpoint connecting the sandbox to the default gw network.
 func (sb *Sandbox) clearDefaultGW() error {
-	var ep *endpoint
+	var ep *Endpoint
 
 	if ep = sb.getEndpointInGWNetwork(); ep == nil {
 		return nil
@@ -116,7 +114,7 @@ func (sb *Sandbox) clearDefaultGW() error {
 func (sb *Sandbox) needDefaultGW() bool {
 	var needGW bool
 
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		if ep.endpointInGWNetwork() {
 			continue
 		}
@@ -145,8 +143,8 @@ func (sb *Sandbox) needDefaultGW() bool {
 	return needGW
 }
 
-func (sb *Sandbox) getEndpointInGWNetwork() *endpoint {
-	for _, ep := range sb.getConnectedEndpoints() {
+func (sb *Sandbox) getEndpointInGWNetwork() *Endpoint {
+	for _, ep := range sb.Endpoints() {
 		if ep.getNetwork().name == libnGWNetwork && strings.HasPrefix(ep.Name(), "gateway_") {
 			return ep
 		}
@@ -154,7 +152,7 @@ func (sb *Sandbox) getEndpointInGWNetwork() *endpoint {
 	return nil
 }
 
-func (ep *endpoint) endpointInGWNetwork() bool {
+func (ep *Endpoint) endpointInGWNetwork() bool {
 	if ep.getNetwork().name == libnGWNetwork && strings.HasPrefix(ep.Name(), "gateway_") {
 		return true
 	}
@@ -175,8 +173,8 @@ func (c *Controller) defaultGwNetwork() (Network, error) {
 }
 
 // Returns the endpoint which is providing external connectivity to the sandbox
-func (sb *Sandbox) getGatewayEndpoint() *endpoint {
-	for _, ep := range sb.getConnectedEndpoints() {
+func (sb *Sandbox) getGatewayEndpoint() *Endpoint {
+	for _, ep := range sb.Endpoints() {
 		if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" {
 			continue
 		}

+ 63 - 83
libnetwork/endpoint.go

@@ -14,40 +14,13 @@ import (
 	"github.com/sirupsen/logrus"
 )
 
-// Endpoint represents a logical connection between a network and a sandbox.
-type Endpoint interface {
-	// A system generated id for this endpoint.
-	ID() string
-
-	// Name returns the name of this endpoint.
-	Name() string
-
-	// Network returns the name of the network to which this endpoint is attached.
-	Network() string
-
-	// Join joins the sandbox to the endpoint and populates into the sandbox
-	// the network resources allocated for the endpoint.
-	Join(sandbox *Sandbox, options ...EndpointOption) error
-
-	// Leave detaches the network resources populated in the sandbox.
-	Leave(sandbox *Sandbox, options ...EndpointOption) error
-
-	// Return certain operational data belonging to this endpoint
-	Info() EndpointInfo
-
-	// DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver
-	DriverInfo() (map[string]interface{}, error)
-
-	// Delete and detaches this endpoint from the network.
-	Delete(force bool) error
-}
-
 // EndpointOption is an option setter function type used to pass various options to Network
 // and Endpoint interfaces methods. The various setter functions of type EndpointOption are
 // provided by libnetwork, they look like <Create|Join|Leave>Option[...](...)
-type EndpointOption func(ep *endpoint)
+type EndpointOption func(ep *Endpoint)
 
-type endpoint struct {
+// Endpoint represents a logical connection between a network and a sandbox.
+type Endpoint struct {
 	name              string
 	id                string
 	network           *network
@@ -75,7 +48,7 @@ type endpoint struct {
 	mu                sync.Mutex
 }
 
-func (ep *endpoint) MarshalJSON() ([]byte, error) {
+func (ep *Endpoint) MarshalJSON() ([]byte, error) {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -102,7 +75,7 @@ func (ep *endpoint) MarshalJSON() ([]byte, error) {
 	return json.Marshal(epMap)
 }
 
-func (ep *endpoint) UnmarshalJSON(b []byte) (err error) {
+func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -221,15 +194,15 @@ func (ep *endpoint) UnmarshalJSON(b []byte) (err error) {
 	return nil
 }
 
-func (ep *endpoint) New() datastore.KVObject {
-	return &endpoint{network: ep.getNetwork()}
+func (ep *Endpoint) New() datastore.KVObject {
+	return &Endpoint{network: ep.getNetwork()}
 }
 
-func (ep *endpoint) CopyTo(o datastore.KVObject) error {
+func (ep *Endpoint) CopyTo(o datastore.KVObject) error {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
-	dstEp := o.(*endpoint)
+	dstEp := o.(*Endpoint)
 	dstEp.name = ep.name
 	dstEp.id = ep.id
 	dstEp.sandboxID = ep.sandboxID
@@ -276,28 +249,31 @@ func (ep *endpoint) CopyTo(o datastore.KVObject) error {
 	return nil
 }
 
-func (ep *endpoint) ID() string {
+// ID returns the system-generated id for this endpoint.
+func (ep *Endpoint) ID() string {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
 	return ep.id
 }
 
-func (ep *endpoint) Name() string {
+// Name returns the name of this endpoint.
+func (ep *Endpoint) Name() string {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
 	return ep.name
 }
 
-func (ep *endpoint) MyAliases() []string {
+func (ep *Endpoint) MyAliases() []string {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
 	return ep.myAliases
 }
 
-func (ep *endpoint) Network() string {
+// Network returns the name of the network to which this endpoint is attached.
+func (ep *Endpoint) Network() string {
 	if ep.network == nil {
 		return ""
 	}
@@ -305,41 +281,41 @@ func (ep *endpoint) Network() string {
 	return ep.network.name
 }
 
-func (ep *endpoint) isAnonymous() bool {
+func (ep *Endpoint) isAnonymous() bool {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	return ep.anonymous
 }
 
 // isServiceEnabled check if service is enabled on the endpoint
-func (ep *endpoint) isServiceEnabled() bool {
+func (ep *Endpoint) isServiceEnabled() bool {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	return ep.serviceEnabled
 }
 
 // enableService sets service enabled on the endpoint
-func (ep *endpoint) enableService() {
+func (ep *Endpoint) enableService() {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	ep.serviceEnabled = true
 }
 
 // disableService disables service on the endpoint
-func (ep *endpoint) disableService() {
+func (ep *Endpoint) disableService() {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	ep.serviceEnabled = false
 }
 
-func (ep *endpoint) needResolver() bool {
+func (ep *Endpoint) needResolver() bool {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	return !ep.disableResolution
 }
 
 // endpoint Key structure : endpoint/network-id/endpoint-id
-func (ep *endpoint) Key() []string {
+func (ep *Endpoint) Key() []string {
 	if ep.network == nil {
 		return nil
 	}
@@ -347,7 +323,7 @@ func (ep *endpoint) Key() []string {
 	return []string{datastore.EndpointKeyPrefix, ep.network.id, ep.id}
 }
 
-func (ep *endpoint) KeyPrefix() []string {
+func (ep *Endpoint) KeyPrefix() []string {
 	if ep.network == nil {
 		return nil
 	}
@@ -355,7 +331,7 @@ func (ep *endpoint) KeyPrefix() []string {
 	return []string{datastore.EndpointKeyPrefix, ep.network.id}
 }
 
-func (ep *endpoint) Value() []byte {
+func (ep *Endpoint) Value() []byte {
 	b, err := json.Marshal(ep)
 	if err != nil {
 		return nil
@@ -363,34 +339,34 @@ func (ep *endpoint) Value() []byte {
 	return b
 }
 
-func (ep *endpoint) SetValue(value []byte) error {
+func (ep *Endpoint) SetValue(value []byte) error {
 	return json.Unmarshal(value, ep)
 }
 
-func (ep *endpoint) Index() uint64 {
+func (ep *Endpoint) Index() uint64 {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	return ep.dbIndex
 }
 
-func (ep *endpoint) SetIndex(index uint64) {
+func (ep *Endpoint) SetIndex(index uint64) {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	ep.dbIndex = index
 	ep.dbExists = true
 }
 
-func (ep *endpoint) Exists() bool {
+func (ep *Endpoint) Exists() bool {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	return ep.dbExists
 }
 
-func (ep *endpoint) Skip() bool {
+func (ep *Endpoint) Skip() bool {
 	return ep.getNetwork().Skip()
 }
 
-func (ep *endpoint) processOptions(options ...EndpointOption) {
+func (ep *Endpoint) processOptions(options ...EndpointOption) {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -401,14 +377,14 @@ func (ep *endpoint) processOptions(options ...EndpointOption) {
 	}
 }
 
-func (ep *endpoint) getNetwork() *network {
+func (ep *Endpoint) getNetwork() *network {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
 	return ep.network
 }
 
-func (ep *endpoint) getNetworkFromStore() (*network, error) {
+func (ep *Endpoint) getNetworkFromStore() (*network, error) {
 	if ep.network == nil {
 		return nil, fmt.Errorf("invalid network object in endpoint %s", ep.Name())
 	}
@@ -416,7 +392,9 @@ func (ep *endpoint) getNetworkFromStore() (*network, error) {
 	return ep.network.getController().getNetworkFromStore(ep.network.id)
 }
 
-func (ep *endpoint) Join(sb *Sandbox, options ...EndpointOption) error {
+// Join joins the sandbox to the endpoint and populates into the sandbox
+// the network resources allocated for the endpoint.
+func (ep *Endpoint) Join(sb *Sandbox, options ...EndpointOption) error {
 	if sb == nil || sb.ID() == "" || sb.Key() == "" {
 		return types.BadRequestErrorf("invalid Sandbox passed to endpoint join: %v", sb)
 	}
@@ -427,7 +405,7 @@ func (ep *endpoint) Join(sb *Sandbox, options ...EndpointOption) error {
 	return ep.sbJoin(sb, options...)
 }
 
-func (ep *endpoint) sbJoin(sb *Sandbox, options ...EndpointOption) (err error) {
+func (ep *Endpoint) sbJoin(sb *Sandbox, options ...EndpointOption) (err error) {
 	n, err := ep.getNetworkFromStore()
 	if err != nil {
 		return fmt.Errorf("failed to get network from store during join: %v", err)
@@ -586,7 +564,7 @@ func (ep *endpoint) sbJoin(sb *Sandbox, options ...EndpointOption) (err error) {
 	return nil
 }
 
-func (ep *endpoint) rename(name string) error {
+func (ep *Endpoint) rename(name string) error {
 	var (
 		err      error
 		netWatch *netWatch
@@ -669,14 +647,15 @@ func (ep *endpoint) rename(name string) error {
 	return err
 }
 
-func (ep *endpoint) hasInterface(iName string) bool {
+func (ep *Endpoint) hasInterface(iName string) bool {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
 	return ep.iface != nil && ep.iface.srcName == iName
 }
 
-func (ep *endpoint) Leave(sb *Sandbox, options ...EndpointOption) error {
+// Leave detaches the network resources populated in the sandbox.
+func (ep *Endpoint) Leave(sb *Sandbox, options ...EndpointOption) error {
 	if sb == nil || sb.ID() == "" || sb.Key() == "" {
 		return types.BadRequestErrorf("invalid Sandbox passed to endpoint leave: %v", sb)
 	}
@@ -687,7 +666,7 @@ func (ep *endpoint) Leave(sb *Sandbox, options ...EndpointOption) error {
 	return ep.sbLeave(sb, false, options...)
 }
 
-func (ep *endpoint) sbLeave(sb *Sandbox, force bool, options ...EndpointOption) error {
+func (ep *Endpoint) sbLeave(sb *Sandbox, force bool, options ...EndpointOption) error {
 	n, err := ep.getNetworkFromStore()
 	if err != nil {
 		return fmt.Errorf("failed to get network from store during leave: %v", err)
@@ -795,7 +774,8 @@ func (ep *endpoint) sbLeave(sb *Sandbox, force bool, options ...EndpointOption)
 	return nil
 }
 
-func (ep *endpoint) Delete(force bool) error {
+// Delete deletes and detaches this endpoint from the network.
+func (ep *Endpoint) Delete(force bool) error {
 	var err error
 	n, err := ep.getNetworkFromStore()
 	if err != nil {
@@ -853,7 +833,7 @@ func (ep *endpoint) Delete(force bool) error {
 	return nil
 }
 
-func (ep *endpoint) deleteEndpoint(force bool) error {
+func (ep *Endpoint) deleteEndpoint(force bool) error {
 	ep.mu.Lock()
 	n := ep.network
 	name := ep.name
@@ -882,7 +862,7 @@ func (ep *endpoint) deleteEndpoint(force bool) error {
 	return nil
 }
 
-func (ep *endpoint) getSandbox() (*Sandbox, bool) {
+func (ep *Endpoint) getSandbox() (*Sandbox, bool) {
 	c := ep.network.getController()
 	ep.mu.Lock()
 	sid := ep.sandboxID
@@ -895,7 +875,7 @@ func (ep *endpoint) getSandbox() (*Sandbox, bool) {
 	return ps, ok
 }
 
-func (ep *endpoint) getFirstInterfaceIPv4Address() net.IP {
+func (ep *Endpoint) getFirstInterfaceIPv4Address() net.IP {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -906,7 +886,7 @@ func (ep *endpoint) getFirstInterfaceIPv4Address() net.IP {
 	return nil
 }
 
-func (ep *endpoint) getFirstInterfaceIPv6Address() net.IP {
+func (ep *Endpoint) getFirstInterfaceIPv6Address() net.IP {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -920,7 +900,7 @@ func (ep *endpoint) getFirstInterfaceIPv6Address() net.IP {
 // EndpointOptionGeneric function returns an option setter for a Generic option defined
 // in a Dictionary of Key-Value pair
 func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		for k, v := range generic {
 			ep.generic[k] = v
 		}
@@ -934,7 +914,7 @@ var (
 
 // CreateOptionIpam function returns an option setter for the ipam configuration for this endpoint
 func CreateOptionIpam(ipV4, ipV6 net.IP, llIPs []net.IP, ipamOptions map[string]string) EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		ep.prefAddress = ipV4
 		ep.prefAddressV6 = ipV6
 		if len(llIPs) != 0 {
@@ -953,7 +933,7 @@ func CreateOptionIpam(ipV4, ipV6 net.IP, llIPs []net.IP, ipamOptions map[string]
 // CreateOptionExposedPorts function returns an option setter for the container exposed
 // ports option to be passed to network.CreateEndpoint() method.
 func CreateOptionExposedPorts(exposedPorts []types.TransportPort) EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		// Defensive copy
 		eps := make([]types.TransportPort, len(exposedPorts))
 		copy(eps, exposedPorts)
@@ -966,7 +946,7 @@ func CreateOptionExposedPorts(exposedPorts []types.TransportPort) EndpointOption
 // CreateOptionPortMapping function returns an option setter for the mapping
 // ports option to be passed to network.CreateEndpoint() method.
 func CreateOptionPortMapping(portBindings []types.PortBinding) EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		// Store a copy of the bindings as generic data to pass to the driver
 		pbs := make([]types.PortBinding, len(portBindings))
 		copy(pbs, portBindings)
@@ -977,7 +957,7 @@ func CreateOptionPortMapping(portBindings []types.PortBinding) EndpointOption {
 // CreateOptionDNS function returns an option setter for dns entry option to
 // be passed to container Create method.
 func CreateOptionDNS(dns []string) EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		ep.generic[netlabel.DNSServers] = dns
 	}
 }
@@ -985,7 +965,7 @@ func CreateOptionDNS(dns []string) EndpointOption {
 // CreateOptionAnonymous function returns an option setter for setting
 // this endpoint as anonymous
 func CreateOptionAnonymous() EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		ep.anonymous = true
 	}
 }
@@ -993,14 +973,14 @@ func CreateOptionAnonymous() EndpointOption {
 // CreateOptionDisableResolution function returns an option setter to indicate
 // this endpoint doesn't want embedded DNS server functionality
 func CreateOptionDisableResolution() EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		ep.disableResolution = true
 	}
 }
 
 // CreateOptionAlias function returns an option setter for setting endpoint alias
 func CreateOptionAlias(name string, alias string) EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		if ep.aliases == nil {
 			ep.aliases = make(map[string]string)
 		}
@@ -1010,7 +990,7 @@ func CreateOptionAlias(name string, alias string) EndpointOption {
 
 // CreateOptionService function returns an option setter for setting service binding configuration
 func CreateOptionService(name, id string, vip net.IP, ingressPorts []*PortConfig, aliases []string) EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		ep.svcName = name
 		ep.svcID = id
 		ep.virtualIP = vip
@@ -1021,14 +1001,14 @@ func CreateOptionService(name, id string, vip net.IP, ingressPorts []*PortConfig
 
 // CreateOptionMyAlias function returns an option setter for setting endpoint's self alias
 func CreateOptionMyAlias(alias string) EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		ep.myAliases = append(ep.myAliases, alias)
 	}
 }
 
 // CreateOptionLoadBalancer function returns an option setter for denoting the endpoint is a load balancer for a network
 func CreateOptionLoadBalancer() EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		ep.loadBalancer = true
 	}
 }
@@ -1036,7 +1016,7 @@ func CreateOptionLoadBalancer() EndpointOption {
 // JoinOptionPriority function returns an option setter for priority option to
 // be passed to the endpoint.Join() method.
 func JoinOptionPriority(prio int) EndpointOption {
-	return func(ep *endpoint) {
+	return func(ep *Endpoint) {
 		// ep lock already acquired
 		c := ep.network.getController()
 		c.mu.Lock()
@@ -1050,11 +1030,11 @@ func JoinOptionPriority(prio int) EndpointOption {
 	}
 }
 
-func (ep *endpoint) DataScope() string {
+func (ep *Endpoint) DataScope() string {
 	return ep.getNetwork().DataScope()
 }
 
-func (ep *endpoint) assignAddress(ipam ipamapi.Ipam, assignIPv4, assignIPv6 bool) error {
+func (ep *Endpoint) assignAddress(ipam ipamapi.Ipam, assignIPv4, assignIPv6 bool) error {
 	var err error
 
 	n := ep.getNetwork()
@@ -1077,7 +1057,7 @@ func (ep *endpoint) assignAddress(ipam ipamapi.Ipam, assignIPv4, assignIPv6 bool
 	return err
 }
 
-func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
+func (ep *Endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
 	var (
 		poolID  *string
 		address **net.IPNet
@@ -1136,7 +1116,7 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
 	return fmt.Errorf("no available IPv%d addresses on this network's address pools: %s (%s)", ipVer, n.Name(), n.ID())
 }
 
-func (ep *endpoint) releaseAddress() {
+func (ep *Endpoint) releaseAddress() {
 	n := ep.getNetwork()
 	if n.hasSpecialDriver() {
 		return

+ 16 - 15
libnetwork/endpoint_info.go

@@ -187,7 +187,8 @@ type tableEntry struct {
 	value     []byte
 }
 
-func (ep *endpoint) Info() EndpointInfo {
+// Info returns certain operational data belonging to this endpoint.
+func (ep *Endpoint) Info() EndpointInfo {
 	if ep.sandboxID != "" {
 		return ep
 	}
@@ -211,7 +212,7 @@ func (ep *endpoint) Info() EndpointInfo {
 	return sb.getEndpoint(ep.ID())
 }
 
-func (ep *endpoint) Iface() InterfaceInfo {
+func (ep *Endpoint) Iface() InterfaceInfo {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -222,7 +223,7 @@ func (ep *endpoint) Iface() InterfaceInfo {
 	return nil
 }
 
-func (ep *endpoint) Interface() driverapi.InterfaceInfo {
+func (ep *Endpoint) Interface() driverapi.InterfaceInfo {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -288,7 +289,7 @@ func (epi *endpointInterface) SetNames(srcName string, dstPrefix string) error {
 	return nil
 }
 
-func (ep *endpoint) InterfaceName() driverapi.InterfaceNameInfo {
+func (ep *Endpoint) InterfaceName() driverapi.InterfaceNameInfo {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -299,7 +300,7 @@ func (ep *endpoint) InterfaceName() driverapi.InterfaceNameInfo {
 	return nil
 }
 
-func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error {
+func (ep *Endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -315,7 +316,7 @@ func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHo
 	return nil
 }
 
-func (ep *endpoint) AddTableEntry(tableName, key string, value []byte) error {
+func (ep *Endpoint) AddTableEntry(tableName, key string, value []byte) error {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -328,7 +329,7 @@ func (ep *endpoint) AddTableEntry(tableName, key string, value []byte) error {
 	return nil
 }
 
-func (ep *endpoint) Sandbox() *Sandbox {
+func (ep *Endpoint) Sandbox() *Sandbox {
 	cnt, ok := ep.getSandbox()
 	if !ok {
 		return nil
@@ -336,13 +337,13 @@ func (ep *endpoint) Sandbox() *Sandbox {
 	return cnt
 }
 
-func (ep *endpoint) LoadBalancer() bool {
+func (ep *Endpoint) LoadBalancer() bool {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 	return ep.loadBalancer
 }
 
-func (ep *endpoint) StaticRoutes() []*types.StaticRoute {
+func (ep *Endpoint) StaticRoutes() []*types.StaticRoute {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -353,7 +354,7 @@ func (ep *endpoint) StaticRoutes() []*types.StaticRoute {
 	return ep.joinInfo.StaticRoutes
 }
 
-func (ep *endpoint) Gateway() net.IP {
+func (ep *Endpoint) Gateway() net.IP {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -364,7 +365,7 @@ func (ep *endpoint) Gateway() net.IP {
 	return types.GetIPCopy(ep.joinInfo.gw)
 }
 
-func (ep *endpoint) GatewayIPv6() net.IP {
+func (ep *Endpoint) GatewayIPv6() net.IP {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -375,7 +376,7 @@ func (ep *endpoint) GatewayIPv6() net.IP {
 	return types.GetIPCopy(ep.joinInfo.gw6)
 }
 
-func (ep *endpoint) SetGateway(gw net.IP) error {
+func (ep *Endpoint) SetGateway(gw net.IP) error {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -383,7 +384,7 @@ func (ep *endpoint) SetGateway(gw net.IP) error {
 	return nil
 }
 
-func (ep *endpoint) SetGatewayIPv6(gw6 net.IP) error {
+func (ep *Endpoint) SetGatewayIPv6(gw6 net.IP) error {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 
@@ -391,7 +392,7 @@ func (ep *endpoint) SetGatewayIPv6(gw6 net.IP) error {
 	return nil
 }
 
-func (ep *endpoint) retrieveFromStore() (*endpoint, error) {
+func (ep *Endpoint) retrieveFromStore() (*Endpoint, error) {
 	n, err := ep.getNetworkFromStore()
 	if err != nil {
 		return nil, fmt.Errorf("could not find network in store to get latest endpoint %s: %v", ep.Name(), err)
@@ -399,7 +400,7 @@ func (ep *endpoint) retrieveFromStore() (*endpoint, error) {
 	return n.getEndpointFromStore(ep.ID())
 }
 
-func (ep *endpoint) DisableGatewayService() {
+func (ep *Endpoint) DisableGatewayService() {
 	ep.mu.Lock()
 	defer ep.mu.Unlock()
 

+ 2 - 1
libnetwork/endpoint_info_unix.go

@@ -5,7 +5,8 @@ package libnetwork
 
 import "fmt"
 
-func (ep *endpoint) DriverInfo() (map[string]interface{}, error) {
+// DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver.
+func (ep *Endpoint) DriverInfo() (map[string]interface{}, error) {
 	ep, err := ep.retrieveFromStore()
 	if err != nil {
 		return nil, err

+ 2 - 1
libnetwork/endpoint_info_windows.go

@@ -5,7 +5,8 @@ package libnetwork
 
 import "fmt"
 
-func (ep *endpoint) DriverInfo() (map[string]interface{}, error) {
+// DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver.
+func (ep *Endpoint) DriverInfo() (map[string]interface{}, error) {
 	ep, err := ep.retrieveFromStore()
 	if err != nil {
 		return nil, err

+ 2 - 2
libnetwork/libnetwork_internal_test.go

@@ -188,7 +188,7 @@ func TestEndpointMarshalling(t *testing.T) {
 		lla = append(lla, ll)
 	}
 
-	e := &endpoint{
+	e := &Endpoint{
 		name:      "Bau",
 		id:        "efghijklmno",
 		sandboxID: "ambarabaciccicocco",
@@ -213,7 +213,7 @@ func TestEndpointMarshalling(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	ee := &endpoint{}
+	ee := &Endpoint{}
 	err = json.Unmarshal(b, ee)
 	if err != nil {
 		t.Fatal(err)

+ 1 - 1
libnetwork/libnetwork_linux_test.go

@@ -852,7 +852,7 @@ type parallelTester struct {
 
 func (pt parallelTester) Do(t *testing.T, thrNumber int) error {
 	var (
-		ep  libnetwork.Endpoint
+		ep  *libnetwork.Endpoint
 		sb  *libnetwork.Sandbox
 		err error
 	)

+ 2 - 2
libnetwork/libnetwork_test.go

@@ -520,8 +520,8 @@ func TestNetworkEndpointsWalkers(t *testing.T) {
 
 	// Test Endpoint Walk method
 	var epName string
-	var epWanted libnetwork.Endpoint
-	wlk := func(ep libnetwork.Endpoint) bool {
+	var epWanted *libnetwork.Endpoint
+	wlk := func(ep *libnetwork.Endpoint) bool {
 		if ep.Name() == epName {
 			epWanted = ep
 			return true

+ 17 - 24
libnetwork/network.go

@@ -38,22 +38,22 @@ type Network interface {
 
 	// CreateEndpoint creates a new endpoint to this network symbolically identified by the
 	// specified unique name. The options parameter carries driver specific options.
-	CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error)
+	CreateEndpoint(name string, options ...EndpointOption) (*Endpoint, error)
 
 	// Delete the network.
 	Delete(options ...NetworkDeleteOption) error
 
 	// Endpoints returns the list of Endpoint(s) in this network.
-	Endpoints() []Endpoint
+	Endpoints() []*Endpoint
 
 	// WalkEndpoints uses the provided function to walk the Endpoints.
 	WalkEndpoints(walker EndpointWalker)
 
 	// EndpointByName returns the Endpoint which has the passed name. If not found, the error ErrNoSuchEndpoint is returned.
-	EndpointByName(name string) (Endpoint, error)
+	EndpointByName(name string) (*Endpoint, error)
 
 	// EndpointByID returns the Endpoint which has the passed id. If not found, the error ErrNoSuchEndpoint is returned.
-	EndpointByID(id string) (Endpoint, error)
+	EndpointByID(id string) (*Endpoint, error)
 
 	// Info returns certain operational data belonging to this network.
 	Info() NetworkInfo
@@ -86,7 +86,7 @@ type NetworkInfo interface {
 
 // EndpointWalker is a client provided function which will be used to walk the Endpoints.
 // When the function returns true, the walk will stop.
-type EndpointWalker func(ep Endpoint) bool
+type EndpointWalker func(ep *Endpoint) bool
 
 // ipInfo is the reverse mapping from IP to service name to serve the PTR query.
 // extResolver is set if an external server resolves a service name to this IP.
@@ -1135,7 +1135,7 @@ func (n *network) deleteNetwork() error {
 	return nil
 }
 
-func (n *network) addEndpoint(ep *endpoint) error {
+func (n *network) addEndpoint(ep *Endpoint) error {
 	d, err := n.driver(true)
 	if err != nil {
 		return fmt.Errorf("failed to add endpoint: %v", err)
@@ -1150,7 +1150,7 @@ func (n *network) addEndpoint(ep *endpoint) error {
 	return nil
 }
 
-func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error) {
+func (n *network) CreateEndpoint(name string, options ...EndpointOption) (*Endpoint, error) {
 	var err error
 	if !config.IsValidName(name) {
 		return nil, ErrInvalidName(name)
@@ -1170,10 +1170,10 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
 	return n.createEndpoint(name, options...)
 }
 
-func (n *network) createEndpoint(name string, options ...EndpointOption) (Endpoint, error) {
+func (n *network) createEndpoint(name string, options ...EndpointOption) (*Endpoint, error) {
 	var err error
 
-	ep := &endpoint{name: name, generic: make(map[string]interface{}), iface: &endpointInterface{}}
+	ep := &Endpoint{name: name, generic: make(map[string]interface{}), iface: &endpointInterface{}}
 	ep.id = stringid.GenerateRandomID()
 
 	// Initialize ep.network with a possibly stale copy of n. We need this to get network from
@@ -1268,19 +1268,12 @@ func (n *network) createEndpoint(name string, options ...EndpointOption) (Endpoi
 	return ep, nil
 }
 
-func (n *network) Endpoints() []Endpoint {
-	var list []Endpoint
-
+func (n *network) Endpoints() []*Endpoint {
 	endpoints, err := n.getEndpointsFromStore()
 	if err != nil {
 		logrus.Error(err)
 	}
-
-	for _, ep := range endpoints {
-		list = append(list, ep)
-	}
-
-	return list
+	return endpoints
 }
 
 func (n *network) WalkEndpoints(walker EndpointWalker) {
@@ -1291,13 +1284,13 @@ func (n *network) WalkEndpoints(walker EndpointWalker) {
 	}
 }
 
-func (n *network) EndpointByName(name string) (Endpoint, error) {
+func (n *network) EndpointByName(name string) (*Endpoint, error) {
 	if name == "" {
 		return nil, ErrInvalidName(name)
 	}
-	var e Endpoint
+	var e *Endpoint
 
-	s := func(current Endpoint) bool {
+	s := func(current *Endpoint) bool {
 		if current.Name() == name {
 			e = current
 			return true
@@ -1314,7 +1307,7 @@ func (n *network) EndpointByName(name string) (Endpoint, error) {
 	return e, nil
 }
 
-func (n *network) EndpointByID(id string) (Endpoint, error) {
+func (n *network) EndpointByID(id string) (*Endpoint, error) {
 	if id == "" {
 		return nil, ErrInvalidID(id)
 	}
@@ -1327,7 +1320,7 @@ func (n *network) EndpointByID(id string) (Endpoint, error) {
 	return ep, nil
 }
 
-func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool) {
+func (n *network) updateSvcRecord(ep *Endpoint, localEps []*Endpoint, isAdd bool) {
 	var ipv6 net.IP
 	epName := ep.Name()
 	if iface := ep.Iface(); iface != nil && iface.Address() != nil {
@@ -1472,7 +1465,7 @@ func (n *network) deleteSvcRecords(eID, name, serviceID string, epIP net.IP, epI
 	}
 }
 
-func (n *network) getSvcRecords(ep *endpoint) []etchosts.Record {
+func (n *network) getSvcRecords(ep *Endpoint) []etchosts.Record {
 	n.Lock()
 	defer n.Unlock()
 

+ 31 - 42
libnetwork/sandbox.go

@@ -40,7 +40,7 @@ type Sandbox struct {
 	controller         *Controller
 	resolver           Resolver
 	resolverOnce       sync.Once
-	endpoints          []*endpoint
+	endpoints          []*Endpoint
 	epPriority         map[string]int
 	populatedEndpoints map[string]struct{}
 	joinLeaveDone      chan struct{}
@@ -178,7 +178,7 @@ func (sb *Sandbox) delete(force bool) error {
 
 	// Detach from all endpoints
 	retain := false
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		// gw network endpoint detach and removal are automatic
 		if ep.endpointInGWNetwork() && !force {
 			continue
@@ -241,7 +241,7 @@ func (sb *Sandbox) delete(force bool) error {
 func (sb *Sandbox) Rename(name string) error {
 	var err error
 
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		if ep.endpointInGWNetwork() {
 			continue
 		}
@@ -268,7 +268,7 @@ func (sb *Sandbox) Rename(name string) error {
 // re-joins all the endpoints without destroying the osl sandbox
 func (sb *Sandbox) Refresh(options ...SandboxOption) error {
 	// Store connected endpoints
-	epList := sb.getConnectedEndpoints()
+	epList := sb.Endpoints()
 
 	// Detach from all endpoints
 	for _, ep := range epList {
@@ -317,28 +317,17 @@ func (sb *Sandbox) UnmarshalJSON(b []byte) (err error) {
 }
 
 // Endpoints returns all the endpoints connected to the sandbox.
-func (sb *Sandbox) Endpoints() []Endpoint {
+func (sb *Sandbox) Endpoints() []*Endpoint {
 	sb.mu.Lock()
 	defer sb.mu.Unlock()
 
-	endpoints := make([]Endpoint, len(sb.endpoints))
-	for i, ep := range sb.endpoints {
-		endpoints[i] = ep
-	}
-	return endpoints
-}
-
-func (sb *Sandbox) getConnectedEndpoints() []*endpoint {
-	sb.mu.Lock()
-	defer sb.mu.Unlock()
-
-	eps := make([]*endpoint, len(sb.endpoints))
+	eps := make([]*Endpoint, len(sb.endpoints))
 	copy(eps, sb.endpoints)
 
 	return eps
 }
 
-func (sb *Sandbox) addEndpoint(ep *endpoint) {
+func (sb *Sandbox) addEndpoint(ep *Endpoint) {
 	sb.mu.Lock()
 	defer sb.mu.Unlock()
 
@@ -352,14 +341,14 @@ func (sb *Sandbox) addEndpoint(ep *endpoint) {
 	sb.endpoints[i] = ep
 }
 
-func (sb *Sandbox) removeEndpoint(ep *endpoint) {
+func (sb *Sandbox) removeEndpoint(ep *Endpoint) {
 	sb.mu.Lock()
 	defer sb.mu.Unlock()
 
 	sb.removeEndpointRaw(ep)
 }
 
-func (sb *Sandbox) removeEndpointRaw(ep *endpoint) {
+func (sb *Sandbox) removeEndpointRaw(ep *Endpoint) {
 	for i, e := range sb.endpoints {
 		if e == ep {
 			sb.endpoints = append(sb.endpoints[:i], sb.endpoints[i+1:]...)
@@ -368,7 +357,7 @@ func (sb *Sandbox) removeEndpointRaw(ep *endpoint) {
 	}
 }
 
-func (sb *Sandbox) getEndpoint(id string) *endpoint {
+func (sb *Sandbox) getEndpoint(id string) *Endpoint {
 	sb.mu.Lock()
 	defer sb.mu.Unlock()
 
@@ -381,7 +370,7 @@ func (sb *Sandbox) getEndpoint(id string) *endpoint {
 	return nil
 }
 
-func (sb *Sandbox) updateGateway(ep *endpoint) error {
+func (sb *Sandbox) updateGateway(ep *Endpoint) error {
 	sb.mu.Lock()
 	osSbox := sb.osSbox
 	sb.mu.Unlock()
@@ -411,7 +400,7 @@ func (sb *Sandbox) updateGateway(ep *endpoint) error {
 }
 
 func (sb *Sandbox) HandleQueryResp(name string, ip net.IP) {
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		n := ep.getNetwork()
 		n.HandleQueryResp(name, ip)
 	}
@@ -421,7 +410,7 @@ func (sb *Sandbox) ResolveIP(ip string) string {
 	var svc string
 	logrus.Debugf("IP To resolve %v", ip)
 
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		n := ep.getNetwork()
 		svc = n.ResolveIP(ip)
 		if len(svc) != 0 {
@@ -458,7 +447,7 @@ func (sb *Sandbox) ResolveService(name string) ([]*net.SRV, []net.IP) {
 		return nil, nil
 	}
 
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		n := ep.getNetwork()
 
 		srv, ip = n.ResolveService(name)
@@ -469,8 +458,8 @@ func (sb *Sandbox) ResolveService(name string) ([]*net.SRV, []net.IP) {
 	return srv, ip
 }
 
-func getDynamicNwEndpoints(epList []*endpoint) []*endpoint {
-	eps := []*endpoint{}
+func getDynamicNwEndpoints(epList []*Endpoint) []*Endpoint {
+	eps := []*Endpoint{}
 	for _, ep := range epList {
 		n := ep.getNetwork()
 		if n.dynamic && !n.ingress {
@@ -480,7 +469,7 @@ func getDynamicNwEndpoints(epList []*endpoint) []*endpoint {
 	return eps
 }
 
-func getIngressNwEndpoint(epList []*endpoint) *endpoint {
+func getIngressNwEndpoint(epList []*Endpoint) *Endpoint {
 	for _, ep := range epList {
 		n := ep.getNetwork()
 		if n.ingress {
@@ -490,8 +479,8 @@ func getIngressNwEndpoint(epList []*endpoint) *endpoint {
 	return nil
 }
 
-func getLocalNwEndpoints(epList []*endpoint) []*endpoint {
-	eps := []*endpoint{}
+func getLocalNwEndpoints(epList []*Endpoint) []*Endpoint {
+	eps := []*Endpoint{}
 	for _, ep := range epList {
 		n := ep.getNetwork()
 		if !n.dynamic && !n.ingress {
@@ -530,12 +519,12 @@ func (sb *Sandbox) ResolveName(name string, ipType int) ([]net.IP, bool) {
 		}
 	}
 
-	epList := sb.getConnectedEndpoints()
+	epList := sb.Endpoints()
 
 	// In swarm mode services with exposed ports are connected to user overlay
 	// network, ingress network and docker_gwbridge network. Name resolution
 	// should prioritize returning the VIP/IPs on user overlay network.
-	newList := []*endpoint{}
+	newList := []*Endpoint{}
 	if !sb.controller.isDistributedControl() {
 		newList = append(newList, getDynamicNwEndpoints(epList)...)
 		ingressEP := getIngressNwEndpoint(epList)
@@ -568,7 +557,7 @@ func (sb *Sandbox) ResolveName(name string, ipType int) ([]net.IP, bool) {
 	return nil, false
 }
 
-func (sb *Sandbox) resolveName(req string, networkName string, epList []*endpoint, alias bool, ipType int) ([]net.IP, bool) {
+func (sb *Sandbox) resolveName(req string, networkName string, epList []*Endpoint, alias bool, ipType int) ([]net.IP, bool) {
 	var ipv6Miss bool
 
 	for _, ep := range epList {
@@ -664,7 +653,7 @@ func (sb *Sandbox) SetKey(basePath string) error {
 		}
 	}
 
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		if err = sb.populateNetworkResources(ep); err != nil {
 			return err
 		}
@@ -683,7 +672,7 @@ func (sb *Sandbox) EnableService() (err error) {
 			}
 		}
 	}()
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		if !ep.isServiceEnabled() {
 			if err := ep.addServiceInfoToCluster(sb); err != nil {
 				return fmt.Errorf("could not update state for endpoint %s into cluster: %v", ep.Name(), err)
@@ -705,7 +694,7 @@ func (sb *Sandbox) DisableService() (err error) {
 			err = fmt.Errorf("failed to disable service on sandbox:%s, for endpoints %s", sb.ID(), strings.Join(failedEps, ","))
 		}
 	}()
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		if ep.isServiceEnabled() {
 			if err := ep.deleteServiceInfoFromCluster(sb, false, "DisableService"); err != nil {
 				failedEps = append(failedEps, ep.Name())
@@ -718,7 +707,7 @@ func (sb *Sandbox) DisableService() (err error) {
 	return nil
 }
 
-func releaseOSSboxResources(osSbox osl.Sandbox, ep *endpoint) {
+func releaseOSSboxResources(osSbox osl.Sandbox, ep *Endpoint) {
 	for _, i := range osSbox.Info().Interfaces() {
 		// Only remove the interfaces owned by this endpoint from the sandbox.
 		if ep.hasInterface(i.SrcName()) {
@@ -763,7 +752,7 @@ func (sb *Sandbox) releaseOSSbox() {
 		return
 	}
 
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		releaseOSSboxResources(osSbox, ep)
 	}
 
@@ -819,7 +808,7 @@ func (sb *Sandbox) restoreOslSandbox() error {
 	return sb.osSbox.Restore(Ifaces, routes, gwep.joinInfo.gw, gwep.joinInfo.gw6)
 }
 
-func (sb *Sandbox) populateNetworkResources(ep *endpoint) error {
+func (sb *Sandbox) populateNetworkResources(ep *Endpoint) error {
 	sb.mu.Lock()
 	if sb.osSbox == nil {
 		sb.mu.Unlock()
@@ -907,7 +896,7 @@ func (sb *Sandbox) populateNetworkResources(ep *endpoint) error {
 	return nil
 }
 
-func (sb *Sandbox) clearNetworkResources(origEp *endpoint) error {
+func (sb *Sandbox) clearNetworkResources(origEp *Endpoint) error {
 	ep := sb.getEndpoint(origEp.id)
 	if ep == nil {
 		return fmt.Errorf("could not find the sandbox endpoint data for endpoint %s",
@@ -934,7 +923,7 @@ func (sb *Sandbox) clearNetworkResources(origEp *endpoint) error {
 	}
 
 	var (
-		gwepBefore, gwepAfter *endpoint
+		gwepBefore, gwepAfter *Endpoint
 		index                 = -1
 	)
 	for i, e := range sb.endpoints {
@@ -1184,7 +1173,7 @@ func OptionLoadBalancer(nid string) SandboxOption {
 // epi.internal <=> epj.internal   # non-internal < internal
 // epi.joininfo <=> epj.joininfo   # ipv6 < ipv4
 // epi.name <=> epj.name           # bar < foo
-func (epi *endpoint) Less(epj *endpoint) bool {
+func (epi *Endpoint) Less(epj *Endpoint) bool {
 	var (
 		prioi, prioj int
 	)

+ 5 - 5
libnetwork/sandbox_store.go

@@ -147,7 +147,7 @@ func (sb *Sandbox) storeUpdate() error {
 
 retry:
 	sbs.Eps = nil
-	for _, ep := range sb.getConnectedEndpoints() {
+	for _, ep := range sb.Endpoints() {
 		// If the endpoint is not persisted then do not add it to
 		// the sandbox checkpoint
 		if ep.Skip() {
@@ -211,7 +211,7 @@ func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
 			id:                 sbs.ID,
 			controller:         sbs.c,
 			containerID:        sbs.Cid,
-			endpoints:          []*endpoint{},
+			endpoints:          []*Endpoint{},
 			populatedEndpoints: map[string]struct{}{},
 			dbIndex:            sbs.dbIndex,
 			isStub:             true,
@@ -251,16 +251,16 @@ func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
 
 		for _, eps := range sbs.Eps {
 			n, err := c.getNetworkFromStore(eps.Nid)
-			var ep *endpoint
+			var ep *Endpoint
 			if err != nil {
 				logrus.Errorf("getNetworkFromStore for nid %s failed while trying to build sandbox for cleanup: %v", eps.Nid, err)
 				n = &network{id: eps.Nid, ctrlr: c, drvOnce: &sync.Once{}, persist: true}
-				ep = &endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID}
+				ep = &Endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID}
 			} else {
 				ep, err = n.getEndpointFromStore(eps.Eid)
 				if err != nil {
 					logrus.Errorf("getEndpointFromStore for eid %s failed while trying to build sandbox for cleanup: %v", eps.Eid, err)
-					ep = &endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID}
+					ep = &Endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID}
 				}
 			}
 			if _, ok := activeSandboxes[sb.ID()]; ok && err != nil {

+ 5 - 5
libnetwork/service_linux.go

@@ -21,7 +21,7 @@ import (
 
 // Populate all loadbalancers on the network that the passed endpoint
 // belongs to, into this sandbox.
-func (sb *Sandbox) populateLoadBalancers(ep *endpoint) {
+func (sb *Sandbox) populateLoadBalancers(ep *Endpoint) {
 	// This is an interface less endpoint. Nothing to do.
 	if ep.Iface() == nil {
 		return
@@ -37,14 +37,14 @@ func (sb *Sandbox) populateLoadBalancers(ep *endpoint) {
 	}
 }
 
-func (n *network) findLBEndpointSandbox() (*endpoint, *Sandbox, error) {
+func (n *network) findLBEndpointSandbox() (*Endpoint, *Sandbox, error) {
 	// TODO: get endpoint from store?  See EndpointInfo()
-	var ep *endpoint
+	var ep *Endpoint
 	// Find this node's LB sandbox endpoint:  there should be exactly one
 	for _, e := range n.Endpoints() {
 		epi := e.Info()
 		if epi != nil && epi.LoadBalancer() {
-			ep = e.(*endpoint)
+			ep = e
 			break
 		}
 	}
@@ -66,7 +66,7 @@ func (n *network) findLBEndpointSandbox() (*endpoint, *Sandbox, error) {
 // Searches the OS sandbox for the name of the endpoint interface
 // within the sandbox.   This is required for adding/removing IP
 // aliases to the interface.
-func findIfaceDstName(sb *Sandbox, ep *endpoint) string {
+func findIfaceDstName(sb *Sandbox, ep *Endpoint) string {
 	srcName := ep.Iface().SrcName()
 	for _, i := range sb.osSbox.Info().Interfaces() {
 		if i.SrcName() == srcName {

+ 1 - 1
libnetwork/service_windows.go

@@ -161,7 +161,7 @@ func numEnabledBackends(lb *loadBalancer) int {
 	return nEnabled
 }
 
-func (sb *Sandbox) populateLoadBalancers(ep *endpoint) {
+func (sb *Sandbox) populateLoadBalancers(ep *Endpoint) {
 }
 
 func arrangeIngressFilterRule() {

+ 22 - 22
libnetwork/store.go

@@ -158,10 +158,10 @@ func (c *Controller) getNetworksFromStore() []*network {
 	return nl
 }
 
-func (n *network) getEndpointFromStore(eid string) (*endpoint, error) {
+func (n *network) getEndpointFromStore(eid string) (*Endpoint, error) {
 	var errors []string
 	for _, store := range n.ctrlr.getStores() {
-		ep := &endpoint{id: eid, network: n}
+		ep := &Endpoint{id: eid, network: n}
 		err := store.GetObject(datastore.Key(ep.Key()...), ep)
 		// Continue searching in the next store if the key is not found in this store
 		if err != nil {
@@ -176,12 +176,12 @@ func (n *network) getEndpointFromStore(eid string) (*endpoint, error) {
 	return nil, fmt.Errorf("could not find endpoint %s: %v", eid, errors)
 }
 
-func (n *network) getEndpointsFromStore() ([]*endpoint, error) {
-	var epl []*endpoint
+func (n *network) getEndpointsFromStore() ([]*Endpoint, error) {
+	var epl []*Endpoint
 
-	tmp := endpoint{network: n}
+	tmp := Endpoint{network: n}
 	for _, store := range n.getController().getStores() {
-		kvol, err := store.List(datastore.Key(tmp.KeyPrefix()...), &endpoint{network: n})
+		kvol, err := store.List(datastore.Key(tmp.KeyPrefix()...), &Endpoint{network: n})
 		// Continue searching in the next store if no keys found in this store
 		if err != nil {
 			if err != datastore.ErrKeyNotFound {
@@ -192,7 +192,7 @@ func (n *network) getEndpointsFromStore() ([]*endpoint, error) {
 		}
 
 		for _, kvo := range kvol {
-			ep := kvo.(*endpoint)
+			ep := kvo.(*Endpoint)
 			epl = append(epl, ep)
 		}
 	}
@@ -238,16 +238,16 @@ retry:
 }
 
 type netWatch struct {
-	localEps  map[string]*endpoint
-	remoteEps map[string]*endpoint
+	localEps  map[string]*Endpoint
+	remoteEps map[string]*Endpoint
 	stopCh    chan struct{}
 }
 
-func (c *Controller) getLocalEps(nw *netWatch) []*endpoint {
+func (c *Controller) getLocalEps(nw *netWatch) []*Endpoint {
 	c.mu.Lock()
 	defer c.mu.Unlock()
 
-	var epl []*endpoint
+	var epl []*Endpoint
 	for _, ep := range nw.localEps {
 		epl = append(epl, ep)
 	}
@@ -255,15 +255,15 @@ func (c *Controller) getLocalEps(nw *netWatch) []*endpoint {
 	return epl
 }
 
-func (c *Controller) watchSvcRecord(ep *endpoint) {
+func (c *Controller) watchSvcRecord(ep *Endpoint) {
 	c.watchCh <- ep
 }
 
-func (c *Controller) unWatchSvcRecord(ep *endpoint) {
+func (c *Controller) unWatchSvcRecord(ep *Endpoint) {
 	c.unWatchCh <- ep
 }
 
-func (c *Controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan datastore.KVObject) {
+func (c *Controller) networkWatchLoop(nw *netWatch, ep *Endpoint, ecCh <-chan datastore.KVObject) {
 	for {
 		select {
 		case <-nw.stopCh:
@@ -277,9 +277,9 @@ func (c *Controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan da
 			}
 
 			c.mu.Lock()
-			var addEp []*endpoint
+			var addEp []*Endpoint
 
-			delEpMap := make(map[string]*endpoint)
+			delEpMap := make(map[string]*Endpoint)
 			renameEpMap := make(map[string]bool)
 			for k, v := range nw.remoteEps {
 				delEpMap[k] = v
@@ -327,7 +327,7 @@ func (c *Controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan da
 	}
 }
 
-func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoint) {
+func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *Endpoint) {
 	n := ep.getNetwork()
 	if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() {
 		return
@@ -356,8 +356,8 @@ func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoi
 	}
 
 	nw = &netWatch{
-		localEps:  make(map[string]*endpoint),
-		remoteEps: make(map[string]*endpoint),
+		localEps:  make(map[string]*Endpoint),
+		remoteEps: make(map[string]*Endpoint),
 	}
 
 	// Update the svc db for the local endpoint join right away
@@ -389,7 +389,7 @@ func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoi
 	go c.networkWatchLoop(nw, ep, ch)
 }
 
-func (c *Controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoint) {
+func (c *Controller) processEndpointDelete(nmap map[string]*netWatch, ep *Endpoint) {
 	n := ep.getNetwork()
 	if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() {
 		return
@@ -439,8 +439,8 @@ func (c *Controller) startWatch() {
 	if c.watchCh != nil {
 		return
 	}
-	c.watchCh = make(chan *endpoint)
-	c.unWatchCh = make(chan *endpoint)
+	c.watchCh = make(chan *Endpoint)
+	c.unWatchCh = make(chan *Endpoint)
 	c.nmap = make(map[string]*netWatch)
 
 	go c.watchLoop()