chore: Chore: adjust the loading order, and then load the resource at last

This commit is contained in:
Skyxim
2023-03-14 22:37:07 +08:00
parent 0f24c2f849
commit 09c53e7cb7
3 changed files with 54 additions and 28 deletions

View File

@ -26,6 +26,7 @@ import (
)
var (
status C.TunnelStatus
tcpQueue = make(chan C.ConnContext, 200)
udpQueue = make(chan C.PacketAdapter, 200)
natTable = nat.New()
@ -49,6 +50,18 @@ var (
fakeIPRange netip.Prefix
)
func OnSuspend() {
status = C.TunnelSuspend
}
func OnInnerLoading() {
status = C.TunnelInner
}
func OnRunning() {
status = C.TunnelRunning
}
func SetFakeIPRange(p netip.Prefix) {
fakeIPRange = p
}
@ -158,10 +171,18 @@ func SetFindProcessMode(mode P.FindProcessMode) {
findProcessMode = mode
}
func isHandle(t C.Type) bool {
return status == C.TunnelRunning || (status == C.TunnelInner && t == C.INNER)
}
// processUDP starts a loop to handle udp packet
func processUDP() {
queue := udpQueue
for conn := range queue {
if !isHandle(conn.Metadata().Type) {
conn.Drop()
continue
}
handleUDPConn(conn)
}
}
@ -177,6 +198,10 @@ func process() {
queue := tcpQueue
for conn := range queue {
if !isHandle(conn.Metadata().Type) {
_ = conn.Conn().Close()
continue
}
go handleTCPConn(conn)
}
}