Fix response latency calculation

Previously latency calcualted as Response.End - Request.Start
Where both End and Start is a last and first packets

This calcualtion is wrong, because it is total roundtrip

Correct server latency will be Response.End - Request.End

In addition added new `--input-raw-timestamp-type` option
which allows choose more precise packet timestamp source (if available).
This commit is contained in:
Leonid Bugaev
2018-02-05 21:47:48 +02:00
parent f8a1b9dde6
commit 0097c599df
14 changed files with 70 additions and 47 deletions
+5 -3
View File
@@ -20,6 +20,7 @@ type RAWInput struct {
trackResponse bool
listener *raw.Listener
bpfFilter string
timestampType string
}
// Available engines for intercepting traffic
@@ -30,7 +31,7 @@ const (
)
// NewRAWInput constructor for RAWInput. Accepts address with port as argument.
func NewRAWInput(address string, engine int, trackResponse bool, expire time.Duration, realIPHeader string, bpfFilter string) (i *RAWInput) {
func NewRAWInput(address string, engine int, trackResponse bool, expire time.Duration, realIPHeader string, bpfFilter string, timestampType string) (i *RAWInput) {
i = new(RAWInput)
i.data = make(chan *raw.TCPMessage)
i.address = address
@@ -40,6 +41,7 @@ func NewRAWInput(address string, engine int, trackResponse bool, expire time.Dur
i.realIPHeader = []byte(realIPHeader)
i.quit = make(chan bool)
i.trackResponse = trackResponse
i.timestampType = timestampType
i.listen(address)
i.listener.IsReady()
@@ -59,7 +61,7 @@ func (i *RAWInput) Read(data []byte) (int, error) {
buf = proto.SetHeader(buf, i.realIPHeader, []byte(msg.IP().String()))
}
} else {
header = payloadHeader(ResponsePayload, msg.UUID(), msg.AssocMessage.Start.UnixNano(), msg.End.UnixNano()-msg.AssocMessage.Start.UnixNano())
header = payloadHeader(ResponsePayload, msg.UUID(), msg.Start.UnixNano(), msg.End.UnixNano()-msg.AssocMessage.End.UnixNano())
}
copy(data[0:len(header)], header)
@@ -77,7 +79,7 @@ func (i *RAWInput) listen(address string) {
log.Fatal("input-raw: error while parsing address", err)
}
i.listener = raw.NewListener(host, port, i.engine, i.trackResponse, i.expire, i.bpfFilter)
i.listener = raw.NewListener(host, port, i.engine, i.trackResponse, i.expire, i.bpfFilter, i.timestampType)
ch := i.listener.Receiver()