+ ec.err = fmt.Errorf("could not get certs (%v)", err)
+ return &ErrEtcdConnFatal{err}
+ }
+ }
+ } elseif ec.PeerAutoTLS {
+ if ec.Plog != nil {
+ ec.Plog.Warningf("ignoring peer auto TLS since certs given")
+ }
+ }
+ if ec.Plog != nil {
+ if !ec.PeerTLSInfo.Empty() {
+ ec.Plog.Infof("peerTLS: %s", ec.PeerTLSInfo)
+ }
+ }
+
+ varplns []net.Listener
+ for_, u:=range ec.Lpurls {
+ if u.Scheme == "http" {
+ if ec.Plog != nil {
+ if !ec.PeerTLSInfo.Empty() {
+ ec.Plog.Warningf("The scheme of peer url %s is HTTP while peer key/cert files are presented. Ignored peer key/cert files.", u.String())
+ }
+ if ec.PeerTLSInfo.ClientCertAuth {
+ ec.Plog.Warningf("The scheme of peer url %s is HTTP while client cert auth (--peer-client-cert-auth) is enabled. Ignored client cert auth for this url.", u.String())
+ }
+ }
+ }
+ var (
+ l net.Listener
+ tlscfg *tls.Config
+ )
+
+ if ec.PeerTLSInfo != nil && !ec.PeerTLSInfo.Empty() {
+ tlscfg, err = ec.PeerTLSInfo.ServerConfig()
+ if err != nil {
+ ec.err = err
+ return err
+ }
+ }
+
+ l, err = rafthttp.NewListener(u, tlscfg)
+ if err != nil {
+ ec.err = err
+ return err
+ }
+
+ urlStr:= u.String()
+ if ec.Plog != nil {
+ ec.Plog.Info("listening for peers on ", urlStr)
+ }
+ ll:= l // make a unique copy for the closure
+ d1:=func() {
+ if err != nil { // XXX
+ ll.Close()
+ if ec.Plog != nil {
+ ec.Plog.Info("stopping listening for peers on ", urlStr)
+ }
+ }
+ }
+ ec.defers = append(ec.defers, d1)
+ plns = append(plns, ll)
+ }
+
+ if ec.ClientAutoTLS && ec.ClientTLSInfo != nil && ec.ClientTLSInfo.Empty() {
+ if ec.ClientTLSInfo != nil && !ec.ClientTLSInfo.Empty() {
+ if ec.Plog != nil {
+ ec.Plog.Warningf("The scheme of client url %s is HTTP while peer key/cert files are presented. Ignored key/cert files.", u.String())
+ }
+ }
+ if ec.ClientTLSInfo != nil && ec.ClientTLSInfo.ClientCertAuth {
+ if ec.Plog != nil {
+ ec.Plog.Warningf("The scheme of client url %s is HTTP while client cert auth (--client-cert-auth) is enabled. Ignored client cert auth for this url.", u.String())
+ }
+ }
+ }
+ if u.Scheme == "https" && ctlscfg == nil {
+ err = fmt.Errorf("TLS key/cert (--cert-file, --key-file) must be provided for client url %s with HTTPs scheme", u.String())
+ ec.err = err
+ return err
+ }
+
+ ctx:= &serveCtx{host: u.Host}
+
+ if u.Scheme == "https" {
+ ctx.secure = true
+ } else {
+ ctx.insecure = true
+ }
+
+ if sctxs[u.Host] != nil {
+ if ctx.secure {
+ sctxs[u.Host].secure = true
+ }
+ if ctx.insecure {
+ sctxs[u.Host].insecure = true
+ }
+ continue
+ }
+
+ varl net.Listener
+
+ l, err = net.Listen("tcp", u.Host)
+ if err != nil {
+ ec.err = err
+ return err
+ }
+
+ varfdLimituint64
+ if fdLimit, err = runtimeutil.FDLimit(); err == nil {
+ if fdLimit <= reservedInternalFDNum {
+ if ec.Plog != nil {
+ ec.Plog.Fatalf("file descriptor limit[%d] of etcd process is too low, and should be set higher than %d to ensure internal usage", fdLimit, reservedInternalFDNum)
+ } else {
+ err = fmt.Errorf("file descriptor limit[%d] of etcd process is too low, and should be set higher than %d to ensure internal usage", fdLimit, reservedInternalFDNum)
+ ec.err = err
+ return &ErrEtcdConnFatal{err}
+ }
+ }
+ l = etcdtransport.LimitListener(l, int(fdLimit-reservedInternalFDNum))