commit e47dd5e2b44161b6699ca6560878ddc9730a63b1 Author: David Fifield david@bamsoftware.com Date: Tue Jan 28 00:54:26 2020 -0700
Remove some redundancy in websocketconn naming.
Rename websocketconn.WebSocketConn to websocketconn.Conn, and websocketconn.NewWebSocketConn to websocketconn.New
Following the guidelines at https://blog.golang.org/package-names#TOC_3%2e --- common/websocketconn/websocketconn.go | 14 +++++++------- proxy-go/snowflake.go | 2 +- server/server.go | 4 ++-- server/server_test.go | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/common/websocketconn/websocketconn.go b/common/websocketconn/websocketconn.go index 7e12abf..8a9e015 100644 --- a/common/websocketconn/websocketconn.go +++ b/common/websocketconn/websocketconn.go @@ -9,13 +9,13 @@ import (
// An abstraction that makes an underlying WebSocket connection look like an // io.ReadWriteCloser. -type WebSocketConn struct { +type Conn struct { Ws *websocket.Conn r io.Reader }
// Implements io.Reader. -func (conn *WebSocketConn) Read(b []byte) (n int, err error) { +func (conn *Conn) Read(b []byte) (n int, err error) { var opCode int if conn.r == nil { // New message @@ -43,7 +43,7 @@ func (conn *WebSocketConn) Read(b []byte) (n int, err error) { }
// Implements io.Writer. -func (conn *WebSocketConn) Write(b []byte) (n int, err error) { +func (conn *Conn) Write(b []byte) (n int, err error) { var w io.WriteCloser if w, err = conn.Ws.NextWriter(websocket.BinaryMessage); err != nil { return @@ -56,15 +56,15 @@ func (conn *WebSocketConn) Write(b []byte) (n int, err error) { }
// Implements io.Closer. -func (conn *WebSocketConn) Close() error { +func (conn *Conn) Close() error { // Ignore any error in trying to write a Close frame. _ = conn.Ws.WriteControl(websocket.CloseMessage, []byte{}, time.Now().Add(time.Second)) return conn.Ws.Close() }
-// Create a new WebSocketConn. -func NewWebSocketConn(ws *websocket.Conn) WebSocketConn { - var conn WebSocketConn +// Create a new Conn. +func New(ws *websocket.Conn) Conn { + var conn Conn conn.Ws = ws return conn } diff --git a/proxy-go/snowflake.go b/proxy-go/snowflake.go index dce7b70..675d76a 100644 --- a/proxy-go/snowflake.go +++ b/proxy-go/snowflake.go @@ -285,7 +285,7 @@ func datachannelHandler(conn *webRTCConn, remoteAddr net.Addr) { log.Printf("error dialing relay: %s", err) return } - wsConn := websocketconn.NewWebSocketConn(ws) + wsConn := websocketconn.New(ws) log.Printf("connected to relay") defer wsConn.Close() CopyLoop(conn, &wsConn) diff --git a/server/server.go b/server/server.go index acb260a..739a55a 100644 --- a/server/server.go +++ b/server/server.go @@ -52,7 +52,7 @@ additional HTTP listener on port 80 to work with ACME. }
// Copy from WebSocket to socket and vice versa. -func proxy(local *net.TCPConn, conn *websocketconn.WebSocketConn) { +func proxy(local *net.TCPConn, conn *websocketconn.Conn) { var wg sync.WaitGroup wg.Add(2)
@@ -107,7 +107,7 @@ func (handler *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return }
- conn := websocketconn.NewWebSocketConn(ws) + conn := websocketconn.New(ws) defer conn.Close()
// Pass the address of client as the remote address of incoming connection diff --git a/server/server_test.go b/server/server_test.go index 7a72014..bbc9ba9 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -60,7 +60,7 @@ type StubHandler struct{} func (handler *StubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ws, _ := upgrader.Upgrade(w, r, nil)
- conn := websocketconn.NewWebSocketConn(ws) + conn := websocketconn.New(ws) defer conn.Close()
//dial stub OR @@ -90,7 +90,7 @@ func Test(t *testing.T) { So(err, ShouldBeNil)
ws, _, err := websocket.DefaultDialer.Dial("ws://localhost:8888", nil) - wsConn := websocketconn.NewWebSocketConn(ws) + wsConn := websocketconn.New(ws) So(err, ShouldEqual, nil) So(wsConn, ShouldNotEqual, nil)
@@ -133,7 +133,7 @@ func Test(t *testing.T) {
ws, _, err := websocket.DefaultDialer.Dial("ws://localhost:8888", nil) So(err, ShouldEqual, nil) - wsConn := websocketconn.NewWebSocketConn(ws) + wsConn := websocketconn.New(ws) So(wsConn, ShouldNotEqual, nil)
wsConn.Write([]byte("Hello"))
tor-commits@lists.torproject.org