Browse Source

rename connection construction functions for clarity

Alan Shreve 12 years ago
parent
commit
7a1c96a2e0
5 changed files with 18 additions and 18 deletions
  1. 1 1
      client/main.go
  2. 14 14
      conn/conn.go
  3. 1 1
      server/control.go
  4. 1 1
      server/main.go
  5. 1 1
      server/tunnel.go

+ 1 - 1
client/main.go

@@ -31,7 +31,7 @@ func connect(addr string, typ string) (c conn.Conn, err error) {
 		return
 	}
 
-	c = conn.NewLogged(tcpConn, typ)
+	c = conn.NewTCP(tcpConn, typ)
 	c.Debug("Connected to: %v", tcpAddr)
 	return c, nil
 }

+ 14 - 14
conn/conn.go

@@ -17,26 +17,26 @@ type Conn interface {
 	Id() string
 }
 
-type loggedConn struct {
+type tcpConn struct {
 	net.Conn
 	ngrok.Logger
 	id  int32
 	typ string
 }
 
-func NewLogged(conn net.Conn, typ string) *loggedConn {
-	c := &loggedConn{conn, ngrok.NewPrefixLogger(), rand.Int31(), typ}
+func NewTCP(conn net.Conn, typ string) *tcpConn {
+	c := &tcpConn{conn, ngrok.NewPrefixLogger(), rand.Int31(), typ}
 	c.AddLogPrefix(c.Id())
 	c.Info("New connection from %v", conn.RemoteAddr())
 	return c
 }
 
-func (c *loggedConn) Close() error {
+func (c *tcpConn) Close() error {
 	c.Debug("Closing")
 	return c.Conn.Close()
 }
 
-func (c *loggedConn) Id() string {
+func (c *tcpConn) Id() string {
 	return fmt.Sprintf("%s:%x", c.typ, c.id)
 }
 
@@ -65,28 +65,28 @@ func Join(c Conn, c2 Conn) (int64, int64) {
 	return fromBytes, toBytes
 }
 
-type loggedHttpConn struct {
-	*loggedConn
+type httpConn struct {
+	*tcpConn
 	reqBuf *bytes.Buffer
 }
 
-func NewHttp(conn net.Conn, typ string) *loggedHttpConn {
-	return &loggedHttpConn{
-		NewLogged(conn, typ),
+func NewHttp(conn net.Conn, typ string) *httpConn {
+	return &httpConn{
+		NewTCP(conn, typ),
 		bytes.NewBuffer(make([]byte, 0, 1024)),
 	}
 }
 
-func (c *loggedHttpConn) ReadRequest() (*http.Request, error) {
-	r := io.TeeReader(c.loggedConn, c.reqBuf)
+func (c *httpConn) ReadRequest() (*http.Request, error) {
+	r := io.TeeReader(c.tcpConn, c.reqBuf)
 	return http.ReadRequest(bufio.NewReader(r))
 }
 
-func (c *loggedConn) ReadFrom(r io.Reader) (n int64, err error) {
+func (c *tcpConn) ReadFrom(r io.Reader) (n int64, err error) {
 	// special case when we're reading from an http request where
 	// we had to parse the request and consume bytes from the socket
 	// and store them in a temporary request buffer
-	if httpConn, ok := r.(*loggedHttpConn); ok {
+	if httpConn, ok := r.(*httpConn); ok {
 		if n, err = httpConn.reqBuf.WriteTo(c); err != nil {
 			return
 		}

+ 1 - 1
server/control.go

@@ -33,7 +33,7 @@ type Control struct {
 
 func NewControl(tcpConn *net.TCPConn) {
 	c := &Control{
-		conn:     conn.NewLogged(tcpConn, "ctl"),
+		conn:     conn.NewTCP(tcpConn, "ctl"),
 		out:      make(chan (interface{}), 1),
 		in:       make(chan (proto.Message), 1),
 		stop:     make(chan (int), 1),

+ 1 - 1
server/main.go

@@ -89,7 +89,7 @@ func proxyListener(addr *net.TCPAddr, domain string) {
 			panic(err)
 		}
 
-		conn := conn.NewLogged(tcpConn, "pxy")
+		conn := conn.NewTCP(tcpConn, "pxy")
 
 		go func() {
 			defer func() {

+ 1 - 1
server/tunnel.go

@@ -89,7 +89,7 @@ func (t *Tunnel) listenTcp(listener *net.TCPListener) {
 			panic(err)
 		}
 
-		conn := conn.NewLogged(tcpConn, "pub")
+		conn := conn.NewTCP(tcpConn, "pub")
 		conn.AddLogPrefix(t.Id())
 
 		go func() {