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

Add defensive code in case mechanism elements are mistakenly chain elmements #140

Merged
merged 1 commit into from
Feb 23, 2020
Merged
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
11 changes: 10 additions & 1 deletion pkg/networkservice/common/mechanisms/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/pkg/errors"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
)

Expand All @@ -39,7 +40,15 @@ type mechanismsServer struct {
// value: NetworkServiceServer that only handles the work for the specified mechanismType
// Note: Supplied NetworkServiceServer elements should not call next.Server(ctx).{Request,Close} themselves
func NewServer(mechanisms map[string]networkservice.NetworkServiceServer) networkservice.NetworkServiceServer {
return &mechanismsServer{mechanisms: mechanisms}
rv := &mechanismsServer{
mechanisms: make(map[string]networkservice.NetworkServiceServer),
}
for mechanismType, server := range mechanisms {
// We wrap in a chain here to make sure that if the 'server' is calling next.Server(ctx) it doesn't
// skips past returning here.
rv.mechanisms[mechanismType] = chain.NewNetworkServiceServer(server)
}
return rv
}

func (m *mechanismsServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
Expand Down