Skip to content

Commit

Permalink
verbose error handling for smux protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Sep 22, 2019
1 parent fa72823 commit a859f41
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
24 changes: 13 additions & 11 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ func handleClient(mux generic.Mux, p1 net.Conn, quiet bool) {
go func() {
buf := xmitBuf.Get().([]byte)
if _, err := generic.CopyBuffer(dst, src, buf); err != nil {
// error handling
cause := err
if e, ok := err.(interface{ Cause() error }); ok {
cause = e.Cause()
}

switch cause {
case smux.ErrInvalidProtocol:
log.Println(err)
case smuxv2.ErrInvalidProtocol:
log.Println(err)
if s2, ok := p2.(generic.Stream); ok {
// verbose error handling
cause := err
if e, ok := err.(interface{ Cause() error }); ok {
cause = e.Cause()
}

switch cause {
case smux.ErrInvalidProtocol:
log.Println("smux version:1", err, "in:", p1.RemoteAddr(), "out:", fmt.Sprint(s2.RemoteAddr(), "(", s2.ID(), ")"))
case smuxv2.ErrInvalidProtocol:
log.Println("smux version:1", err, "in:", p1.RemoteAddr(), "out:", fmt.Sprint(s2.RemoteAddr(), "(", s2.ID(), ")"))
}
}
}
xmitBuf.Put(buf)
Expand Down
22 changes: 12 additions & 10 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,19 @@ func handleClient(p1 io.ReadWriteCloser, p2 net.Conn, quiet bool) {
go func() {
buf := xmitBuf.Get().([]byte)
if _, err := generic.CopyBuffer(dst, src, buf); err != nil {
// error handling
cause := err
if e, ok := err.(interface{ Cause() error }); ok {
cause = e.Cause()
}
if s1, ok := p1.(generic.Stream); ok {
// verbose error handling
cause := err
if e, ok := err.(interface{ Cause() error }); ok {
cause = e.Cause()
}

switch cause {
case smux.ErrInvalidProtocol:
log.Println(err)
case smuxv2.ErrInvalidProtocol:
log.Println(err)
switch cause {
case smux.ErrInvalidProtocol:
log.Println("smux version:1", err, "in:", fmt.Sprint(s1.RemoteAddr(), "(", s1.ID(), ")"), "out:", p2.RemoteAddr())
case smuxv2.ErrInvalidProtocol:
log.Println("smux version:2", err, "in:", fmt.Sprint(s1.RemoteAddr(), "(", s1.ID(), ")"), "out:", p2.RemoteAddr())
}
}
}
xmitBuf.Put(buf)
Expand Down

0 comments on commit a859f41

Please sign in to comment.