[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/main] Use variables for string matching



commit c3c84fdb48ec27fe8fa5527693d18176df40637f
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date:   Thu Jul 8 12:47:23 2021 -0400

    Use variables for string matching
    
    The legacy code does case matching on these exact strings so it's better
    to ensure they're constant.
---
 broker/http.go         | 4 ++--
 broker/ipc.go          | 5 ++---
 common/messages/ipc.go | 3 +++
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/broker/http.go b/broker/http.go
index 2c45b2b..e30e442 100644
--- a/broker/http.go
+++ b/broker/http.go
@@ -177,10 +177,10 @@ func clientOffers(i *IPC, w http.ResponseWriter, r *http.Request) {
 		switch resp.Error {
 		case "":
 			response = []byte(resp.Answer)
-		case "no snowflake proxies currently available":
+		case messages.StrNoProxies:
 			w.WriteHeader(http.StatusServiceUnavailable)
 			return
-		case "timed out waiting for answer!":
+		case messages.StrTimedOut:
 			w.WriteHeader(http.StatusGatewayTimeout)
 			return
 		default:
diff --git a/broker/ipc.go b/broker/ipc.go
index a05f560..7ab27af 100644
--- a/broker/ipc.go
+++ b/broker/ipc.go
@@ -190,7 +190,7 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
 		i.ctx.metrics.lock.Unlock()
 		switch version {
 		case v1:
-			resp := &messages.ClientPollResponse{Error: "no snowflake proxies currently available"}
+			resp := &messages.ClientPollResponse{Error: messages.StrNoProxies}
 			return sendClientResponse(resp, response)
 		default:
 			panic("unknown version")
@@ -226,8 +226,7 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
 		log.Println("Client: Timed out.")
 		switch version {
 		case v1:
-			resp := &messages.ClientPollResponse{
-				Error: "timed out waiting for answer!"}
+			resp := &messages.ClientPollResponse{Error: messages.StrTimedOut}
 			err = sendClientResponse(resp, response)
 		default:
 			panic("unknown version")
diff --git a/common/messages/ipc.go b/common/messages/ipc.go
index ee29a57..13e096f 100644
--- a/common/messages/ipc.go
+++ b/common/messages/ipc.go
@@ -12,4 +12,7 @@ type Arg struct {
 var (
 	ErrBadRequest = errors.New("bad request")
 	ErrInternal   = errors.New("internal error")
+
+	StrTimedOut  = "timed out waiting for answer!"
+	StrNoProxies = "no snowflake proxies currently available"
 )



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits