mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-17 22:29:54 +00:00
[client] iOS: structured ResolvedIPs collection for domain routes (#6090)
* [client] iOS: structured ResolvedIPs collection for domain routes Replace comma-joined ResolvedIPs string with a gomobile-friendly ResolvedIPs collection (Add/Get/Size), mirroring the Android bridge in client/android/network_domains.go. This allows the iOS app to match domain-route resolved IPs against connected peer routes without parsing CSV strings, fixing the route status indicator for dynamic (DNS) routes. * [client] iOS: align dynamic route exposure with Android bridge For dynamic (DNS) routes the Swift side previously received "invalid Prefix" as the Network value, forcing UI code to special-case that sentinel. The Android bridge uses Domains.SafeString() instead so peer.routes entries (which also derive from Domains.SafeString()) match directly. Mirror that here. Also fix the resolved IP lookup: resolvedDomains is keyed by the resolved domain (e.g. api.ipify.org), not the configured pattern (e.g. *.ipify.org). Group entries by ParentDomain like the daemon does in client/server/network.go, so wildcard route patterns get their resolved IPs populated.
This commit is contained in:
@@ -413,25 +413,40 @@ func (c *Client) GetRoutesSelectionDetails() (*RoutesSelectionDetails, error) {
|
|||||||
func prepareRouteSelectionDetails(routes []*selectRoute, resolvedDomains map[domain.Domain]peer.ResolvedDomainInfo) *RoutesSelectionDetails {
|
func prepareRouteSelectionDetails(routes []*selectRoute, resolvedDomains map[domain.Domain]peer.ResolvedDomainInfo) *RoutesSelectionDetails {
|
||||||
var routeSelection []RoutesSelectionInfo
|
var routeSelection []RoutesSelectionInfo
|
||||||
for _, r := range routes {
|
for _, r := range routes {
|
||||||
domainList := make([]DomainInfo, 0)
|
// resolvedDomains is keyed by the resolved domain (e.g. api.ipify.org),
|
||||||
|
// not the configured pattern (e.g. *.ipify.org). Group entries whose
|
||||||
|
// ParentDomain belongs to this route, mirroring the daemon logic in
|
||||||
|
// client/server/network.go.
|
||||||
|
domainList := make([]DomainInfo, 0, len(r.Domains))
|
||||||
|
domainIndex := make(map[domain.Domain]int, len(r.Domains))
|
||||||
for _, d := range r.Domains {
|
for _, d := range r.Domains {
|
||||||
domainResp := DomainInfo{
|
domainIndex[d] = len(domainList)
|
||||||
Domain: d.SafeString(),
|
domainList = append(domainList, DomainInfo{Domain: d.SafeString()})
|
||||||
}
|
|
||||||
|
|
||||||
if info, exists := resolvedDomains[d]; exists {
|
|
||||||
var ipStrings []string
|
|
||||||
for _, prefix := range info.Prefixes {
|
|
||||||
ipStrings = append(ipStrings, prefix.Addr().String())
|
|
||||||
}
|
|
||||||
domainResp.ResolvedIPs = strings.Join(ipStrings, ", ")
|
|
||||||
}
|
|
||||||
domainList = append(domainList, domainResp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, info := range resolvedDomains {
|
||||||
|
idx, ok := domainIndex[info.ParentDomain]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, prefix := range info.Prefixes {
|
||||||
|
domainList[idx].AddResolvedIP(prefix.Addr().String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
domainDetails := DomainDetails{items: domainList}
|
domainDetails := DomainDetails{items: domainList}
|
||||||
|
|
||||||
|
// For dynamic (DNS) routes, expose the joined domain pattern as the
|
||||||
|
// Network value so it matches the peer.routes entries on the Swift
|
||||||
|
// side (mirroring the Android bridge in client/android/client.go).
|
||||||
|
netStr := r.Network.String()
|
||||||
|
if len(r.Domains) > 0 {
|
||||||
|
netStr = r.Domains.SafeString()
|
||||||
|
}
|
||||||
|
|
||||||
routeSelection = append(routeSelection, RoutesSelectionInfo{
|
routeSelection = append(routeSelection, RoutesSelectionInfo{
|
||||||
ID: r.NetID,
|
ID: r.NetID,
|
||||||
Network: r.Network.String(),
|
Network: netStr,
|
||||||
Domains: &domainDetails,
|
Domains: &domainDetails,
|
||||||
Selected: r.Selected,
|
Selected: r.Selected,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -34,7 +34,34 @@ type DomainDetails struct {
|
|||||||
|
|
||||||
type DomainInfo struct {
|
type DomainInfo struct {
|
||||||
Domain string
|
Domain string
|
||||||
ResolvedIPs string
|
resolvedIPs ResolvedIPs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DomainInfo) AddResolvedIP(ipAddress string) {
|
||||||
|
d.resolvedIPs.Add(ipAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DomainInfo) GetResolvedIPs() *ResolvedIPs {
|
||||||
|
return &d.resolvedIPs
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResolvedIPs struct {
|
||||||
|
items []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ResolvedIPs) Add(ipAddress string) {
|
||||||
|
r.items = append(r.items, ipAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ResolvedIPs) Get(i int) string {
|
||||||
|
if i < 0 || i >= len(r.items) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return r.items[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *ResolvedIPs) Size() int {
|
||||||
|
return len(r.items)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new PeerInfo to the collection
|
// Add new PeerInfo to the collection
|
||||||
|
|||||||
Reference in New Issue
Block a user