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

Function ParsePeers

config.go:318–369  ·  view source on GitHub ↗

ParsePeers parses the [Peer] section and extract the information into `peers`

(cfg *ini.File, peers *[]PeerConfig)

Source from the content-addressed store, hash-verified

316
317// ParsePeers parses the [Peer] section and extract the information into `peers`
318func ParsePeers(cfg *ini.File, peers *[]PeerConfig) error {
319 sections, err := cfg.SectionsByName("Peer")
320 if len(sections) < 1 || err != nil {
321 return errors.New("at least one [Peer] is expected")
322 }
323
324 for _, section := range sections {
325 peer := PeerConfig{
326 PreSharedKey: "0000000000000000000000000000000000000000000000000000000000000000",
327 KeepAlive: 0,
328 }
329
330 decoded, err := parseBase64KeyToHex(section, "PublicKey")
331 if err != nil {
332 return err
333 }
334 peer.PublicKey = decoded
335
336 if sectionKey, err := section.GetKey("PreSharedKey"); err == nil {
337 value, err := encodeBase64ToHex(sectionKey.String())
338 if err != nil {
339 return err
340 }
341 peer.PreSharedKey = value
342 }
343
344 if sectionKey, err := section.GetKey("Endpoint"); err == nil {
345 value := sectionKey.String()
346 decoded, err = resolveIPPAndPort(strings.ToLower(value))
347 if err != nil {
348 return err
349 }
350 peer.Endpoint = &decoded
351 }
352
353 if sectionKey, err := section.GetKey("PersistentKeepalive"); err == nil {
354 value, err := sectionKey.Int()
355 if err != nil {
356 return err
357 }
358 peer.KeepAlive = value
359 }
360
361 peer.AllowedIPs, err = parseAllowedIPs(section)
362 if err != nil {
363 return err
364 }
365
366 *peers = append(*peers, peer)
367 }
368 return nil
369}
370
371func parseTCPClientTunnelConfig(section *ini.Section) (RoutineSpawner, error) {
372 config := &TCPClientTunnelConfig{}

Callers 1

ParseConfigFunction · 0.85

Calls 4

parseBase64KeyToHexFunction · 0.85
encodeBase64ToHexFunction · 0.85
resolveIPPAndPortFunction · 0.85
parseAllowedIPsFunction · 0.85

Tested by

no test coverage detected