mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-03 03:47:39 +03:00
Update udpant usages
This commit is contained in:
parent
c177abb523
commit
59a6bdc1fa
5 changed files with 34 additions and 20 deletions
|
@ -16,8 +16,9 @@ import (
|
|||
|
||||
type Mixed struct {
|
||||
*System
|
||||
stack *stack.Stack
|
||||
endpoint *channel.Endpoint
|
||||
stack *stack.Stack
|
||||
endpoint *channel.Endpoint
|
||||
udpForwarder *UDPForwarder
|
||||
}
|
||||
|
||||
func NewMixed(
|
||||
|
@ -42,14 +43,29 @@ func (m *Mixed) Start() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ipStack.SetTransportProtocolHandler(udp.ProtocolNumber, NewUDPForwarder(m.ctx, ipStack, m.handler, m.udpTimeout).HandlePacket)
|
||||
udpForwarder := NewUDPForwarder(m.ctx, ipStack, m.handler, m.udpTimeout)
|
||||
ipStack.SetTransportProtocolHandler(udp.ProtocolNumber, udpForwarder.HandlePacket)
|
||||
m.stack = ipStack
|
||||
m.endpoint = endpoint
|
||||
m.udpForwarder = udpForwarder
|
||||
go m.tunLoop()
|
||||
go m.packetLoop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mixed) Close() error {
|
||||
if m.stack == nil {
|
||||
return nil
|
||||
}
|
||||
m.endpoint.Attach(nil)
|
||||
m.stack.Close()
|
||||
for _, endpoint := range m.stack.CleanupEndpoints() {
|
||||
endpoint.Abort()
|
||||
}
|
||||
m.udpNat.Close()
|
||||
return m.System.Close()
|
||||
}
|
||||
|
||||
func (m *Mixed) tunLoop() {
|
||||
if winTun, isWinTun := m.tun.(WinTun); isWinTun {
|
||||
m.wintunLoop(winTun)
|
||||
|
@ -222,15 +238,3 @@ func (m *Mixed) packetLoop() {
|
|||
packet.DecRef()
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Mixed) Close() error {
|
||||
if m.stack == nil {
|
||||
return nil
|
||||
}
|
||||
m.endpoint.Attach(nil)
|
||||
m.stack.Close()
|
||||
for _, endpoint := range m.stack.CleanupEndpoints() {
|
||||
endpoint.Abort()
|
||||
}
|
||||
return m.System.Close()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue