diff options
author | meskio <meskio@torproject.org> | 2024-02-19 09:55:49 +0100 |
---|---|---|
committer | meskio <meskio@torproject.org> | 2024-02-19 09:55:49 +0100 |
commit | bbd8b3af7555c1b5925fba91e7a830e449d6e868 (patch) | |
tree | 1d1e021ee305241b0447ea8a49c9e70b743ab852 | |
parent | 35984c0876273adb810ab3cc558464ba786aafcd (diff) | |
parent | acce1f1fd90222008dae644fe4b4c07a8225057e (diff) | |
download | snowflake-bbd8b3af7555c1b5925fba91e7a830e449d6e868.tar.gz snowflake-bbd8b3af7555c1b5925fba91e7a830e449d6e868.zip |
Merge remote-tracking branch 'gitlab/mr/253'
-rw-r--r-- | broker/http.go | 7 | ||||
-rw-r--r-- | broker/snowflake-broker_test.go | 7 | ||||
-rw-r--r-- | client/lib/rendezvous_ampcache.go | 3 | ||||
-rw-r--r-- | client/lib/rendezvous_http.go | 3 | ||||
-rw-r--r-- | client/lib/rendezvous_test.go | 3 | ||||
-rw-r--r-- | client/snowflake.go | 7 | ||||
-rw-r--r-- | common/amp/armor_test.go | 3 | ||||
-rw-r--r-- | common/encapsulation/encapsulation.go | 5 | ||||
-rw-r--r-- | common/websocketconn/websocketconn_test.go | 9 | ||||
-rw-r--r-- | probetest/probetest.go | 3 | ||||
-rw-r--r-- | proxy/lib/proxy-go_test.go | 3 | ||||
-rw-r--r-- | proxy/lib/snowflake.go | 3 | ||||
-rw-r--r-- | proxy/main.go | 3 | ||||
-rw-r--r-- | server/server.go | 5 |
14 files changed, 25 insertions, 39 deletions
diff --git a/broker/http.go b/broker/http.go index 2b68747..d1ba20d 100644 --- a/broker/http.go +++ b/broker/http.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -94,7 +93,7 @@ func debugHandler(i *IPC, w http.ResponseWriter, r *http.Request) { For snowflake proxies to request a client from the Broker. */ func proxyPolls(i *IPC, w http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit)) + body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, readLimit)) if err != nil { log.Println("Invalid data.", err.Error()) w.WriteHeader(http.StatusBadRequest) @@ -132,7 +131,7 @@ snowflake proxy, which responds with the SDP answer to be sent in the HTTP response back to the client. */ func clientOffers(i *IPC, w http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit)) + body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, readLimit)) if err != nil { log.Printf("Error reading client request: %s", err.Error()) w.WriteHeader(http.StatusBadRequest) @@ -212,7 +211,7 @@ an offer from proxyHandler to respond with an answer in an HTTP POST, which the broker will pass back to the original client. */ func proxyAnswers(i *IPC, w http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit)) + body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, readLimit)) if err != nil { log.Println("Invalid data.", err.Error()) w.WriteHeader(http.StatusBadRequest) diff --git a/broker/snowflake-broker_test.go b/broker/snowflake-broker_test.go index 8179bb0..92d5700 100644 --- a/broker/snowflake-broker_test.go +++ b/broker/snowflake-broker_test.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "log" "net/http" "net/http/httptest" @@ -22,7 +21,7 @@ import ( func NullLogger() *log.Logger { logger := log.New(os.Stdout, "", 0) - logger.SetOutput(ioutil.Discard) + logger.SetOutput(io.Discard) return logger } @@ -78,7 +77,7 @@ func decodeAMPArmorToString(r io.Reader) (string, error) { if err != nil { return "", err } - p, err := ioutil.ReadAll(dec) + p, err := io.ReadAll(dec) return string(p), err } @@ -460,7 +459,7 @@ client-sqs-count 0 So(err, ShouldBeNil) proxyAnswers(i, w, r) So(w.Code, ShouldEqual, http.StatusOK) - b, err := ioutil.ReadAll(w.Body) + b, err := io.ReadAll(w.Body) So(err, ShouldBeNil) So(b, ShouldResemble, []byte(`{"Status":"client gone"}`)) }) diff --git a/client/lib/rendezvous_ampcache.go b/client/lib/rendezvous_ampcache.go index b6fa2c7..f6e1d0c 100644 --- a/client/lib/rendezvous_ampcache.go +++ b/client/lib/rendezvous_ampcache.go @@ -3,7 +3,6 @@ package snowflake_client import ( "errors" "io" - "io/ioutil" "log" "math/rand" "net/http" @@ -115,7 +114,7 @@ func (r *ampCacheRendezvous) Exchange(encPollReq []byte) ([]byte, error) { if err != nil { return nil, err } - encPollResp, err := ioutil.ReadAll(dec) + encPollResp, err := io.ReadAll(dec) if err != nil { return nil, err } diff --git a/client/lib/rendezvous_http.go b/client/lib/rendezvous_http.go index 26733bb..2f7dd9e 100644 --- a/client/lib/rendezvous_http.go +++ b/client/lib/rendezvous_http.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "io" - "io/ioutil" "log" "math/rand" "net/http" @@ -71,7 +70,7 @@ func (r *httpRendezvous) Exchange(encPollReq []byte) ([]byte, error) { } func limitedRead(r io.Reader, limit int64) ([]byte, error) { - p, err := ioutil.ReadAll(&io.LimitedReader{R: r, N: limit + 1}) + p, err := io.ReadAll(&io.LimitedReader{R: r, N: limit + 1}) if err != nil { return p, err } else if int64(len(p)) == limit+1 { diff --git a/client/lib/rendezvous_test.go b/client/lib/rendezvous_test.go index 5ff8ae9..d74aa0e 100644 --- a/client/lib/rendezvous_test.go +++ b/client/lib/rendezvous_test.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" "testing" @@ -32,7 +31,7 @@ func (t *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) { return &http.Response{ Status: fmt.Sprintf("%d %s", t.statusCode, http.StatusText(t.statusCode)), StatusCode: t.statusCode, - Body: ioutil.NopCloser(bytes.NewReader(t.body)), + Body: io.NopCloser(bytes.NewReader(t.body)), }, nil } diff --git a/client/snowflake.go b/client/snowflake.go index c678964..7ff0a35 100644 --- a/client/snowflake.go +++ b/client/snowflake.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "net" "os" @@ -198,7 +197,7 @@ func main() { // buffer is full. // https://bugs.torproject.org/26360 // https://bugs.torproject.org/25600#comment:14 - var logOutput = ioutil.Discard + var logOutput = io.Discard if *logFilename != "" { if *logToStateDir || *oldLogToStateDir { stateDir, err := pt.MakeStateDir() @@ -298,8 +297,8 @@ func main() { // This environment variable means we should treat EOF on stdin // just like SIGTERM: https://bugs.torproject.org/15435. go func() { - if _, err := io.Copy(ioutil.Discard, os.Stdin); err != nil { - log.Printf("calling io.Copy(ioutil.Discard, os.Stdin) returned error: %v", err) + if _, err := io.Copy(io.Discard, os.Stdin); err != nil { + log.Printf("calling io.Copy(io.Discard, os.Stdin) returned error: %v", err) } log.Printf("synthesizing SIGTERM because of stdin close") sigChan <- syscall.SIGTERM diff --git a/common/amp/armor_test.go b/common/amp/armor_test.go index fc7561e..c65c5f1 100644 --- a/common/amp/armor_test.go +++ b/common/amp/armor_test.go @@ -2,7 +2,6 @@ package amp import ( "io" - "io/ioutil" "math/rand" "strings" "testing" @@ -13,7 +12,7 @@ func armorDecodeToString(src string) (string, error) { if err != nil { return "", err } - p, err := ioutil.ReadAll(dec) + p, err := io.ReadAll(dec) return string(p), err } diff --git a/common/encapsulation/encapsulation.go b/common/encapsulation/encapsulation.go index a8ed539..058f2fd 100644 --- a/common/encapsulation/encapsulation.go +++ b/common/encapsulation/encapsulation.go @@ -43,7 +43,6 @@ package encapsulation import ( "errors" "io" - "io/ioutil" ) // ErrTooLong is the error returned when an encoded length prefix is longer than @@ -93,7 +92,7 @@ func ReadData(r io.Reader, p []byte) (int, error) { // If the caller's buffer was too short, discard // the rest of the data and return // io.ErrShortBuffer. - _, err = io.CopyN(ioutil.Discard, r, int64(n-numData)) + _, err = io.CopyN(io.Discard, r, int64(n-numData)) if err == nil { err = io.ErrShortBuffer } @@ -103,7 +102,7 @@ func ReadData(r io.Reader, p []byte) (int, error) { } return numData, err } else if n > 0 { - _, err := io.CopyN(ioutil.Discard, r, int64(n)) + _, err := io.CopyN(io.Discard, r, int64(n)) if err == io.EOF { err = io.ErrUnexpectedEOF } diff --git a/common/websocketconn/websocketconn_test.go b/common/websocketconn/websocketconn_test.go index 672d83d..e3191f3 100644 --- a/common/websocketconn/websocketconn_test.go +++ b/common/websocketconn/websocketconn_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net" "net/http" "net/url" @@ -87,7 +86,7 @@ func TestWrite(t *testing.T) { // goroutine, reading from the Conn s and writing to the dataCh // and errCh channels, whose ultimate effect in the select loop // below is like - // data, err := ioutil.ReadAll(s) + // data, err := io.ReadAll(s) dataCh := make(chan []byte) errCh := make(chan error) go func() { @@ -162,7 +161,7 @@ func TestConcurrentRead(t *testing.T) { for i := 0; i < 2; i++ { go func() { defer wg.Done() - _, err := io.Copy(ioutil.Discard, s) + _, err := io.Copy(io.Discard, s) if err != nil { errCh <- err } @@ -224,7 +223,7 @@ func TestConcurrentWrite(t *testing.T) { }() // Read from the other end. - _, err = io.Copy(ioutil.Discard, c) + _, err = io.Copy(io.Discard, c) c.Close() if err != nil { t.Fatalf("Read: %v", err) @@ -336,7 +335,7 @@ func BenchmarkUpgradeBufferSize(b *testing.B) { func BenchmarkReadWrite(b *testing.B) { trial := func(b *testing.B, readConn, writeConn *Conn, msgSize int) { go func() { - io.Copy(ioutil.Discard, readConn) + io.Copy(io.Discard, readConn) }() data := make([]byte, msgSize) b.ResetTimer() diff --git a/probetest/probetest.go b/probetest/probetest.go index c5cb194..55152c9 100644 --- a/probetest/probetest.go +++ b/probetest/probetest.go @@ -13,7 +13,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -110,7 +109,7 @@ func makePeerConnectionFromOffer(stunURL string, sdp *webrtc.SessionDescription, func probeHandler(stunURL string, w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") - resp, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, readLimit)) + resp, err := io.ReadAll(http.MaxBytesReader(w, r.Body, readLimit)) if nil != err { log.Println("Invalid data.") w.WriteHeader(http.StatusBadRequest) diff --git a/proxy/lib/proxy-go_test.go b/proxy/lib/proxy-go_test.go index 547492b..50be0da 100644 --- a/proxy/lib/proxy-go_test.go +++ b/proxy/lib/proxy-go_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net" "net/http" "strconv" @@ -25,7 +24,7 @@ type MockTransport struct { // Just returns a response with fake SDP answer. func (m *MockTransport) RoundTrip(req *http.Request) (*http.Response, error) { - s := ioutil.NopCloser(bytes.NewReader(m.body)) + s := io.NopCloser(bytes.NewReader(m.body)) r := &http.Response{ StatusCode: m.statusOverride, Body: s, diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go index ca38a3d..39c4c2f 100644 --- a/proxy/lib/snowflake.go +++ b/proxy/lib/snowflake.go @@ -31,7 +31,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -163,7 +162,7 @@ func genSessionID() string { } func limitedRead(r io.Reader, limit int64) ([]byte, error) { - p, err := ioutil.ReadAll(&io.LimitedReader{R: r, N: limit + 1}) + p, err := io.ReadAll(&io.LimitedReader{R: r, N: limit + 1}) if err != nil { return p, err } else if int64(len(p)) == limit+1 { diff --git a/proxy/main.go b/proxy/main.go index 5fc8db8..a385aee 100644 --- a/proxy/main.go +++ b/proxy/main.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "net" "os" @@ -102,7 +101,7 @@ func main() { SummaryInterval: *summaryInterval, } - var logOutput = ioutil.Discard + var logOutput = io.Discard var eventlogOutput io.Writer = os.Stderr log.SetFlags(log.LstdFlags | log.LUTC) diff --git a/server/server.go b/server/server.go index eba933e..ae4120a 100644 --- a/server/server.go +++ b/server/server.go @@ -7,7 +7,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -320,8 +319,8 @@ func main() { // This environment variable means we should treat EOF on stdin // just like SIGTERM: https://bugs.torproject.org/15435. go func() { - if _, err := io.Copy(ioutil.Discard, os.Stdin); err != nil { - log.Printf("error copying os.Stdin to ioutil.Discard: %v", err) + if _, err := io.Copy(io.Discard, os.Stdin); err != nil { + log.Printf("error copying os.Stdin to io.Discard: %v", err) } log.Printf("synthesizing SIGTERM because of stdin close") sigChan <- syscall.SIGTERM |