From c8bd4a0947706c74edb060ef52a95e151bbba63e Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 15 Jun 2026 06:22:22 +0000 Subject: [PATCH] types: remove dead types, constants, and methods --- hscontrol/types/api_key.go | 8 +-- hscontrol/types/common.go | 134 ------------------------------------- hscontrol/types/config.go | 34 ---------- hscontrol/types/const.go | 1 - hscontrol/types/node.go | 4 -- hscontrol/types/routes.go | 3 - hscontrol/types/version.go | 1 - 7 files changed, 2 insertions(+), 183 deletions(-) diff --git a/hscontrol/types/api_key.go b/hscontrol/types/api_key.go index f58a9f31..552acd8b 100644 --- a/hscontrol/types/api_key.go +++ b/hscontrol/types/api_key.go @@ -9,12 +9,8 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" ) -const ( - // NewAPIKeyPrefixLength is the length of the prefix for new API keys. - NewAPIKeyPrefixLength = 12 - // LegacyAPIKeyPrefixLength is the length of the prefix for legacy API keys. - LegacyAPIKeyPrefixLength = 7 -) +// NewAPIKeyPrefixLength is the length of the prefix for new API keys. +const NewAPIKeyPrefixLength = 12 // APIKey describes the datamodel for API keys used to remotely authenticate with // headscale. diff --git a/hscontrol/types/common.go b/hscontrol/types/common.go index ee94593a..3f0802ad 100644 --- a/hscontrol/types/common.go +++ b/hscontrol/types/common.go @@ -12,7 +12,6 @@ import ( "time" "github.com/juanfont/headscale/hscontrol/util" - "tailscale.com/tailcfg" ) const ( @@ -28,139 +27,6 @@ var ( ErrInvalidAuthIDPrefix = errors.New("auth ID has invalid prefix") ) -type StateUpdateType int - -func (su StateUpdateType) String() string { - switch su { - case StateFullUpdate: - return "StateFullUpdate" - case StatePeerChanged: - return "StatePeerChanged" - case StatePeerChangedPatch: - return "StatePeerChangedPatch" - case StatePeerRemoved: - return "StatePeerRemoved" - case StateSelfUpdate: - return "StateSelfUpdate" - case StateDERPUpdated: - return "StateDERPUpdated" - } - - return "unknown state update type" -} - -const ( - StateFullUpdate StateUpdateType = iota - // StatePeerChanged is used for updates that needs - // to be calculated with all peers and all policy rules. - // This would typically be things that include tags, routes - // and similar. - StatePeerChanged - StatePeerChangedPatch - StatePeerRemoved - // StateSelfUpdate is used to indicate that the node - // has changed in control, and the client needs to be - // informed. - // The updated node is inside the ChangeNodes field - // which should have a length of one. - StateSelfUpdate - StateDERPUpdated -) - -// StateUpdate is an internal message containing information about -// a state change that has happened to the network. -// If type is [StateFullUpdate], all fields are ignored. -type StateUpdate struct { - // The type of update - Type StateUpdateType - - // ChangeNodes must be set when Type is StatePeerAdded - // and [StatePeerChanged] and contains the full node - // object for added nodes. - ChangeNodes []NodeID - - // ChangePatches must be set when Type is [StatePeerChangedPatch] - // and contains a populated [tailcfg.PeerChange] object. - ChangePatches []*tailcfg.PeerChange - - // Removed must be set when Type is [StatePeerRemoved] and - // contain a list of the nodes that has been removed from - // the network. - Removed []NodeID - - // DERPMap must be set when Type is [StateDERPUpdated] and - // contain the new DERP Map. - DERPMap *tailcfg.DERPMap - - // Additional message for tracking origin or what being - // updated, useful for ambiguous updates like [StatePeerChanged]. - Message string -} - -// Empty reports if there are any updates in the [StateUpdate]. -func (su *StateUpdate) Empty() bool { - switch su.Type { - case StatePeerChanged: - return len(su.ChangeNodes) == 0 - case StatePeerChangedPatch: - return len(su.ChangePatches) == 0 - case StatePeerRemoved: - return len(su.Removed) == 0 - case StateFullUpdate, StateSelfUpdate, StateDERPUpdated: - // These update types don't have associated data to check, - // so they are never considered empty. - return false - } - - return false -} - -func UpdateFull() StateUpdate { - return StateUpdate{ - Type: StateFullUpdate, - } -} - -func UpdateSelf(nodeID NodeID) StateUpdate { - return StateUpdate{ - Type: StateSelfUpdate, - ChangeNodes: []NodeID{nodeID}, - } -} - -func UpdatePeerChanged(nodeIDs ...NodeID) StateUpdate { - return StateUpdate{ - Type: StatePeerChanged, - ChangeNodes: nodeIDs, - } -} - -func UpdatePeerPatch(changes ...*tailcfg.PeerChange) StateUpdate { - return StateUpdate{ - Type: StatePeerChangedPatch, - ChangePatches: changes, - } -} - -func UpdatePeerRemoved(nodeIDs ...NodeID) StateUpdate { - return StateUpdate{ - Type: StatePeerRemoved, - Removed: nodeIDs, - } -} - -func UpdateExpire(nodeID NodeID, expiry time.Time) StateUpdate { - return StateUpdate{ - Type: StatePeerChangedPatch, - ChangePatches: []*tailcfg.PeerChange{ - { - NodeID: nodeID.NodeID(), - KeyExpiry: &expiry, - }, - }, - } -} - const ( authIDPrefix = "hskey-authreq-" authIDRandomLength = 24 diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index 6a6d59dc..0293918c 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -1354,26 +1354,6 @@ type deprecator struct { fatals set.Set[string] } -// warnWithAlias will register an alias between the newKey and the oldKey, -// and log a deprecation warning if the oldKey is set. -// -//nolint:unused -func (d *deprecator) warnWithAlias(newKey, oldKey string) { - // NOTE: RegisterAlias is called with NEW KEY -> OLD KEY - viper.RegisterAlias(newKey, oldKey) - - if viper.IsSet(oldKey) { - d.warns.Add( - fmt.Sprintf( - "The %q configuration key is deprecated. Please use %q instead. %q will be removed in the future.", - oldKey, - newKey, - oldKey, - ), - ) - } -} - // fatal deprecates and adds an entry to the fatal list of options if the oldKey is set. func (d *deprecator) fatal(oldKey string) { if viper.IsSet(oldKey) { @@ -1450,20 +1430,6 @@ func (d *deprecator) warnNoAlias(newKey, oldKey string) { } } -// warn deprecates and adds an entry to the warn list of options if the oldKey is set. -// -//nolint:unused -func (d *deprecator) warn(oldKey string) { - if viper.IsSet(oldKey) { - d.warns.Add( - fmt.Sprintf( - "The %q configuration key is deprecated and has been removed. Please see the changelog for more details.", - oldKey, - ), - ) - } -} - func (d *deprecator) String() string { var b strings.Builder diff --git a/hscontrol/types/const.go b/hscontrol/types/const.go index 019c14b6..ba15df52 100644 --- a/hscontrol/types/const.go +++ b/hscontrol/types/const.go @@ -11,6 +11,5 @@ const ( JSONLogFormat = "json" TextLogFormat = "text" - KeepAliveInterval = 60 * time.Second MaxHostnameLength = 255 ) diff --git a/hscontrol/types/node.go b/hscontrol/types/node.go index cc0a51d0..260936b4 100644 --- a/hscontrol/types/node.go +++ b/hscontrol/types/node.go @@ -78,10 +78,6 @@ type ( NodeIDs []NodeID ) -func (n NodeIDs) Len() int { return len(n) } -func (n NodeIDs) Less(i, j int) bool { return n[i] < n[j] } -func (n NodeIDs) Swap(i, j int) { n[i], n[j] = n[j], n[i] } - func (id NodeID) StableID() tailcfg.StableNodeID { return tailcfg.StableNodeID(strconv.FormatUint(uint64(id), util.Base10)) } diff --git a/hscontrol/types/routes.go b/hscontrol/types/routes.go index 5f3958f4..ac54f004 100644 --- a/hscontrol/types/routes.go +++ b/hscontrol/types/routes.go @@ -26,6 +26,3 @@ type Route struct { // when the server is up. IsPrimary bool } - -// Deprecated: Approval of routes is denormalised onto the relevant node. -type Routes []Route diff --git a/hscontrol/types/version.go b/hscontrol/types/version.go index 62124db1..ec07a239 100644 --- a/hscontrol/types/version.go +++ b/hscontrol/types/version.go @@ -50,7 +50,6 @@ var GetVersionInfo = sync.OnceValue(func() *VersionInfo { OS: runtime.GOOS, Arch: runtime.GOARCH, }, - Dirty: false, } buildInfo, ok := buildInfo()