etcd: manually construct HTTP client for peer communication

This commit is contained in:
Brian Waldon 2014-09-23 08:43:20 -07:00
parent 5470a6d3d6
commit 0c7351c309
2 changed files with 17 additions and 7 deletions

10
main.go
View File

@ -151,13 +151,9 @@ func startEtcd() {
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{

View File

@ -7,6 +7,8 @@ import (
"fmt"
"io/ioutil"
"net"
"net/http"
"time"
)
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
}
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 {
CertFile string
KeyFile string