ping: Add timeout to destinations

This commit is contained in:
世界 2025-08-24 17:46:03 +08:00
parent 8f6cc9f62e
commit 737ebf01c4
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 81 additions and 19 deletions

View file

@ -13,6 +13,7 @@ import (
type DirectRouteDestination interface {
WritePacket(packet *buf.Buffer) error
Close() error
IsClosed() bool
}
type DirectRouteSession struct {
@ -28,6 +29,9 @@ type DirectRouteMapping struct {
func NewDirectRouteMapping(timeout time.Duration) *DirectRouteMapping {
mapping := common.Must1(freelru.NewSharded[DirectRouteSession, DirectRouteDestination](1024, maphash.NewHasher[DirectRouteSession]().Hash32))
mapping.SetHealthCheck(func(session DirectRouteSession, destination DirectRouteDestination) bool {
return !destination.IsClosed()
})
mapping.SetOnEvict(func(session DirectRouteSession, action DirectRouteDestination) {
action.Close()
})