This commit is contained in:
Vladimir Stoilov
2022-09-20 11:23:21 +02:00
committed by Daniel
parent b4e2687884
commit ddfa3722be
7 changed files with 64 additions and 57 deletions

View File

@@ -446,9 +446,9 @@ func GetConnection(id string) (*Connection, bool) {
return conns.get(id)
}
// GetAllIDs Get all connection IDs.
func GetAllIDs() []string {
return append(conns.keys(), dnsConns.keys()...)
// GetAllConnections Gets all connection.
func GetAllConnections() []*Connection {
return append(conns.list(), dnsConns.list()...)
}
// SetLocalIP sets the local IP address together with its network scope. The
@@ -524,14 +524,17 @@ func (conn *Connection) Failed(reason, reasonOptionKey string) {
func (conn *Connection) SetVerdict(newVerdict Verdict, reason, reasonOptionKey string, reasonCtx interface{}) (ok bool) {
conn.SetVerdictDirectly(newVerdict)
conn.Reason.Msg = reason
conn.Reason.Context = reasonCtx
// Only set if it matches the user verdict. For a consistent reason
if newVerdict == conn.Verdict.User {
conn.Reason.Msg = reason
conn.Reason.Context = reasonCtx
conn.Reason.OptionKey = ""
conn.Reason.Profile = ""
if reasonOptionKey != "" && conn.Process() != nil {
conn.Reason.OptionKey = reasonOptionKey
conn.Reason.Profile = conn.Process().Profile().GetProfileSource(conn.Reason.OptionKey)
conn.Reason.OptionKey = ""
conn.Reason.Profile = ""
if reasonOptionKey != "" && conn.Process() != nil {
conn.Reason.OptionKey = reasonOptionKey
conn.Reason.Profile = conn.Process().Profile().GetProfileSource(conn.Reason.OptionKey)
}
}
return true

View File

@@ -48,18 +48,15 @@ func (cs *connectionStore) clone() map[string]*Connection {
return m
}
func (cs *connectionStore) keys() []string {
func (cs *connectionStore) list() []*Connection {
cs.rw.RLock()
defer cs.rw.RUnlock()
keys := make([]string, len(cs.items))
i := 0
for key := range cs.items {
keys[i] = key
i++
l := []*Connection{}
for _, conn := range cs.items {
l = append(l, conn)
}
return keys
return l
}
func (cs *connectionStore) len() int { //nolint:unused // TODO: Clean up if still unused.