build: upgrade to go 1.17 and dependencies
This commit is contained in:
69
vendor/github.com/eclipse/paho.mqtt.golang/messageids.go
generated
vendored
69
vendor/github.com/eclipse/paho.mqtt.golang/messageids.go
generated
vendored
@ -28,6 +28,8 @@ type MId uint16
|
||||
type messageIds struct {
|
||||
sync.RWMutex
|
||||
index map[uint16]tokenCompletor
|
||||
|
||||
lastIssuedID uint16 // The most recently issued ID. Used so we cycle through ids rather than immediately reusing them (can make debugging easier)
|
||||
}
|
||||
|
||||
const (
|
||||
@ -40,11 +42,11 @@ func (mids *messageIds) cleanUp() {
|
||||
for _, token := range mids.index {
|
||||
switch token.(type) {
|
||||
case *PublishToken:
|
||||
token.setError(fmt.Errorf("Connection lost before Publish completed"))
|
||||
token.setError(fmt.Errorf("connection lost before Publish completed"))
|
||||
case *SubscribeToken:
|
||||
token.setError(fmt.Errorf("Connection lost before Subscribe completed"))
|
||||
token.setError(fmt.Errorf("connection lost before Subscribe completed"))
|
||||
case *UnsubscribeToken:
|
||||
token.setError(fmt.Errorf("Connection lost before Unsubscribe completed"))
|
||||
token.setError(fmt.Errorf("connection lost before Unsubscribe completed"))
|
||||
case nil:
|
||||
continue
|
||||
}
|
||||
@ -71,18 +73,33 @@ func (mids *messageIds) claimID(token tokenCompletor, id uint16) {
|
||||
old.flowComplete()
|
||||
mids.index[id] = token
|
||||
}
|
||||
if id > mids.lastIssuedID {
|
||||
mids.lastIssuedID = id
|
||||
}
|
||||
}
|
||||
|
||||
// getID will return an available id or 0 if none available
|
||||
// The id will generally be the previous id + 1 (because this makes tracing messages a bit simpler)
|
||||
func (mids *messageIds) getID(t tokenCompletor) uint16 {
|
||||
mids.Lock()
|
||||
defer mids.Unlock()
|
||||
for i := midMin; i < midMax; i++ {
|
||||
i := mids.lastIssuedID // note: the only situation where lastIssuedID is 0 the map will be empty
|
||||
looped := false // uint16 will loop from 65535->0
|
||||
for {
|
||||
i++
|
||||
if i == 0 { // skip 0 because its not a valid id (Control Packets MUST contain a non-zero 16-bit Packet Identifier [MQTT-2.3.1-1])
|
||||
i++
|
||||
looped = true
|
||||
}
|
||||
if _, ok := mids.index[i]; !ok {
|
||||
mids.index[i] = t
|
||||
mids.lastIssuedID = i
|
||||
return i
|
||||
}
|
||||
if (looped && i == mids.lastIssuedID) || (mids.lastIssuedID == 0 && i == midMax) { // lastIssuedID will be 0 at startup
|
||||
return 0 // no free ids
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (mids *messageIds) getToken(id uint16) tokenCompletor {
|
||||
@ -98,14 +115,23 @@ type DummyToken struct {
|
||||
id uint16
|
||||
}
|
||||
|
||||
// Wait implements the Token Wait method.
|
||||
func (d *DummyToken) Wait() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// WaitTimeout implements the Token WaitTimeout method.
|
||||
func (d *DummyToken) WaitTimeout(t time.Duration) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Done implements the Token Done method.
|
||||
func (d *DummyToken) Done() <-chan struct{} {
|
||||
ch := make(chan struct{})
|
||||
close(ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
func (d *DummyToken) flowComplete() {
|
||||
ERROR.Printf("A lookup for token %d returned nil\n", d.id)
|
||||
}
|
||||
@ -115,3 +141,36 @@ func (d *DummyToken) Error() error {
|
||||
}
|
||||
|
||||
func (d *DummyToken) setError(e error) {}
|
||||
|
||||
// PlaceHolderToken does nothing and was implemented to allow a messageid to be reserved
|
||||
// it differs from DummyToken in that calling flowComplete does not generate an error (it
|
||||
// is expected that flowComplete will be called when the token is overwritten with a real token)
|
||||
type PlaceHolderToken struct {
|
||||
id uint16
|
||||
}
|
||||
|
||||
// Wait implements the Token Wait method.
|
||||
func (p *PlaceHolderToken) Wait() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// WaitTimeout implements the Token WaitTimeout method.
|
||||
func (p *PlaceHolderToken) WaitTimeout(t time.Duration) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Done implements the Token Done method.
|
||||
func (p *PlaceHolderToken) Done() <-chan struct{} {
|
||||
ch := make(chan struct{})
|
||||
close(ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
func (p *PlaceHolderToken) flowComplete() {
|
||||
}
|
||||
|
||||
func (p *PlaceHolderToken) Error() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PlaceHolderToken) setError(e error) {}
|
||||
|
Reference in New Issue
Block a user