func (c *Config) ClientListener(override string, port int) (net.Addr, error) {
	var addr string
	if override != "" {
		addr = override
	} else {
		addr = c.ClientAddr
	}
	if path, ok := unixSocketAddr(addr); ok {
		return &net.UnixAddr{Name: path, Net: "unix"}, nil
	}
	ip := net.ParseIP(addr)
	if ip == nil {
		return nil, fmt.Errorf("Failed to parse IP: %v", addr)
	}
	return &net.TCPAddr{IP: ip, Port: port}, nil
}
ClientListener is used to format a listener for a
port on a ClientAddr
package agent
import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io"
	"net"
	"os"
	"path/filepath"
	"sort"
	"strings"
	"time"
	"github.com/socketplane/socketplane/Godeps/_workspace/src/github.com/hashicorp/consul/consul"
	"github.com/socketplane/socketplane/Godeps/_workspace/src/github.com/hashicorp/consul/watch"
	"github.com/socketplane/socketplane/Godeps/_workspace/src/github.com/mitchellh/mapstructure"
)
type PortConfig struct {
	DNS     int  
	HTTP    int  
	HTTPS   int  
	RPC     int  
	SerfLan int `mapstructure:"serf_lan"`  
	SerfWan int `mapstructure:"serf_wan"`  
	Server  int  
}
type AddressConfig struct {
	DNS   string  
	HTTP  string  
	HTTPS string  
	RPC   string  
}
type DNSConfig struct {
	NodeTTL    time.Duration `mapstructure:"-"`
	NodeTTLRaw string        `mapstructure:"node_ttl" json:"-"`
	ServiceTTL    map[string]time.Duration `mapstructure:"-"`
	ServiceTTLRaw map[string]string        `mapstructure:"service_ttl" json:"-"`
	AllowStale bool `mapstructure:"allow_stale"`
	EnableTruncate bool `mapstructure:"enable_truncate"`
	MaxStale    time.Duration `mapstructure:"-"`
	MaxStaleRaw string        `mapstructure:"max_stale" json:"-"`
	OnlyPassing bool `mapstructure:"only_passing"`
}
type Config struct {
	Bootstrap bool `mapstructure:"bootstrap"`
	BootstrapExpect int `mapstructure:"bootstrap_expect"`
	Server bool `mapstructure:"server"`
	Datacenter string `mapstructure:"datacenter"`
	DataDir string `mapstructure:"data_dir"`
	DNSRecursor string `mapstructure:"recursor"`
	DNSRecursors []string `mapstructure:"recursors"`
	DNSConfig DNSConfig `mapstructure:"dns_config"`
	Domain string `mapstructure:"domain"`
	EncryptKey string `mapstructure:"encrypt" json:"-"`
	LogLevel string `mapstructure:"log_level"`
	NodeName string `mapstructure:"node_name"`
	ClientAddr string `mapstructure:"client_addr"`
	BindAddr string `mapstructure:"bind_addr"`
	AdvertiseAddr string `mapstructure:"advertise_addr"`
	Ports PortConfig
	Addresses AddressConfig
	LeaveOnTerm bool `mapstructure:"leave_on_terminate"`
	SkipLeaveOnInt bool `mapstructure:"skip_leave_on_interrupt"`
	StatsiteAddr string `mapstructure:"statsite_addr"`
	StatsdAddr string `mapstructure:"statsd_addr"`
	Protocol int `mapstructure:"protocol"`
	EnableDebug bool `mapstructure:"enable_debug"`
	VerifyIncoming bool `mapstructure:"verify_incoming"`
	VerifyOutgoing bool `mapstructure:"verify_outgoing"`
	CAFile string `mapstructure:"ca_file"`
	CertFile string `mapstructure:"cert_file"`
	KeyFile string `mapstructure:"key_file"`
	ServerName string `mapstructure:"server_name"`
	StartJoin []string `mapstructure:"start_join"`
	StartJoinWan []string `mapstructure:"start_join_wan"`
	RetryJoin []string `mapstructure:"retry_join"`
	RetryMaxAttempts int `mapstructure:"retry_max"`
	RetryInterval    time.Duration `mapstructure:"-" json:"-"`
	RetryIntervalRaw string        `mapstructure:"retry_interval"`
	RetryJoinWan []string `mapstructure:"retry_join_wan"`
	RetryMaxAttemptsWan int `mapstructure:"retry_max_wan"`
	RetryIntervalWan    time.Duration `mapstructure:"-" json:"-"`
	RetryIntervalWanRaw string        `mapstructure:"retry_interval_wan"`
	UiDir string `mapstructure:"ui_dir"`
	PidFile string `mapstructure:"pid_file"`
	EnableSyslog bool `mapstructure:"enable_syslog"`
	SyslogFacility string `mapstructure:"syslog_facility"`
	RejoinAfterLeave bool `mapstructure:"rejoin_after_leave"`
	CheckUpdateInterval    time.Duration `mapstructure:"-"`
	CheckUpdateIntervalRaw string        `mapstructure:"check_update_interval" json:"-"`
	ACLToken string `mapstructure:"acl_token" json:"-"`
	ACLMasterToken string `mapstructure:"acl_master_token" json:"-"`
	ACLDatacenter string `mapstructure:"acl_datacenter"`
	ACLTTL    time.Duration `mapstructure:"-"`
	ACLTTLRaw string        `mapstructure:"acl_ttl"`
	ACLDefaultPolicy string `mapstructure:"acl_default_policy"`
	ACLDownPolicy string `mapstructure:"acl_down_policy"`
	Watches []map[string]interface{} `mapstructure:"watches"`
	DisableRemoteExec bool `mapstructure:"disable_remote_exec"`
	DisableUpdateCheck bool `mapstructure:"disable_update_check"`
	DisableAnonymousSignature bool `mapstructure:"disable_anonymous_signature"`
	HTTPAPIResponseHeaders map[string]string `mapstructure:"http_api_response_headers"`
	AEInterval time.Duration `mapstructure:"-" json:"-"`
	Checks []*CheckDefinition `mapstructure:"-" json:"-"`
	Services []*ServiceDefinition `mapstructure:"-" json:"-"`
	ConsulConfig *consul.Config `mapstructure:"-" json:"-"`
	Revision string `mapstructure:"-"`
	Version string `mapstructure:"-"`
	VersionPrerelease string `mapstructure:"-"`
	WatchPlans []*watch.WatchPlan `mapstructure:"-" json:"-"`
}
func unixSocketAddr(addr string) (string, bool) {
	if !strings.HasPrefix(addr, "unix://") {
		return "", false
	}
	return strings.TrimPrefix(addr, "unix://"), true
}
type dirEnts []os.FileInfo
func DefaultConfig() *Config {
	return &Config{
		Bootstrap:       false,
		BootstrapExpect: 0,
		Server:          false,
		Datacenter:      consul.DefaultDC,
		Domain:          "consul.",
		LogLevel:        "INFO",
		ClientAddr:      "127.0.0.1",
		BindAddr:        "0.0.0.0",
		Ports: PortConfig{
			DNS:     8600,
			HTTP:    8500,
			HTTPS:   -1,
			RPC:     8400,
			SerfLan: consul.DefaultLANSerfPort,
			SerfWan: consul.DefaultWANSerfPort,
			Server:  8300,
		},
		DNSConfig: DNSConfig{
			MaxStale: 5 * time.Second,
		},
		SyslogFacility:      "LOCAL0",
		Protocol:            consul.ProtocolVersionMax,
		CheckUpdateInterval: 5 * time.Minute,
		AEInterval:          time.Minute,
		ACLTTL:              30 * time.Second,
		ACLDownPolicy:       "extend-cache",
		ACLDefaultPolicy:    "allow",
		RetryInterval:       30 * time.Second,
		RetryIntervalWan:    30 * time.Second,
	}
}
func (c *Config) EncryptBytes() ([]byte, error) {
	return base64.StdEncoding.DecodeString(c.EncryptKey)
}