Skip to content

Commit

Permalink
smart logging
Browse files Browse the repository at this point in the history
  • Loading branch information
linyows committed Feb 6, 2021
1 parent 35cdd93 commit 86fe30b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (p *Pipe) copy(dr Direction, fn Mediator) (written int64, err error) {
continue
}
if dr == upstream {
log.Printf("-> %s", buf[0:nr])
log.Printf("-> %s", p.escapeCRLF(buf[0:nr]))
} else {
if bytes.Contains(buf, []byte(readyToStartTLS)) {
continue
Expand Down Expand Up @@ -195,11 +195,10 @@ func (p *Pipe) readReceiverConn() error {
}

func (p *Pipe) waitForTLSConn(b []byte, i int) {
log.Print("wait for tls connection")
log.Print("pipe locked for tls connection")
<-p.blocker
log.Print("tls connected")
log.Print("tls connected, to pipe unlocked")
p.locked = false
log.Printf("|> %s", b[0:i])
}

func (p *Pipe) connectTLS() error {
Expand Down Expand Up @@ -232,6 +231,6 @@ func (p *Pipe) close() func() {
return func() {
defer p.rConn.Close()
defer p.sConn.Close()
defer log.Print("connection closed")
defer log.Print("connections closed")
}
}
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ func (s *Server) Start() error {
}

func (s *Server) HandleConnection(conn net.Conn) {
log.Print("new connection")
log.Printf("connected from %s", conn.RemoteAddr())

raddr, err := s.OriginalAddrDst(conn)
if err != nil {
log.Printf("original addr error: %#v", err)
return
}
log.Printf("remote addr: %s origin addr: %s", conn.RemoteAddr(), raddr)

laddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:0", s.Addr))
if err != nil {
Expand All @@ -58,6 +57,7 @@ func (s *Server) HandleConnection(conn net.Conn) {
log.Printf("dial '%s' error: %#v", raddr, err)
return
}
log.Printf("connected to %s", raddr)

p := &Pipe{sConn: conn, rConn: dstConn}
p.Do()
Expand Down

0 comments on commit 86fe30b

Please sign in to comment.