summaryrefslogtreecommitdiffhomepage
path: root/types
AgeCommit message (Collapse)AuthorFilesLines
2024-11-11all: use iterators over slice views moreBrad Fitzpatrick1-8/+7
This gets close to all of the remaining ones. Updates #12912 Change-Id: I9c672bbed2654a6c5cab31e0cbece6c107d8c6fa Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-11-05types/result, util/lineiter: add package for a result type, use itBrad Fitzpatrick1-0/+49
This adds a new generic result type (motivated by golang/go#70084) to try it out, and uses it in the new lineutil package (replacing the old lineread package), changing that package to return iterators: sometimes over []byte (when the input is all in memory), but sometimes iterators over results of []byte, if errors might happen at runtime. Updates #12912 Updates golang/go#70084 Change-Id: Iacdc1070e661b5fb163907b1e8b07ac7d51d3f83 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-10-30util/syspolicy/setting: make setting.RawItem JSON-marshallableNick Khyl1-1/+1
We add setting.RawValue, a new type that facilitates unmarshalling JSON numbers and arrays as uint64 and []string (instead of float64 and []any) for policy setting values. We then use it to make setting.RawItem JSON-marshallable and update the tests. Updates #12687 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2024-10-11types/bools: add Compare to compare boolean values (#13792)Joe Tsai2-0/+38
The bools.Compare function compares boolean values by reporting -1, 0, +1 for ordering so that it can be easily used with slices.SortFunc. Updates #cleanup Updates tailscale/corp#11038 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2024-10-09types/views: add iterators to the three Map view typesBrad Fitzpatrick2-0/+77
Their callers using Range are all kinda clunky feeling. Iterators should make them more readable. Updates #12912 Change-Id: I93461eba8e735276fda4a8558a4ae4bfd6c04922 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-10-07types/lazy: add DeferredInit typeNick Hill2-0/+375
It is sometimes necessary to defer initialization steps until the first actual usage or until certain prerequisites have been met. For example, policy setting and policy source registration should not occur during package initialization. Instead, they should be deferred until the syspolicy package is actually used. Additionally, any errors should be properly handled and reported, rather than causing a panic within the package's init function. In this PR, we add DeferredInit, to facilitate the registration and invocation of deferred initialization functions. Updates #12687 Signed-off-by: Nick Hill <mykola.khyl@gmail.com>
2024-10-07types/key: use tlpub: in error message (#13707)Erisa A1-3/+3
Fixes tailscale/corp#19442 Signed-off-by: Erisa A <erisa@tailscale.com>
2024-09-24cli: add `tailscale dns query` (#13368)Andrea Gottardo1-0/+84
Updates tailscale/tailscale#13326 Adds a CLI subcommand to perform DNS queries using the internal DNS forwarder and observe its internals (namely, which upstream resolvers are being used). Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
2024-09-20types/views: add SliceView.All iterator (#13536)Joe Tsai2-0/+43
And convert a all relevant usages. Updates #12912 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2024-08-26types/opt: add BoolFlag for setting Bool value as a flagWill Norris2-0/+63
Updates tailscale/corp#22578 Signed-off-by: Will Norris <will@tailscale.com>
2024-08-22types/views: add Slice.All iteratorBrad Fitzpatrick2-0/+26
And convert a few callers as an example, but nowhere near all. Updates #12912 Change-Id: I5eaa12a29a6cd03b58d6f1072bd27bc0467852f2 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-08-21types/prefs: add a package containing generic preference typesNick Khyl14-0/+2877
This adds a new package containing generic types to be used for defining preference hierarchies. These include prefs.Item, prefs.List, prefs.StructList, and prefs.StructMap. Each of these types represents a configurable preference, holding the preference's state, value, and metadata. The metadata includes the default value (if it differs from the zero value of the Go type) and flags indicating whether a preference is managed via syspolicy or is hidden/read-only for another reason. This information can be marshaled and sent to the GUI, CLI and web clients as a source of truth regarding preference configuration, management, and visibility/mutability states. We plan to use these types to define device preferences, such as the updater preferences, the permission mode to be used on Windows with #tailscale/corp#18342, and certain global options that are currently exposed as tailscaled flags. We also aim to eventually use these types for profile-local preferences in ipn.Prefs and and as a replacement for ipn.MaskedPrefs. The generic preference types are compatible with the tailscale.com/cmd/viewer and tailscale.com/cmd/cloner utilities. Updates #12736 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2024-07-24types/lazy: re-init SyncValue during test cleanup if it wasn't set before ↵Nick Khyl2-3/+23
SetForTest Updates #12687 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2024-07-22types/lazy: add (*SyncValue[T]).SetForTest methodNick Khyl2-0/+223
It is sometimes necessary to change a global lazy.SyncValue for the duration of a test. This PR adds a (*SyncValue[T]).SetForTest method to facilitate that. Updates #12687 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2024-07-19types/opt: add (Value[T]).GetOr(def T) T methodNick Khyl1-0/+8
Updates #12736 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2024-07-19cmd/viewer, types/views, util/codegen: add viewer support for custom ↵Nick Khyl2-0/+274
container types This adds support for container-like types such as Container[T] that don't explicitly specify a view type for T. Instead, a package implementing a container type should also implement and export a ContainerView[T, V] type and a ContainerViewOf(*Container[T]) ContainerView[T, V] function, which returns a view for the specified container, inferring the element view type V from the element type T. Updates #12736 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2024-07-10all: add test for package comments, fix, add comments as neededBrad Fitzpatrick1-0/+6
Updates #cleanup Change-Id: Ic4304e909d2131a95a38b26911f49e7b1729aaef Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-07-08types/opt: add generic Value[T any] for optional values of any typesNick Khyl2-0/+418
Updates #12736 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2024-06-24types/lazy: add Peek method to SyncValueAndrew Dunham2-5/+114
This adds the ability to "peek" at the value of a SyncValue, so that it's possible to observe a value without computing this. Updates tailscale/corp#17122 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I06f88c22a1f7ffcbc7ff82946335356bb0ef4622
2024-06-17types/logid: add Add method (#12478)Joe Tsai2-0/+128
The Add method derives a new ID by adding a signed integer to the ID, treating it as an unsigned 256-bit big-endian integer. We also add Less and Compare methods to PrivateID to provide feature parity with existing methods on PublicID. Updates tailscale/corp#11038 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2024-06-16net/ipset, wgengine/filter/filtertype: add split-out packagesBrad Fitzpatrick1-2/+2
This moves NewContainsIPFunc from tsaddr to new ipset package. And wgengine/filter types gets split into wgengine/filter/filtertype, so netmap (and thus the CLI, etc) doesn't need to bring in ipset, bart, etc. Then add a test making sure the CLI deps don't regress. Updates #1278 Change-Id: Ia246d6d9502bbefbdeacc4aef1bed9c8b24f54d5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-06-15cmd/viewer,type/views: add MapSlice for maps of slicesMaisem Ali1-5/+98
This abstraction provides a nicer way to work with maps of slices without having to write out three long type params. This also allows it to provide an AsMap implementation which copies the map and the slices at least. Updates tailscale/corp#20910 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2024-05-17ipn,wgengine: remove vestigial Prefs.AllowSingleHostsBrad Fitzpatrick1-1/+1
It was requested by the first customer 4-5 years ago and only used for a brief moment of time. We later added netmap visibility trimming which removes the need for this. It's been hidden by the CLI for quite some time and never documented anywhere else. This keeps the CLI flag, though, out of caution. It just returns an error if it's set to anything but true (its default). Fixes #12058 Change-Id: I7514ba572e7b82519b04ed603ff9f3bdbaecfda7 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-05-11types/views: move AsMap to Map from *MapMaisem Ali1-2/+2
This was a typo in 2e19790f611cd15d603eac35bae46cb3c707ef85. It should have been on `Map` and not on `*Map` as otherwise it doesn't allow for chaining like `someView.SomeMap().AsMap()` and requires first assigning it to a variable. Updates #typo Signed-off-by: Maisem Ali <maisem@tailscale.com>
2024-05-03types/views: add AppendStrings util funcMaisem Ali1-0/+9
Updates tailscale/corp#19623 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2024-05-03types/views: remove duplicate SliceContainsFuncMaisem Ali2-13/+1
We already have `(Slice[T]).ContainsFunc`. Updates #cleanup Signed-off-by: Maisem Ali <maisem@tailscale.com>
2024-04-30types/views: use slices.Contains{,Func}Brad Fitzpatrick1-12/+2
Updates #8419 Change-Id: Ib1a9cb3fb425284b7e02684072a4e7a35975f35c Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-04-21types/persist: remove unused field Persist.ProviderBrad Fitzpatrick4-16/+1
It was only obviously unused after the previous change, c39cde79d. Updates #19334 Change-Id: I9896d5fa692cb4346c070b4a339d0d12340c18f7 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-04-16all: use Go 1.22 range-over-intBrad Fitzpatrick11-18/+18
Updates #11058 Change-Id: I35e7ef9b90e83cac04ca93fd964ad00ed5b48430 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-03-22ipn/ipnlocal, types/netmap: replace hasCapability with set lookup on NetworkMapBrad Fitzpatrick1-0/+7
When node attributes were super rare, the O(n) slice scans looking for node attributes was more acceptable. But now more code and more users are using increasingly more node attributes. Time to make it a map. Noticed while working on tailscale/corp#17879 Updates #cleanup Change-Id: Ic17c80341f418421002fbceb47490729048756d2 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-03-21control/controlclient: fix panic regression from earlier load balancer hint ↵Brad Fitzpatrick1-0/+21
header In the recent 20e9f3369 we made HealthChangeRequest machine requests include a NodeKey, as it was the oddball machine request that didn't include one. Unfortunately, that code was sometimes being called (at least in some of our integration tests) without a node key due to its registration with health.RegisterWatcher(direct.ReportHealthChange). Fortunately tests in corp caught this before we cut a release. It's possible this only affects this particular integration test's environment, but still worth fixing. Updates tailscale/corp#1297 Change-Id: I84046779955105763dc1be5121c69fec3c138672 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-03-18types/views: optimize slices contains under some conditions (#11449)James Tucker1-6/+6
In control there are conditions where the leaf functions are not being optimized away (i.e. At is not inlined), resulting in undesirable time spent copying during SliceContains. This optimization is likely irrelevant to simpler code or smaller structures. Updates #optimization Signed-off-by: James Tucker <james@tailscale.com>
2024-03-07cmd/derper, types/logger: move log filter to shared packageAndrew Dunham2-0/+43
So we can use it in trunkd to quiet down the logs there. Updates #5563 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: Ie3177dc33f5ad103db832aab5a3e0e4f128f973f
2024-02-26types/key: remove copy returning array by valueBrad Fitzpatrick1-4/+3
It's unnecessary. Returning an array value is already a copy. Updates #cleanup Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: If7f350b61003ea08f16a531b7b4e8ae483617939
2024-02-25all: remove LenIter, use Go 1.22 range-over-int insteadBrad Fitzpatrick2-36/+0
Updates #11058 Updates golang/go#65685 Change-Id: Ibb216b346e511d486271ab3d84e4546c521e4e22 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-02-12types/views: add test that LenIter doesn't allocateBrad Fitzpatrick1-0/+9
For a second we thought this was allocating but we were looking at a CPU profile (which showed calls to mallocgc view makeslice) instead of the alloc profile. Updates golang/go#65685 (which if fixed wouldn't have confused us) Change-Id: Ic0132310d52d8a65758a516142525339aa23b1ed Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-02-11tailcfg: remove UserProfile.GroupsMaisem Ali2-7/+6
Removing as per go/group-all-the-things. Updates tailscale/corp#17445 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2024-02-08all: use new AppendEncode methods available in Go 1.22 (#11079)Joe Tsai2-21/+5
Updates #cleanup Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2024-02-08all: use reflect.TypeFor now available in Go 1.22 (#11078)Joe Tsai4-5/+5
Updates #cleanup Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2024-02-06types/views: add SliceMapKey[T]Maisem Ali2-0/+70
views.Slice are meant to be immutable, and if used as such it is at times desirable to use them as a key in a map. For non-viewed slices it was kinda doable by creating a custom key struct but views.Slice didn't allow for the same so add a method to create that struct here. Updates tailscale/corp#17122 Signed-off-by: Maisem Ali <maisem@tailscale.com>
2024-01-23wgengine/magicsock: implement probing of UDP path lifetime (#10844)Jordan Whited1-0/+9
This commit implements probing of UDP path lifetime on the tail end of an active direct connection. Probing configuration has two parts - Cliffs, which are various timeout cliffs of interest, and CycleCanStartEvery, which limits how often a probing cycle can start, per-endpoint. Initially a statically defined default configuration will be used. The default configuration has cliffs of 10s, 30s, and 60s, with a CycleCanStartEvery of 24h. Probing results are communicated via clientmetric counters. Probing is off by default, and can be enabled via control knob. Probing is purely informational and does not yet drive any magicsock behaviors. Updates #540 Signed-off-by: Jordan Whited <jordan@tailscale.com>
2024-01-17appc,ipn/ipnlocal,types/appctype: implement control provided routesJames Tucker1-0/+2
Control can now send down a set of routes along with the domains, and the routes will be advertised, with any newly overlapped routes being removed to reduce the size of the routing table. Fixes tailscale/corp#16833 Signed-off-by: James Tucker <james@tailscale.com>
2024-01-16all: make use of ctxkey everywhere (#10846)Joe Tsai1-8/+12
Also perform minor cleanups on the ctxkey package itself. Provide guidance on when to use ctxkey.Key[T] over ctxkey.New. Also, allow for interface kinds because the value wrapping trick also happens to fix edge cases with interfaces in Go. Updates #cleanup Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2024-01-05controlclient,tailcfg,types: expose MaxKeyDuration via localapi (#10401)James 'zofrex' Sanderson3-2/+6
Updates tailscale/corp#16016 Signed-off-by: James Sanderson <jsanderson@tailscale.com>
2023-12-19util/cmpx: remove code that's in the stdlib nowAndrew Dunham2-4/+4
The cmpx.Compare function (and associated interface) are now available in the standard library as cmp.Compare. Remove our version of it and use the version from the standard library. Updates #cleanup Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: I4be3ac63d466c05eb7a0babb25cb0d41816fbd53
2023-12-18ipn: apply tailnet-wide default for auto-updates (#10508)Andrew Lytvynov3-1/+12
When auto-update setting in local Prefs is unset, apply the tailnet default value from control. This only happens once, when we apply the default (or when the user manually overrides it), tailnet default no longer affects the node. Updates #16244 Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
2023-11-22appc,ipn/local: support wildcard when matching app-connectorsTom DNetto1-1/+2
Updates: ENG-2453 Signed-off-by: Tom DNetto <tom@tailscale.com>
2023-11-17ipn/ipnlocal,cmd/tailscale: persist tailnet name in user profileMarwan Sulaiman1-0/+10
This PR starts to persist the NetMap tailnet name in SetPrefs so that tailscaled clients can use this value to disambiguate fast user switching from one tailnet to another that are under the same exact login. We will also try to backfill this information during backend starts and profile switches so that users don't have to re-authenticate their profile. The first client to use this new information is the CLI in 'tailscale switch -list' which now uses text/tabwriter to display the ID, Tailnet, and Account. Since account names are ambiguous, we allow the user to pass 'tailscale switch ID' to specify the exact tailnet they want to switch to. Updates #9286 Signed-off-by: Marwan Sulaiman <marwan@tailscale.com>
2023-11-17control/controlclient: support incremental packet filter updates [capver 81]Brad Fitzpatrick1-0/+1
Updates #10299 Change-Id: I87e4235c668a1db7de7ef1abc743f0beecb86d3d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-11-15types/appctype: correct app-connector cap name in documentationJames Tucker1-1/+1
Updates #cleanup Signed-off-by: James Tucker <james@tailscale.com>