Skip to content

"CoAP ping" is acknowleged #603

@svenschwermer

Description

@svenschwermer

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).

go-coap/udp/client/conn.go

Lines 645 to 658 in 71407da

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions