Skip to content

Commit

Permalink
all: use ++ to increment
Browse files Browse the repository at this point in the history
Make the code slightly more idiomatic. No functional changes.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
  • Loading branch information
josharian authored and zx2c4 committed Dec 23, 2020
1 parent f5576ba commit e467e07
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions device/allowedips_rand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ func TestTrieRandomIPv4(t *testing.T) {

const AddressLength = 4

for n := 0; n < NumberOfPeers; n += 1 {
for n := 0; n < NumberOfPeers; n++ {
peers = append(peers, &Peer{})
}

for n := 0; n < NumberOfAddresses; n += 1 {
for n := 0; n < NumberOfAddresses; n++ {
var addr [AddressLength]byte
rand.Read(addr[:])
cidr := uint(rand.Uint32() % (AddressLength * 8))
Expand All @@ -86,7 +86,7 @@ func TestTrieRandomIPv4(t *testing.T) {
slow = slow.Insert(addr[:], cidr, peers[index])
}

for n := 0; n < NumberOfTests; n += 1 {
for n := 0; n < NumberOfTests; n++ {
var addr [AddressLength]byte
rand.Read(addr[:])
peer1 := slow.Lookup(addr[:])
Expand All @@ -106,11 +106,11 @@ func TestTrieRandomIPv6(t *testing.T) {

const AddressLength = 16

for n := 0; n < NumberOfPeers; n += 1 {
for n := 0; n < NumberOfPeers; n++ {
peers = append(peers, &Peer{})
}

for n := 0; n < NumberOfAddresses; n += 1 {
for n := 0; n < NumberOfAddresses; n++ {
var addr [AddressLength]byte
rand.Read(addr[:])
cidr := uint(rand.Uint32() % (AddressLength * 8))
Expand All @@ -119,7 +119,7 @@ func TestTrieRandomIPv6(t *testing.T) {
slow = slow.Insert(addr[:], cidr, peers[index])
}

for n := 0; n < NumberOfTests; n += 1 {
for n := 0; n < NumberOfTests; n++ {
var addr [AddressLength]byte
rand.Read(addr[:])
peer1 := slow.Lookup(addr[:])
Expand Down
6 changes: 3 additions & 3 deletions device/allowedips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ func benchmarkTrie(peerNumber int, addressNumber int, addressLength int, b *test

const AddressLength = 4

for n := 0; n < peerNumber; n += 1 {
for n := 0; n < peerNumber; n++ {
peers = append(peers, &Peer{})
}

for n := 0; n < addressNumber; n += 1 {
for n := 0; n < addressNumber; n++ {
var addr [AddressLength]byte
rand.Read(addr[:])
cidr := uint(rand.Uint32() % (AddressLength * 8))
index := rand.Int() % peerNumber
trie = trie.insert(addr[:], cidr, peers[index])
}

for n := 0; n < b.N; n += 1 {
for n := 0; n < b.N; n++ {
var addr [AddressLength]byte
rand.Read(addr[:])
trie.lookup(addr[:])
Expand Down
2 changes: 1 addition & 1 deletion device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func NewDevice(tunDevice tun.Device, logger *Logger) *Device {

cpus := runtime.NumCPU()
device.state.stopping.Wait()
for i := 0; i < cpus; i += 1 {
for i := 0; i < cpus; i++ {
device.state.stopping.Add(2) // decryption and handshake
go device.RoutineEncryption()
go device.RoutineDecryption()
Expand Down
6 changes: 3 additions & 3 deletions device/pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ func (device *Device) PopulatePools() {
}
} else {
device.pool.messageBufferReuseChan = make(chan *[MaxMessageSize]byte, PreallocatedBuffersPerPool)
for i := 0; i < PreallocatedBuffersPerPool; i += 1 {
for i := 0; i < PreallocatedBuffersPerPool; i++ {
device.pool.messageBufferReuseChan <- new([MaxMessageSize]byte)
}
device.pool.inboundElementReuseChan = make(chan *QueueInboundElement, PreallocatedBuffersPerPool)
for i := 0; i < PreallocatedBuffersPerPool; i += 1 {
for i := 0; i < PreallocatedBuffersPerPool; i++ {
device.pool.inboundElementReuseChan <- new(QueueInboundElement)
}
device.pool.outboundElementReuseChan = make(chan *QueueOutboundElement, PreallocatedBuffersPerPool)
for i := 0; i < PreallocatedBuffersPerPool; i += 1 {
for i := 0; i < PreallocatedBuffersPerPool; i++ {
device.pool.outboundElementReuseChan <- new(QueueOutboundElement)
}
}
Expand Down
2 changes: 1 addition & 1 deletion tun/tun_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
if ifIndex != -1 {
tunfile, err = os.OpenFile(fmt.Sprintf("/dev/tun%d", ifIndex), unix.O_RDWR, 0)
} else {
for ifIndex = 0; ifIndex < 256; ifIndex += 1 {
for ifIndex = 0; ifIndex < 256; ifIndex++ {
tunfile, err = os.OpenFile(fmt.Sprintf("/dev/tun%d", ifIndex), unix.O_RDWR, 0)
if err == nil || !errorIsEBUSY(err) {
break
Expand Down

0 comments on commit e467e07

Please sign in to comment.