From 19cd1676a41e3b463d55dd170b88d3c3813dcef9 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Thu, 21 Sep 2023 14:36:32 +0200 Subject: [PATCH] fix tls to tcp socket --- HFP.go | 58 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/HFP.go b/HFP.go index 9d064f5..ace6216 100644 --- a/HFP.go +++ b/HFP.go @@ -15,7 +15,7 @@ import ( "github.com/guumaster/logsymbols" ) -const AppVersion = "0.55.13" +const AppVersion = "0.55.14" var localAddr *string = flag.String("l", ":9060", "Local HEP listening address") var remoteAddr *string = flag.String("r", "192.168.2.2:9060", "Remote HEP address") @@ -98,13 +98,21 @@ func connectToHEPBackend(dst, proto string) net.Conn { } else { log.Println("Connected to server successfully") + + var tcpCon *net.TCPConn + if proto == "tls" { + tcpCon = conn.(*tls.Conn).NetConn().(*net.TCPConn) + } else { + tcpCon = conn.(*net.TCPConn) + } //Keep Alive if *KeepAlive > 0 { - conn.(*net.TCPConn).SetKeepAlive(true) - conn.(*net.TCPConn).SetKeepAlivePeriod(time.Second * time.Duration(*KeepAlive)) + tcpCon.SetKeepAlive(true) + tcpCon.SetKeepAlivePeriod(time.Second * time.Duration(*KeepAlive)) + } //Nodelay - conn.(*net.TCPConn).SetNoDelay(*noDelayTCP) + tcpCon.SetNoDelay(*noDelayTCP) SendPingHEPPacket(conn) time.Sleep(time.Second * 1) @@ -207,12 +215,20 @@ func handleConnection(clientConn net.Conn, destAddr, destProto string) { } else { log.Println("||--> Connected to ", destAddr, ", proto:", destProto) //Keep Alive + var tcpCon *net.TCPConn + if destProto == "tls" { + tcpCon = destConn.(*tls.Conn).NetConn().(*net.TCPConn) + } else { + tcpCon = destConn.(*net.TCPConn) + } + //Keep Alive if *KeepAlive > 0 { - destConn.(*net.TCPConn).SetKeepAlive(true) - destConn.(*net.TCPConn).SetKeepAlivePeriod(time.Second * time.Duration(*KeepAlive)) + tcpCon.SetKeepAlive(true) + tcpCon.SetKeepAlivePeriod(time.Second * time.Duration(*KeepAlive)) + } //Nodelay - destConn.(*net.TCPConn).SetNoDelay(*noDelayTCP) + tcpCon.SetNoDelay(*noDelayTCP) SendPingHEPPacket(destConn) time.Sleep(time.Second * 1) @@ -290,13 +306,21 @@ func handleConnection(clientConn net.Conn, destAddr, destProto string) { } else { log.Println("||--> Diallout to ", destAddr, ", proto:", destProto) + //Keep Alive + var tcpCon *net.TCPConn + if destProto == "tls" { + tcpCon = destConn.(*tls.Conn).NetConn().(*net.TCPConn) + } else { + tcpCon = destConn.(*net.TCPConn) + } //Keep Alive if *KeepAlive > 0 { - destConn.(*net.TCPConn).SetKeepAlive(true) - destConn.(*net.TCPConn).SetKeepAlivePeriod(time.Second * time.Duration(*KeepAlive)) + tcpCon.SetKeepAlive(true) + tcpCon.SetKeepAlivePeriod(time.Second * time.Duration(*KeepAlive)) + } //Nodelay - destConn.(*net.TCPConn).SetNoDelay(*noDelayTCP) + tcpCon.SetNoDelay(*noDelayTCP) SendPingHEPPacket(destConn) time.Sleep(time.Second * 1) @@ -340,13 +364,21 @@ func handleConnection(clientConn net.Conn, destAddr, destProto string) { } else { log.Println("||--> Diallout after reconnect to ", destAddr, ", proto:", destProto) + //Keep Alive + var tcpCon *net.TCPConn + if destProto == "tls" { + tcpCon = destConn.(*tls.Conn).NetConn().(*net.TCPConn) + } else { + tcpCon = destConn.(*net.TCPConn) + } //Keep Alive if *KeepAlive > 0 { - destConn.(*net.TCPConn).SetKeepAlive(true) - destConn.(*net.TCPConn).SetKeepAlivePeriod(time.Second * time.Duration(*KeepAlive)) + tcpCon.SetKeepAlive(true) + tcpCon.SetKeepAlivePeriod(time.Second * time.Duration(*KeepAlive)) + } //Nodelay - destConn.(*net.TCPConn).SetNoDelay(*noDelayTCP) + tcpCon.SetNoDelay(*noDelayTCP) SendPingHEPPacket(destConn) time.Sleep(time.Second * 1)