This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
205 lines
6.2 KiB
TypeScript
205 lines
6.2 KiB
TypeScript
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
import { useMemo } from "react"
|
|
import {
|
|
CityCode,
|
|
CountryCode,
|
|
ExitNode,
|
|
ExitNodeLocation,
|
|
NodeData,
|
|
} from "src/types"
|
|
import useSWR from "swr"
|
|
|
|
export default function useExitNodes(node: NodeData, filter?: string) {
|
|
const { data } = useSWR<ExitNode[]>("/exit-nodes")
|
|
|
|
const { tailnetNodesSorted, locationNodesMap } = useMemo(() => {
|
|
// First going through exit nodes and splitting them into two groups:
|
|
// 1. tailnetNodes: exit nodes advertised by tailnet's own nodes
|
|
// 2. locationNodes: exit nodes advertised by non-tailnet Mullvad nodes
|
|
let tailnetNodes: ExitNode[] = []
|
|
const locationNodes = new Map<CountryCode, Map<CityCode, ExitNode[]>>()
|
|
|
|
if (!node.Features["use-exit-node"]) {
|
|
// early-return
|
|
return {
|
|
tailnetNodesSorted: tailnetNodes,
|
|
locationNodesMap: locationNodes,
|
|
}
|
|
}
|
|
|
|
data?.forEach((n) => {
|
|
const loc = n.Location
|
|
if (!loc) {
|
|
// 2023-11-15: Currently, if the node doesn't have
|
|
// location information, it is owned by the tailnet.
|
|
// Only Mullvad exit nodes have locations filled.
|
|
tailnetNodes.push({
|
|
...n,
|
|
Name: trimDNSSuffix(n.Name, node.TailnetName),
|
|
})
|
|
return
|
|
}
|
|
const countryNodes =
|
|
locationNodes.get(loc.CountryCode) || new Map<CityCode, ExitNode[]>()
|
|
const cityNodes = countryNodes.get(loc.CityCode) || []
|
|
countryNodes.set(loc.CityCode, [...cityNodes, n])
|
|
locationNodes.set(loc.CountryCode, countryNodes)
|
|
})
|
|
|
|
return {
|
|
tailnetNodesSorted: tailnetNodes.sort(compareByName),
|
|
locationNodesMap: locationNodes,
|
|
}
|
|
}, [data, node.Features, node.TailnetName])
|
|
|
|
const hasFilter = Boolean(filter)
|
|
|
|
const mullvadNodesSorted = useMemo(() => {
|
|
const nodes: ExitNode[] = []
|
|
if (!node.Features["use-exit-node"]) {
|
|
return nodes // early-return
|
|
}
|
|
|
|
// addBestMatchNode adds the node with the "higest priority"
|
|
// match from a list of exit node `options` to `nodes`.
|
|
const addBestMatchNode = (
|
|
options: ExitNode[],
|
|
name: (loc: ExitNodeLocation) => string
|
|
) => {
|
|
const bestNode = highestPriorityNode(options)
|
|
if (!bestNode || !bestNode.Location) {
|
|
return // not possible, doing this for type safety
|
|
}
|
|
nodes.push({
|
|
...bestNode,
|
|
Name: name(bestNode.Location),
|
|
})
|
|
}
|
|
|
|
if (!hasFilter) {
|
|
// When nothing is searched, only show a single best-matching
|
|
// exit node per-country.
|
|
//
|
|
// There's too many location-based nodes to display all of them.
|
|
locationNodesMap.forEach(
|
|
// add one node per country
|
|
(countryNodes) =>
|
|
addBestMatchNode(flattenMap(countryNodes), (loc) => loc.Country)
|
|
)
|
|
} else {
|
|
// Otherwise, show the best match on a city-level,
|
|
// with a "Country: Best Match" node at top.
|
|
//
|
|
// i.e. We allow for discovering cities through searching.
|
|
locationNodesMap.forEach((countryNodes) => {
|
|
countryNodes.forEach(
|
|
// add one node per city
|
|
(cityNodes) =>
|
|
addBestMatchNode(cityNodes, (loc) => `${loc.Country}: ${loc.City}`)
|
|
)
|
|
// add the "Country: Best Match" node
|
|
addBestMatchNode(
|
|
flattenMap(countryNodes),
|
|
(loc) => `${loc.Country}: Best Match`
|
|
)
|
|
})
|
|
}
|
|
|
|
return nodes.sort(compareByName)
|
|
}, [hasFilter, locationNodesMap, node.Features])
|
|
|
|
// Ordered and filtered grouping of exit nodes.
|
|
const exitNodeGroups = useMemo(() => {
|
|
const filterLower = !filter ? undefined : filter.toLowerCase()
|
|
|
|
const selfGroup = {
|
|
id: "self",
|
|
name: undefined,
|
|
nodes: filter
|
|
? []
|
|
: !node.Features["advertise-exit-node"]
|
|
? [noExitNode] // don't show "runAsExitNode" option
|
|
: [noExitNode, runAsExitNode],
|
|
}
|
|
|
|
if (!node.Features["use-exit-node"]) {
|
|
return [selfGroup]
|
|
}
|
|
return [
|
|
selfGroup,
|
|
{
|
|
id: "tailnet",
|
|
nodes: filterLower
|
|
? tailnetNodesSorted.filter((n) =>
|
|
n.Name.toLowerCase().includes(filterLower)
|
|
)
|
|
: tailnetNodesSorted,
|
|
},
|
|
{
|
|
id: "mullvad",
|
|
name: "Mullvad VPN",
|
|
nodes: filterLower
|
|
? mullvadNodesSorted.filter((n) =>
|
|
n.Name.toLowerCase().includes(filterLower)
|
|
)
|
|
: mullvadNodesSorted,
|
|
},
|
|
]
|
|
}, [filter, node.Features, tailnetNodesSorted, mullvadNodesSorted])
|
|
|
|
return { data: exitNodeGroups }
|
|
}
|
|
|
|
// highestPriorityNode finds the highest priority node for use
|
|
// (the "best match" node) from a list of exit nodes.
|
|
// Nodes with equal priorities are picked between arbitrarily.
|
|
function highestPriorityNode(nodes: ExitNode[]): ExitNode | undefined {
|
|
return nodes.length === 0
|
|
? undefined
|
|
: nodes.sort(
|
|
(a, b) => (b.Location?.Priority || 0) - (a.Location?.Priority || 0)
|
|
)[0]
|
|
}
|
|
|
|
// compareName compares two exit nodes alphabetically by name.
|
|
function compareByName(a: ExitNode, b: ExitNode): number {
|
|
if (a.Location && b.Location && a.Location.Country === b.Location.Country) {
|
|
// Always put "<Country>: Best Match" node at top of country list.
|
|
if (a.Name.includes(": Best Match")) {
|
|
return -1
|
|
} else if (b.Name.includes(": Best Match")) {
|
|
return 1
|
|
}
|
|
}
|
|
return a.Name.localeCompare(b.Name)
|
|
}
|
|
|
|
function flattenMap<T, V>(m: Map<T, V[]>): V[] {
|
|
return Array.from(m.values()).reduce((prev, curr) => [...prev, ...curr])
|
|
}
|
|
|
|
// trimDNSSuffix trims the tailnet dns name from s, leaving no
|
|
// trailing dots.
|
|
//
|
|
// trimDNSSuffix("hello.ts.net", "ts.net") = "hello"
|
|
// trimDNSSuffix("hello", "ts.net") = "hello"
|
|
export function trimDNSSuffix(s: string, tailnetDNSName: string): string {
|
|
if (s.endsWith(".")) {
|
|
s = s.slice(0, -1)
|
|
}
|
|
if (s.endsWith("." + tailnetDNSName)) {
|
|
s = s.replace("." + tailnetDNSName, "")
|
|
}
|
|
return s
|
|
}
|
|
|
|
// Neither of these are really "online", but setting this makes them selectable.
|
|
export const noExitNode: ExitNode = { ID: "NONE", Name: "None", Online: true }
|
|
export const runAsExitNode: ExitNode = {
|
|
ID: "RUNNING",
|
|
Name: "Run as exit node",
|
|
Online: true,
|
|
}
|