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 all commits
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
6 changes: 6 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,12 @@ type="{{ .Backend.Type }}"
# the time would otherwise be unset.
fake_rx_time={{ .Backend.SemtechUDP.FakeRxTime }}

# Connection timeout duration
#
# ChirpStack Gateway Bridge keeps a list of connected gateways. If a gateway does not send any
# UDP data within the configured timeout, then ChirpStack Gateway Bridge will consider the gateway
# disconnected and it will unsubscribe from the gateway MQTT topic and cleanup the UDP docket.
connection_timeout_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", time.Minute)

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
9 changes: 3 additions & 6 deletions internal/backend/semtechudp/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ var (
errGatewayDoesNotExist = errors.New("gateway does not exist")
)

// gatewayCleanupDuration contains the duration after which the gateway is
// cleaned up from the registry after no activity
var gatewayCleanupDuration = -1 * time.Minute

// gateway contains a connection and meta-data for a gateway connection.
type gateway struct {
stats *stats.Collector
Expand All @@ -31,7 +27,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 +79,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:"connection_timeout_duration"`
} `mapstructure:"semtech_udp"`

BasicStation struct {
Expand Down