-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Request Monitoring Feature to CoAP Connection
The WithRequestMonitor function has been implemented to enable request monitoring for the connection. This function is called for each CoAP message received from the peer before it is processed. Details of the Feature: - Functionality: WithRequestMonitor allows developers to implement custom request monitoring logic for incoming CoAP messages. - Error Handling: If the function returns an error, the connection is closed, providing a mechanism to handle and respond to issues in the monitoring process. - Message Dropping: If the function returns true, the incoming message is dropped, allowing for selective handling or filtering of messages based on monitoring criteria. --------- Co-authored-by: Jeff Welder <[email protected]>
- Loading branch information
1 parent
ce37a93
commit 42d43eb
Showing
20 changed files
with
689 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package message | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/plgd-dev/go-coap/v3/message/codes" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMessageIsPing(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
message *Message | ||
isTCP bool | ||
want bool | ||
}{ | ||
{ | ||
name: "Ping message (TCP)", | ||
message: &Message{ | ||
Code: codes.Ping, | ||
Type: Confirmable, | ||
Token: nil, | ||
Options: nil, | ||
Payload: nil, | ||
}, | ||
isTCP: true, | ||
want: true, | ||
}, | ||
{ | ||
name: "Ping message (UDP)", | ||
message: &Message{ | ||
Code: codes.Empty, | ||
Type: Confirmable, | ||
Token: nil, | ||
Options: nil, | ||
Payload: nil, | ||
}, | ||
isTCP: false, | ||
want: true, | ||
}, | ||
{ | ||
name: "Non-ping message (TCP)", | ||
message: &Message{ | ||
Code: codes.GET, | ||
Type: Confirmable, | ||
Token: []byte{1, 2, 3}, | ||
Options: []Option{{ID: 1, Value: []byte{4, 5, 6}}}, | ||
Payload: []byte{7, 8, 9}, | ||
}, | ||
isTCP: true, | ||
want: false, | ||
}, | ||
{ | ||
name: "Non-ping message (UDP)", | ||
message: &Message{ | ||
Code: codes.GET, | ||
Type: Confirmable, | ||
Token: []byte{1, 2, 3}, | ||
Options: []Option{{ID: 1, Value: []byte{4, 5, 6}}}, | ||
Payload: []byte{7, 8, 9}, | ||
}, | ||
isTCP: false, | ||
want: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := tt.message.IsPing(tt.isTCP) | ||
require.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.