Skip to content

Commit

Permalink
return error SNAC from OService ServiceRequest for unknown SNAC
Browse files Browse the repository at this point in the history
  • Loading branch information
mk6i committed Jun 7, 2024
1 parent 944cb56 commit f95c180
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
22 changes: 12 additions & 10 deletions foodgroup/oservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,7 @@ type chatLoginCookie struct {

// ServiceRequest handles service discovery, providing a host name and metadata
// for connecting to the food group service specified in inFrame.
// Depending on the food group specified, the method behaves as follows:
// - ChatNav: Directs the user back to the current BOS server, which provides
// ChatNav services. AIM 4.8 requests ChatNav service info even though
// HostOnline reports it as available via BOS.
// - Chat: Directs the client to the chat server along with metadata for
// connecting to the chat room specified in inFrame.
// - Other Food Groups: Returns wire.ErrUnsupportedFoodGroup.
func (s OServiceServiceForBOS) ServiceRequest(_ context.Context, sess *state.Session, inFrame wire.SNACFrame, inBody wire.SNAC_0x01_0x04_OServiceServiceRequest) (wire.SNACMessage, error) {
func (s OServiceServiceForBOS) ServiceRequest(ctx context.Context, sess *state.Session, inFrame wire.SNACFrame, inBody wire.SNAC_0x01_0x04_OServiceServiceRequest) (wire.SNACMessage, error) {
switch inBody.FoodGroup {
case wire.Alert:
cookie, err := s.cookieIssuer.Issue([]byte(sess.ScreenName()))
Expand Down Expand Up @@ -662,8 +655,17 @@ func (s OServiceServiceForBOS) ServiceRequest(_ context.Context, sess *state.Ses
},
}, nil
default:
err := fmt.Errorf("%w. food group: %s", wire.ErrUnsupportedFoodGroup, wire.FoodGroupName(inBody.FoodGroup))
return wire.SNACMessage{}, err
s.logger.InfoContext(ctx, "client service request for unsupported service", "food_group", wire.FoodGroupName(inBody.FoodGroup))
return wire.SNACMessage{
Frame: wire.SNACFrame{
FoodGroup: wire.OService,
SubGroup: wire.OServiceErr,
RequestID: inFrame.RequestID,
},
Body: wire.SNACError{
Code: wire.ErrorCodeServiceUnavailable,
},
}, nil
}
}

Expand Down
11 changes: 10 additions & 1 deletion foodgroup/oservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ func TestOServiceServiceForBOS_ServiceRequest(t *testing.T) {
FoodGroup: wire.ICBM,
},
},
expectErr: wire.ErrUnsupportedFoodGroup,
expectOutput: wire.SNACMessage{
Frame: wire.SNACFrame{
FoodGroup: wire.OService,
SubGroup: wire.OServiceErr,
RequestID: 1234,
},
Body: wire.SNACError{
Code: wire.ErrorCodeServiceUnavailable,
},
},
},
{
name: "request info for connecting to chat nav, return chat nav connection metadata",
Expand Down
2 changes: 1 addition & 1 deletion server/oscar/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func dispatchIncomingMessages(ctx context.Context, sess *state.Session, flapc *w
// handler may write a response to the client connection.
if err := router.Handle(ctx, sess, inFrame, m.payload, flapc); err != nil {
middleware.LogRequestError(ctx, logger, inFrame, err)
if errors.Is(err, ErrRouteNotFound) || errors.Is(err, wire.ErrUnsupportedFoodGroup) {
if errors.Is(err, ErrRouteNotFound) {
if err1 := sendInvalidSNACErr(inFrame, flapc); err1 != nil {
return errors.Join(err1, err)
}
Expand Down
4 changes: 0 additions & 4 deletions wire/snacs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import (
"fmt"
)

// ErrUnsupportedFoodGroup indicates that a foodgroup value is either invalid
// or unsupported by a method.
var ErrUnsupportedFoodGroup = errors.New("foodgroup is unsupported")

//
// Food Group Codes
//
Expand Down

0 comments on commit f95c180

Please sign in to comment.