Documentation
¶
Overview ¶
Package geo manages the geoip.dat / geosite.dat databases Xray needs to resolve geosite:/geoip: routing rules. They live in an asset dir pointed at by XRAY_LOCATION_ASSET.
Index ¶
- Constants
- func Categories(dir string) (geosite, geoip []string, err error)
- func Ensure(dir string) error
- func EnsureLists(dir string) error
- func ParseRef(entry string) (key string, ok bool)
- func Refresh(dir string) error
- func RefreshLists(dir string) error
- type FileInfo
- type GroupRules
- type GroupSet
Constants ¶
const RefPrefix = "iplist:"
RefPrefix marks a routing entry that names an iplist group rather than a literal matcher: "iplist:<source>/<group>", e.g. "iplist:global/youtube" or "iplist:russia/vk". The same ref means different things by the field it sits in — in a domain list it expands to the group's domains, in an IP list to its CIDRs — mirroring how geosite:/geoip: already divide.
Variables ¶
This section is empty.
Functions ¶
func Categories ¶
Categories parses the category names out of geosite.dat and geoip.dat in dir. Both files are v2ray's GeoSiteList/GeoIPList protobuf: a flat sequence of length-delimited entries (field 1), each whose first field (1) is the uppercase category code (string). We only need that code, so a tiny reader avoids pulling in the full xray proto. Codes are returned lowercased + sorted.
func Ensure ¶
Ensure downloads any missing Xray asset database into dir (best-effort). Existing files are left as-is; refresh is handled separately.
func EnsureLists ¶ added in v1.1.0
EnsureLists downloads any missing iplist database (panel only, best-effort).
func ParseRef ¶ added in v1.1.0
ParseRef splits an "iplist:<source>/<group>" entry into its lookup key ("<source>/<group>"). ok is false for anything that is not such a ref, so callers can pass unrecognised entries through untouched.
func Refresh ¶
Refresh re-downloads every Xray asset database into dir regardless of whether it already exists, pulling the latest published version. It attempts all files and returns the first error encountered.
func RefreshLists ¶ added in v1.1.0
RefreshLists re-downloads the iplist databases (panel only).
Types ¶
type FileInfo ¶
type FileInfo struct {
Name string `json:"name"`
Present bool `json:"present"`
Size int64 `json:"size"`
ModifiedAt int64 `json:"modified_at"` // unix seconds ≈ last successful download
}
FileInfo is the on-disk state of one geo database (for the settings UI).
func Status ¶
Status returns metadata for the Xray asset databases in dir. The file mtime doubles as the "last downloaded" timestamp (download writes atomically via rename).
func StatusLists ¶ added in v1.1.0
StatusLists returns metadata for the iplist databases (panel only).
type GroupRules ¶ added in v1.1.0
type GroupRules struct {
Domains []string `json:"domains"`
IPs []string `json:"ips"` // cidr4 + cidr6
}
GroupRules is one iplist group's merged rule data: every domain and every CIDR belonging to any site in the group.
type GroupSet ¶ added in v1.1.0
type GroupSet map[string]GroupRules
GroupSet maps "<source>/<group>" to its rules.
func Groups ¶ added in v1.1.0
Groups parses the iplist databases in dir into their groups. A source whose file is missing or unreadable is skipped rather than failing the whole set, so one dead service does not take the other's groups down with it; an error is returned only when no source yielded anything.
func (GroupSet) GroupNames ¶ added in v1.1.0
GroupNames returns the "<source>/<group>" keys, sorted — the options the routing UI offers.