diff --git a/captain/intel.go b/captain/intel.go index e7fd5d7..ae74457 100644 --- a/captain/intel.go +++ b/captain/intel.go @@ -15,7 +15,7 @@ import ( var ( intelResource *updater.File - intelResourcePath = "intel/spn/main-intel.dsd" + intelResourcePath = "intel/spn/main-intel.yaml" intelResourceMapName = "main" intelResourceUpdateLock sync.Mutex ) diff --git a/hub/intel.go b/hub/intel.go index 0f98099..90319bf 100644 --- a/hub/intel.go +++ b/hub/intel.go @@ -5,8 +5,8 @@ import ( "fmt" "net" + "github.com/ghodss/yaml" "github.com/safing/jess/lhash" - "github.com/safing/portbase/formats/dsd" "github.com/safing/portmaster/profile/endpoints" ) @@ -33,6 +33,9 @@ type Intel struct { // DestinationHubAdvisory is only taken into account when selecting a Destination Hub. DestinationHubAdvisory []string + // InfoOverrides is used to override certain Hub information. + InfoOverrides map[string]*InfoOverride + parsed *ParsedIntel } @@ -57,7 +60,7 @@ func (i *Intel) Parsed() *ParsedIntel { func ParseIntel(data []byte) (*Intel, error) { // Load data into struct. intel := &Intel{} - _, err := dsd.Load(data, intel) + err := yaml.Unmarshal(data, intel) if err != nil { return nil, fmt.Errorf("failed to parse data: %w", err) } diff --git a/hub/intel_override.go b/hub/intel_override.go new file mode 100644 index 0000000..b12da1f --- /dev/null +++ b/hub/intel_override.go @@ -0,0 +1,17 @@ +package hub + +import "github.com/safing/portmaster/intel/geoip" + +// InfoOverride holds data to overide hub info information. +type InfoOverride struct { + // ContinentCode overrides the continent code of the geoip data. + ContinentCode string + // CountryCode overrides the country code of the geoip data. + CountryCode string + // Coordinates overrides the geo coordinates code of the geoip data. + Coordinates *geoip.Coordinates + // ASN overrides the Autonomous System Number of the geoip data. + ASN uint + // ASOrg overrides the Autonomous System Organization of the geoip data. + ASOrg string +} diff --git a/navigator/intel.go b/navigator/intel.go index 37175ec..e05a2cd 100644 --- a/navigator/intel.go +++ b/navigator/intel.go @@ -27,6 +27,7 @@ func (m *Map) UpdateIntel(update *hub.Intel) error { // go through map for _, pin := range m.all { m.updateIntelStatuses(pin) + m.updateInfoOverrides(pin) } log.Infof("spn/navigator: updated intel on map %s", m.Name) @@ -96,3 +97,38 @@ func checkStatusList(pin *Pin, state PinState, requireTrusted bool, endpointList pin.addStates(state) } } + +func (m *Map) updateInfoOverrides(pin *Pin) { + // Check if Intel data is loaded and if there are any overrides. + if m.intel == nil || m.intel.InfoOverrides == nil { + return + } + + // Get overrides for this pin. + overrides, ok := m.intel.InfoOverrides[pin.Hub.ID] + if !ok { + return + } + + // Apply overrides + if overrides.ContinentCode != "" { + pin.LocationV4.Continent.Code = overrides.ContinentCode + pin.LocationV6.Continent.Code = overrides.ContinentCode + } + if overrides.CountryCode != "" { + pin.LocationV4.Country.ISOCode = overrides.CountryCode + pin.LocationV6.Country.ISOCode = overrides.CountryCode + } + if overrides.Coordinates != nil { + pin.LocationV4.Coordinates = *overrides.Coordinates + pin.LocationV6.Coordinates = *overrides.Coordinates + } + if overrides.ASN != 0 { + pin.LocationV4.AutonomousSystemNumber = overrides.ASN + pin.LocationV6.AutonomousSystemNumber = overrides.ASN + } + if overrides.ASOrg != "" { + pin.LocationV4.AutonomousSystemOrganization = overrides.ASOrg + pin.LocationV6.AutonomousSystemOrganization = overrides.ASOrg + } +} diff --git a/navigator/update.go b/navigator/update.go index 2a66da9..622ee53 100644 --- a/navigator/update.go +++ b/navigator/update.go @@ -170,8 +170,9 @@ func (m *Map) updateHub(h *hub.Hub, lockMap, lockHub bool) { pin.updateStateHasRequiredInfo() pin.updateStateActive(time.Now().Unix()) - // Update Trust and Advisory Statuses. + // Update Trust and Advisory Statuses and Overrides. m.updateIntelStatuses(pin) + m.updateInfoOverrides(pin) // Update Hub cost. pin.Cost = CalculateHubCost(pin.Hub.Status.Load)