Skip to content

Commit

Permalink
Merge pull request #79 from negbie/master
Browse files Browse the repository at this point in the history
Add DiscardMethod option
  • Loading branch information
negbie authored Jun 18, 2018
2 parents 885f343 + 1b1caf5 commit 365570f
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 37 deletions.
2 changes: 1 addition & 1 deletion cmd/heplify-server/heplify-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/negbie/logp"
)

const version = "heplify-server 0.92"
const version = "heplify-server 0.93"

type server interface {
Run()
Expand Down
66 changes: 34 additions & 32 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@ package config
var Setting HeplifyServer

type HeplifyServer struct {
HEPAddr string `default:"0.0.0.0:9060"`
MQDriver string `default:""`
MQAddr string `default:""`
MQTopic string `default:""`
PromAddr string `default:""`
PromTargetIP string `default:""`
PromTargetName string `default:""`
HoraclifixStats bool `default:"false"`
RTPAgentStats bool `default:"false"`
DBShema string `default:"homer5"`
DBDriver string `default:"mysql"`
DBAddr string `default:"localhost:3306"`
DBUser string `default:"root"`
DBPass string `default:""`
DBDataTable string `default:"homer_data"`
DBConfTable string `default:"homer_configuration"`
DBTableSpace string `default:""`
DBBulk int `default:"200"`
DBTimer int `default:"2"`
DBRotate bool `default:"true"`
DBPartLog string `default:"6h"`
DBPartSip string `default:"2h"`
DBPartQos string `default:"12h"`
DBDropDays int `default:"0"`
DBDropOnStart bool `default:"false"`
Dedup bool `default:"false"`
AlegID string `default:"x-cid"`
LogDbg string `default:""`
LogLvl string `default:"info"`
LogStd bool `default:"false"`
Config string `default:"./heplify-server.toml"`
Version bool `default:"false"`
HEPAddr string `default:"0.0.0.0:9060"`
MQDriver string `default:""`
MQAddr string `default:""`
MQTopic string `default:""`
PromAddr string `default:""`
PromTargetIP string `default:""`
PromTargetName string `default:""`
HoraclifixStats bool `default:"false"`
RTPAgentStats bool `default:"false"`
DBShema string `default:"homer5"`
DBDriver string `default:"mysql"`
DBAddr string `default:"localhost:3306"`
DBUser string `default:"root"`
DBPass string `default:""`
DBDataTable string `default:"homer_data"`
DBConfTable string `default:"homer_configuration"`
DBTableSpace string `default:""`
DBBulk int `default:"200"`
DBTimer int `default:"2"`
DBRotate bool `default:"true"`
DBPartLog string `default:"6h"`
DBPartSip string `default:"2h"`
DBPartQos string `default:"12h"`
DBDropDays int `default:"0"`
DBDropOnStart bool `default:"false"`
Dedup bool `default:"false"`
DiscardMethod []string `default:""`
AlegID string `default:"x-cid"`
LogDbg string `default:""`
LogLvl string `default:"info"`
LogStd bool `default:"false"`
Config string `default:"./heplify-server.toml"`
Version bool `default:"false"`
}

func NewConfig() *HeplifyServer {
Expand Down Expand Up @@ -65,6 +66,7 @@ func NewConfig() *HeplifyServer {
DBDropDays: 0,
DBDropOnStart: false,
Dedup: false,
DiscardMethod: nil,
AlegID: "x-cid",
LogDbg: "",
LogLvl: "info",
Expand Down
2 changes: 1 addition & 1 deletion database/sqlhomer5.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (s *SQLHomer5) insert(hCh chan *decoder.HEP) {
}

}
} else if pkt.ProtoType >= 2 && pkt.ProtoType <= 200 && pkt.CID != "" {
} else if pkt.ProtoType >= 2 && pkt.Payload != "" && pkt.CID != "" {
switch pkt.ProtoType {
case 5:
rtcpRows = addRTCRow(rtcpRows)
Expand Down
2 changes: 1 addition & 1 deletion database/sqlhomer7.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (s *SQLHomer7) insert(hCh chan *decoder.HEP) {
pHeader = formProtocolHeader(pkt)
dHeader = formDataHeader(pkt, date)

if pkt.ProtoType == 1 && pkt.Payload != "" && pkt.CID != "" {
if pkt.ProtoType == 1 && pkt.Payload != "" && pkt.SIP != nil {
switch pkt.SIP.CseqMethod {
case "INVITE", "UPDATE", "BYE", "ACK", "PRACK", "REFER", "CANCEL", "INFO":
callRows = append(callRows, []interface{}{pkt.CID, date, pHeader, dHeader, pkt.Payload}...)
Expand Down
12 changes: 10 additions & 2 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func DecodeHEP(packet []byte) (*HEP, error) {

func (h *HEP) parse(packet []byte) error {
var err error
if packet[0] == 0x48 && packet[1] == 0x45 && packet[2] == 0x50 && packet[3] == 0x33 {
if bytes.HasPrefix(packet, []byte("HEP3")) {
err = h.parseHEP(packet)
if err != nil {
logp.Warn("%v", err)
Expand Down Expand Up @@ -102,6 +102,14 @@ func (h *HEP) parse(packet []byte) error {
return err
}
h.CID = h.SIP.CallID

if len(config.Setting.DiscardMethod) > 0 {
for k := range config.Setting.DiscardMethod {
if config.Setting.DiscardMethod[k] == h.SIP.CseqMethod {
h.Payload = ""
}
}
}
}

logp.Debug("hep", "%+v\n\n", h)
Expand Down Expand Up @@ -319,7 +327,7 @@ func makeChuncks(h *HEP, w *bytes.Buffer) []byte {
// Chunk VLAN
w.Write([]byte{0x00, 0x00, 0x00, 0x12})
w.Write(hepLen8)
binary.BigEndian.PutUint16(chunck16, h.Vlan)
binary.BigEndian.PutUint16(chunck16, uint16(h.Vlan))
w.Write(chunck16)
// Chunk MOS only
Expand Down
2 changes: 2 additions & 0 deletions example/homer5_config/heplify-server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DBPartQos = "12h"
DBDropDays = 0
DBDropOnStart = false
Dedup = false
DiscardMethod = []
AlegID = "x-cid"
LogDbg = ""
LogLvl = "info"
Expand All @@ -39,6 +40,7 @@ Version = false
# PromAddr = "0.0.0.0:8899"
# PromTargetIP = "10.1.2.111,10.1.2.4,10.1.2.5,10.1.2.6,10.12.44.222"
# PromTargetName = "sbc_access,sbc_core,kamailio,asterisk,pstn_gateway"
# DiscardMethod = ["OPTIONS","NOTIFY"]
# LogDbg = "hep,sql"
# LogLvl = "warning"
# -------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions example/homer7_config/heplify-server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DBPartQos = "12h"
DBDropDays = 0
DBDropOnStart = false
Dedup = false
DiscardMethod = []
AlegID = "x-cid"
LogDbg = ""
LogLvl = "info"
Expand All @@ -39,6 +40,7 @@ Version = false
# PromAddr = "0.0.0.0:8899"
# PromTargetIP = "10.1.2.111,10.1.2.4,10.1.2.5,10.1.2.6,10.12.44.222"
# PromTargetName = "sbc_access,sbc_core,kamailio,asterisk,pstn_gateway"
# DiscardMethod = ["OPTIONS","NOTIFY"]
# LogDbg = "hep,sql"
# LogLvl = "warning"
# -------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions server/hep.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ GO:
} else if hepPkt.ProtoType == 0 {
atomic.AddUint64(&h.stats.DupCount, 1)
continue
} else if hepPkt.Payload == "" {
continue
}

atomic.AddUint64(&h.stats.HEPCount, 1)
Expand Down

0 comments on commit 365570f

Please sign in to comment.