mirror of
https://github.com/safing/portmaster
synced 2025-09-04 03:29:12 +00:00
Update BytesReceived/Sent field names
This commit is contained in:
parent
e70fd9abd7
commit
f0ebc6e72f
6 changed files with 29 additions and 24 deletions
|
@ -133,10 +133,10 @@ func reportBandwidth(ctx context.Context, objs bpfObjects, bandwidthUpdates chan
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
update := &packet.BandwidthUpdate{
|
update := &packet.BandwidthUpdate{
|
||||||
ConnID: connID,
|
ConnID: connID,
|
||||||
RecvBytes: skInfo.Rx,
|
BytesReceived: skInfo.Rx,
|
||||||
SentBytes: skInfo.Tx,
|
BytesSent: skInfo.Tx,
|
||||||
Method: packet.Absolute,
|
Method: packet.Absolute,
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case bandwidthUpdates <- update:
|
case bandwidthUpdates <- update:
|
||||||
|
|
|
@ -63,10 +63,10 @@ func reportBandwidth(ctx context.Context, bandwidthUpdates chan *packet.Bandwidt
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
update := &packet.BandwidthUpdate{
|
update := &packet.BandwidthUpdate{
|
||||||
ConnID: connID,
|
ConnID: connID,
|
||||||
RecvBytes: stat.receivedBytes,
|
BytesReceived: stat.receivedBytes,
|
||||||
SentBytes: stat.transmittedBytes,
|
BytesSent: stat.transmittedBytes,
|
||||||
Method: packet.Additive,
|
Method: packet.Additive,
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case bandwidthUpdates <- update:
|
case bandwidthUpdates <- update:
|
||||||
|
|
|
@ -629,7 +629,7 @@ func bandwidthUpdateHandler(ctx context.Context) error {
|
||||||
|
|
||||||
func updateBandwidth(ctx context.Context, bwUpdate *packet.BandwidthUpdate) {
|
func updateBandwidth(ctx context.Context, bwUpdate *packet.BandwidthUpdate) {
|
||||||
// Check if update makes sense.
|
// Check if update makes sense.
|
||||||
if bwUpdate.RecvBytes == 0 && bwUpdate.SentBytes == 0 {
|
if bwUpdate.BytesReceived == 0 && bwUpdate.BytesSent == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,11 +649,11 @@ func updateBandwidth(ctx context.Context, bwUpdate *packet.BandwidthUpdate) {
|
||||||
// Update stats according to method.
|
// Update stats according to method.
|
||||||
switch bwUpdate.Method {
|
switch bwUpdate.Method {
|
||||||
case packet.Absolute:
|
case packet.Absolute:
|
||||||
conn.RecvBytes = bwUpdate.RecvBytes
|
conn.BytesReceived = bwUpdate.BytesReceived
|
||||||
conn.SentBytes = bwUpdate.SentBytes
|
conn.BytesSent = bwUpdate.BytesSent
|
||||||
case packet.Additive:
|
case packet.Additive:
|
||||||
conn.RecvBytes += bwUpdate.RecvBytes
|
conn.BytesReceived += bwUpdate.BytesReceived
|
||||||
conn.SentBytes += bwUpdate.SentBytes
|
conn.BytesSent += bwUpdate.BytesSent
|
||||||
default:
|
default:
|
||||||
log.Warningf("filter: unsupported bandwidth update method: %d", bwUpdate.Method)
|
log.Warningf("filter: unsupported bandwidth update method: %d", bwUpdate.Method)
|
||||||
}
|
}
|
||||||
|
@ -664,8 +664,8 @@ func updateBandwidth(ctx context.Context, bwUpdate *packet.BandwidthUpdate) {
|
||||||
conn.HistoryEnabled,
|
conn.HistoryEnabled,
|
||||||
conn.Process().GetID(),
|
conn.Process().GetID(),
|
||||||
conn.ID,
|
conn.ID,
|
||||||
&conn.RecvBytes,
|
conn.BytesReceived,
|
||||||
&conn.SentBytes,
|
conn.BytesSent,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Errorf("firewall: failed to persist bandwidth data: %s", err)
|
log.Errorf("firewall: failed to persist bandwidth data: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,14 +399,14 @@ func (db *Database) UpdateBandwidth(ctx context.Context, enableHistory bool, pro
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := []string{}
|
parts := []string{}
|
||||||
if incoming != nil {
|
if bytesReceived != 0 {
|
||||||
parts = append(parts, "bytes_received = :bytes_received")
|
parts = append(parts, "bytes_received = :bytes_received")
|
||||||
params[":bytes_received"] = *incoming
|
params[":bytes_received"] = bytesReceived
|
||||||
}
|
}
|
||||||
|
|
||||||
if outgoing != nil {
|
if bytesSent != 0 {
|
||||||
parts = append(parts, "bytes_sent = :bytes_sent")
|
parts = append(parts, "bytes_sent = :bytes_sent")
|
||||||
params[":bytes_sent"] = *outgoing
|
params[":bytes_sent"] = bytesSent
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSet := strings.Join(parts, ", ")
|
updateSet := strings.Join(parts, ", ")
|
||||||
|
|
|
@ -178,6 +178,11 @@ type Connection struct { //nolint:maligned // TODO: fix alignment
|
||||||
RecvBytes uint64
|
RecvBytes uint64
|
||||||
SentBytes uint64
|
SentBytes uint64
|
||||||
|
|
||||||
|
// BytesReceived holds the observed received bytes of the connection.
|
||||||
|
BytesReceived uint64
|
||||||
|
// BytesSent holds the observed sent bytes of the connection.
|
||||||
|
BytesSent uint64
|
||||||
|
|
||||||
// pkgQueue is used to serialize packet handling for a single
|
// pkgQueue is used to serialize packet handling for a single
|
||||||
// connection and is served by the connections packetHandler.
|
// connection and is served by the connections packetHandler.
|
||||||
pktQueue chan packet.Packet
|
pktQueue chan packet.Packet
|
||||||
|
|
|
@ -4,10 +4,10 @@ import "fmt"
|
||||||
|
|
||||||
// BandwidthUpdate holds an update to the seen bandwidth of a connection.
|
// BandwidthUpdate holds an update to the seen bandwidth of a connection.
|
||||||
type BandwidthUpdate struct {
|
type BandwidthUpdate struct {
|
||||||
ConnID string
|
ConnID string
|
||||||
RecvBytes uint64
|
BytesReceived uint64
|
||||||
SentBytes uint64
|
BytesSent uint64
|
||||||
Method BandwidthUpdateMethod
|
Method BandwidthUpdateMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
// BandwidthUpdateMethod defines how the bandwidth data of a bandwidth update should be interpreted.
|
// BandwidthUpdateMethod defines how the bandwidth data of a bandwidth update should be interpreted.
|
||||||
|
@ -20,7 +20,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (bu *BandwidthUpdate) String() string {
|
func (bu *BandwidthUpdate) String() string {
|
||||||
return fmt.Sprintf("%s: %dB recv | %dB sent [%s]", bu.ConnID, bu.RecvBytes, bu.SentBytes, bu.Method)
|
return fmt.Sprintf("%s: %dB recv | %dB sent [%s]", bu.ConnID, bu.BytesReceived, bu.BytesSent, bu.Method)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bum BandwidthUpdateMethod) String() string {
|
func (bum BandwidthUpdateMethod) String() string {
|
||||||
|
|
Loading…
Add table
Reference in a new issue