Skip to content

Commit

Permalink
style: remove unused code and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AkinoKaede committed May 28, 2023
1 parent d6c52f7 commit 6c1bf1e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
15 changes: 1 addition & 14 deletions app/tun/handler_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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: "",
Expand Down
5 changes: 2 additions & 3 deletions app/tun/handler_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions app/tun/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type TCPConn interface {

type UDPConn interface {
net.Conn
net.PacketConn

ID() *stack.TransportEndpointID
}
Expand Down

0 comments on commit 6c1bf1e

Please sign in to comment.