Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/internal/io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Write(w io.Writer, format string, data any) (err error) {
}
}
n := rv.Len()
for i := 0; i < n; i++ {
for i := range n {
if err = writeItem(rv.Index(i).Interface()); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ttn-lw-cli/commands/end_device_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ This command takes end device templates from stdin.`,
return err
}

for i := 0; i < count; i++ {
for range count {
res := ttnpb.Clone(&template)

var devEUI types.EUI64
Expand Down
5 changes: 2 additions & 3 deletions cmd/ttn-lw-cli/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package commands
import (
"fmt"
"io"
"maps"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -70,9 +71,7 @@ func forceFlags() *pflag.FlagSet {

func mergeKV(attributes map[string]string, kv []string) map[string]string {
out := make(map[string]string, len(attributes)+len(kv))
for k, v := range attributes {
out[k] = v
}
maps.Copy(out, attributes)
for _, kv := range kv {
kv := strings.SplitN(kv, "=", 2)
if len(kv) != 2 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/ttn-lw-cli/commands/lorawan.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func decodeUplink(msg *ttnpb.Message, config lorawanConfig) (*lorawanDecodedFram
} else {
logger.Debug("Decrypting MAC buffer")
encOpts := macspec.EncryptionOptions(config.MACVersion, macspec.UplinkFrame, pld.FPort, cmdsInFOpts)
for msb := uint32(0); msb < 0xff; msb++ {
for msb := range uint32(0xff) {
fCnt := msb<<8 | pld.FHdr.FCnt
macBuf, err := crypto.DecryptUplink(config.NwkSEncKey, devAddr, fCnt, macBuf, encOpts...)
if err == nil {
Expand Down Expand Up @@ -171,7 +171,7 @@ func decodeDownlink(msg *ttnpb.Message, config lorawanConfig) (*lorawanDecodedFr
if len(macBuf) > 0 && (!cmdsInFOpts || macspec.EncryptFOpts(config.MACVersion)) && !config.NwkSKey.IsZero() {
logger.Debug("Decrypting MAC buffer")
encOpts := macspec.EncryptionOptions(config.MACVersion, macspec.DownlinkFrame, pld.FPort, cmdsInFOpts)
for msb := uint32(0); msb < 0xffff; msb++ {
for msb := range uint32(0xffff) {
fCnt := msb<<16 | pld.FHdr.FCnt
macBuf, err := crypto.DecryptDownlink(config.NwkSKey, devAddr, fCnt, macBuf, encOpts...)
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ttn-lw-cli/commands/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func startSimulation(
logger.Info("Sent uplink")

expect, _ := cmd.Flags().GetInt("downlinks")
for i := 0; i < expect; i++ {
for range expect {
down, err := link.Recv()
if err != nil {
return err
Expand Down
5 changes: 1 addition & 4 deletions cmd/ttn-lw-stack/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,7 @@ var startCommand = &cobra.Command{

logger.Info("Setting up Network Server")

applicationUplinkQueueSize := config.NS.ApplicationUplinkQueue.BufferSize
if config.NS.ApplicationUplinkQueue.BufferSize > math.MaxInt64 {
applicationUplinkQueueSize = math.MaxInt64
}
applicationUplinkQueueSize := min(config.NS.ApplicationUplinkQueue.BufferSize, math.MaxInt64)
applicationUplinkQueue := nsredis.NewApplicationUplinkQueue(
NewNetworkServerApplicationUplinkQueueRedis(config),
int64(applicationUplinkQueueSize),
Expand Down
2 changes: 1 addition & 1 deletion cmd/ttn-lw-stack/commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewClusterComponentConnection(ctx context.Context,
return nil, nil, err
}
var cc *grpc.ClientConn
for i := 0; i < maxRetries; i++ {
for range maxRetries {
time.Sleep(delay)
cc, err = c.GetPeerConn(ctx, role, nil)
if err == nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/applicationserver/applicationserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ func TestApplicationServer(t *testing.T) {
default:
t.Fatal("Expected downlink error")
}
for i := 0; i < len(items); i++ {
for range items {
select {
case up := <-chs.up:
a.So(up.Up, should.HaveSameTypeAs, &ttnpb.ApplicationUp_DownlinkQueued{})
Expand Down Expand Up @@ -2245,7 +2245,7 @@ func TestApplicationServer(t *testing.T) {
default:
t.Fatal("Expected downlink error")
}
for i := 0; i < 2; i++ {
for range 2 {
select {
case up := <-chs.up:
a.So(up.Up, should.HaveSameTypeAs, &ttnpb.ApplicationUp_DownlinkQueued{})
Expand Down Expand Up @@ -2784,7 +2784,7 @@ func TestSkipPayloadCrypto(t *testing.T) {
default:
t.Fatal("Expected downlink error")
}
for i := 0; i < len(items); i++ {
for range items {
select {
case up := <-chs.up:
a.So(up.Up, should.HaveSameTypeAs, &ttnpb.ApplicationUp_DownlinkQueued{})
Expand Down Expand Up @@ -2973,7 +2973,7 @@ func TestLocationFromPayload(t *testing.T) {
// The uplink message and the location solved message may come out of order.
// Expect exactly two messages.
var loc *ttnpb.ApplicationLocation
for i := 0; i < 2; i++ {
for i := range 2 {
select {
case msg := <-sub.Up():
msgLoc := msg.ApplicationUp.GetLocationSolved()
Expand Down Expand Up @@ -3144,7 +3144,7 @@ func TestUplinkNormalized(t *testing.T) {
// The uplink message and the normalized payload message may come out of order.
// Expect exactly two messages.
var normalized *ttnpb.ApplicationUplinkNormalized
for i := 0; i < 2; i++ {
for i := range 2 {
select {
case msg := <-sub.Up():
if n := msg.GetUplinkNormalized(); n != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/applicationserver/io/grpc/grpc_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (m *mockRegisterer) RegisterHandlers(s *runtime.ServeMux, conn *grpc.Client
}

func mustHavePeer(ctx context.Context, c *component.Component, role ttnpb.ClusterRole) {
for i := 0; i < 20; i++ {
for range 20 {
time.Sleep(20 * time.Millisecond)
if _, err := c.GetPeer(ctx, role, nil); err == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/applicationserver/io/mqtt/mqtt_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var testRights = []ttnpb.Right{
}

func mustHavePeer(ctx context.Context, c *component.Component, role ttnpb.ClusterRole) {
for i := 0; i < 20; i++ {
for range 20 {
time.Sleep(20 * time.Millisecond)
if _, err := c.GetPeer(ctx, role, nil); err == nil {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ type Hex []byte

// MarshalJSON implements json.Marshaler.
func (h Hex) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s\"", hex.EncodeToString(h))), nil
return fmt.Appendf(nil, "\"%s\"", hex.EncodeToString(h)), nil
}

// String implements fmt.Stringer.
Expand All @@ -337,7 +337,7 @@ const (

// MarshalJSON implements json.Marshaler.
func (e EUI) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(hyphenatedEUIPattern, e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7])), nil
return fmt.Appendf(nil, hyphenatedEUIPattern, e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7]), nil
}

// UnmarshalJSON implements json.Unmarshaler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ type Hex []byte

// MarshalJSON implements json.Marshaler.
func (h Hex) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s\"", hex.EncodeToString(h))), nil
return fmt.Appendf(nil, "\"%s\"", hex.EncodeToString(h)), nil
}

// String implements fmt.Stringer.
Expand Down
2 changes: 1 addition & 1 deletion pkg/applicationserver/io/packages/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func mustHavePeer(ctx context.Context, c *component.Component, role ttnpb.ClusterRole) {
for i := 0; i < 20; i++ {
for range 20 {
time.Sleep(20 * time.Millisecond)
if _, err := c.GetPeer(ctx, role, nil); err == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/applicationserver/io/pubsub/provider/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func isNil(c any) bool {
if c == nil {
return true
}
if val := reflect.ValueOf(c); val.Kind() == reflect.Ptr {
if val := reflect.ValueOf(c); val.Kind() == reflect.Pointer {
return val.IsNil()
}
return false
Expand Down
4 changes: 2 additions & 2 deletions pkg/applicationserver/io/pubsub/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func providerStatusFromString(s string) (ProviderStatus, error) {
func providerTypeFromString(ctx context.Context, s string) (reflect.Type, error) {
switch s {
case "mqtt":
return reflect.TypeOf(&ttnpb.ApplicationPubSub_Mqtt{}), nil
return reflect.TypeFor[*ttnpb.ApplicationPubSub_Mqtt](), nil
case "nats":
return reflect.TypeOf(&ttnpb.ApplicationPubSub_Nats{}), nil
return reflect.TypeFor[*ttnpb.ApplicationPubSub_Nats](), nil
default:
log.FromContext(ctx).WithField("provider", s).Warn("Unknown PubSub provider specified")
return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/applicationserver/io/pubsub/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (m *mockRegisterer) RegisterHandlers(s *runtime.ServeMux, conn *grpc.Client
}

func mustHavePeer(ctx context.Context, c *component.Component, role ttnpb.ClusterRole) {
for i := 0; i < 20; i++ {
for range 20 {
time.Sleep(20 * time.Millisecond)
if _, err := c.GetPeer(ctx, role, nil); err == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/applicationserver/io/web/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (m *mockRegisterer) RegisterHandlers(s *runtime.ServeMux, conn *grpc.Client
}

func mustHavePeer(ctx context.Context, c *component.Component, role ttnpb.ClusterRole) {
for i := 0; i < 20; i++ {
for range 20 {
time.Sleep(20 * time.Millisecond)
if _, err := c.GetPeer(ctx, role, nil); err == nil {
return
Expand Down
9 changes: 3 additions & 6 deletions pkg/applicationserver/metadata/end_device_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package metadata_test

import (
"maps"
"testing"
"time"

Expand Down Expand Up @@ -136,17 +137,13 @@ func TestClusterEndDeviceRegistry(t *testing.T) { // nolint:gocyclo
stored.Locations = make(map[string]*ttnpb.Location, len(locationsPatch))
}

for k, l := range locationsPatch {
stored.Locations[k] = l
}
maps.Copy(stored.Locations, locationsPatch)

if len(stored.Attributes) == 0 {
stored.Attributes = make(map[string]string, len(attributesPatch))
}

for k, v := range attributesPatch {
stored.Attributes[k] = v
}
maps.Copy(stored.Attributes, attributesPatch)

return stored, []string{"locations", "attributes"}, nil
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/applicationserver/metadata/metadata_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func mustHavePeer(ctx context.Context, c *component.Component, role ttnpb.ClusterRole) { // nolint: unparam
for i := 0; i < 20; i++ {
for range 20 {
time.Sleep(20 * time.Millisecond)
if _, err := c.GetPeer(ctx, role, nil); err == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/applicationserver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var testRights = []ttnpb.Right{
}

func mustHavePeer(ctx context.Context, c *component.Component, role ttnpb.ClusterRole) {
for i := 0; i < 20; i++ {
for range 20 {
time.Sleep(20 * time.Millisecond)
if _, err := c.GetPeer(ctx, role, nil); err == nil {
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/mtls/proxy_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func FromProxyHeaders(h HeaderReader) (*x509.Certificate, bool, error) {
// See https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-forwarded-client-cert
key: "x-forwarded-client-cert",
parse: func(value string) (*x509.Certificate, bool, error) {
parts := strings.Split(value, ";")
for _, part := range parts {
parts := strings.SplitSeq(value, ";")
for part := range parts {
chainPEM, found := strings.CutPrefix(part, "Chain=")
if !found {
continue
Expand Down
5 changes: 1 addition & 4 deletions pkg/auth/rights/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ type inMemoryCache struct {

// maybeCleanup cleans up expired results if necessary.
func (f *inMemoryCache) maybeCleanup() {
cleanupTTL := f.successTTL
if f.errorTTL > cleanupTTL {
cleanupTTL = f.errorTTL
}
cleanupTTL := max(f.errorTTL, f.successTTL)
if now().Sub(f.lastCleanup) <= cleanupTTL*10 {
return
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/band/au_915_928.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ var (

au915928UplinkChannels = func(commonDelta, wideChannelDelta ttnpb.DataRateIndex) []Channel {
uplinkChannels := make([]Channel, 0, 72)
for i := 0; i < 64; i++ {
for i := range 64 {
uplinkChannels = append(uplinkChannels, Channel{
Frequency: uint64(915200000 + 200000*i),
MaxDataRate: ttnpb.DataRateIndex_DATA_RATE_5 + commonDelta,
})
}
for i := 0; i < 8; i++ {
for i := range 8 {
uplinkChannels = append(uplinkChannels, Channel{
Frequency: uint64(915900000 + 1600000*i),
MinDataRate: ttnpb.DataRateIndex_DATA_RATE_6 + commonDelta,
Expand All @@ -61,7 +61,7 @@ var (

au915928DownlinkChannels = func() []Channel {
downlinkChannels := make([]Channel, 0, 8)
for i := 0; i < 8; i++ {
for i := range 8 {
downlinkChannels = append(downlinkChannels, Channel{
Frequency: uint64(923300000 + 600000*i),
MinDataRate: ttnpb.DataRateIndex_DATA_RATE_8,
Expand Down
2 changes: 1 addition & 1 deletion pkg/band/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Beacon struct {

var usAuBeaconFrequencies = func() []uint64 {
freqs := make([]uint64, 8)
for i := 0; i < 8; i++ {
for i := range 8 {
freqs[i] = 923300000 + uint64(i*600000)
}
return freqs
Expand Down
4 changes: 2 additions & 2 deletions pkg/band/channel_mask.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func generateChMaskMatrix(pairs []ChMaskCntlPair, currentChs, desiredChs []bool)
return nil, errInvalidChannelCount.New()
}
for i := 0; i < n/16; i++ {
for j := 0; j < 16; j++ {
for j := range 16 {
if currentChs[16*i+j] != desiredChs[16*i+j] {
pairs = append(pairs, ChMaskCntlPair{
Cntl: uint8(i),
Expand Down Expand Up @@ -460,7 +460,7 @@ func makeGenerateChMask72(supportChMaskCntl5 bool, atomic bool) func([]bool, []b
}

var fsbs [8]bool
for i := 0; i < 8; i++ {
for i := range 8 {
if trueCount(desiredChs[8*i:8*i+8]...) == 8 {
fsbs[i] = true
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/band/cn_470_510.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (

cn470510UplinkChannels = func() []Channel {
uplinkChannels := make([]Channel, 0, 96)
for i := 0; i < 96; i++ {
for i := range 96 {
uplinkChannels = append(uplinkChannels, Channel{
Frequency: uint64(470300000 + 200000*i),
MaxDataRate: ttnpb.DataRateIndex_DATA_RATE_5,
Expand All @@ -44,7 +44,7 @@ var (

cn470510DownlinkChannels = func() []Channel {
downlinkChannels := make([]Channel, 0, 48)
for i := 0; i < 48; i++ {
for i := range 48 {
downlinkChannels = append(downlinkChannels, Channel{
Frequency: uint64(500300000 + 200000*i),
MaxDataRate: ttnpb.DataRateIndex_DATA_RATE_5,
Expand All @@ -55,7 +55,7 @@ var (

cn470510BeaconFrequencies = func() []uint64 {
freqs := make([]uint64, 8)
for i := 0; i < 8; i++ {
for i := range 8 {
freqs[i] = 508300000 + uint64(i*200000)
}
return freqs
Expand Down
Loading
Loading