mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 23:20:25 +08:00
优化代码
This commit is contained in:
@@ -290,7 +290,9 @@ func (this *ListenerManager) addToFirewalld(groupAddrs []string) {
|
|||||||
if newPortStrings == this.lastPortStrings {
|
if newPortStrings == this.lastPortStrings {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.locker.Lock()
|
||||||
this.lastPortStrings = newPortStrings
|
this.lastPortStrings = newPortStrings
|
||||||
|
this.locker.Unlock()
|
||||||
|
|
||||||
remotelogs.Println("FIREWALLD", "opening ports automatically ...")
|
remotelogs.Println("FIREWALLD", "opening ports automatically ...")
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -302,8 +304,10 @@ func (this *ListenerManager) addToFirewalld(groupAddrs []string) {
|
|||||||
var udpPortRanges = utils.MergePorts(udpPorts)
|
var udpPortRanges = utils.MergePorts(udpPorts)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
this.locker.Lock()
|
||||||
this.lastTCPPortRanges = tcpPortRanges
|
this.lastTCPPortRanges = tcpPortRanges
|
||||||
this.lastUDPPortRanges = udpPortRanges
|
this.lastUDPPortRanges = udpPortRanges
|
||||||
|
this.locker.Unlock()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// 删除老的不存在的端口
|
// 删除老的不存在的端口
|
||||||
@@ -339,3 +343,28 @@ func (this *ListenerManager) addToFirewalld(groupAddrs []string) {
|
|||||||
_ = this.firewalld.AllowPortRangesPermanently(tcpPortRanges, "tcp")
|
_ = this.firewalld.AllowPortRangesPermanently(tcpPortRanges, "tcp")
|
||||||
_ = this.firewalld.AllowPortRangesPermanently(udpPortRanges, "udp")
|
_ = this.firewalld.AllowPortRangesPermanently(udpPortRanges, "udp")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ListenerManager) reloadFirewalld() {
|
||||||
|
this.locker.Lock()
|
||||||
|
defer this.locker.Unlock()
|
||||||
|
|
||||||
|
var nodeConfig = sharedNodeConfig
|
||||||
|
|
||||||
|
// 所有的新地址
|
||||||
|
var groupAddrs = []string{}
|
||||||
|
var availableServerGroups = nodeConfig.AvailableGroups()
|
||||||
|
if !nodeConfig.IsOn {
|
||||||
|
availableServerGroups = []*serverconfigs.ServerAddressGroup{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(availableServerGroups) == 0 {
|
||||||
|
remotelogs.Println("LISTENER_MANAGER", "no available servers to startup")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, group := range availableServerGroups {
|
||||||
|
var addr = group.FullAddr()
|
||||||
|
groupAddrs = append(groupAddrs, addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
go this.addToFirewalld(groupAddrs)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user