Skip to content

Commit 347ad67

Browse files
committed
Fix cached RouterConfig response.
Because the RouterConfig struct was cached, it would return the same MuxTime on every response.
1 parent b63309c commit 347ad67

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
@@ -65,13 +65,13 @@ type Backend struct {
6565
gatewayStatsFunc func(gw.GatewayStats)
6666
rawPacketForwarderEventFunc func(gw.RawPacketForwarderEvent)
6767

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

7676
// Cache to store diid to UUIDs.
7777
diidCache *cache.Cache
@@ -96,9 +96,10 @@ func NewBackend(conf config.Config) (*Backend, error) {
9696
readTimeout: conf.Backend.BasicStation.ReadTimeout,
9797
writeTimeout: conf.Backend.BasicStation.WriteTimeout,
9898

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

103104
diidCache: cache.New(time.Minute, time.Minute),
104105
}
@@ -129,11 +130,6 @@ func NewBackend(conf config.Config) (*Backend, error) {
129130
return nil, errors.Wrap(err, "get band config error")
130131
}
131132

132-
b.routerConfig, err = structs.GetRouterConfig(b.region, b.netIDs, b.joinEUIs, b.frequencyMin, b.frequencyMax, conf.Backend.BasicStation.Concentrators)
133-
if err != nil {
134-
return nil, errors.Wrap(err, "get router config error")
135-
}
136-
137133
mux := http.NewServeMux()
138134
mux.HandleFunc("/router-info", func(w http.ResponseWriter, r *http.Request) {
139135
b.websocketWrap(b.handleRouterInfo, w, r)
@@ -309,6 +305,10 @@ func (b *Backend) Stop() error {
309305
return b.ln.Close()
310306
}
311307

308+
func (b *Backend) getRouterConfig() (structs.RouterConfig, error) {
309+
return structs.GetRouterConfig(b.region, b.netIDs, b.joinEUIs, b.frequencyMin, b.frequencyMax, b.concentrators)
310+
}
311+
312312
func (b *Backend) handleRouterInfo(r *http.Request, conn *connection) {
313313
websocketReceiveCounter("router_info").Inc()
314314
var req structs.RouterInfoRequest
@@ -574,8 +574,14 @@ func (b *Backend) handleVersion(gatewayID lorawan.EUI64, pl structs.Version) {
574574
// "features": pl.Features,
575575
}).Info("backend/basicstation: gateway version received")
576576

577+
routerConfig, err := b.getRouterConfig()
578+
if err != nil {
579+
log.WithError(err).Error("backend/basicstation: get router config error")
580+
return
581+
}
582+
577583
websocketSendCounter("router_config").Inc()
578-
if err := b.sendToGateway(gatewayID, b.routerConfig); err != nil {
584+
if err := b.sendToGateway(gatewayID, routerConfig); err != nil {
579585
log.WithError(err).Error("backend/basicstation: send to gateway error")
580586
return
581587
}

internal/backend/basicstation/backend_test.go

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

114114
func (ts *BackendTestSuite) TestVersion() {
115115
assert := require.New(ts.T())
116-
ts.backend.routerConfig = structs.RouterConfig{
117-
MessageType: structs.RouterConfigMessage,
118-
}
119116

120117
ver := structs.Version{
121118
MessageType: structs.VersionMessage,
@@ -127,7 +124,10 @@ func (ts *BackendTestSuite) TestVersion() {
127124
var routerConfig structs.RouterConfig
128125
assert.NoError(ts.wsClient.ReadJSON(&routerConfig))
129126

130-
assert.Equal(ts.backend.routerConfig, routerConfig)
127+
routerConfig, err := ts.backend.getRouterConfig()
128+
assert.NoError(err)
129+
130+
assert.Equal(routerConfig, routerConfig)
131131
}
132132

133133
func (ts *BackendTestSuite) TestUplinkDataFrame() {

0 commit comments

Comments
 (0)