diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 540f5b0..9ff5789 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,8 +20,9 @@ jobs: git diff --exit-code go vet ./... - - name: Build project + - name: Build and test project run: | + go test ./... mkdir bin GOBIN="$PWD/bin" CGO_ENABLED=0 go install ./... diff --git a/etcdconfigweb/config.go b/etcdconfigweb/config.go index d974903..a2b91c4 100644 --- a/etcdconfigweb/config.go +++ b/etcdconfigweb/config.go @@ -34,6 +34,31 @@ var MISSING_V6MTU = errors.New("Missing v6mtu query parameter") var MISSING_PUBKEY = errors.New("Missing pubkey query parameter") var MISSING_NONCE = errors.New("Missing nonce query parameter") +func generateNodeAddressesAndRanges(info *ffbs.NodeInfo) { + const V4_BASE uint32 = 10 << 24 + const V4_RANGE_SIZE uint8 = 10 + const V6_BASE_HIGH uint64 = 0x20010bf70381 << 16 + + num := *info.ID + + var v4Addr [net.IPv4len]byte + binary.BigEndian.PutUint32(v4Addr[:], V4_BASE|(uint32(num)< 22-8 = 14 bits of freedom + id := uint64(16383) + node := ffbs.NodeInfo{ID: &id} + generateNodeAddressesAndRanges(&node) + assert.Equal(t, "10.255.252.1", *node.Address4) + assert.Equal(t, "10.255.252.0/22", *node.Range4) + assert.Equal(t, "2001:bf7:381:3fff::1", *node.Address6) + assert.Equal(t, "2001:bf7:381:3fff::/64", *node.Range6) +} diff --git a/go.mod b/go.mod index 57e1d66..b70dbf5 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ toolchain go1.22.9 require ( github.com/spf13/cobra v1.8.1 + github.com/stretchr/testify v1.9.0 go.etcd.io/etcd/client/v3 v3.5.17 go.seankhliao.com/signify v0.0.0-20200507101447-944db0e32d56 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6 @@ -14,6 +15,7 @@ require ( require ( github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/ebfe/bcrypt_pbkdf v0.0.0-20140212075826-3c8d2dcb253a // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.4 // indirect @@ -23,6 +25,7 @@ require ( github.com/mdlayher/genetlink v1.3.2 // indirect github.com/mdlayher/netlink v1.7.2 // indirect github.com/mdlayher/socket v0.4.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect go.etcd.io/etcd/api/v3 v3.5.17 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.17 // indirect @@ -40,4 +43,5 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect google.golang.org/grpc v1.59.0 // indirect google.golang.org/protobuf v1.33.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c2042db..2596a95 100644 --- a/go.sum +++ b/go.sum @@ -108,6 +108,7 @@ google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=