Skip to content

Commit 6b202d1

Browse files
committed
Fix cached RouterConfig response.
Because the RouterConfig struct was cached, it would return the same MuxTime on every response.
1 parent b4fe733 commit 6b202d1

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

internal/backend/basicstation/backend.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ type Backend struct {
6363
gatewayStatsFunc func(*gw.GatewayStats)
6464
rawPacketForwarderEventFunc func(*gw.RawPacketForwarderEvent)
6565

66-
band band.Band
67-
region band.Name
68-
netIDs []lorawan.NetID
69-
joinEUIs [][2]lorawan.EUI64
70-
frequencyMin uint32
71-
frequencyMax uint32
72-
routerConfig structs.RouterConfig
66+
band band.Band
67+
region band.Name
68+
netIDs []lorawan.NetID
69+
joinEUIs [][2]lorawan.EUI64
70+
frequencyMin uint32
71+
frequencyMax uint32
72+
concentrators []config.BasicStationConcentrator
7373

7474
// Cache to store diid to UUIDs.
7575
diidCache *cache.Cache
@@ -94,9 +94,10 @@ func NewBackend(conf config.Config) (*Backend, error) {
9494
readTimeout: conf.Backend.BasicStation.ReadTimeout,
9595
writeTimeout: conf.Backend.BasicStation.WriteTimeout,
9696

97-
region: band.Name(conf.Backend.BasicStation.Region),
98-
frequencyMin: conf.Backend.BasicStation.FrequencyMin,
99-
frequencyMax: conf.Backend.BasicStation.FrequencyMax,
97+
region: band.Name(conf.Backend.BasicStation.Region),
98+
frequencyMin: conf.Backend.BasicStation.FrequencyMin,
99+
frequencyMax: conf.Backend.BasicStation.FrequencyMax,
100+
concentrators: config.C.Backend.BasicStation.Concentrators,
100101

101102
diidCache: cache.New(time.Minute, time.Minute),
102103
}
@@ -127,11 +128,6 @@ func NewBackend(conf config.Config) (*Backend, error) {
127128
return nil, errors.Wrap(err, "get band config error")
128129
}
129130

130-
b.routerConfig, err = structs.GetRouterConfig(b.region, b.netIDs, b.joinEUIs, b.frequencyMin, b.frequencyMax, conf.Backend.BasicStation.Concentrators)
131-
if err != nil {
132-
return nil, errors.Wrap(err, "get router config error")
133-
}
134-
135131
mux := http.NewServeMux()
136132
mux.HandleFunc("/router-info", func(w http.ResponseWriter, r *http.Request) {
137133
b.websocketWrap(b.handleRouterInfo, w, r)
@@ -295,6 +291,10 @@ func (b *Backend) Stop() error {
295291
return b.ln.Close()
296292
}
297293

294+
func (b *Backend) getRouterConfig() (structs.RouterConfig, error) {
295+
return structs.GetRouterConfig(b.region, b.netIDs, b.joinEUIs, b.frequencyMin, b.frequencyMax, b.concentrators)
296+
}
297+
298298
func (b *Backend) handleRouterInfo(r *http.Request, conn *connection) {
299299
websocketReceiveCounter("router_info").Inc()
300300
var req structs.RouterInfoRequest
@@ -553,8 +553,14 @@ func (b *Backend) handleVersion(gatewayID lorawan.EUI64, pl structs.Version) {
553553
// "features": pl.Features,
554554
}).Info("backend/basicstation: gateway version received")
555555

556+
routerConfig, err := b.getRouterConfig()
557+
if err != nil {
558+
log.WithError(err).Error("backend/basicstation: get router config error")
559+
return
560+
}
561+
556562
websocketSendCounter("router_config").Inc()
557-
if err := b.sendToGateway(gatewayID, b.routerConfig); err != nil {
563+
if err := b.sendToGateway(gatewayID, routerConfig); err != nil {
558564
log.WithError(err).Error("backend/basicstation: send to gateway error")
559565
return
560566
}

internal/backend/basicstation/backend_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ func (ts *BackendTestSuite) TestRouterInfo() {
111111

112112
func (ts *BackendTestSuite) TestVersion() {
113113
assert := require.New(ts.T())
114-
ts.backend.routerConfig = structs.RouterConfig{
115-
MessageType: structs.RouterConfigMessage,
116-
}
117114

118115
ver := structs.Version{
119116
MessageType: structs.VersionMessage,
@@ -125,7 +122,10 @@ func (ts *BackendTestSuite) TestVersion() {
125122
var routerConfig structs.RouterConfig
126123
assert.NoError(ts.wsClient.ReadJSON(&routerConfig))
127124

128-
assert.Equal(ts.backend.routerConfig, routerConfig)
125+
routerConfig, err := ts.backend.getRouterConfig()
126+
assert.NoError(err)
127+
128+
assert.Equal(routerConfig, routerConfig)
129129
}
130130

131131
func (ts *BackendTestSuite) TestUplinkDataFrame() {

0 commit comments

Comments
 (0)