@ -6,6 +6,7 @@ package ipn
import (
import (
"errors"
"errors"
"fmt"
"fmt"
"iter"
"net"
"net"
"net/netip"
"net/netip"
"net/url"
"net/url"
@ -564,40 +565,43 @@ func ExpandProxyTargetValue(target string, supportedSchemes []string, defaultSch
return u . String ( ) , nil
return u . String ( ) , nil
}
}
// RangeOverTCPs ranges over both background and foreground TCPs.
// TCPs returns an iterator over both background and foreground TCP
// If the returned bool from the given f is false, then this function stops
// listeners.
// iterating immediately and does not check other foreground configs.
//
func ( v ServeConfigView ) RangeOverTCPs ( f func ( port uint16 , _ TCPPortHandlerView ) bool ) {
// The key is the port number.
func ( v ServeConfigView ) TCPs ( ) iter . Seq2 [ uint16 , TCPPortHandlerView ] {
return func ( yield func ( uint16 , TCPPortHandlerView ) bool ) {
for k , v := range v . TCP ( ) . All ( ) {
for k , v := range v . TCP ( ) . All ( ) {
if ! f ( k , v ) {
if ! yield ( k , v ) {
return
return
}
}
}
}
for _ , conf := range v . Foreground ( ) . All ( ) {
for _ , conf := range v . Foreground ( ) . All ( ) {
for k , v := range conf . TCP ( ) . All ( ) {
for k , v := range conf . TCP ( ) . All ( ) {
if ! f ( k , v ) {
if ! yield ( k , v ) {
return
return
}
}
}
}
}
}
}
}
}
// RangeOverWebs ranges over both background and foreground Webs.
// Webs returns an iterator over both background and foreground Web configurations.
// If the returned bool from the given f is false, then this function stops
func ( v ServeConfigView ) Webs ( ) iter . Seq2 [ HostPort , WebServerConfigView ] {
// iterating immediately and does not check other foreground configs.
return func ( yield func ( HostPort , WebServerConfigView ) bool ) {
func ( v ServeConfigView ) RangeOverWebs ( f func ( HostPort , WebServerConfigView ) bool ) {
for k , v := range v . Web ( ) . All ( ) {
for k , v := range v . Web ( ) . All ( ) {
if ! f ( k , v ) {
if ! yield ( k , v ) {
return
return
}
}
}
}
for _ , conf := range v . Foreground ( ) . All ( ) {
for _ , conf := range v . Foreground ( ) . All ( ) {
for k , v := range conf . Web ( ) . All ( ) {
for k , v := range conf . Web ( ) . All ( ) {
if ! f ( k , v ) {
if ! yield ( k , v ) {
return
return
}
}
}
}
}
}
}
}
}
// FindTCP returns the first TCP that matches with the given port. It
// FindTCP returns the first TCP that matches with the given port. It