Fix a bunch of golangci-lint issues
This commit is contained in:
parent
e4fae94588
commit
9cd116c5e4
9 changed files with 48 additions and 26 deletions
10
main.go
10
main.go
|
@ -10,11 +10,11 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
listen_addr := ":1883"
|
||||
listener, err := net.Listen("tcp", listen_addr)
|
||||
listenAddr := ":1883"
|
||||
listener, err := net.Listen("tcp", listenAddr)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Coulde't start a listener on tcp %v. Error: %e", listen_addr, err)
|
||||
log.Fatalf("Coulde't start a listener on tcp %v. Error: %e", listenAddr, err)
|
||||
}
|
||||
|
||||
var sessions map[string]*session.Session = make(map[string]*session.Session)
|
||||
|
@ -37,8 +37,8 @@ func main() {
|
|||
select {
|
||||
case con := <-connChan:
|
||||
handleConnection(con, sessions, removeSessChan)
|
||||
case sesId := <- removeSessChan:
|
||||
delete(sessions, sesId)
|
||||
case sesID := <-removeSessChan:
|
||||
delete(sessions, sesID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,13 @@ func (c controlPacket) write(w io.Writer) error {
|
|||
return err
|
||||
}
|
||||
|
||||
types.WriteDataWithVarIntLen(buf, data)
|
||||
w.Write(buf.Bytes())
|
||||
err = types.WriteDataWithVarIntLen(buf, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(buf.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -74,7 +74,10 @@ func WriteVariableByteInt(w io.Writer, v uint32) error {
|
|||
encodedByte = encodedByte | 128
|
||||
}
|
||||
|
||||
w.Write([]byte{encodedByte})
|
||||
_,err := w.Write([]byte{encodedByte})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if v == 0 {
|
||||
return nil
|
||||
|
|
|
@ -59,7 +59,10 @@ func (s *Session) Connect(req ConnectionRequest) {
|
|||
connAck.Properties.SharedSubscriptionAvailable.Value = &false
|
||||
|
||||
s.Connection = req.Connection
|
||||
s.Connection.sendPacket(connAck)
|
||||
err := s.Connection.sendPacket(connAck)
|
||||
if err != nil {
|
||||
panic("TODO, handle this")
|
||||
}
|
||||
}
|
||||
|
||||
// Starts a loop the recieves and responds to packets
|
||||
|
@ -69,7 +72,7 @@ func (s *Session) HandlerLoop() {
|
|||
select {
|
||||
case packet := <-s.Connection.PacketChannel:
|
||||
packet.Visit(s)
|
||||
case _ = <-s.Connection.ClientDisconnectedChan:
|
||||
case <-s.Connection.ClientDisconnectedChan:
|
||||
s.onDisconnect()
|
||||
case c := <-s.ConnecionChannel:
|
||||
s.Connect(c)
|
||||
|
@ -77,7 +80,10 @@ func (s *Session) HandlerLoop() {
|
|||
// TODO implement other qos levels
|
||||
subMessage.QOSLevel = 0
|
||||
subMessage.Dup = false
|
||||
s.Connection.sendPacket(subMessage)
|
||||
err := s.Connection.sendPacket(subMessage)
|
||||
if err != nil {
|
||||
panic("TOOO handle this")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +92,7 @@ func (s *Session) HandlerLoop() {
|
|||
s.Connect(c)
|
||||
// Tail recursion baybeeee
|
||||
s.HandlerLoop()
|
||||
case _ = <- s.expireTimer.C:
|
||||
case <- s.expireTimer.C:
|
||||
s.expireSession()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ type Connection struct {
|
|||
|
||||
func (c *Connection) resetKeepAlive() {
|
||||
if c.KeepAliveInterval != 0 {
|
||||
panic("TODO")
|
||||
// TODO IMPLEMENT THIS
|
||||
//s.keepAliveTicker.Reset(s.KeepAliveInterval)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func (s *Session) expireSession() {
|
|||
|
||||
// newTime is nullable
|
||||
func (s *Session) SetExpireTimer(newTime *uint32) {
|
||||
var expiry = uint32(0)
|
||||
expiry := uint32(0)
|
||||
if newTime != nil {
|
||||
expiry = *newTime
|
||||
} else {
|
||||
|
|
|
@ -31,7 +31,10 @@ func (s *Session) VisitPublish(p packets.PublishPacket) {
|
|||
PacketID: *p.PacketId,
|
||||
Reason: reason,
|
||||
}
|
||||
s.Connection.sendPacket(ack)
|
||||
err := s.Connection.sendPacket(ack)
|
||||
if err != nil {
|
||||
panic("TODO")
|
||||
}
|
||||
} else if p.QOSLevel == 2 {
|
||||
panic("UNIMPLEMENTED QOS level 2")
|
||||
}
|
||||
|
@ -56,24 +59,30 @@ func (s *Session) VisitSubscribe(p packets.SubscribePacket) {
|
|||
for _, filter := range p.TopicFilters {
|
||||
subscription.Subscriptions.Subscribe(filter, s.SubscriptionChannel)
|
||||
}
|
||||
s.Connection.sendPacket(packets.SubAckPacket{
|
||||
err := s.Connection.sendPacket(packets.SubAckPacket{
|
||||
PacketID: p.PacketId,
|
||||
Reason: packets.SubackReasonGrantedQoSTwo,
|
||||
})
|
||||
if err != nil {
|
||||
panic("TODO")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) VisitUnsubscribe(p packets.UnsubscribePacket) {
|
||||
for _, topic := range p.Topics {
|
||||
subscription.Subscriptions.Unsubscribe(topic, s.SubscriptionChannel)
|
||||
}
|
||||
s.Connection.sendPacket(packets.UnsubAckPacket{
|
||||
err := s.Connection.sendPacket(packets.UnsubAckPacket{
|
||||
PacketID: p.PacketID,
|
||||
Reason: packets.UnsubackReasonSuccess,
|
||||
})
|
||||
if err != nil {
|
||||
panic("TODO")
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Session) VisitPing(p packets.PingreqPacket) {
|
||||
s.Connection.sendPacket(packets.PingrespPacket{})
|
||||
_ = s.Connection.sendPacket(packets.PingrespPacket{})
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,17 +24,14 @@ func genClientID() *string {
|
|||
return &id
|
||||
}
|
||||
|
||||
func (s *Session) Disconnect(code packets.DisconnectReasonCode) error {
|
||||
s.Connection.sendPacket(packets.DisconnectPacket{
|
||||
func (s *Session) Disconnect(code packets.DisconnectReasonCode) {
|
||||
// If disconnetion fails that means we are already disconnected, great!
|
||||
_ = s.Connection.sendPacket(packets.DisconnectPacket{
|
||||
ReasonCode: code,
|
||||
})
|
||||
_ = s.Connection.close()
|
||||
|
||||
err := s.Connection.close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.onDisconnect()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ func (s *SubscriptionTreeNode) findNode(fields []string) *SubscriptionTreeNode {
|
|||
s.NodeLock.RLock()
|
||||
}
|
||||
|
||||
child, _ := s.children[field]
|
||||
child := s.children[field]
|
||||
s.NodeLock.RUnlock()
|
||||
return child.findNode(fields[1:])
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue