Skip to content

Commit

Permalink
chore: minor code tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyxdd committed Nov 8, 2024
1 parent 9cb8cb4 commit 3e8c205
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions core/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"sync/atomic"
"time"

"github.com/apernet/hysteria/core/v2/internal/utils"

"github.com/apernet/hysteria/core/v2/errors"
"github.com/apernet/hysteria/core/v2/internal/pmtud"
"github.com/apernet/hysteria/core/v2/internal/utils"
"github.com/apernet/quic-go"
)

Expand Down
4 changes: 2 additions & 2 deletions core/server/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func copyBufferLog(dst io.Writer, src io.Reader, log func(n uint64) bool) error
}
}

func copyTwoWayWithLogger(id string, serverRw, remoteRw io.ReadWriter, l TrafficLogger, stats *StreamStats) error {
func copyTwoWayEx(id string, serverRw, remoteRw io.ReadWriter, l TrafficLogger, stats *StreamStats) error {
errChan := make(chan error, 2)
go func() {
errChan <- copyBufferLog(serverRw, remoteRw, func(n uint64) bool {
Expand All @@ -52,7 +52,7 @@ func copyTwoWayWithLogger(id string, serverRw, remoteRw io.ReadWriter, l Traffic
return <-errChan
}

// copyTwoWay is the "fast-path" version of copyTwoWayWithLogger that does not log traffic.
// copyTwoWay is the "fast-path" version of copyTwoWayEx that does not log traffic or update stream stats.
// It uses the built-in io.Copy instead of our own copyBufferLog.
func copyTwoWay(serverRw, remoteRw io.ReadWriter) error {
errChan := make(chan error, 2)
Expand Down
2 changes: 1 addition & 1 deletion core/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (h *h3sHandler) handleTCPRequest(stream quic.Stream) {
}
// Start proxying
if trafficLogger != nil {
err = copyTwoWayWithLogger(h.authID, stream, tConn, trafficLogger, streamStats)
err = copyTwoWayEx(h.authID, stream, tConn, trafficLogger, streamStats)
} else {
// Use the fast path if no traffic logger is set
err = copyTwoWay(stream, tConn)
Expand Down
3 changes: 1 addition & 2 deletions extras/trafficlogger/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (
"sync"
"time"

"github.com/apernet/quic-go"

"github.com/apernet/hysteria/core/v2/server"
"github.com/apernet/quic-go"
)

const (
Expand Down

0 comments on commit 3e8c205

Please sign in to comment.