Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #236 Class C timeout #238

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
brocaar marked this conversation as resolved.
Show resolved Hide resolved
# 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)
Xantios marked this conversation as resolved.
Show resolved Hide resolved

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]
Xantios marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading