ソースを参照

etcd: manually construct HTTP client for peer communication

Brian Waldon 11 年 前
コミット
0c7351c309
2 ファイル変更17 行追加7 行削除
  1. 3 7
      main.go
  2. 14 0
      transport/listener.go

+ 3 - 7
main.go

@@ -151,13 +151,9 @@ func startEtcd() {
 		n = raft.RestartNode(id, peers.IDs(), 10, 1, snapshot, st, ents)
 		n = raft.RestartNode(id, peers.IDs(), 10, 1, snapshot, st, ents)
 	}
 	}
 
 
-	pt := &http.Transport{
-		// timeouts copied from http.DefaultTransport
-		Dial: (&net.Dialer{
-			Timeout:   30 * time.Second,
-			KeepAlive: 30 * time.Second,
-		}).Dial,
-		TLSHandshakeTimeout: 10 * time.Second,
+	pt, err := transport.NewTransport()
+	if err != nil {
+		log.Fatal(err)
 	}
 	}
 
 
 	s := &etcdserver.EtcdServer{
 	s := &etcdserver.EtcdServer{

+ 14 - 0
transport/listener.go

@@ -7,6 +7,8 @@ import (
 	"fmt"
 	"fmt"
 	"io/ioutil"
 	"io/ioutil"
 	"net"
 	"net"
+	"net/http"
+	"time"
 )
 )
 
 
 func NewListener(addr string, info TLSInfo) (net.Listener, error) {
 func NewListener(addr string, info TLSInfo) (net.Listener, error) {
@@ -27,6 +29,18 @@ func NewListener(addr string, info TLSInfo) (net.Listener, error) {
 	return l, nil
 	return l, nil
 }
 }
 
 
+func NewTransport() (*http.Transport, error) {
+	t := &http.Transport{
+		// timeouts taken from http.DefaultTransport
+		Dial: (&net.Dialer{
+			Timeout:   30 * time.Second,
+			KeepAlive: 30 * time.Second,
+		}).Dial,
+		TLSHandshakeTimeout: 10 * time.Second,
+	}
+	return t, nil
+}
+
 type TLSInfo struct {
 type TLSInfo struct {
 	CertFile string
 	CertFile string
 	KeyFile  string
 	KeyFile  string