embed IPNet for MarshalJSON
This commit is contained in:
parent
be849964e7
commit
099324b7f8
14
init.go
14
init.go
@ -25,8 +25,8 @@ func Init() {
|
|||||||
Domain: "dsnet",
|
Domain: "dsnet",
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(conf.Network.String())
|
//fmt.Println(conf.Network.String())
|
||||||
fmt.Printf("%-+v/n",conf)
|
//fmt.Printf("%-+v/n",conf)
|
||||||
|
|
||||||
_json, _ := json.MarshalIndent(conf, "", " ")
|
_json, _ := json.MarshalIndent(conf, "", " ")
|
||||||
|
|
||||||
@ -35,13 +35,15 @@ func Init() {
|
|||||||
|
|
||||||
// get a random /22 subnet on 10.0.0.0 (1023 hosts) (or /24?)
|
// get a random /22 subnet on 10.0.0.0 (1023 hosts) (or /24?)
|
||||||
// TODO also the 20 bit block and 16 bit block?
|
// TODO also the 20 bit block and 16 bit block?
|
||||||
func getRandomNetwork() net.IPNet {
|
func getRandomNetwork() IPNet {
|
||||||
rbs := make([]byte, 2)
|
rbs := make([]byte, 2)
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
rand.Read(rbs)
|
rand.Read(rbs)
|
||||||
|
|
||||||
return net.IPNet {
|
return IPNet{
|
||||||
net.IP{10,rbs[0],rbs[1]<<2,0},
|
net.IPNet {
|
||||||
net.IPMask{255,255,252,0},
|
net.IP{10,rbs[0],rbs[1]<<2,0},
|
||||||
|
net.IPMask{255,255,252,0},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
types.go
15
types.go
@ -49,10 +49,11 @@ type DsnetConfig struct {
|
|||||||
Peers []PeerConfig
|
Peers []PeerConfig
|
||||||
// IP network from which to allocate automatic sequential addresses
|
// IP network from which to allocate automatic sequential addresses
|
||||||
// Network is chosen randomly when not specified
|
// Network is chosen randomly when not specified
|
||||||
Network net.IPNet `validate:"required"`
|
Network IPNet `validate:"required"`
|
||||||
// domain to append to hostnames. Relies on separate DNS server for
|
// domain to append to hostnames. Relies on separate DNS server for
|
||||||
// resolution. Informational only.
|
// resolution. Informational only.
|
||||||
Domain string `validate:"required,gte=1,lte=255"`
|
Domain string `validate:"required,gte=1,lte=255"`
|
||||||
|
// TODO Default subnets to route via VPN
|
||||||
}
|
}
|
||||||
|
|
||||||
type Dsnet struct {
|
type Dsnet struct {
|
||||||
@ -62,3 +63,15 @@ type Dsnet struct {
|
|||||||
ListenPort int
|
ListenPort int
|
||||||
Peers []Peer
|
Peers []Peer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IPNet struct {
|
||||||
|
ipNet net.IPNet
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n IPNet) MarshalJSON() ([]byte, error) {
|
||||||
|
return []byte("\"" + n.ipNet.String() + "\""), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *IPNet) String() string {
|
||||||
|
return n.ipNet.String()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user