Skip to content

Commit d001e55

Browse files
authored
Make UDP connection timeout configurable. (#238)
1 parent dfbaf37 commit d001e55

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ type="{{ .Backend.Type }}"
8888
# the time would otherwise be unset.
8989
fake_rx_time={{ .Backend.SemtechUDP.FakeRxTime }}
9090
91+
# Connection timeout duration
92+
#
93+
# ChirpStack Gateway Bridge keeps a list of connected gateways. If a gateway does not send any
94+
# UDP data within the configured timeout, then ChirpStack Gateway Bridge will consider the gateway
95+
# disconnected and it will unsubscribe from the gateway MQTT topic and cleanup the UDP docket.
96+
connection_timeout_duration={{ .Backend.SemtechUDP.CleanupDuration }}
9197
9298
# ChirpStack Concentratord backend.
9399
[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", time.Minute)
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: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ var (
1616
errGatewayDoesNotExist = errors.New("gateway does not exist")
1717
)
1818

19-
// gatewayCleanupDuration contains the duration after which the gateway is
20-
// cleaned up from the registry after no activity
21-
var gatewayCleanupDuration = -1 * time.Minute
22-
2319
// gateway contains a connection and meta-data for a gateway connection.
2420
type gateway struct {
2521
stats *stats.Collector
@@ -31,7 +27,8 @@ type gateway struct {
3127
// gateways contains the gateways registry.
3228
type gateways struct {
3329
sync.RWMutex
34-
gateways map[lorawan.EUI64]gateway
30+
gateways map[lorawan.EUI64]gateway
31+
cleanupDuration time.Duration
3532

3633
subscribeEventFunc func(events.Subscribe)
3734
}
@@ -82,7 +79,7 @@ func (c *gateways) cleanup() error {
8279
defer c.Unlock()
8380

8481
for gatewayID := range c.gateways {
85-
if c.gateways[gatewayID].lastSeen.Before(time.Now().Add(gatewayCleanupDuration)) {
82+
if c.gateways[gatewayID].lastSeen.Before(time.Now().Add(c.cleanupDuration)) {
8683
disconnectCounter().Inc()
8784

8885
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:"connection_timeout_duration"`
2728
} `mapstructure:"semtech_udp"`
2829

2930
BasicStation struct {

0 commit comments

Comments
 (0)