mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 23:59:53 +00:00
forwarder.scanner. (#173)
This commit is contained in:
@@ -33,6 +33,7 @@ type Forwarder struct {
|
||||
sessions *sessionTable
|
||||
destinations *destinationTable
|
||||
faulter *Faulter
|
||||
scanner *scanner
|
||||
metricsRegistry metrics.UsageRegistry
|
||||
traceController trace.Controller
|
||||
Options *Options
|
||||
@@ -63,6 +64,8 @@ func NewForwarder(metricsRegistry metrics.UsageRegistry, faulter *Faulter, optio
|
||||
Options: options,
|
||||
CloseNotify: closeNotify,
|
||||
}
|
||||
forwarder.scanner = newScanner(forwarder.sessions, 30 * time.Second, 30 * time.Second, forwarder.CloseNotify)
|
||||
go forwarder.scanner.run()
|
||||
|
||||
return forwarder
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright NetFoundry, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package forwarder
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
)
|
||||
|
||||
type scanner struct {
|
||||
sessions *sessionTable
|
||||
interval time.Duration
|
||||
timeout time.Duration
|
||||
closeNotify <-chan struct{}
|
||||
}
|
||||
|
||||
func newScanner(sessions *sessionTable, interval time.Duration, timeout time.Duration, closeNotify <-chan struct{}) *scanner {
|
||||
return &scanner{
|
||||
sessions: sessions,
|
||||
interval: interval,
|
||||
timeout: timeout,
|
||||
closeNotify: closeNotify,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *scanner) run() {
|
||||
logrus.Info("started")
|
||||
defer logrus.Warn("exited")
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-time.After(self.interval):
|
||||
self.scan()
|
||||
|
||||
case <-self.closeNotify:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *scanner) scan() {
|
||||
for sessionId, ft := range self.sessions.sessions.Items() {
|
||||
var idleSessionIds []string
|
||||
if time.Since(ft.(*forwardTable).last) > self.timeout {
|
||||
idleSessionIds = append(idleSessionIds, sessionId)
|
||||
logrus.Warnf("[s/%s] idle after [%s]", sessionId, self.timeout)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user