Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Add InfoOverrides to the Intel data and switch to new source
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Jan 18, 2022
1 parent 2cb3ce1 commit c7ec138
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
2 changes: 1 addition & 1 deletion captain/intel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
7 changes: 5 additions & 2 deletions hub/intel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}

Expand All @@ -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)
}
Expand Down
17 changes: 17 additions & 0 deletions hub/intel_override.go
Original file line number Diff line number Diff line change
@@ -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
}
36 changes: 36 additions & 0 deletions navigator/intel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
3 changes: 2 additions & 1 deletion navigator/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c7ec138

Please sign in to comment.