Skip to content

Commit 4238596

Browse files
committed
Fix #238.
This fixes PR #238 (which was only included in the v4.1.0 release). It fixes the time (replaces int type by time.Duration) and fixes the last-seen comparison clause. It also cleans up the internal variable naming.
1 parent e9fdad0 commit 4238596

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type="{{ .Backend.Type }}"
9292
# ChirpStack Gateway Bridge keeps a list of connected gateways. If a gateway does not send any
9393
# UDP data within the configured timeout, then ChirpStack Gateway Bridge will consider the gateway
9494
# disconnected and it will unsubscribe from the gateway MQTT topic and cleanup the UDP docket.
95-
connection_timeout_duration={{ .Backend.SemtechUDP.CleanupDuration }}
95+
connection_timeout_duration="{{ .Backend.SemtechUDP.ConnectionTimeoutDuration }}"
9696
9797
# Cache expiration
9898
#

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +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)
42+
viper.SetDefault("backend.semtech_udp.connection_timeout_duration", time.Minute)
4343

4444
viper.SetDefault("backend.semtech_udp.cache_default_expiration", 15*time.Second)
4545
viper.SetDefault("backend.semtech_udp.cache_cleanup_interval", 15*time.Second)

internal/backend/semtechudp/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +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),
71-
cleanupDuration: time.Duration(conf.Backend.SemtechUDP.CleanupDuration),
70+
gateways: make(map[lorawan.EUI64]gateway),
71+
connectionTimeoutDuration: conf.Backend.SemtechUDP.ConnectionTimeoutDuration,
7272
},
7373
fakeRxTime: conf.Backend.SemtechUDP.FakeRxTime,
7474
skipCRCCheck: conf.Backend.SemtechUDP.SkipCRCCheck,

internal/backend/semtechudp/registry.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ type gateway struct {
2727
// gateways contains the gateways registry.
2828
type gateways struct {
2929
sync.RWMutex
30-
gateways map[lorawan.EUI64]gateway
31-
cleanupDuration time.Duration
30+
gateways map[lorawan.EUI64]gateway
31+
connectionTimeoutDuration time.Duration
3232

3333
subscribeEventFunc func(events.Subscribe)
3434
}
@@ -79,7 +79,7 @@ func (c *gateways) cleanup() error {
7979
defer c.Unlock()
8080

8181
for gatewayID := range c.gateways {
82-
if c.gateways[gatewayID].lastSeen.Before(time.Now().Add(c.cleanupDuration)) {
82+
if c.gateways[gatewayID].lastSeen.Before(time.Now().Add(-1 * c.connectionTimeoutDuration)) {
8383
disconnectCounter().Inc()
8484

8585
if c.subscribeEventFunc != nil {

internal/config/config.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ 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"`
27-
CleanupDuration int `mapstructure:"connection_timeout_duration"`
28-
CacheDefaultExpiration time.Duration `mapstructure:"cache_default_expiration"`
29-
CacheCleanupInterval time.Duration `mapstructure:"cache_cleanup_interval"`
24+
UDPBind string `mapstructure:"udp_bind"`
25+
SkipCRCCheck bool `mapstructure:"skip_crc_check"`
26+
FakeRxTime bool `mapstructure:"fake_rx_time"`
27+
ConnectionTimeoutDuration time.Duration `mapstructure:"connection_timeout_duration"`
28+
CacheDefaultExpiration time.Duration `mapstructure:"cache_default_expiration"`
29+
CacheCleanupInterval time.Duration `mapstructure:"cache_cleanup_interval"`
3030
} `mapstructure:"semtech_udp"`
3131

3232
BasicStation struct {

0 commit comments

Comments
 (0)