geo

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

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

View Source
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

func Categories(dir string) (geosite, geoip []string, err error)

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

func Ensure(dir string) error

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

func EnsureLists(dir string) error

EnsureLists downloads any missing iplist database (panel only, best-effort).

func ParseRef added in v1.1.0

func ParseRef(entry string) (key string, ok bool)

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

func Refresh(dir string) error

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

func RefreshLists(dir string) error

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

func Status(dir string) []FileInfo

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

func StatusLists(dir string) []FileInfo

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

func Groups(dir string) (GroupSet, error)

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

func (g GroupSet) GroupNames() []string

GroupNames returns the "<source>/<group>" keys, sorted — the options the routing UI offers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL