(config *AgentConfig, opts ...AgentOption)
| 193 | } |
| 194 | |
| 195 | func newAgentFromConfig(config *AgentConfig, opts ...AgentOption) (*Agent, error) { |
| 196 | if config == nil { |
| 197 | config = &AgentConfig{} |
| 198 | } |
| 199 | |
| 200 | agent, err := createAgentBase(config) |
| 201 | if err != nil { |
| 202 | return nil, err |
| 203 | } |
| 204 | |
| 205 | agent.localUfrag = config.LocalUfrag |
| 206 | agent.localPwd = config.LocalPwd |
| 207 | if config.NAT1To1IPs != nil { |
| 208 | if err := validateLegacyNAT1To1IPs(config.NAT1To1IPs); err != nil { |
| 209 | return nil, err |
| 210 | } |
| 211 | |
| 212 | typ := CandidateTypeHost |
| 213 | if config.NAT1To1IPCandidateType != CandidateTypeUnspecified { |
| 214 | typ = config.NAT1To1IPCandidateType |
| 215 | } |
| 216 | |
| 217 | rules, err := legacyNAT1To1Rules(config.NAT1To1IPs, typ) |
| 218 | if err != nil { |
| 219 | return nil, err |
| 220 | } |
| 221 | agent.addressRewriteRules = rules |
| 222 | } |
| 223 | |
| 224 | return newAgentWithConfig(agent, opts...) |
| 225 | } |
| 226 | |
| 227 | func validateLegacyNAT1To1IPs(ips []string) error { |
| 228 | var hasIPv4CatchAll, hasIPv6CatchAll bool |
searching dependent graphs…