@@ -17,7 +17,7 @@ import (
1717 uuid "github.com/gofrs/uuid"
1818 piondtls "github.com/pion/dtls/v2"
1919 "github.com/plgd-dev/go-coap/v2/dtls"
20- "github.com/plgd-dev/go-coap/v2/net/keepalive "
20+ "github.com/plgd-dev/go-coap/v2/net/monitor/inactivity "
2121 "github.com/plgd-dev/go-coap/v2/tcp"
2222 "github.com/plgd-dev/go-coap/v2/udp"
2323
@@ -429,7 +429,7 @@ func newClientCloseHandler(conn ClientConn, onClose *OnCloseHandler) *ClientClos
429429type dialOptions struct {
430430 DisableTCPSignalMessageCSM bool
431431 DisablePeerTCPSignalMessageCSMs bool
432- KeepAlive * keepalive. KeepAlive
432+ KeepaliveTimeout time. Duration
433433 errors func (err error )
434434 maxMessageSize int
435435 dialer * net.Dialer
@@ -458,7 +458,7 @@ func WithDialDisablePeerTCPSignalMessageCSMs() DialOptionFunc {
458458// while attempting to make 3 pings during that period.
459459func WithKeepAlive (connectionTimeout time.Duration ) DialOptionFunc {
460460 return func (c dialOptions ) dialOptions {
461- c .KeepAlive = keepalive . New ( keepalive . WithConfig ( keepalive . MakeConfig ( connectionTimeout )))
461+ c .KeepaliveTimeout = connectionTimeout
462462 return c
463463 }
464464}
@@ -491,8 +491,11 @@ func DialUDP(ctx context.Context, addr string, opts ...DialOptionFunc) (*ClientC
491491 cfg = o (cfg )
492492 }
493493 dopts := make ([]udp.DialOption , 0 , 4 )
494- if cfg .KeepAlive != nil {
495- dopts = append (dopts , udp .WithKeepAlive (cfg .KeepAlive ))
494+ if cfg .KeepaliveTimeout != 0 {
495+ dopts = append (dopts , udp .WithKeepAlive (3 , cfg .KeepaliveTimeout / 3 , func (cc inactivity.ClientConn ) {
496+ cc .Close ()
497+ cfg .errors (fmt .Errorf ("keep alive was reached fail limit:: closing connection" ))
498+ }))
496499 }
497500 if cfg .errors != nil {
498501 dopts = append (dopts , udp .WithErrors (cfg .errors ))
@@ -527,8 +530,11 @@ func DialTCP(ctx context.Context, addr string, opts ...DialOptionFunc) (*ClientC
527530 cfg = o (cfg )
528531 }
529532 dopts := make ([]tcp.DialOption , 0 , 4 )
530- if cfg .KeepAlive != nil {
531- dopts = append (dopts , tcp .WithKeepAlive (cfg .KeepAlive ))
533+ if cfg .KeepaliveTimeout != 0 {
534+ dopts = append (dopts , tcp .WithKeepAlive (3 , cfg .KeepaliveTimeout / 3 , func (cc inactivity.ClientConn ) {
535+ cc .Close ()
536+ cfg .errors (fmt .Errorf ("keep alive was reached fail limit:: closing connection" ))
537+ }))
532538 }
533539 if cfg .DisablePeerTCPSignalMessageCSMs {
534540 dopts = append (dopts , tcp .WithDisablePeerTCPSignalMessageCSMs ())
@@ -606,8 +612,11 @@ func DialTCPSecure(ctx context.Context, addr string, tlsCfg *tls.Config, opts ..
606612 }
607613 dopts := make ([]tcp.DialOption , 0 , 4 )
608614 dopts = append (dopts , tcp .WithTLS (tlsCfg ))
609- if cfg .KeepAlive != nil {
610- dopts = append (dopts , tcp .WithKeepAlive (cfg .KeepAlive ))
615+ if cfg .KeepaliveTimeout != 0 {
616+ dopts = append (dopts , tcp .WithKeepAlive (3 , cfg .KeepaliveTimeout / 3 , func (cc inactivity.ClientConn ) {
617+ cc .Close ()
618+ cfg .errors (fmt .Errorf ("keep alive was reached fail limit:: closing connection" ))
619+ }))
611620 }
612621 if cfg .DisablePeerTCPSignalMessageCSMs {
613622 dopts = append (dopts , tcp .WithDisablePeerTCPSignalMessageCSMs ())
@@ -655,8 +664,11 @@ func DialUDPSecure(ctx context.Context, addr string, dtlsCfg *piondtls.Config, o
655664 cfg = o (cfg )
656665 }
657666 dopts := make ([]dtls.DialOption , 0 , 4 )
658- if cfg .KeepAlive != nil {
659- dopts = append (dopts , dtls .WithKeepAlive (cfg .KeepAlive ))
667+ if cfg .KeepaliveTimeout != 0 {
668+ dopts = append (dopts , dtls .WithKeepAlive (3 , cfg .KeepaliveTimeout / 3 , func (cc inactivity.ClientConn ) {
669+ cc .Close ()
670+ cfg .errors (fmt .Errorf ("keep alive was reached fail limit:: closing connection" ))
671+ }))
660672 }
661673 if cfg .errors != nil {
662674 dopts = append (dopts , dtls .WithErrors (cfg .errors ))
0 commit comments