fix ip report bug

This commit is contained in:
yuzuki999 2022-08-19 22:42:51 +08:00
parent 27b97927c1
commit ca2669a575

View File

@ -108,10 +108,12 @@ func (c *Node) Start() error {
time.Sleep(time.Duration(c.config.UpdatePeriodic) * time.Second) time.Sleep(time.Duration(c.config.UpdatePeriodic) * time.Second)
_ = c.userReportPeriodic.Start() _ = c.userReportPeriodic.Start()
}() }()
if c.config.EnableIpRecorder {
c.onlineIpReportPeriodic = &task.Periodic{ c.onlineIpReportPeriodic = &task.Periodic{
Interval: time.Duration(c.config.UpdatePeriodic) * 30, Interval: time.Duration(c.config.IpRecorderConfig.Periodic) * time.Second,
Execute: c.onlineIpReport, Execute: c.onlineIpReport,
} }
}
log.Printf("[%s: %d] Start report online ip", c.nodeInfo.NodeType, c.nodeInfo.NodeId) log.Printf("[%s: %d] Start report online ip", c.nodeInfo.NodeType, c.nodeInfo.NodeId)
// delay to start onlineIpReport // delay to start onlineIpReport
go func() { go func() {
@ -381,12 +383,14 @@ func (c *Node) userInfoMonitor() (err error) {
} }
} }
userTraffic = nil userTraffic = nil
if !c.config.EnableIpRecorder {
c.server.ClearOnlineIps(c.Tag)
}
runtime.GC() runtime.GC()
return nil return nil
} }
func (c *Node) onlineIpReport() (err error) { func (c *Node) onlineIpReport() (err error) {
if c.config.EnableIpRecorder {
onlineIp, err := c.server.GetOnlineIps(c.Tag) onlineIp, err := c.server.GetOnlineIps(c.Tag)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
@ -417,9 +421,6 @@ func (c *Node) onlineIpReport() (err error) {
} else { } else {
c.server.ClearOnlineIps(c.Tag) c.server.ClearOnlineIps(c.Tag)
} }
} else {
c.server.ClearOnlineIps(c.Tag)
}
return nil return nil
} }