Merge remote-tracking branch 'gitlab/mr/253'

This commit is contained in:
meskio 2024-02-19 09:55:49 +01:00
commit bbd8b3af75
No known key found for this signature in database
GPG key ID: 52B8F5AC97A2DA86
14 changed files with 25 additions and 39 deletions

View file

@ -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)

View file

@ -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"}`))
})

View file

@ -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
}

View file

@ -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 {

View file

@ -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
}

View file

@ -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

View file

@ -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
}

View file

@ -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
}

View file

@ -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()

View file

@ -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)

View file

@ -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,

View file

@ -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 {

View file

@ -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)

View file

@ -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