From fef7813d15fe1eb21606e211036aae939fbcc4ce Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Mon, 12 Aug 2024 10:14:34 +0200 Subject: [PATCH 1/4] removed conditions --- publish/hep.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/publish/hep.go b/publish/hep.go index bcaf8ec..7e7d091 100644 --- a/publish/hep.go +++ b/publish/hep.go @@ -149,7 +149,6 @@ func (h *HEPOutputer) ReSendPingPacket() { } func (h *HEPOutputer) Send(msg []byte) { - onceSent := false for n := range h.addr { if h.client[n].conn == nil || h.client[n].writer == nil { @@ -171,7 +170,7 @@ func (h *HEPOutputer) Send(msg []byte) { h.client[n].errCnt = 0 if err = h.ReConnect(n); err != nil { logp.Err("reconnect error: %v", err) - if config.Cfg.HEPBufferEnable && (!onceSent && n == (len(h.addr)-1)) { + if config.Cfg.HEPBufferEnable { h.copyHEPbufftoFile(msg) } } else { @@ -188,18 +187,16 @@ func (h *HEPOutputer) Send(msg []byte) { err = h.client[n].writer.Flush() if err != nil { logp.Err("Bad resend: %v", err) - if config.Cfg.HEPBufferEnable && (!onceSent && n == (len(h.addr)-1)) { + if config.Cfg.HEPBufferEnable { h.copyHEPbufftoFile(msg) } } } } else { - if config.Cfg.HEPBufferEnable && (!onceSent && n == (len(h.addr)-1)) { + if config.Cfg.HEPBufferEnable { h.copyHEPbufftoFile(msg) } } - } else { - onceSent = true } } } From 1d5262b4b499d1c53fa073a0c401285c40a48515 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Mon, 12 Aug 2024 14:07:56 +0200 Subject: [PATCH 2/4] fixed conditions --- publish/hep.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/publish/hep.go b/publish/hep.go index 7e7d091..53f4f89 100644 --- a/publish/hep.go +++ b/publish/hep.go @@ -149,10 +149,14 @@ func (h *HEPOutputer) ReSendPingPacket() { } func (h *HEPOutputer) Send(msg []byte) { + onceSent := false for n := range h.addr { if h.client[n].conn == nil || h.client[n].writer == nil { logp.Debug("connection is not up, index: ", strconv.Itoa(n)) + if config.Cfg.HEPBufferEnable && (!onceSent && n == (len(h.addr)-1)) { + h.copyHEPbufftoFile(msg) + } continue } @@ -170,7 +174,7 @@ func (h *HEPOutputer) Send(msg []byte) { h.client[n].errCnt = 0 if err = h.ReConnect(n); err != nil { logp.Err("reconnect error: %v", err) - if config.Cfg.HEPBufferEnable { + if config.Cfg.HEPBufferEnable && (!onceSent && n == (len(h.addr)-1)) { h.copyHEPbufftoFile(msg) } } else { @@ -187,16 +191,18 @@ func (h *HEPOutputer) Send(msg []byte) { err = h.client[n].writer.Flush() if err != nil { logp.Err("Bad resend: %v", err) - if config.Cfg.HEPBufferEnable { + if config.Cfg.HEPBufferEnable && (!onceSent && n == (len(h.addr)-1)) { h.copyHEPbufftoFile(msg) } } } } else { - if config.Cfg.HEPBufferEnable { + if config.Cfg.HEPBufferEnable && (!onceSent && n == (len(h.addr)-1)) { h.copyHEPbufftoFile(msg) } } + } else { + onceSent = true } } } From 04b25db6693316fb6f83177501097dc6ca09b96e Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Tue, 13 Aug 2024 09:18:28 +0200 Subject: [PATCH 3/4] fixed conditions --- publish/hep.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/publish/hep.go b/publish/hep.go index 53f4f89..c98eb72 100644 --- a/publish/hep.go +++ b/publish/hep.go @@ -7,7 +7,6 @@ import ( "net" "os" "runtime/debug" - "strconv" "strings" "time" "unicode" @@ -153,7 +152,7 @@ func (h *HEPOutputer) Send(msg []byte) { for n := range h.addr { if h.client[n].conn == nil || h.client[n].writer == nil { - logp.Debug("connection is not up, index: ", strconv.Itoa(n)) + logp.Debug("connection is not up", fmt.Sprintf("index: %d, Len: %d, once: %v", n, len(h.addr), onceSent)) if config.Cfg.HEPBufferEnable && (!onceSent && n == (len(h.addr)-1)) { h.copyHEPbufftoFile(msg) } From bc9f7c33c9818b31359bbb38b25438896d140152 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Wed, 14 Aug 2024 10:40:32 +0200 Subject: [PATCH 4/4] fixed reconnect condition --- main.go | 2 +- publish/hep.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 74aae63..acdb7f8 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( "github.com/sipcapture/heplify/sniffer" ) -const version = "heplify 1.66.6" +const version = "heplify 1.66.7" func createFlags() { diff --git a/publish/hep.go b/publish/hep.go index c98eb72..49ea3a1 100644 --- a/publish/hep.go +++ b/publish/hep.go @@ -151,16 +151,16 @@ func (h *HEPOutputer) Send(msg []byte) { onceSent := false for n := range h.addr { + var err error + if h.client[n].conn == nil || h.client[n].writer == nil { logp.Debug("connection is not up", fmt.Sprintf("index: %d, Len: %d, once: %v", n, len(h.addr), onceSent)) - if config.Cfg.HEPBufferEnable && (!onceSent && n == (len(h.addr)-1)) { - h.copyHEPbufftoFile(msg) - } - continue + err = fmt.Errorf("connection is broken") + } else { + h.client[n].writer.Write(msg) + err = h.client[n].writer.Flush() } - h.client[n].writer.Write(msg) - err := h.client[n].writer.Flush() if err != nil { h.client[n].errCnt++ var retry bool