فهرست منبع

etcdserver: stop worrying about scheme

Stop worrying about the scheme. This puts a TODO on adding validation to
the schemes if TLS is specified. But we can worry about that later.
Brandon Philips 12 سال پیش
والد
کامیت
04bd48fef3
3فایلهای تغییر یافته به همراه12 افزوده شده و 17 حذف شده
  1. 3 3
      Procfile
  2. 3 3
      etcdserver/cluster.go
  3. 6 11
      etcdserver/cluster_store.go

+ 3 - 3
Procfile

@@ -1,5 +1,5 @@
 # Use goreman to run `go get github.com/mattn/goreman`
-etcd1: bin/etcd -name node1 -bind-addr 127.0.0.1:4001 -peer-bind-addr :7001 -bootstrap-config 'node1=localhost:7001,node2=localhost:7002,node3=localhost:7003'
-etcd2: bin/etcd -name node2 -bind-addr 127.0.0.1:4002 -peer-bind-addr :7002 -bootstrap-config 'node1=localhost:7001,node2=localhost:7002,node3=localhost:7003'
-etcd3: bin/etcd -name node3 -bind-addr 127.0.0.1:4003 -peer-bind-addr :7003 -bootstrap-config 'node1=localhost:7001,node2=localhost:7002,node3=localhost:7003'
+etcd1: bin/etcd -name node1 -listen-client-urls http://127.0.0.1:4001 -advertise-client-urls http://127.0.0.1:4001 -listen-peer-urls http://127.0.0.1:7001 -advertise-peer-urls http://127.0.0.1:7001 -bootstrap-config 'node1=http://localhost:7001,node2=http://localhost:7002,node3=http://localhost:7003'
+etcd2: bin/etcd -name node2 -listen-client-urls http://127.0.0.1:4002 -advertise-client-urls http://127.0.0.1:4002 -listen-peer-urls http://127.0.0.1:7002 -advertise-peer-urls http://127.0.0.1:7002 -bootstrap-config 'node1=http://localhost:7001,node2=http://localhost:7002,node3=http://localhost:7003'
+etcd3: bin/etcd -name node3 -listen-client-urls http://127.0.0.1:4003 -advertise-client-urls http://127.0.0.1:4003 -listen-peer-urls http://127.0.0.1:7003 -advertise-peer-urls http://127.0.0.1:7003 -bootstrap-config 'node1=http://localhost:7001,node2=http://localhost:7002,node3=http://localhost:7003'
 #proxy: bin/etcd -proxy=on -bind-addr 127.0.0.1:8080 -peers 'localhost:7001,localhost:7002,localhost:7003'

+ 3 - 3
etcdserver/cluster.go

@@ -48,11 +48,11 @@ func (c *Cluster) AddSlice(mems []Member) error {
 // an addressible URI. If the given member does not exist, an empty string is returned.
 func (c Cluster) Pick(id int64) string {
 	if m := c.FindID(id); m != nil {
-		addrs := m.PeerURLs
-		if len(addrs) == 0 {
+		urls := m.PeerURLs
+		if len(urls) == 0 {
 			return ""
 		}
-		return addrs[rand.Intn(len(addrs))]
+		return urls[rand.Intn(len(urls))]
 	}
 
 	return ""

+ 6 - 11
etcdserver/cluster_store.go

@@ -78,25 +78,20 @@ func (s *clusterStore) Delete(id int64) {
 func Sender(t *http.Transport, cls ClusterStore) func(msgs []raftpb.Message) {
 	c := &http.Client{Transport: t}
 
-	scheme := "http"
-	if t.TLSClientConfig != nil {
-		scheme = "https"
-	}
-
 	return func(msgs []raftpb.Message) {
 		for _, m := range msgs {
 			// TODO: reuse go routines
 			// limit the number of outgoing connections for the same receiver
-			go send(c, scheme, cls, m)
+			go send(c, cls, m)
 		}
 	}
 }
 
-func send(c *http.Client, scheme string, cls ClusterStore, m raftpb.Message) {
+func send(c *http.Client, cls ClusterStore, m raftpb.Message) {
 	// TODO (xiangli): reasonable retry logic
 	for i := 0; i < 3; i++ {
-		addr := cls.Get().Pick(m.To)
-		if addr == "" {
+		u := cls.Get().Pick(m.To)
+		if u == "" {
 			// TODO: unknown peer id.. what do we do? I
 			// don't think his should ever happen, need to
 			// look into this further.
@@ -104,7 +99,7 @@ func send(c *http.Client, scheme string, cls ClusterStore, m raftpb.Message) {
 			return
 		}
 
-		url := fmt.Sprintf("%s://%s%s", scheme, addr, raftPrefix)
+		u = fmt.Sprintf("%s%s", u, raftPrefix)
 
 		// TODO: don't block. we should be able to have 1000s
 		// of messages out at a time.
@@ -113,7 +108,7 @@ func send(c *http.Client, scheme string, cls ClusterStore, m raftpb.Message) {
 			log.Println("etcdhttp: dropping message:", err)
 			return // drop bad message
 		}
-		if httpPost(c, url, data) {
+		if httpPost(c, u, data) {
 			return // success
 		}
 		// TODO: backoff