mirror of
https://github.com/safing/portmaster
synced 2025-09-02 02:29:12 +00:00
Fix and improve network database ops
This commit is contained in:
parent
a33808685c
commit
92d41961e0
3 changed files with 25 additions and 34 deletions
|
@ -57,8 +57,7 @@ func cleanConnections() (activePIDs map[int]struct{}) {
|
||||||
// Step 2: mark end
|
// Step 2: mark end
|
||||||
activePIDs[conn.process.Pid] = struct{}{}
|
activePIDs[conn.process.Pid] = struct{}{}
|
||||||
conn.Ended = now
|
conn.Ended = now
|
||||||
// "save"
|
conn.Save()
|
||||||
dbController.PushUpdate(conn)
|
|
||||||
}
|
}
|
||||||
case conn.Ended < deleteOlderThan:
|
case conn.Ended < deleteOlderThan:
|
||||||
// Step 3: delete
|
// Step 3: delete
|
||||||
|
|
|
@ -230,39 +230,31 @@ func (conn *Connection) SaveWhenFinished() {
|
||||||
|
|
||||||
// Save saves the connection in the storage and propagates the change through the database system.
|
// Save saves the connection in the storage and propagates the change through the database system.
|
||||||
func (conn *Connection) Save() {
|
func (conn *Connection) Save() {
|
||||||
if conn.ID == "" {
|
conn.UpdateMeta()
|
||||||
|
|
||||||
// dns request
|
if !conn.KeyIsSet() {
|
||||||
if !conn.KeyIsSet() {
|
if conn.ID == "" {
|
||||||
|
// dns request
|
||||||
|
|
||||||
|
// set key
|
||||||
conn.SetKey(fmt.Sprintf("network:tree/%d/%s", conn.process.Pid, conn.Scope))
|
conn.SetKey(fmt.Sprintf("network:tree/%d/%s", conn.process.Pid, conn.Scope))
|
||||||
conn.UpdateMeta()
|
mapKey := strconv.Itoa(conn.process.Pid) + "/" + conn.Scope
|
||||||
}
|
|
||||||
// save to internal state
|
// save
|
||||||
// check if it already exists
|
dnsConnsLock.Lock()
|
||||||
mapKey := strconv.Itoa(conn.process.Pid) + "/" + conn.Scope
|
|
||||||
dnsConnsLock.Lock()
|
|
||||||
_, ok := dnsConns[mapKey]
|
|
||||||
if !ok {
|
|
||||||
dnsConns[mapKey] = conn
|
dnsConns[mapKey] = conn
|
||||||
}
|
dnsConnsLock.Unlock()
|
||||||
dnsConnsLock.Unlock()
|
} else {
|
||||||
|
// network connection
|
||||||
|
|
||||||
} else {
|
// set key
|
||||||
|
|
||||||
// connection
|
|
||||||
if !conn.KeyIsSet() {
|
|
||||||
conn.SetKey(fmt.Sprintf("network:tree/%d/%s/%s", conn.process.Pid, conn.Scope, conn.ID))
|
conn.SetKey(fmt.Sprintf("network:tree/%d/%s/%s", conn.process.Pid, conn.Scope, conn.ID))
|
||||||
conn.UpdateMeta()
|
|
||||||
}
|
|
||||||
// save to internal state
|
|
||||||
// check if it already exists
|
|
||||||
connsLock.Lock()
|
|
||||||
_, ok := conns[conn.ID]
|
|
||||||
if !ok {
|
|
||||||
conns[conn.ID] = conn
|
|
||||||
}
|
|
||||||
connsLock.Unlock()
|
|
||||||
|
|
||||||
|
// save
|
||||||
|
connsLock.Lock()
|
||||||
|
conns[conn.ID] = conn
|
||||||
|
connsLock.Unlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify database controller
|
// notify database controller
|
||||||
|
|
|
@ -77,7 +77,7 @@ func (s *StorageInterface) processQuery(q *query.Query, it *iterator.Iterator) {
|
||||||
if slashes <= 1 {
|
if slashes <= 1 {
|
||||||
// processes
|
// processes
|
||||||
for _, proc := range process.All() {
|
for _, proc := range process.All() {
|
||||||
if strings.HasPrefix(proc.DatabaseKey(), q.DatabaseKeyPrefix()) {
|
if q.Matches(proc) {
|
||||||
it.Next <- proc
|
it.Next <- proc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,9 +86,9 @@ func (s *StorageInterface) processQuery(q *query.Query, it *iterator.Iterator) {
|
||||||
if slashes <= 2 {
|
if slashes <= 2 {
|
||||||
// dns scopes only
|
// dns scopes only
|
||||||
dnsConnsLock.RLock()
|
dnsConnsLock.RLock()
|
||||||
for _, dnsConns := range dnsConns {
|
for _, dnsConn := range dnsConns {
|
||||||
if strings.HasPrefix(dnsConns.DatabaseKey(), q.DatabaseKeyPrefix()) {
|
if q.Matches(dnsConn) {
|
||||||
it.Next <- dnsConns
|
it.Next <- dnsConn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dnsConnsLock.RUnlock()
|
dnsConnsLock.RUnlock()
|
||||||
|
@ -98,7 +98,7 @@ func (s *StorageInterface) processQuery(q *query.Query, it *iterator.Iterator) {
|
||||||
// connections
|
// connections
|
||||||
connsLock.RLock()
|
connsLock.RLock()
|
||||||
for _, conn := range conns {
|
for _, conn := range conns {
|
||||||
if strings.HasPrefix(conn.DatabaseKey(), q.DatabaseKeyPrefix()) {
|
if q.Matches(conn) {
|
||||||
it.Next <- conn
|
it.Next <- conn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue