Skip to content

Commit 36361ee

Browse files
committed
Fixes #236 Class C timeout
1 parent dfbaf37 commit 36361ee

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

cmd/chirpstack-gateway-bridge/cmd/configfile.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ type="{{ .Backend.Type }}"
8888
# the time would otherwise be unset.
8989
fake_rx_time={{ .Backend.SemtechUDP.FakeRxTime }}
9090
91+
# Cleanup duration
92+
# Cleaup duration for class C devices
93+
cleanup_duration={{ .Backend.SemtechUDP.CleanupDuration }}
9194
9295
# ChirpStack Concentratord backend.
9396
[backend.concentratord]

cmd/chirpstack-gateway-bridge/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func init() {
3939
viper.SetDefault("general.log_level", 4)
4040
viper.SetDefault("backend.type", "semtech_udp")
4141
viper.SetDefault("backend.semtech_udp.udp_bind", "0.0.0.0:1700")
42+
viper.SetDefault("backend.semtech_udp.cleanup_duration", -1)
4243

4344
viper.SetDefault("backend.concentratord.crc_check", true)
4445
viper.SetDefault("backend.concentratord.event_url", "ipc:///tmp/concentratord_event")

internal/backend/semtechudp/backend.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ func NewBackend(conf config.Config) (*Backend, error) {
6767
conn: conn,
6868
udpSendChan: make(chan udpPacket),
6969
gateways: gateways{
70-
gateways: make(map[lorawan.EUI64]gateway),
70+
gateways: make(map[lorawan.EUI64]gateway),
71+
cleanupDuration: time.Duration(conf.Backend.SemtechUDP.CleanupDuration),
7172
},
7273
fakeRxTime: conf.Backend.SemtechUDP.FakeRxTime,
7374
skipCRCCheck: conf.Backend.SemtechUDP.SkipCRCCheck,

internal/backend/semtechudp/registry.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var (
1818

1919
// gatewayCleanupDuration contains the duration after which the gateway is
2020
// cleaned up from the registry after no activity
21-
var gatewayCleanupDuration = -1 * time.Minute
21+
// This value can be set in config [backend.SemtechUDP.cleanup_duration]
22+
// var gatewayCleanupDuration = time.Duration(config.C.Backend.SemtechUDP.CleanupDuration) + (-1 * time.Minute)
2223

2324
// gateway contains a connection and meta-data for a gateway connection.
2425
type gateway struct {
@@ -31,7 +32,8 @@ type gateway struct {
3132
// gateways contains the gateways registry.
3233
type gateways struct {
3334
sync.RWMutex
34-
gateways map[lorawan.EUI64]gateway
35+
gateways map[lorawan.EUI64]gateway
36+
cleanupDuration time.Duration
3537

3638
subscribeEventFunc func(events.Subscribe)
3739
}
@@ -82,7 +84,7 @@ func (c *gateways) cleanup() error {
8284
defer c.Unlock()
8385

8486
for gatewayID := range c.gateways {
85-
if c.gateways[gatewayID].lastSeen.Before(time.Now().Add(gatewayCleanupDuration)) {
87+
if c.gateways[gatewayID].lastSeen.Before(time.Now().Add(c.cleanupDuration)) {
8688
disconnectCounter().Inc()
8789

8890
if c.subscribeEventFunc != nil {

internal/config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ type Config struct {
2121
Type string `mapstructure:"type"`
2222

2323
SemtechUDP struct {
24-
UDPBind string `mapstructure:"udp_bind"`
25-
SkipCRCCheck bool `mapstructure:"skip_crc_check"`
26-
FakeRxTime bool `mapstructure:"fake_rx_time"`
24+
UDPBind string `mapstructure:"udp_bind"`
25+
SkipCRCCheck bool `mapstructure:"skip_crc_check"`
26+
FakeRxTime bool `mapstructure:"fake_rx_time"`
27+
CleanupDuration int `mapstructure:"cleanup_duration"`
2728
} `mapstructure:"semtech_udp"`
2829

2930
BasicStation struct {

0 commit comments

Comments
 (0)