buildProviderRouter constructs a router snapshot from a classified provider reload. Only providers with Status == aibridged.ProviderStatusEnabled are included in the active routing tables; the refresh function is responsible for classifying disabled and errored rows. First entry wins on duplicate ho
(reload ProviderReload, allowedPorts []string)
| 119 | // defense-in-depth measure even though the refresh function should |
| 120 | // mark duplicates as errors. |
| 121 | func buildProviderRouter(reload ProviderReload, allowedPorts []string) (*providerRouter, error) { |
| 122 | nameByHost := make(map[string]string, len(reload.Providers)) |
| 123 | domains := make([]string, 0, len(reload.Providers)) |
| 124 | for _, p := range reload.Providers { |
| 125 | if p.Status != aibridged.ProviderStatusEnabled { |
| 126 | continue |
| 127 | } |
| 128 | host := strings.ToLower(p.Host) |
| 129 | if host == "" { |
| 130 | continue |
| 131 | } |
| 132 | if _, exists := nameByHost[host]; exists { |
| 133 | continue |
| 134 | } |
| 135 | nameByHost[host] = p.Name |
| 136 | domains = append(domains, host) |
| 137 | } |
| 138 | mitmHosts, err := convertDomainsToHosts(domains, allowedPorts) |
| 139 | if err != nil { |
| 140 | return nil, err |
| 141 | } |
| 142 | return &providerRouter{mitmHosts: mitmHosts, nameByHost: nameByHost}, nil |
| 143 | } |