Skip to content

Commit

Permalink
chore: refine some errors print
Browse files Browse the repository at this point in the history
  • Loading branch information
nange committed Nov 11, 2024
1 parent 358365f commit 144d17e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
13 changes: 10 additions & 3 deletions cipherstream/cipherstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/nange/easyss/v2/log"
"github.com/nange/easyss/v2/util"
"github.com/nange/easyss/v2/util/bytespool"
"github.com/nange/easyss/v2/util/netpipe"
)

const (
Expand Down Expand Up @@ -82,7 +83,9 @@ func (cs *CipherStream) WriteFrame(f *Frame) error {
}

if _, ew := cs.Conn.Write(frameBytes); ew != nil {
log.Warn("[CIPHERSTREAM] write cipher data to cipher stream failed", "err", ew)
if !errors.Is(ew, netpipe.ErrPipeClosed) {
log.Warn("[CIPHERSTREAM] write cipher data to cipher stream failed", "err", ew)
}
if timeout(ew) {
return ErrTimeout
}
Expand Down Expand Up @@ -135,7 +138,9 @@ func (cs *CipherStream) ReadFrom(r io.Reader) (n int64, err error) {
}

if _, ew := cs.Conn.Write(frameBytes); ew != nil {
log.Warn("[CIPHERSTREAM] write cipher data to cipher stream failed", "err", ew)
if !errors.Is(ew, netpipe.ErrPipeClosed) {
log.Warn("[CIPHERSTREAM] write cipher data to cipher stream failed", "err", ew)
}
if timeout(ew) {
return ErrTimeout
}
Expand All @@ -159,7 +164,9 @@ func (cs *CipherStream) ReadFrom(r io.Reader) (n int64, err error) {
}

if er := cs.RandomWritePing(); er != nil {
log.Error("[CIPHERSTREAM] random write ping failed", "err", er)
if !errors.Is(er, netpipe.ErrPipeClosed) {
log.Error("[CIPHERSTREAM] random write ping failed", "err", er)
}
err = errors.Join(err, er)
break
}
Expand Down
7 changes: 5 additions & 2 deletions httptunnel/local_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func (l *LocalConn) Pull() {
}
resp.Payload = ""
if _, err := l.conn2.Write(data); err != nil {
log.Error("[HTTP_TUNNEL_LOCAL] write text", "err", err, "uuid", l.uuid)
if !errors.Is(err, netpipe.ErrPipeClosed) {
log.Error("[HTTP_TUNNEL_LOCAL] write text", "err", err, "uuid", l.uuid)
}
break
}
}
Expand All @@ -109,7 +111,8 @@ func (l *LocalConn) Pull() {

func (l *LocalConn) Push() {
if err := l.push(); err != nil {
if !errors.Is(err, io.EOF) && !errors.Is(err, netpipe.ErrPipeClosed) {
if !errors.Is(err, io.EOF) && !errors.Is(err, netpipe.ErrPipeClosed) &&
!strings.Contains(err.Error(), "pipe closed") {
log.Error("[HTTP_TUNNEL_LOCAL] push", "err", err, "uuid", l.uuid)
}
}
Expand Down
4 changes: 3 additions & 1 deletion httptunnel/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ func (s *Server) push(w http.ResponseWriter, r *http.Request) {
}

if _, err = conns.conns[0].Write(cipher); err != nil {
log.Warn("[HTTP_TUNNEL_SERVER] write local", "err", err)
if !errors.Is(err, netpipe.ErrPipeClosed) {
log.Warn("[HTTP_TUNNEL_SERVER] write local", "err", err)
}
writeServiceUnavailableError(w, "write local:"+err.Error())
return
}
Expand Down
4 changes: 3 additions & 1 deletion local_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package easyss

import (
"encoding/base64"
"errors"
"net/http"
"net/http/httputil"
"net/url"
Expand All @@ -10,6 +11,7 @@ import (

"github.com/nange/easyss/v2/log"
"github.com/nange/easyss/v2/util/bytespool"
"github.com/nange/easyss/v2/util/netpipe"
"github.com/wzshiming/sysproxy"
)

Expand Down Expand Up @@ -115,7 +117,7 @@ func (h *httpProxy) doWithHijack(w http.ResponseWriter, r *http.Request) {
return
}

if err := h.ss.localRelay(hijConn, r.URL.Host); err != nil {
if err := h.ss.localRelay(hijConn, r.URL.Host); err != nil && !errors.Is(err, netpipe.ErrPipeClosed) {
log.Warn("[HTTP_PROXY] local relay", "err", err)
}
}
Expand Down
5 changes: 4 additions & 1 deletion relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/nange/easyss/v2/cipherstream"
"github.com/nange/easyss/v2/log"
"github.com/nange/easyss/v2/util/bytespool"
"github.com/nange/easyss/v2/util/netpipe"
)

// RelayBufferSize set to MaxCipherRelaySize
Expand Down Expand Up @@ -107,7 +108,9 @@ func copyPlainTxtToCipher(cipher, plainTxt net.Conn, timeout time.Duration, tryR
if er := CloseWrite(cipher); er != nil {
tryReuse = false
err = errors.Join(err, er)
log.Warn("[REPAY] close write for cipher stream", "err", err)
if !errors.Is(er, netpipe.ErrPipeClosed) {
log.Warn("[REPAY] close write for cipher stream", "err", err)
}
}
if er := cipher.SetReadDeadline(time.Now().Add(3 * timeout)); er != nil {
err = errors.Join(err, er)
Expand Down
8 changes: 6 additions & 2 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,16 @@ func (es *EasyServer) handleConn(conn net.Conn, tryReuse bool) {
switch {
case res.frameHeader.IsTCPProto():
if err := es.remoteTCPHandle(conn, addrStr, res.method, tryReuse); err != nil {
log.Warn("[REMOTE] tcp handle", "err", err)
if !errors.Is(err, netpipe.ErrPipeClosed) {
log.Warn("[REMOTE] tcp handle", "err", err)
}
return
}
case res.frameHeader.IsUDPProto():
if err := es.remoteUDPHandle(conn, addrStr, res.method, res.frameHeader.IsDNSProto(), tryReuse); err != nil {
log.Warn("[REMOTE] udp handle", "err", err)
if !errors.Is(err, netpipe.ErrPipeClosed) {
log.Warn("[REMOTE] udp handle", "err", err)
}
return
}
default:
Expand Down

0 comments on commit 144d17e

Please sign in to comment.