mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* MF-166 - Add lora-adapter service (#416) * MF-166 - Add lora-adapter service Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix NATS connexion and use credentials with gRPC Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Forward lora msgs to nats Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add make cmd and docker-compose Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Define lora conf as private Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename funcs fix nats conn Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update README and fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rm NATS sub Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * MF-166 - Add lora-adapter service (#461) * MF-166 - Add lora-adapter service Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix NATS connexion and use credentials with gRPC Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Forward lora msgs to nats Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Add make cmd and docker-compose Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Define lora conf as private Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rename funcs fix nats conn Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update README and fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Rm NATS sub Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix lora server topic and logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix HTTP port Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * NOISSUE - Add event sourcing client to LoRa adapter (#471) * Add event sourcing client to LoRa adapter Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Update redis version in docker compose and update env vars Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add ES subscription to main LoRa function Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add new env vars to readme file of LoRa adapter Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add message acknowledgement to LoRa adapter Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add handling of empty values to event sourcing client (#474) Signed-off-by: Aleksandar Novaković <anovakovic01@gmail.com> * Add routemap and handle event sourcing Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix eventStore decoding Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Mv docker-compose in docker/addons Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix routemap and logs Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update Gopkg.toml Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix route map and typos Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update README Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
/*
|
|
* Copyright (c) 2013 IBM Corp.
|
|
*
|
|
* All rights reserved. This program and the accompanying materials
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
* which accompanies this distribution, and is available at
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
*
|
|
* Contributors:
|
|
* Seth Hoenig
|
|
* Allan Stockdill-Mander
|
|
* Mike Robertson
|
|
*/
|
|
|
|
package mqtt
|
|
|
|
import (
|
|
"errors"
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"github.com/eclipse/paho.mqtt.golang/packets"
|
|
)
|
|
|
|
func keepalive(c *client) {
|
|
defer c.workers.Done()
|
|
DEBUG.Println(PNG, "keepalive starting")
|
|
var checkInterval int64
|
|
var pingSent time.Time
|
|
|
|
if c.options.KeepAlive > 10 {
|
|
checkInterval = 5
|
|
} else {
|
|
checkInterval = c.options.KeepAlive / 2
|
|
}
|
|
|
|
intervalTicker := time.NewTicker(time.Duration(checkInterval * int64(time.Second)))
|
|
defer intervalTicker.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-c.stop:
|
|
DEBUG.Println(PNG, "keepalive stopped")
|
|
return
|
|
case <-intervalTicker.C:
|
|
DEBUG.Println(PNG, "ping check", time.Now().Unix()-atomic.LoadInt64(&c.lastSent))
|
|
if time.Now().Unix()-atomic.LoadInt64(&c.lastSent) >= c.options.KeepAlive || time.Now().Unix()-atomic.LoadInt64(&c.lastReceived) >= c.options.KeepAlive {
|
|
if atomic.LoadInt32(&c.pingOutstanding) == 0 {
|
|
DEBUG.Println(PNG, "keepalive sending ping")
|
|
ping := packets.NewControlPacket(packets.Pingreq).(*packets.PingreqPacket)
|
|
//We don't want to wait behind large messages being sent, the Write call
|
|
//will block until it it able to send the packet.
|
|
atomic.StoreInt32(&c.pingOutstanding, 1)
|
|
ping.Write(c.conn)
|
|
atomic.StoreInt64(&c.lastSent, time.Now().Unix())
|
|
pingSent = time.Now()
|
|
}
|
|
}
|
|
if atomic.LoadInt32(&c.pingOutstanding) > 0 && time.Now().Sub(pingSent) >= c.options.PingTimeout {
|
|
CRITICAL.Println(PNG, "pingresp not received, disconnecting")
|
|
c.errors <- errors.New("pingresp not received, disconnecting")
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|