Skip to content

Commit

Permalink
fix tls to tcp socket
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovikov committed Sep 21, 2023
1 parent eaa2d5a commit 19cd167
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions HFP.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 19cd167

Please sign in to comment.