Skip to content

Commit

Permalink
Fixes #236 Class C timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Xantios committed Jun 12, 2024
1 parent dfbaf37 commit 36361ee
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cmd/chirpstack-gateway-bridge/cmd/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ type="{{ .Backend.Type }}"
# the time would otherwise be unset.
fake_rx_time={{ .Backend.SemtechUDP.FakeRxTime }}
# Cleanup duration
# Cleaup duration for class C devices
cleanup_duration={{ .Backend.SemtechUDP.CleanupDuration }}
# ChirpStack Concentratord backend.
[backend.concentratord]
Expand Down
1 change: 1 addition & 0 deletions cmd/chirpstack-gateway-bridge/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func init() {
viper.SetDefault("general.log_level", 4)
viper.SetDefault("backend.type", "semtech_udp")
viper.SetDefault("backend.semtech_udp.udp_bind", "0.0.0.0:1700")
viper.SetDefault("backend.semtech_udp.cleanup_duration", -1)

viper.SetDefault("backend.concentratord.crc_check", true)
viper.SetDefault("backend.concentratord.event_url", "ipc:///tmp/concentratord_event")
Expand Down
3 changes: 2 additions & 1 deletion internal/backend/semtechudp/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func NewBackend(conf config.Config) (*Backend, error) {
conn: conn,
udpSendChan: make(chan udpPacket),
gateways: gateways{
gateways: make(map[lorawan.EUI64]gateway),
gateways: make(map[lorawan.EUI64]gateway),
cleanupDuration: time.Duration(conf.Backend.SemtechUDP.CleanupDuration),
},
fakeRxTime: conf.Backend.SemtechUDP.FakeRxTime,
skipCRCCheck: conf.Backend.SemtechUDP.SkipCRCCheck,
Expand Down
8 changes: 5 additions & 3 deletions internal/backend/semtechudp/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var (

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

// gateway contains a connection and meta-data for a gateway connection.
type gateway struct {
Expand All @@ -31,7 +32,8 @@ type gateway struct {
// gateways contains the gateways registry.
type gateways struct {
sync.RWMutex
gateways map[lorawan.EUI64]gateway
gateways map[lorawan.EUI64]gateway
cleanupDuration time.Duration

subscribeEventFunc func(events.Subscribe)
}
Expand Down Expand Up @@ -82,7 +84,7 @@ func (c *gateways) cleanup() error {
defer c.Unlock()

for gatewayID := range c.gateways {
if c.gateways[gatewayID].lastSeen.Before(time.Now().Add(gatewayCleanupDuration)) {
if c.gateways[gatewayID].lastSeen.Before(time.Now().Add(c.cleanupDuration)) {
disconnectCounter().Inc()

if c.subscribeEventFunc != nil {
Expand Down
7 changes: 4 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ type Config struct {
Type string `mapstructure:"type"`

SemtechUDP struct {
UDPBind string `mapstructure:"udp_bind"`
SkipCRCCheck bool `mapstructure:"skip_crc_check"`
FakeRxTime bool `mapstructure:"fake_rx_time"`
UDPBind string `mapstructure:"udp_bind"`
SkipCRCCheck bool `mapstructure:"skip_crc_check"`
FakeRxTime bool `mapstructure:"fake_rx_time"`
CleanupDuration int `mapstructure:"cleanup_duration"`
} `mapstructure:"semtech_udp"`

BasicStation struct {
Expand Down

0 comments on commit 36361ee

Please sign in to comment.