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",
|
||||
}
|
||||
|
||||
fmt.Println(conf.Network.String())
|
||||
fmt.Printf("%-+v/n",conf)
|
||||
//fmt.Println(conf.Network.String())
|
||||
//fmt.Printf("%-+v/n",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?)
|
||||
// TODO also the 20 bit block and 16 bit block?
|
||||
func getRandomNetwork() net.IPNet {
|
||||
func getRandomNetwork() IPNet {
|
||||
rbs := make([]byte, 2)
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
rand.Read(rbs)
|
||||
|
||||
return net.IPNet {
|
||||
net.IP{10,rbs[0],rbs[1]<<2,0},
|
||||
net.IPMask{255,255,252,0},
|
||||
return IPNet{
|
||||
net.IPNet {
|
||||
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
|
||||
// IP network from which to allocate automatic sequential addresses
|
||||
// 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
|
||||
// resolution. Informational only.
|
||||
Domain string `validate:"required,gte=1,lte=255"`
|
||||
// TODO Default subnets to route via VPN
|
||||
}
|
||||
|
||||
type Dsnet struct {
|
||||
@ -62,3 +63,15 @@ type Dsnet struct {
|
||||
ListenPort int
|
||||
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