Skip to content

Commit

Permalink
fix bufffer
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovikov committed Sep 26, 2023
1 parent 699efdb commit 21f4094
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions HFP.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"crypto/tls"
"flag"
"fmt"
Expand All @@ -16,7 +17,7 @@ import (
"github.com/ivlovric/HFP/queue"
)

const AppVersion = "0.56.2"
const AppVersion = "0.56.3"

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 @@ -123,6 +124,8 @@ func handleConnection(clientConn net.Conn) {
}
}()

var bufferPool bytes.Buffer

// use a buffer to transfer data between connections
buf := make([]byte, 65535)

Expand All @@ -138,6 +141,8 @@ func handleConnection(clientConn net.Conn) {
return
}

bufferPool.Write(buf[:n])

if *Debug == "on" {
log.Println("-->|| Got", n, "bytes on wire -- Total buffer size:", len(buf))
}
Expand Down Expand Up @@ -178,7 +183,10 @@ func handleConnection(clientConn net.Conn) {
if hepPkt.SrcIP == string(ipf) || hepPkt.DstIP == string(ipf) || string(buf[:n]) == "HELLO HFP" {

//Send HEP out to backend
hepJob := queue.Job{Type: 1, Data: buf[:n], Len: n, Action: sendHepOut}
hepJob := queue.Job{Type: 1, Len: n, Action: sendHepOut}
hepJob.Data = make([]byte, n)
copy(hepJob.Data, buf[:n])

productsQueue.AddJob(hepJob)

if *Debug == "on" {
Expand Down Expand Up @@ -223,7 +231,10 @@ func handleConnection(clientConn net.Conn) {

if !rejected {
//Send HEP out to backend
hepJob := queue.Job{Type: 1, Data: buf[:n], Len: n, Action: sendHepOut}
hepJob := queue.Job{Type: 1, Len: n, Action: sendHepOut}
hepJob.Data = make([]byte, n)
copy(hepJob.Data, buf[:n])

productsQueue.AddJob(hepJob)
if *Debug == "on" {
log.Println("||-->", logsymbols.Success, " Sending HEP OUT successful with filter")
Expand All @@ -233,7 +244,10 @@ func handleConnection(clientConn net.Conn) {
} else {

//Send HEP out to backend
hepJob := queue.Job{Type: 1, Data: buf[:n], Len: n, Action: sendHepOut}
hepJob := queue.Job{Type: 1, Len: n, Action: sendHepOut}
hepJob.Data = make([]byte, n)
copy(hepJob.Data, buf[:n])

productsQueue.AddJob(hepJob)

if *Debug == "on" {
Expand Down Expand Up @@ -282,10 +296,12 @@ func sendHepOut(data []byte, len int) error {
}

//
if _, err_HEPout := hepConnect.Write(data); err_HEPout != nil {
size, err := hepConnect.Write(data)

if err != nil {

if *Debug == "on" {
log.Println("||-->", logsymbols.Error, "Sending HEP OUT error:", err_HEPout)
log.Println("||-->", logsymbols.Error, "Sending HEP OUT error:", err)
}

connectionStatus.Set(0)
Expand All @@ -303,7 +319,7 @@ func sendHepOut(data []byte, len int) error {
}
} else {
if *Debug == "on" {
log.Println("||-->", logsymbols.Success, " Sent HEP successful. Size: ", len)
log.Println("||-->", logsymbols.Success, " Sent HEP successful. Orig size: ", len, ", Sent size: ", size)
}
}

Expand Down

0 comments on commit 21f4094

Please sign in to comment.