safing-portmaster/service/intel/geoip/regions.go
Daniel Hååvi 80664d1a27
Restructure modules ()
* Move portbase into monorepo

* Add new simple module mgr

* [WIP] Switch to new simple module mgr

* Add StateMgr and more worker variants

* [WIP] Switch more modules

* [WIP] Switch more modules

* [WIP] swtich more modules

* [WIP] switch all SPN modules

* [WIP] switch all service modules

* [WIP] Convert all workers to the new module system

* [WIP] add new task system to module manager

* [WIP] Add second take for scheduling workers

* [WIP] Add FIXME for bugs in new scheduler

* [WIP] Add minor improvements to scheduler

* [WIP] Add new worker scheduler

* [WIP] Fix more bug related to new module system

* [WIP] Fix start handing of the new module system

* [WIP] Improve startup process

* [WIP] Fix minor issues

* [WIP] Fix missing subsystem in settings

* [WIP] Initialize managers in constructor

* [WIP] Move module event initialization to constrictors

* [WIP] Fix setting for enabling and disabling the SPN module

* [WIP] Move API registeration into module construction

* [WIP] Update states mgr for all modules

* [WIP] Add CmdLine operation support

* Add state helper methods to module group and instance

* Add notification and module status handling to status package

* Fix starting issues

* Remove pilot widget and update security lock to new status data

* Remove debug logs

* Improve http server shutdown

* Add workaround for cleanly shutting down firewall+netquery

* Improve logging

* Add syncing states with notifications for new module system

* Improve starting, stopping, shutdown; resolve FIXMEs/TODOs

* [WIP] Fix most unit tests

* Review new module system and fix minor issues

* Push shutdown and restart events again via API

* Set sleep mode via interface

* Update example/template module

* [WIP] Fix spn/cabin unit test

* Remove deprecated UI elements

* Make log output more similar for the logging transition phase

* Switch spn hub and observer cmds to new module system

* Fix log sources

* Make worker mgr less error prone

* Fix tests and minor issues

* Fix observation hub

* Improve shutdown and restart handling

* Split up big connection.go source file

* Move varint and dsd packages to structures repo

* Improve expansion test

* Fix linter warnings

* Fix interception module on windows

* Fix linter errors

---------

Co-authored-by: Vladimir Stoilov <vladimir@safing.io>
2024-08-09 18:15:48 +03:00

245 lines
3.7 KiB
Go

package geoip
import (
"github.com/safing/portmaster/base/utils"
)
// IsRegionalNeighbor returns whether the supplied location is a regional neighbor.
func (l *Location) IsRegionalNeighbor(other *Location) bool {
if l.Country.Continent.Region == "" || other.Country.Continent.Region == "" {
return false
}
if region, ok := regions[l.Country.Continent.Region]; ok {
return utils.StringInSlice(region.Neighbors, other.Country.Continent.Region)
}
return false
}
// Region defines a geographic region and neighboring regions.
type Region struct {
ID string
Name string
Neighbors []string
}
var regions = map[string]*Region{
"AF-C": {
ID: "AF-C",
Name: "Africa, Sub-Saharan Africa, Middle Africa",
Neighbors: []string{
"AF-E",
"AF-N",
"AF-S",
"AF-W",
},
},
"AF-E": {
ID: "AF-E",
Name: "Africa, Sub-Saharan Africa, Eastern Africa",
Neighbors: []string{
"AF-C",
"AF-N",
"AF-S",
},
},
"AF-N": {
ID: "AF-N",
Name: "Africa, Northern Africa",
Neighbors: []string{
"AF-C",
"AF-E",
"AF-W",
"AS-W",
"EU-S",
},
},
"AF-S": {
ID: "AF-S",
Name: "Africa, Sub-Saharan Africa, Southern Africa",
Neighbors: []string{
"AF-C",
"AF-E",
"AF-W",
},
},
"AF-W": {
ID: "AF-W",
Name: "Africa, Sub-Saharan Africa, Western Africa",
Neighbors: []string{
"AF-C",
"AF-N",
"AF-S",
},
},
"AN": {
ID: "AN",
Name: "Antarctica",
Neighbors: []string{},
},
"AS-C": {
ID: "AS-C",
Name: "Asia, Central Asia",
Neighbors: []string{
"AS-E",
"AS-S",
"AS-SE",
"AS-W",
},
},
"AS-E": {
ID: "AS-E",
Name: "Asia, Eastern Asia",
Neighbors: []string{
"AS-C",
"AS-S",
"AS-SE",
},
},
"AS-S": {
ID: "AS-S",
Name: "Asia, Southern Asia",
Neighbors: []string{
"AS-C",
"AS-E",
"AS-SE",
"AS-W",
},
},
"AS-SE": {
ID: "AS-SE",
Name: "Asia, South-eastern Asia",
Neighbors: []string{
"AS-C",
"AS-E",
"AS-S",
"OC-C",
"OC-E",
"OC-N",
"OC-S",
},
},
"AS-W": {
ID: "AS-W",
Name: "Asia, Western Asia",
Neighbors: []string{
"AF-N",
"AS-C",
"AS-S",
"EU-E",
},
},
"EU-E": {
ID: "EU-E",
Name: "Europe, Eastern Europe",
Neighbors: []string{
"AS-W",
"EU-N",
"EU-S",
"EU-W",
},
},
"EU-N": {
ID: "EU-N",
Name: "Europe, Northern Europe",
Neighbors: []string{
"EU-E",
"EU-S",
"EU-W",
},
},
"EU-S": {
ID: "EU-S",
Name: "Europe, Southern Europe",
Neighbors: []string{
"AF-N",
"EU-E",
"EU-N",
"EU-W",
},
},
"EU-W": {
ID: "EU-W",
Name: "Europe, Western Europe",
Neighbors: []string{
"EU-E",
"EU-N",
"EU-S",
},
},
"NA-E": {
ID: "NA-E",
Name: "North America, Caribbean",
Neighbors: []string{
"NA-N",
"NA-S",
"SA",
},
},
"NA-N": {
ID: "NA-N",
Name: "North America, Northern America",
Neighbors: []string{
"NA-E",
"NA-N",
"NA-S",
},
},
"NA-S": {
ID: "NA-S",
Name: "North America, Central America",
Neighbors: []string{
"NA-E",
"NA-N",
"NA-S",
"SA",
},
},
"OC-C": {
ID: "OC-C",
Name: "Oceania, Melanesia",
Neighbors: []string{
"AS-SE",
"OC-E",
"OC-N",
"OC-S",
},
},
"OC-E": {
ID: "OC-E",
Name: "Oceania, Polynesia",
Neighbors: []string{
"AS-SE",
"OC-C",
"OC-N",
"OC-S",
},
},
"OC-N": {
ID: "OC-N",
Name: "Oceania, Micronesia",
Neighbors: []string{
"AS-SE",
"OC-C",
"OC-E",
"OC-S",
},
},
"OC-S": {
ID: "OC-S",
Name: "Oceania, Australia and New Zealand",
Neighbors: []string{
"AS-SE",
"OC-C",
"OC-E",
"OC-N",
},
},
"SA": { // TODO: Split up
ID: "SA",
Name: "South America",
Neighbors: []string{
"NA-E",
"NA-S",
},
},
}