Skip to content

Commit

Permalink
fix: inbound context
Browse files Browse the repository at this point in the history
  • Loading branch information
AkinoKaede committed May 28, 2023
1 parent 0df1b43 commit 0472120
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
27 changes: 18 additions & 9 deletions app/tun/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/tun/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ message Config {
uint32 mtu = 2;
uint32 user_level = 3;
v2ray.core.net.packetaddr.PacketAddrType packet_encoding = 4;
string tag = 6;
}
4 changes: 3 additions & 1 deletion app/tun/handler_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/log"
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/session"
"github.com/v2fly/v2ray-core/v5/common/signal"
"github.com/v2fly/v2ray-core/v5/common/task"
"github.com/v2fly/v2ray-core/v5/features/policy"
Expand Down Expand Up @@ -65,12 +66,13 @@ func SetTCPHandler(ctx context.Context, dispatcher routing.Dispatcher, policyMan
}

func (h *TCPHandler) Handle(conn net.Conn) error {
ctx := session.ContextWithInbound(h.ctx, &session.Inbound{Tag: h.config.Tag})
sessionPolicy := h.policyManager.ForLevel(h.config.UserLevel)

addr := conn.RemoteAddr()

dest := net.DestinationFromAddr(addr)
ctx := log.ContextWithAccessMessage(h.ctx, &log.AccessMessage{
ctx = log.ContextWithAccessMessage(h.ctx, &log.AccessMessage{
From: addr,
To: dest,
Status: log.AccessAccepted,
Expand Down
3 changes: 2 additions & 1 deletion app/tun/handler_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
udp_proto "github.com/v2fly/v2ray-core/v5/common/protocol/udp"
"github.com/v2fly/v2ray-core/v5/common/session"
"github.com/v2fly/v2ray-core/v5/features/policy"
"github.com/v2fly/v2ray-core/v5/features/routing"
"github.com/v2fly/v2ray-core/v5/transport/internet/udp"
Expand Down Expand Up @@ -50,7 +51,7 @@ func SetUDPHandler(ctx context.Context, dispatcher routing.Dispatcher, policyMan
}
}
func (h *UDPHandler) Handle(conn net.Conn) error {
ctx := h.ctx
ctx := session.ContextWithInbound(h.ctx, &session.Inbound{Tag: h.config.Tag})
packetConn := conn.(net.PacketConn)

udpDispatcherConstructor := udp.NewSplitDispatcher
Expand Down

0 comments on commit 0472120

Please sign in to comment.