Skip to content

Commit

Permalink
Store all used DevNonce values.
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Oct 4, 2016
1 parent d4b7fbf commit a132738
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Redirect to JWT token form on authorization error
* Add small delay between http server start and gprc-gateway init (to work
around internal connection errors)
* Store all used DevNonce values instead of max. 10.

## 0.1.0

Expand Down
7 changes: 0 additions & 7 deletions internal/storage/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import (
"github.com/brocaar/lorawan"
)

// UsedDevNonceCount is the number of used dev-nonces to track.
const UsedDevNonceCount = 10

// DevNonceList represents a list of dev nonces
type DevNonceList [][2]byte

Expand Down Expand Up @@ -98,10 +95,6 @@ func (n *Node) ValidateDevNonce(nonce [2]byte) bool {
}
}
n.UsedDevNonces = append(n.UsedDevNonces, nonce)
if len(n.UsedDevNonces) > UsedDevNonceCount {
n.UsedDevNonces = n.UsedDevNonces[len(n.UsedDevNonces)-UsedDevNonceCount:]
}

return true
}

Expand Down
8 changes: 2 additions & 6 deletions internal/storage/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ func TestValidateDevNonce(t *testing.T) {
Convey("Then a new nonce is valid", func() {
So(n.ValidateDevNonce([2]byte{0, 0}), ShouldBeTrue)

Convey("Then the UsedDevNonces still has length 10", func() {
So(n.UsedDevNonces, ShouldHaveLength, 10)
})

Convey("Then the new nonce was added to the back of the list", func() {
So(n.UsedDevNonces[9], ShouldEqual, [2]byte{0, 0})
Convey("Then the UsedDevNonces has length 11", func() {
So(n.UsedDevNonces, ShouldHaveLength, 11)
})
})
})
Expand Down

0 comments on commit a132738

Please sign in to comment.