Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Proper Blockwise Handling for Initial GET and DELETE Requests #525

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions net/blockwise/blockwise.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ func (b *BlockWise[C]) handleReceivedMessage(w *responsewriter.ResponseWriter[C]
next(w, r)
return nil
case codes.GET, codes.DELETE:
// For GET and DELETE requests in CoAP, the initial request cannot have the message type of Acknowledge (ACK) or Reset (RST)
if !r.HasOption(message.Observe) && (r.Type() == message.Acknowledgement || r.Type() == message.Reset) {
return fmt.Errorf("invalid message type(%v) for code(%v)", r.Type(), r.Code())
}
maxSZX = fitSZX(r, message.Block2, maxSZX)
block, errG := r.GetOptionUint32(message.Block2)
if errG == nil {
Expand Down Expand Up @@ -519,11 +523,7 @@ func (b *BlockWise[C]) continueSendingMessage(w *responsewriter.ResponseWriter[C
}

func isObserveResponse(msg *pool.Message) bool {
_, err := msg.GetOptionUint32(message.Observe)
if err != nil {
return false
}
return msg.Code() >= codes.Created
return msg.HasOption(message.Observe) && msg.Code() >= codes.Created
}

func (b *BlockWise[C]) startSendingMessage(w *responsewriter.ResponseWriter[C], maxSZX SZX, maxMessageSize uint32, block uint32) error {
Expand Down
Loading