IsPing correctly identifying empty confirmable messages over unreliable transport as "CoAP pings" (RFC 7252).
|
func (r *Message) IsPing(isTCP bool) bool { |
|
if isTCP { |
|
return r.Code == codes.Ping |
|
} |
|
return r.Code == codes.Empty && r.Type == Confirmable && len(r.Token) == 0 && len(r.Options) == 0 && len(r.Payload) == 0 |
|
} |
However, the response is an acknowledgment which is incorrect. It should be a Reset Message (RST).
|
func (cc *Conn) sendPong(w *responsewriter.ResponseWriter[*Conn], r *pool.Message) { |
|
if err := w.SetResponse(codes.Empty, message.TextPlain, nil); err != nil { |
|
cc.errors(fmt.Errorf("cannot send pong response: %w", err)) |
|
} |
|
if r.Type() == message.Confirmable { |
|
w.Message().SetType(message.Acknowledgement) |
|
w.Message().SetMessageID(r.MessageID()) |
|
} else { |
|
if w.Message().Type() != message.Reset { |
|
w.Message().SetType(message.NonConfirmable) |
|
} |
|
w.Message().SetMessageID(cc.GetMessageID()) |
|
} |
|
} |
Quoting RFC 7252:
Provoking a Reset message (e.g., by sending an Empty Confirmable message) is also useful as an inexpensive check of the liveness of an endpoint ("CoAP ping").
and
"*" means that the combination is not used in normal operation but only to elicit a Reset message ("CoAP ping").
where * refers to an empty confirmable message.
IsPingcorrectly identifying empty confirmable messages over unreliable transport as "CoAP pings" (RFC 7252).go-coap/message/message.go
Lines 53 to 58 in 71407da
However, the response is an acknowledgment which is incorrect. It should be a Reset Message (RST).
go-coap/udp/client/conn.go
Lines 645 to 658 in 71407da
Quoting RFC 7252:
and
where
*refers to an empty confirmable message.