This commit is contained in:
Callan Bryant 2020-03-01 23:08:10 +00:00
parent 87317e374a
commit a99449e960
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
4 changed files with 49 additions and 53 deletions

View File

@ -30,7 +30,7 @@ func main() {
case "down": case "down":
default: default:
help(); help()
} }
} }

View File

@ -7,13 +7,11 @@ const (
// these end up in the config file // these end up in the config file
DEFAULT_INTERFACE_NAME = "dsnet" DEFAULT_INTERFACE_NAME = "dsnet"
DEFAULT_REPORT_FILE = "/var/lib/dsnet-report.json" DEFAULT_REPORT_FILE = "/var/lib/dsnet-report.json"
DEFAULT_LISTEN_PORT = 51820; DEFAULT_LISTEN_PORT = 51820
// keepalive always configured for everything // keepalive always configured for everything
KEEPALIVE_SECONDS = 21; KEEPALIVE_SECONDS = 21
// when is a peer considered gone forever? (could remove) // when is a peer considered gone forever? (could remove)
EXPIRY_DAYS = 28; EXPIRY_DAYS = 28
) )

18
init.go
View File

@ -1,12 +1,11 @@
package dsnet package dsnet
import ( import (
"net"
"math/rand"
"fmt"
"time"
"encoding/json" "encoding/json"
"fmt"
"math/rand"
"net"
"time"
//"github.com/mikioh/ipaddr" //"github.com/mikioh/ipaddr"
) )
@ -19,7 +18,7 @@ func Init() {
PresharedKey: presharedKey, PresharedKey: presharedKey,
ListenPort: DEFAULT_LISTEN_PORT, ListenPort: DEFAULT_LISTEN_PORT,
Network: getRandomNetwork(), Network: getRandomNetwork(),
Peers: make([]PeerConfig,0), Peers: make([]PeerConfig, 0),
Domain: "dsnet", Domain: "dsnet",
} }
@ -32,16 +31,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?
func getRandomNetwork() JSONIPNet { func getRandomNetwork() JSONIPNet {
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 JSONIPNet{ return JSONIPNet{
net.IPNet { net.IPNet{
net.IP{10,rbs[0],rbs[1]<<2,0}, net.IP{10, rbs[0], rbs[1] << 2, 0},
net.IPMask{255,255,252,0}, net.IPMask{255, 255, 252, 0},
}, },
} }
} }

View File

@ -1,9 +1,9 @@
package dsnet package dsnet
import ( import (
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"net" "net"
"time" "time"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
) )
// see https://github.com/WireGuard/wgctrl-go/blob/master/wgtypes/types.go for definitions // see https://github.com/WireGuard/wgctrl-go/blob/master/wgtypes/types.go for definitions
@ -87,7 +87,7 @@ func (k JSONKey) MarshalJSON() ([]byte, error) {
func GenerateJSONPrivateKey() JSONKey { func GenerateJSONPrivateKey() JSONKey {
privateKey, err := wgtypes.GeneratePrivateKey() privateKey, err := wgtypes.GeneratePrivateKey()
if (err != nil) { if err != nil {
panic(err) panic(err)
} }
@ -99,7 +99,7 @@ func GenerateJSONPrivateKey() JSONKey {
func GenerateJSONKey() JSONKey { func GenerateJSONKey() JSONKey {
privateKey, err := wgtypes.GenerateKey() privateKey, err := wgtypes.GenerateKey()
if (err != nil) { if err != nil {
panic(err) panic(err)
} }