Skip to content

Commit

Permalink
Fix stat
Browse files Browse the repository at this point in the history
  • Loading branch information
RPRX authored Nov 12, 2020
1 parent 553bf33 commit f06ede1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
8 changes: 7 additions & 1 deletion proxy/vless/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"v2ray.com/core/common/net"
"v2ray.com/core/common/protocol"
"v2ray.com/core/common/signal"
"v2ray.com/core/features/stats"
"v2ray.com/core/proxy/vless"
"v2ray.com/core/transport/internet/xtls"
)
Expand Down Expand Up @@ -173,18 +174,23 @@ func DecodeResponseHeader(reader io.Reader, request *protocol.RequestHeader) (*A
return responseAddons, nil
}

func ReadV(reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdater, conn *xtls.Conn, rawConn syscall.RawConn) error {
func ReadV(reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdater, conn *xtls.Conn, rawConn syscall.RawConn, counter stats.Counter) error {
err := func() error {
var ct stats.Counter
for {
if conn.DirectIn {
conn.DirectIn = false
reader = buf.NewReadVReader(conn.Connection, rawConn)
ct = counter
if conn.SHOW {
fmt.Println(conn.MARK, "ReadV")
}
}
buffer, err := reader.ReadMultiBuffer()
if !buffer.IsEmpty() {
if ct != nil {
ct.Add(int64(buffer.Len()))
}
timer.Update()
if werr := writer.WriteMultiBuffer(buffer); werr != nil {
return werr
Expand Down
11 changes: 9 additions & 2 deletions proxy/vless/inbound/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
feature_inbound "v2ray.com/core/features/inbound"
"v2ray.com/core/features/policy"
"v2ray.com/core/features/routing"
"v2ray.com/core/features/stats"
"v2ray.com/core/proxy/vless"
"v2ray.com/core/proxy/vless/encoding"
"v2ray.com/core/transport/internet"
Expand Down Expand Up @@ -145,8 +146,10 @@ func (*Handler) Network() []net.Network {
// Process implements proxy.Inbound.Process().
func (h *Handler) Process(ctx context.Context, network net.Network, connection internet.Connection, dispatcher routing.Dispatcher) error {
sid := session.ExportIDToError(ctx)

iConn := connection
if statConn, ok := iConn.(*internet.StatCouterConnection); ok {
statConn, ok := iConn.(*internet.StatCouterConnection)
if ok {
iConn = statConn.Connection
}

Expand Down Expand Up @@ -438,7 +441,11 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i
var err error

if rawConn != nil {
err = encoding.ReadV(clientReader, serverWriter, timer, iConn.(*xtls.Conn), rawConn)
var counter stats.Counter
if statConn != nil {
counter = statConn.ReadCounter
}
err = encoding.ReadV(clientReader, serverWriter, timer, iConn.(*xtls.Conn), rawConn, counter)
} else {
// from clientReader.ReadMultiBuffer to serverWriter.WriteMultiBufer
err = buf.Copy(clientReader, serverWriter, buf.UpdateActivity(timer))
Expand Down
10 changes: 8 additions & 2 deletions proxy/vless/outbound/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"v2ray.com/core/common/signal"
"v2ray.com/core/common/task"
"v2ray.com/core/features/policy"
"v2ray.com/core/features/stats"
"v2ray.com/core/proxy/vless"
"v2ray.com/core/proxy/vless/encoding"
"v2ray.com/core/transport"
Expand Down Expand Up @@ -91,7 +92,8 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
defer conn.Close()

iConn := conn
if statConn, ok := iConn.(*internet.StatCouterConnection); ok {
statConn, ok := iConn.(*internet.StatCouterConnection)
if ok {
iConn = statConn.Connection
}

Expand Down Expand Up @@ -213,7 +215,11 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
serverReader := encoding.DecodeBodyAddons(conn, request, responseAddons)

if rawConn != nil {
err = encoding.ReadV(serverReader, clientWriter, timer, iConn.(*xtls.Conn), rawConn)
var counter stats.Counter
if statConn != nil {
counter = statConn.ReadCounter
}
err = encoding.ReadV(serverReader, clientWriter, timer, iConn.(*xtls.Conn), rawConn, counter)
} else {
// from serverReader.ReadMultiBuffer to clientWriter.WriteMultiBufer
err = buf.Copy(serverReader, clientWriter, buf.UpdateActivity(timer))
Expand Down

0 comments on commit f06ede1

Please sign in to comment.