style: remove unused code and comments

This commit is contained in:
AkinoKaede 2023-05-28 22:32:01 +08:00 committed by Shelikhoo
parent 4b5f788b2f
commit d1c3007d30
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
3 changed files with 4 additions and 17 deletions

View File

@ -55,19 +55,6 @@ func HandleTCP(handle func(tun_net.TCPConn)) StackOption {
// TODO: set sockopt
// tcpHandler := &TCPHandler{
// ctx: ctx,
// dispatcher: dispatcher,
// policyManager: policyManager,
// config: config,
// stack: s,
// }
// if err := tcpHandler.Handle(gonet.NewTCPConn(wg, linkedEndpoint)); err != nil {
// // TODO: log
// // return newError("failed to handle tcp connection").Base(err)
// }
tcpConn := &tcpConn{
TCPConn: gonet.NewTCPConn(wg, linkedEndpoint),
id: r.ID(),
@ -103,7 +90,7 @@ func (h *TCPHandler) Handle(conn tun_net.TCPConn) error {
dest := net.TCPDestination(tun_net.AddressFromTCPIPAddr(id.LocalAddress), net.Port(id.LocalPort))
src := net.TCPDestination(tun_net.AddressFromTCPIPAddr(id.RemoteAddress), net.Port(id.RemotePort))
ctx = log.ContextWithAccessMessage(ctx, &log.AccessMessage{
From: src, // Parse IpAddr to Destination
From: src,
To: dest,
Status: log.AccessAccepted,
Reason: "",

View File

@ -75,7 +75,6 @@ func (h *UDPHandler) Handle(conn tun_net.UDPConn) error {
defer conn.Close()
id := conn.ID()
ctx := session.ContextWithInbound(h.ctx, &session.Inbound{Tag: h.config.Tag})
packetConn := conn.(net.PacketConn)
udpDispatcherConstructor := udp.NewSplitDispatcher
switch h.config.PacketEncoding {
@ -90,7 +89,7 @@ func (h *UDPHandler) Handle(conn tun_net.UDPConn) error {
src := net.UDPDestination(tun_net.AddressFromTCPIPAddr(id.RemoteAddress), net.Port(id.RemotePort))
udpServer := udpDispatcherConstructor(h.dispatcher, func(ctx context.Context, packet *udp_proto.Packet) {
if _, err := packetConn.WriteTo(packet.Payload.Bytes(), &net.UDPAddr{
if _, err := conn.WriteTo(packet.Payload.Bytes(), &net.UDPAddr{
IP: src.Address.IP(),
Port: int(src.Port),
}); err != nil {
@ -104,7 +103,7 @@ func (h *UDPHandler) Handle(conn tun_net.UDPConn) error {
return nil
default:
var buffer [2048]byte
n, _, err := packetConn.ReadFrom(buffer[:])
n, _, err := conn.ReadFrom(buffer[:])
if err != nil {
return newError("failed to read UDP packet").Base(err)
}

View File

@ -15,6 +15,7 @@ type TCPConn interface {
type UDPConn interface {
net.Conn
net.PacketConn
ID() *stack.TransportEndpointID
}