Pull request 1989: AG-24794-client-source

Squashed commit of the following:

commit 5cf83aafc8ddfea15b4f8e9b4061af021727f68c
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 1 14:58:03 2023 +0300

    client: imp code

commit 4325c8f610d1329ad38c800e20275668f1690f51
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Fri Sep 1 14:38:33 2023 +0300

    all: add client source
This commit is contained in:
Stanislav Chzhen
2023-09-01 15:24:44 +03:00
parent 0182b9ec18
commit 905f9615a8
6 changed files with 93 additions and 86 deletions

View File

@@ -1,10 +1,10 @@
package home
import (
"encoding"
"fmt"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/client"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/filtering/safesearch"
"github.com/AdguardTeam/AdGuardHome/internal/whois"
@@ -83,50 +83,6 @@ func (c *Client) setSafeSearch(
return nil
}
// clientSource represents the source from which the information about the
// client has been obtained.
type clientSource uint
// Clients information sources. The order determines the priority.
const (
ClientSourceNone clientSource = iota
ClientSourceWHOIS
ClientSourceARP
ClientSourceRDNS
ClientSourceDHCP
ClientSourceHostsFile
ClientSourcePersistent
)
// type check
var _ fmt.Stringer = clientSource(0)
// String returns a human-readable name of cs.
func (cs clientSource) String() (s string) {
switch cs {
case ClientSourceWHOIS:
return "WHOIS"
case ClientSourceARP:
return "ARP"
case ClientSourceRDNS:
return "rDNS"
case ClientSourceDHCP:
return "DHCP"
case ClientSourceHostsFile:
return "etc/hosts"
default:
return ""
}
}
// type check
var _ encoding.TextMarshaler = clientSource(0)
// MarshalText implements encoding.TextMarshaler for the clientSource.
func (cs clientSource) MarshalText() (text []byte, err error) {
return []byte(cs.String()), nil
}
// RuntimeClient is a client information about which has been obtained using the
// source described in the Source field.
type RuntimeClient struct {
@@ -138,5 +94,5 @@ type RuntimeClient struct {
// Source is the source from which the information about the client has
// been obtained.
Source clientSource
Source client.Source
}