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

Moved to using a generic map instead of generated maps #1421

Merged
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions pkg/networkservice/chains/nsmgr/dns_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -25,6 +27,7 @@ import (
"testing"
"time"

"github.com/edwarnicke/genericsync"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls"
kernelmech "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
Expand All @@ -33,7 +36,6 @@ import (

"github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
"github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext"
"github.com/networkservicemesh/sdk/pkg/tools/dnsconfig"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils/cache"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils/dnsconfigs"
Expand Down Expand Up @@ -74,7 +76,7 @@ func Test_DNSUsecase(t *testing.T) {

nse := domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)

dnsConfigsMap := new(dnsconfig.Map)
dnsConfigsMap := new(genericsync.Map[string, []*networkservice.DNSConfig])
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, client.WithAdditionalFunctionality(dnscontext.NewClient(
dnscontext.WithChainContext(ctx),
dnscontext.WithDNSConfigsMap(dnsConfigsMap),
Expand All @@ -88,7 +90,7 @@ func Test_DNSUsecase(t *testing.T) {
}

// DNS server on nse side
dnsRecords := new(memory.Map)
dnsRecords := new(genericsync.Map[string, []net.IP])
dnsRecords.Store("my.domain.", []net.IP{net.ParseIP("4.4.4.4")})
dnsRecords.Store("my.domain.com.", []net.IP{net.ParseIP("5.5.5.5")})
dnsutils.ListenAndServe(ctx, memory.NewDNSHandler(dnsRecords), ":40053")
Expand Down
6 changes: 3 additions & 3 deletions pkg/networkservice/chains/nsmgr/vl3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"testing"
"time"

"github.com/edwarnicke/genericsync"
"github.com/google/uuid"
"github.com/networkservicemesh/api/pkg/api/ipam"
"github.com/networkservicemesh/api/pkg/api/networkservice"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext/vl3dns"
"github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/ipcontext/vl3"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkconnection"
"github.com/networkservicemesh/sdk/pkg/tools/dnsconfig"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils/memory"
"github.com/networkservicemesh/sdk/pkg/tools/sandbox"
Expand Down Expand Up @@ -137,7 +137,7 @@ func Test_vl3NSE_ConnectsTo_vl3NSE(t *testing.T) {
SetRegistryProxySupplier(nil).
Build()

var records memory.Map
var records genericsync.Map[string, []net.IP]
var dnsServer = memory.NewDNSHandler(&records)

records.Store("nsc1.vl3.", []net.IP{net.ParseIP("1.1.1.1")})
Expand All @@ -156,7 +156,7 @@ func Test_vl3NSE_ConnectsTo_vl3NSE(t *testing.T) {

serverPrefixCh <- &ipam.PrefixResponse{Prefix: "10.0.0.1/24"}

var dnsConfigs = new(dnsconfig.Map)
var dnsConfigs = new(genericsync.Map[string, []*networkservice.DNSConfig])
dnsServerIPCh := make(chan net.IP, 1)
dnsServerIPCh <- net.ParseIP("0.0.0.0")

Expand Down
11 changes: 7 additions & 4 deletions pkg/networkservice/common/authorize/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2020-2022 Cisco Systems, Inc.
// Copyright (c) 2020-2023 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -18,11 +18,14 @@

package authorize

import "github.com/networkservicemesh/sdk/pkg/tools/spire"
import (
"github.com/edwarnicke/genericsync"
"github.com/spiffe/go-spiffe/v2/spiffeid"
)

type options struct {
policyPaths []string
spiffeIDConnectionMap *spire.SpiffeIDConnectionMap
spiffeIDConnectionMap *genericsync.Map[spiffeid.ID, *genericsync.Map[string, struct{}]]
}

// Option is authorization option for network service server
Expand All @@ -42,7 +45,7 @@ func WithPolicies(policyPaths ...string) Option {
}

// WithSpiffeIDConnectionMap sets map to keep spiffeIDConnectionMap to authorize connections with MonitorConnectionServer
func WithSpiffeIDConnectionMap(s *spire.SpiffeIDConnectionMap) Option {
func WithSpiffeIDConnectionMap(s *genericsync.Map[spiffeid.ID, *genericsync.Map[string, struct{}]]) Option {
return func(o *options) {
o.spiffeIDConnectionMap = s
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/networkservice/common/authorize/server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2020-2022 Cisco Systems, Inc.
// Copyright (c) 2020-2023 Cisco Systems, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -22,21 +22,22 @@ package authorize
import (
"context"

"github.com/edwarnicke/genericsync"
"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"github.com/spiffe/go-spiffe/v2/spiffeid"
"google.golang.org/grpc/peer"

"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/opa"
"github.com/networkservicemesh/sdk/pkg/tools/spire"
"github.com/networkservicemesh/sdk/pkg/tools/stringset"
)

type authorizeServer struct {
policies policiesList
spiffeIDConnectionMap *spire.SpiffeIDConnectionMap
spiffeIDConnectionMap *genericsync.Map[spiffeid.ID, *genericsync.Map[string, struct{}]]
}

// NewServer - returns a new authorization networkservicemesh.NetworkServiceServers
Expand All @@ -47,7 +48,7 @@ func NewServer(opts ...Option) networkservice.NetworkServiceServer {
"etc/nsm/opa/common/.*.rego",
"etc/nsm/opa/server/.*.rego",
},
spiffeIDConnectionMap: &spire.SpiffeIDConnectionMap{},
spiffeIDConnectionMap: &genericsync.Map[spiffeid.ID, *genericsync.Map[string, struct{}]]{},
}
for _, opt := range opts {
opt(o)
Expand Down Expand Up @@ -86,7 +87,7 @@ func (a *authorizeServer) Request(ctx context.Context, request *networkservice.N
connID := conn.GetPath().GetPathSegments()[index-1].GetId()
ids, ok := a.spiffeIDConnectionMap.Load(spiffeID)
if !ok {
ids = new(stringset.StringSet)
ids = new(genericsync.Map[string, struct{}])
}
ids.Store(connID, struct{}{})
a.spiffeIDConnectionMap.Store(spiffeID, ids)
Expand Down
4 changes: 2 additions & 2 deletions pkg/networkservice/connectioncontext/dnscontext/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"os"
"strings"

"github.com/edwarnicke/genericsync"
"github.com/golang/protobuf/ptypes/empty"
"github.com/miekg/dns"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/pkg/errors"
"google.golang.org/grpc"

"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/tools/dnsconfig"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils"
"github.com/networkservicemesh/sdk/pkg/tools/log"
)
Expand All @@ -40,7 +40,7 @@ type dnsContextClient struct {
resolveConfigPath string
defaultNameServerIP string
resolvconfDNSConfig *networkservice.DNSConfig
dnsConfigsMap *dnsconfig.Map
dnsConfigsMap *genericsync.Map[string, []*networkservice.DNSConfig]
}

// NewClient creates a new DNS client chain component. Setups all DNS traffic to the localhost. Monitors DNS configs from connections.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2022 Cisco and/or its affiliates.
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -26,14 +26,14 @@ import (
"testing"
"time"

"github.com/edwarnicke/genericsync"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/dnsconfig"
)

func Test_DNSContextClient_Usecases(t *testing.T) {
Expand All @@ -51,7 +51,7 @@ func Test_DNSContextClient_Usecases(t *testing.T) {
dnscontext.NewClient(
dnscontext.WithChainContext(ctx),
dnscontext.WithResolveConfigPath(resolveConfigPath),
dnscontext.WithDNSConfigsMap(new(dnsconfig.Map)),
dnscontext.WithDNSConfigsMap(new(genericsync.Map[string, []*networkservice.DNSConfig])),
),
)

Expand Down
7 changes: 4 additions & 3 deletions pkg/networkservice/connectioncontext/dnscontext/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2022 Cisco and/or its affiliates.
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -21,7 +21,8 @@ package dnscontext
import (
"context"

"github.com/networkservicemesh/sdk/pkg/tools/dnsconfig"
"github.com/edwarnicke/genericsync"
"github.com/networkservicemesh/api/pkg/api/networkservice"
)

// DNSOption is applying options for DNS client.
Expand Down Expand Up @@ -50,7 +51,7 @@ func WithDefaultNameServerIP(ip string) DNSOption {
}

// WithDNSConfigsMap sets configs map for DNS client.
func WithDNSConfigsMap(configsMap *dnsconfig.Map) DNSOption {
func WithDNSConfigsMap(configsMap *genericsync.Map[string, []*networkservice.DNSConfig]) DNSOption {
return applyFunc(func(c *dnsContextClient) {
c.dnsConfigsMap = configsMap
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -20,23 +20,23 @@ import (
"context"
"net"

"github.com/edwarnicke/genericsync"
"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"google.golang.org/grpc"

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

type vl3DNSClient struct {
dnsServerIP net.IP
dnsConfigs *dnsconfig.Map
dnsConfigs *genericsync.Map[string, []*networkservice.DNSConfig]
}

// NewClient - returns a new null client that does nothing but call next.Client(ctx).{Request/Close} and return the result
//
// This is very useful in testing
func NewClient(dnsServerIP net.IP, dnsConfigs *dnsconfig.Map) networkservice.NetworkServiceClient {
func NewClient(dnsServerIP net.IP, dnsConfigs *genericsync.Map[string, []*networkservice.DNSConfig]) networkservice.NetworkServiceClient {
return &vl3DNSClient{
dnsServerIP: dnsServerIP,
dnsConfigs: dnsConfigs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Cisco and/or its affiliates.
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -21,15 +21,18 @@ import (
"fmt"
"text/template"

"github.com/networkservicemesh/sdk/pkg/tools/dnsconfig"
"github.com/edwarnicke/genericsync"

"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/networkservicemesh/sdk/pkg/tools/dnsutils"
)

// Option configures vl3DNSServer
type Option func(*vl3DNSServer)

// WithConfigs sets initial list to fanout queries
func WithConfigs(m *dnsconfig.Map) Option {
func WithConfigs(m *genericsync.Map[string, []*networkservice.DNSConfig]) Option {
return func(vd *vl3DNSServer) {
vd.dnsConfigs = m
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
"sync/atomic"
"text/template"

"github.com/edwarnicke/genericsync"
"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/pkg/errors"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/monitor"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/dnsconfig"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils"
dnschain "github.com/networkservicemesh/sdk/pkg/tools/dnsutils/chain"
"github.com/networkservicemesh/sdk/pkg/tools/dnsutils/dnsconfigs"
Expand All @@ -47,8 +47,8 @@ import (

type vl3DNSServer struct {
chainCtx context.Context
dnsServerRecords memory.Map
dnsConfigs *dnsconfig.Map
dnsServerRecords genericsync.Map[string, []net.IP]
dnsConfigs *genericsync.Map[string, []*networkservice.DNSConfig]
domainSchemeTemplates []*template.Template
dnsPort int
dnsServer dnsutils.Handler
Expand All @@ -71,7 +71,7 @@ func NewServer(chainCtx context.Context, dnsServerIPCh <-chan net.IP, opts ...Op
chainCtx: chainCtx,
dnsPort: 53,
listenAndServeDNS: dnsutils.ListenAndServe,
dnsConfigs: new(dnsconfig.Map),
dnsConfigs: new(genericsync.Map[string, []*networkservice.DNSConfig]),
dnsServerIPCh: dnsServerIPCh,
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/registry/common/authorize/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package authorize
import (
"context"

"github.com/edwarnicke/genericsync"
"github.com/golang-jwt/jwt/v4"
"github.com/pkg/errors"
"github.com/spiffe/go-spiffe/v2/spiffeid"
Expand Down Expand Up @@ -63,7 +64,7 @@ func (l *policiesList) check(ctx context.Context, input RegistryOpaInput) error
return nil
}

func getRawMap(m *PathIdsMap) map[string][]string {
func getRawMap(m *genericsync.Map[string, []string]) map[string][]string {
rawMap := make(map[string][]string)
m.Range(func(key string, value []string) bool {
rawMap[key] = value
Expand Down
26 changes: 0 additions & 26 deletions pkg/registry/common/authorize/gen.go

This file was deleted.

Loading