MCPcopy
hub / github.com/windtf/wireproxy / ParseInterface

Function ParseInterface

config.go:253–315  ·  view source on GitHub ↗

ParseInterface parses the [Interface] section and extract the information into `device`

(cfg *ini.File, device *DeviceConfig)

Source from the content-addressed store, hash-verified

251
252// ParseInterface parses the [Interface] section and extract the information into `device`
253func ParseInterface(cfg *ini.File, device *DeviceConfig) error {
254 sections, err := cfg.SectionsByName("Interface")
255 if len(sections) != 1 || err != nil {
256 return errors.New("one and only one [Interface] is expected")
257 }
258 section := sections[0]
259
260 address, err := parseCIDRNetIP(section, "Address")
261 if err != nil {
262 return err
263 }
264
265 device.Endpoint = address
266
267 privKey, err := parseBase64KeyToHex(section, "PrivateKey")
268 if err != nil {
269 return err
270 }
271 device.SecretKey = privKey
272
273 dns, err := parseNetIP(section, "DNS")
274 if err != nil {
275 return err
276 }
277 device.DNS = dns
278
279 if sectionKey, err := section.GetKey("MTU"); err == nil {
280 value, err := sectionKey.Int()
281 if err != nil {
282 return err
283 }
284 device.MTU = value
285 }
286
287 if sectionKey, err := section.GetKey("ListenPort"); err == nil {
288 value, err := sectionKey.Int()
289 if err != nil {
290 return err
291 }
292 device.ListenPort = &value
293 }
294
295 checkAlive, err := parseNetIP(section, "CheckAlive")
296 if err != nil {
297 return err
298 }
299 device.CheckAlive = checkAlive
300
301 device.CheckAliveInterval = 5
302 if sectionKey, err := section.GetKey("CheckAliveInterval"); err == nil {
303 value, err := sectionKey.Int()
304 if err != nil {
305 return err
306 }
307 if len(checkAlive) == 0 {
308 return errors.New("CheckAliveInterval is only valid when CheckAlive is set")
309 }
310

Callers 4

ParseConfigFunction · 0.85

Calls 3

parseCIDRNetIPFunction · 0.85
parseBase64KeyToHexFunction · 0.85
parseNetIPFunction · 0.85