WIP
This commit is contained in:
@@ -21,13 +21,6 @@ func Config_Validate(c *Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Session_Sanitize(s *Session) {
|
||||
}
|
||||
|
||||
func Session_Validate(s *Session) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Network_Sanitize(n *Network) {
|
||||
n.Name = strings.TrimSpace(n.Name)
|
||||
|
||||
@@ -66,25 +59,39 @@ func Network_Validate(c *Network) error {
|
||||
|
||||
func Peer_Sanitize(p *Peer) {
|
||||
p.Name = strings.TrimSpace(p.Name)
|
||||
if len(p.PublicIP) != 0 {
|
||||
addr, ok := netip.AddrFromSlice(p.PublicIP)
|
||||
if ok && addr.Is4() {
|
||||
p.PublicIP = addr.AsSlice()
|
||||
if len(p.PublicIP1) != 0 {
|
||||
if addr, ok := netip.AddrFromSlice(p.PublicIP1); ok {
|
||||
p.PublicIP1 = addr.AsSlice()
|
||||
}
|
||||
}
|
||||
if p.Port == 0 {
|
||||
p.Port = 456
|
||||
if len(p.PublicIP2) != 0 {
|
||||
if addr, ok := netip.AddrFromSlice(p.PublicIP2); ok {
|
||||
p.PublicIP2 = addr.AsSlice()
|
||||
}
|
||||
}
|
||||
if p.Port1 == 0 {
|
||||
p.Port1 = 456
|
||||
}
|
||||
if len(p.PublicIP2) != 0 && p.Port2 == 0 {
|
||||
p.Port2 = 456
|
||||
}
|
||||
}
|
||||
|
||||
func Peer_Validate(p *Peer) error {
|
||||
if len(p.PublicIP) > 0 {
|
||||
_, ok := netip.AddrFromSlice(p.PublicIP)
|
||||
if !ok {
|
||||
if len(p.PublicIP1) > 0 {
|
||||
if _, ok := netip.AddrFromSlice(p.PublicIP1); !ok {
|
||||
return ErrInvalidIP
|
||||
}
|
||||
}
|
||||
if p.Port == 0 {
|
||||
if len(p.PublicIP2) > 0 {
|
||||
if _, ok := netip.AddrFromSlice(p.PublicIP2); !ok {
|
||||
return ErrInvalidIP
|
||||
}
|
||||
if p.Port2 == 0 {
|
||||
return ErrInvalidPort
|
||||
}
|
||||
}
|
||||
if p.Port1 == 0 {
|
||||
return ErrInvalidPort
|
||||
}
|
||||
|
||||
@@ -98,7 +105,6 @@ func Peer_Validate(p *Peer) error {
|
||||
if c == '.' || c == '-' || c == '_' {
|
||||
continue
|
||||
}
|
||||
|
||||
return ErrInvalidPeerName
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user