diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 20999ecd5..81014f074 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,6 +16,8 @@ jobs: golangci-lint: uses: networkservicemesh/.github/.github/workflows/golangci-lint.yaml@main + with: + linter-version: v1.51.1 exclude-fmt-errorf: uses: networkservicemesh/.github/.github/workflows/exclude-fmt-errorf.yaml@main diff --git a/.golangci.yml b/.golangci.yml index c8af21515..ec564aaab 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,7 @@ --- run: # concurrency: 6 - go: "1.17" + go: "1.19" timeout: 2m issues-exit-code: 1 tests: true diff --git a/go.mod b/go.mod index 2663a8abd..1f77655a0 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/antonfisher/nested-logrus-formatter v1.3.1 github.com/benbjohnson/clock v1.3.0 github.com/edwarnicke/exechelper v1.0.2 + github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 github.com/edwarnicke/grpcfd v1.1.2 github.com/edwarnicke/serialize v1.0.7 github.com/fsnotify/fsnotify v1.5.4 diff --git a/go.sum b/go.sum index e463dd3aa..1499b72dd 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,8 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/edwarnicke/exechelper v1.0.2 h1:dD49Ui2U0FBFxxhalnKw6vLS0P0TkgnXBRvKL/xmC5w= github.com/edwarnicke/exechelper v1.0.2/go.mod h1:/T271jtNX/ND4De6pa2aRy2+8sNtyCDB1A2pp4M+fUs= +github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 h1:4/2wgileNvQB4HfJbq7u4FFLKIfc38a6P0S/51ZGgX8= +github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29/go.mod h1:3m+ZfVq+z0pTLW798jmqnifMsalrVLIKmfXaMFvqSuc= github.com/edwarnicke/grpcfd v1.1.2 h1:2b8kCABQ1+JjSKGDoHadqSW7whCeTXMqtyo6jmB5B8k= github.com/edwarnicke/grpcfd v1.1.2/go.mod h1:rHihB9YvNMixz8rS+ZbwosI2kj65VLkeyYAI2M+/cGA= github.com/edwarnicke/serialize v0.0.0-20200705214914-ebc43080eecf/go.mod h1:XvbCO/QGsl3X8RzjBMoRpkm54FIAZH5ChK2j+aox7pw= diff --git a/pkg/networkservice/common/begin/client.go b/pkg/networkservice/common/begin/client.go index 78c389c3d..3980cd24f 100644 --- a/pkg/networkservice/common/begin/client.go +++ b/pkg/networkservice/common/begin/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2022 Cisco and/or its affiliates. +// Copyright (c) 2021-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -19,6 +19,7 @@ package begin import ( "context" + "github.com/edwarnicke/genericsync" "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/pkg/errors" "google.golang.org/grpc" @@ -30,7 +31,7 @@ import ( ) type beginClient struct { - clientMap + genericsync.Map[string, *eventFactoryClient] } // NewClient - creates a new begin chain element diff --git a/pkg/networkservice/common/begin/client_map.gen.go b/pkg/networkservice/common/begin/client_map.gen.go deleted file mode 100644 index 41410c7b0..000000000 --- a/pkg/networkservice/common/begin/client_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output client_map.gen.go -type clientMap -output client_map.gen.go -type clientMap"; DO NOT EDIT. -// Install -output client_map.gen.go -type clientMap by "go get -u github.com/searKing/golang/tools/-output client_map.gen.go -type clientMap" - -package begin - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert clientMap literal (type clientMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(clientMap{}) -} - -var _nil_clientMap_eventFactoryClient_value = func() (val *eventFactoryClient) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *clientMap) Load(key string) (*eventFactoryClient, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_clientMap_eventFactoryClient_value, ok - } - return value.(*eventFactoryClient), ok -} - -// Store sets the value for a key. -func (m *clientMap) Store(key string, value *eventFactoryClient) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *clientMap) LoadOrStore(key string, value *eventFactoryClient) (*eventFactoryClient, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_clientMap_eventFactoryClient_value, loaded - } - return actual.(*eventFactoryClient), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *clientMap) LoadAndDelete(key string) (value *eventFactoryClient, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_clientMap_eventFactoryClient_value, loaded - } - return actual.(*eventFactoryClient), loaded -} - -// Delete deletes the value for a key. -func (m *clientMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *clientMap) Range(f func(key string, value *eventFactoryClient) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*eventFactoryClient)) - }) -} diff --git a/pkg/networkservice/common/begin/gen.go b/pkg/networkservice/common/begin/gen.go deleted file mode 100644 index cc32d7669..000000000 --- a/pkg/networkservice/common/begin/gen.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2021 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package begin - -import ( - "sync" -) - -//go:generate go-syncmap -output client_map.gen.go -type clientMap - -// clientMap - sync.Map with key == string and value == *eventFactoryClient -type clientMap sync.Map - -//go:generate go-syncmap -output server_map.gen.go -type serverMap - -// serverMap - sync.Map with key == string and value == *eventFactoryServer -type serverMap sync.Map diff --git a/pkg/networkservice/common/begin/server.go b/pkg/networkservice/common/begin/server.go index aa465ea1d..023d22124 100644 --- a/pkg/networkservice/common/begin/server.go +++ b/pkg/networkservice/common/begin/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2022 Cisco and/or its affiliates. +// Copyright (c) 2021-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -19,6 +19,7 @@ package begin import ( "context" + "github.com/edwarnicke/genericsync" "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/pkg/errors" "google.golang.org/protobuf/types/known/emptypb" @@ -29,7 +30,7 @@ import ( ) type beginServer struct { - serverMap + genericsync.Map[string, *eventFactoryServer] } // NewServer - creates a new begin chain element diff --git a/pkg/networkservice/common/begin/server_map.gen.go b/pkg/networkservice/common/begin/server_map.gen.go deleted file mode 100644 index 40e006cf9..000000000 --- a/pkg/networkservice/common/begin/server_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output server_map.gen.go -type serverMap -output server_map.gen.go -type serverMap"; DO NOT EDIT. -// Install -output server_map.gen.go -type serverMap by "go get -u github.com/searKing/golang/tools/-output server_map.gen.go -type serverMap" - -package begin - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert serverMap literal (type serverMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(serverMap{}) -} - -var _nil_serverMap_eventFactoryServer_value = func() (val *eventFactoryServer) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *serverMap) Load(key string) (*eventFactoryServer, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_serverMap_eventFactoryServer_value, ok - } - return value.(*eventFactoryServer), ok -} - -// Store sets the value for a key. -func (m *serverMap) Store(key string, value *eventFactoryServer) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *serverMap) LoadOrStore(key string, value *eventFactoryServer) (*eventFactoryServer, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_serverMap_eventFactoryServer_value, loaded - } - return actual.(*eventFactoryServer), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *serverMap) LoadAndDelete(key string) (value *eventFactoryServer, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_serverMap_eventFactoryServer_value, loaded - } - return actual.(*eventFactoryServer), loaded -} - -// Delete deletes the value for a key. -func (m *serverMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *serverMap) Range(f func(key string, value *eventFactoryServer) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*eventFactoryServer)) - }) -} diff --git a/pkg/networkservice/common/externalips/gen.go b/pkg/networkservice/common/externalips/gen.go deleted file mode 100644 index aa873b2eb..000000000 --- a/pkg/networkservice/common/externalips/gen.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package externalips - -import "sync" - -//go:generate go-syncmap -output string_map.gen.go -type stringMap - -// stringMap is like a Go map[string]string but is safe for concurrent use -// by multiple goroutines without additional locking or coordination. -type stringMap sync.Map diff --git a/pkg/networkservice/common/externalips/server.go b/pkg/networkservice/common/externalips/server.go index 3c12f6173..c658a88f2 100644 --- a/pkg/networkservice/common/externalips/server.go +++ b/pkg/networkservice/common/externalips/server.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2021 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"); @@ -22,6 +24,7 @@ import ( "net" "sync/atomic" + "github.com/edwarnicke/genericsync" "github.com/ghodss/yaml" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" @@ -59,8 +62,8 @@ func NewServer(chainCtx context.Context, options ...Option) networkservice.Netwo result := &externalIPsServer{ chainCtx: chainCtx, } - result.externalToInternalMap.Store(new(stringMap)) - result.internalToExternalMap.Store(new(stringMap)) + result.externalToInternalMap.Store(new(genericsync.Map[string, string])) + result.internalToExternalMap.Store(new(genericsync.Map[string, string])) for _, o := range options { o(result) } @@ -86,7 +89,7 @@ func NewServer(chainCtx context.Context, options ...Option) networkservice.Netwo } func replaceFunc(v atomic.Value) func(ip net.IP) net.IP { - m := v.Load().(*stringMap) + m := v.Load().(*genericsync.Map[string, string]) return func(ip net.IP) net.IP { key := ip.String() value, _ := m.Load(key) @@ -109,7 +112,7 @@ func (e *externalIPsServer) build(ips map[string]string) error { return err } } - internalIPs, externalIPs := new(stringMap), new(stringMap) + internalIPs, externalIPs := new(genericsync.Map[string, string]), new(genericsync.Map[string, string]) for k, v := range ips { internalIPs.Store(k, v) externalIPs.Store(v, k) diff --git a/pkg/networkservice/common/externalips/string_map.gen.go b/pkg/networkservice/common/externalips/string_map.gen.go deleted file mode 100644 index 2ac1a810f..000000000 --- a/pkg/networkservice/common/externalips/string_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output string_map.gen.go -type stringMap -output string_map.gen.go -type stringMap"; DO NOT EDIT. -// Install -output string_map.gen.go -type stringMap by "go get -u github.com/searKing/golang/tools/-output string_map.gen.go -type stringMap" - -package externalips - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert stringMap literal (type stringMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(stringMap{}) -} - -var _nil_stringMap_string_value = func() (val string) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *stringMap) Load(key string) (string, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_stringMap_string_value, ok - } - return value.(string), ok -} - -// Store sets the value for a key. -func (m *stringMap) Store(key string, value string) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *stringMap) LoadOrStore(key string, value string) (string, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_stringMap_string_value, loaded - } - return actual.(string), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *stringMap) LoadAndDelete(key string) (value string, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_stringMap_string_value, loaded - } - return actual.(string), loaded -} - -// Delete deletes the value for a key. -func (m *stringMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *stringMap) Range(f func(key string, value string) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(string)) - }) -} diff --git a/pkg/networkservice/common/interdomainbypass/server.go b/pkg/networkservice/common/interdomainbypass/server.go index 10d13651d..ccda893b4 100644 --- a/pkg/networkservice/common/interdomainbypass/server.go +++ b/pkg/networkservice/common/interdomainbypass/server.go @@ -1,5 +1,7 @@ // Copyright (c) 2021-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"); @@ -21,6 +23,7 @@ import ( "context" "net/url" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" "github.com/networkservicemesh/api/pkg/api/registry" @@ -29,11 +32,10 @@ import ( "github.com/networkservicemesh/sdk/pkg/registry/common/interdomainbypass" "github.com/networkservicemesh/sdk/pkg/tools/clienturlctx" "github.com/networkservicemesh/sdk/pkg/tools/interdomain" - "github.com/networkservicemesh/sdk/pkg/tools/stringurl" ) type interdomainBypassServer struct { - m stringurl.Map + m genericsync.Map[string, *url.URL] } // NewServer - returns a new NetworkServiceServer that injects the URL to remote side into context on requesting resolved endpoint diff --git a/pkg/networkservice/common/mechanisms/recvfd/client.go b/pkg/networkservice/common/mechanisms/recvfd/client.go index 494a087a5..09cd360a5 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/client.go +++ b/pkg/networkservice/common/mechanisms/recvfd/client.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. -// // Copyright (c) 2021-2022 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,6 +26,7 @@ import ( "net/url" "os" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" "google.golang.org/grpc" @@ -37,7 +38,7 @@ import ( ) type recvFDClient struct { - fileMaps perConnectionFileMapMap + fileMaps genericsync.Map[string, *perConnectionFileMap] } // NewClient - returns client chain element to recv FDs over the connection (if possible) for any Mechanism.Parameters[common.InodeURL] diff --git a/pkg/networkservice/common/mechanisms/recvfd/common.go b/pkg/networkservice/common/mechanisms/recvfd/common.go index dbbce758e..117005d57 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/common.go +++ b/pkg/networkservice/common/mechanisms/recvfd/common.go @@ -25,10 +25,17 @@ import ( "os" "github.com/edwarnicke/grpcfd" + "github.com/edwarnicke/serialize" "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/common" "github.com/pkg/errors" ) +type perConnectionFileMap struct { + executor serialize.Executor + filesByInodeURL map[string]*os.File + inodeURLbyFilename map[string]*url.URL +} + func recvFDAndSwapInodeToFile(ctx context.Context, fileMap *perConnectionFileMap, parameters map[string]string, recv grpcfd.FDRecver) error { // Get the inodeURL from parameters inodeURLStr, ok := parameters[common.InodeURL] diff --git a/pkg/networkservice/common/mechanisms/recvfd/gen.go b/pkg/networkservice/common/mechanisms/recvfd/gen.go deleted file mode 100644 index e648f720d..000000000 --- a/pkg/networkservice/common/mechanisms/recvfd/gen.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recvfd - -import ( - "net/url" - "os" - "sync" - - "github.com/edwarnicke/serialize" -) - -//go:generate go-syncmap -output per_connection_file_map.gen.go -type perConnectionFileMapMap - -// PerConnectionFileMap - sync.Map with key == string and value == *perConnectionFileMap -type perConnectionFileMapMap sync.Map - -type perConnectionFileMap struct { - executor serialize.Executor - filesByInodeURL map[string]*os.File - inodeURLbyFilename map[string]*url.URL -} diff --git a/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go b/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go deleted file mode 100644 index 534ea63e1..000000000 --- a/pkg/networkservice/common/mechanisms/recvfd/per_connection_file_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output per_connection_file_map.gen.go -type perConnectionFileMapMap -output per_connection_file_map.gen.go -type perConnectionFileMapMap"; DO NOT EDIT. -// Install -output per_connection_file_map.gen.go -type perConnectionFileMapMap by "go get -u github.com/searKing/golang/tools/-output per_connection_file_map.gen.go -type perConnectionFileMapMap" - -package recvfd - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert perConnectionFileMapMap literal (type perConnectionFileMapMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(perConnectionFileMapMap{}) -} - -var _nil_perConnectionFileMapMap_perConnectionFileMap_value = func() (val *perConnectionFileMap) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *perConnectionFileMapMap) Load(key string) (*perConnectionFileMap, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_perConnectionFileMapMap_perConnectionFileMap_value, ok - } - return value.(*perConnectionFileMap), ok -} - -// Store sets the value for a key. -func (m *perConnectionFileMapMap) Store(key string, value *perConnectionFileMap) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *perConnectionFileMapMap) LoadOrStore(key string, value *perConnectionFileMap) (*perConnectionFileMap, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_perConnectionFileMapMap_perConnectionFileMap_value, loaded - } - return actual.(*perConnectionFileMap), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *perConnectionFileMapMap) LoadAndDelete(key string) (value *perConnectionFileMap, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_perConnectionFileMapMap_perConnectionFileMap_value, loaded - } - return actual.(*perConnectionFileMap), loaded -} - -// Delete deletes the value for a key. -func (m *perConnectionFileMapMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *perConnectionFileMapMap) Range(f func(key string, value *perConnectionFileMap) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*perConnectionFileMap)) - }) -} diff --git a/pkg/networkservice/common/mechanisms/recvfd/server.go b/pkg/networkservice/common/mechanisms/recvfd/server.go index 8b6001e9d..6846f488c 100644 --- a/pkg/networkservice/common/mechanisms/recvfd/server.go +++ b/pkg/networkservice/common/mechanisms/recvfd/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -24,16 +24,16 @@ import ( "net/url" "os" + "github.com/edwarnicke/genericsync" + "github.com/edwarnicke/grpcfd" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/networkservice" - "github.com/edwarnicke/grpcfd" - "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" ) type recvFDServer struct { - fileMaps perConnectionFileMapMap + fileMaps genericsync.Map[string, *perConnectionFileMap] } // NewServer - returns server chain element to recv FDs over the connection (if possible) for any Mechanism.Parameters[common.InodeURL] diff --git a/pkg/networkservice/common/mechanisms/vxlan/vni/gen.go b/pkg/networkservice/common/mechanisms/vxlan/vni/gen.go deleted file mode 100644 index b79da6e0c..000000000 --- a/pkg/networkservice/common/mechanisms/vxlan/vni/gen.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2020-2021 Cisco and/or its affiliates. -// -// Copyright (c) 2021 Nordix Foundation. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package vni - -import ( - "sync" -) - -//go:generate go-syncmap -output vni_map.gen.go -type Map - -type vniKey struct { - srcIPString string - vni uint32 -} - -// Map - sync.Map with key == vniKey and value == struct{} -type Map sync.Map diff --git a/pkg/networkservice/common/mechanisms/vxlan/vni/server.go b/pkg/networkservice/common/mechanisms/vxlan/vni/server.go index 8abb6e434..28532a44f 100644 --- a/pkg/networkservice/common/mechanisms/vxlan/vni/server.go +++ b/pkg/networkservice/common/mechanisms/vxlan/vni/server.go @@ -23,7 +23,8 @@ package vni import ( "context" "net" - "sync" + + "github.com/edwarnicke/genericsync" "github.com/networkservicemesh/sdk/pkg/tools/log" @@ -37,12 +38,17 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" ) +type vniKey struct { + srcIPString string + vni uint32 +} + type vniServer struct { tunnelIP net.IP tunnelPort uint16 // This map stores all generated VNIs - sync.Map + genericsync.Map[vniKey, *vniKey] } // NewServer - set the DstIP *and* VNI for the vxlan mechanism diff --git a/pkg/networkservice/common/mechanisms/vxlan/vni/vni_map.gen.go b/pkg/networkservice/common/mechanisms/vxlan/vni/vni_map.gen.go deleted file mode 100644 index 489c496e0..000000000 --- a/pkg/networkservice/common/mechanisms/vxlan/vni/vni_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output vni_map.gen.go -type Map -output vni_map.gen.go -type Map"; DO NOT EDIT. -// Install -output vni_map.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output vni_map.gen.go -type Map" - -package vni - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert Map literal (type Map) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(Map{}) -} - -var _nil_Map_vniKey_value = func() (val *vniKey) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *Map) Load(key vniKey) (*vniKey, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_Map_vniKey_value, ok - } - return value.(*vniKey), ok -} - -// Store sets the value for a key. -func (m *Map) Store(key vniKey, value *vniKey) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *Map) LoadOrStore(key vniKey, value *vniKey) (*vniKey, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_Map_vniKey_value, loaded - } - return actual.(*vniKey), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *Map) LoadAndDelete(key vniKey) (value *vniKey, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_Map_vniKey_value, loaded - } - return actual.(*vniKey), loaded -} - -// Delete deletes the value for a key. -func (m *Map) Delete(key vniKey) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *Map) Range(f func(key vniKey, value *vniKey) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(vniKey), value.(*vniKey)) - }) -} diff --git a/pkg/networkservice/common/mechanismtranslation/gen.go b/pkg/networkservice/common/mechanismtranslation/gen.go deleted file mode 100644 index aa6be83cf..000000000 --- a/pkg/networkservice/common/mechanismtranslation/gen.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package mechanismtranslation - -import ( - "sync" -) - -//go:generate go-syncmap -output mechanism_map.gen.go -type mechanismMap - -type mechanismMap sync.Map diff --git a/pkg/networkservice/common/mechanismtranslation/mechanism_map.gen.go b/pkg/networkservice/common/mechanismtranslation/mechanism_map.gen.go deleted file mode 100644 index 1d82c2085..000000000 --- a/pkg/networkservice/common/mechanismtranslation/mechanism_map.gen.go +++ /dev/null @@ -1,77 +0,0 @@ -// Code generated by "-output mechanism_map.gen.go -type mechanismMap -output mechanism_map.gen.go -type mechanismMap"; DO NOT EDIT. -// Install -output mechanism_map.gen.go -type mechanismMap by "go get -u github.com/searKing/golang/tools/-output mechanism_map.gen.go -type mechanismMap" - -package mechanismtranslation - -import ( - "sync" // Used by sync.Map. - - "github.com/networkservicemesh/api/pkg/api/networkservice" -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert mechanismMap literal (type mechanismMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(mechanismMap{}) -} - -var _nil_mechanismMap_networkservice_Mechanism_value = func() (val *networkservice.Mechanism) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *mechanismMap) Load(key string) (*networkservice.Mechanism, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_mechanismMap_networkservice_Mechanism_value, ok - } - return value.(*networkservice.Mechanism), ok -} - -// Store sets the value for a key. -func (m *mechanismMap) Store(key string, value *networkservice.Mechanism) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *mechanismMap) LoadOrStore(key string, value *networkservice.Mechanism) (*networkservice.Mechanism, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_mechanismMap_networkservice_Mechanism_value, loaded - } - return actual.(*networkservice.Mechanism), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *mechanismMap) LoadAndDelete(key string) (value *networkservice.Mechanism, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_mechanismMap_networkservice_Mechanism_value, loaded - } - return actual.(*networkservice.Mechanism), loaded -} - -// Delete deletes the value for a key. -func (m *mechanismMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *mechanismMap) Range(f func(key string, value *networkservice.Mechanism) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*networkservice.Mechanism)) - }) -} diff --git a/pkg/networkservice/ipam/point2pointipam/connectionInfoMap.gen.go b/pkg/networkservice/ipam/point2pointipam/connectionInfoMap.gen.go deleted file mode 100644 index 978b0e9c5..000000000 --- a/pkg/networkservice/ipam/point2pointipam/connectionInfoMap.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output connectionInfoMap.gen.go -type Map -output connectionInfoMap.gen.go -type Map"; DO NOT EDIT. -// Install -output connectionInfoMap.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output connectionInfoMap.gen.go -type Map" - -package point2pointipam - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert Map literal (type Map) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(Map{}) -} - -var _nil_Map_connectionInfo_value = func() (val *connectionInfo) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *Map) Load(key string) (*connectionInfo, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_Map_connectionInfo_value, ok - } - return value.(*connectionInfo), ok -} - -// Store sets the value for a key. -func (m *Map) Store(key string, value *connectionInfo) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *Map) LoadOrStore(key string, value *connectionInfo) (*connectionInfo, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_Map_connectionInfo_value, loaded - } - return actual.(*connectionInfo), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *Map) LoadAndDelete(key string) (value *connectionInfo, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_Map_connectionInfo_value, loaded - } - return actual.(*connectionInfo), loaded -} - -// Delete deletes the value for a key. -func (m *Map) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *Map) Range(f func(key string, value *connectionInfo) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*connectionInfo)) - }) -} diff --git a/pkg/networkservice/ipam/point2pointipam/gen.go b/pkg/networkservice/ipam/point2pointipam/gen.go deleted file mode 100644 index 62148f8b5..000000000 --- a/pkg/networkservice/ipam/point2pointipam/gen.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2021 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package point2pointipam - -import ( - "sync" -) - -//go:generate go-syncmap -output connectionInfoMap.gen.go -type Map - -// Map - sync.Map with key == string and value == networkservice.NetworkServiceClient -type Map sync.Map diff --git a/pkg/networkservice/ipam/point2pointipam/server.go b/pkg/networkservice/ipam/point2pointipam/server.go index fd38c8d46..a9e9874d4 100644 --- a/pkg/networkservice/ipam/point2pointipam/server.go +++ b/pkg/networkservice/ipam/point2pointipam/server.go @@ -24,6 +24,7 @@ import ( "net" "sync" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" @@ -35,7 +36,7 @@ import ( ) type ipamServer struct { - Map + genericsync.Map[string, *connectionInfo] ipPools []*ippool.IPPool prefixes []*net.IPNet once sync.Once diff --git a/pkg/networkservice/ipam/singlepointipam/connectionInfoMap.gen.go b/pkg/networkservice/ipam/singlepointipam/connectionInfoMap.gen.go deleted file mode 100644 index 034611700..000000000 --- a/pkg/networkservice/ipam/singlepointipam/connectionInfoMap.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output connectionInfoMap.gen.go -type Map -output connectionInfoMap.gen.go -type Map"; DO NOT EDIT. -// Install -output connectionInfoMap.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output connectionInfoMap.gen.go -type Map" - -package singlepointipam - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert Map literal (type Map) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(Map{}) -} - -var _nil_Map_connectionInfo_value = func() (val *connectionInfo) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *Map) Load(key string) (*connectionInfo, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_Map_connectionInfo_value, ok - } - return value.(*connectionInfo), ok -} - -// Store sets the value for a key. -func (m *Map) Store(key string, value *connectionInfo) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *Map) LoadOrStore(key string, value *connectionInfo) (*connectionInfo, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_Map_connectionInfo_value, loaded - } - return actual.(*connectionInfo), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *Map) LoadAndDelete(key string) (value *connectionInfo, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_Map_connectionInfo_value, loaded - } - return actual.(*connectionInfo), loaded -} - -// Delete deletes the value for a key. -func (m *Map) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *Map) Range(f func(key string, value *connectionInfo) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*connectionInfo)) - }) -} diff --git a/pkg/networkservice/ipam/singlepointipam/gen.go b/pkg/networkservice/ipam/singlepointipam/gen.go deleted file mode 100644 index 8cc2b67d9..000000000 --- a/pkg/networkservice/ipam/singlepointipam/gen.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2021 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package singlepointipam - -import ( - "sync" -) - -//go:generate go-syncmap -output connectionInfoMap.gen.go -type Map - -// Map - sync.Map with key == string and value == networkservice.NetworkServiceClient -type Map sync.Map diff --git a/pkg/networkservice/ipam/singlepointipam/server.go b/pkg/networkservice/ipam/singlepointipam/server.go index 7314a441d..eb60a6236 100644 --- a/pkg/networkservice/ipam/singlepointipam/server.go +++ b/pkg/networkservice/ipam/singlepointipam/server.go @@ -25,6 +25,7 @@ import ( "net" "sync" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" @@ -35,7 +36,7 @@ import ( ) type singlePIpam struct { - Map + genericsync.Map[string, *connectionInfo] ipPools []*ippool.IPPool prefixes []*net.IPNet myIPs []string diff --git a/pkg/networkservice/utils/metadata/client.go b/pkg/networkservice/utils/metadata/client.go index 1f7bd2b39..d1e24f7c1 100644 --- a/pkg/networkservice/utils/metadata/client.go +++ b/pkg/networkservice/utils/metadata/client.go @@ -1,6 +1,6 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -21,6 +21,8 @@ package metadata import ( "context" + "github.com/edwarnicke/genericsync" + "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/golang/protobuf/ptypes/empty" @@ -31,7 +33,7 @@ import ( ) type metaDataClient struct { - Map metaDataMap + Map genericsync.Map[string, *metaData] } // NewClient - Enable per Connection.Id metadata for the client diff --git a/pkg/networkservice/utils/metadata/context.go b/pkg/networkservice/utils/metadata/context.go index baf40c245..4fe4f6208 100644 --- a/pkg/networkservice/utils/metadata/context.go +++ b/pkg/networkservice/utils/metadata/context.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// // Copyright (c) 2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2023 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,12 +22,18 @@ import ( "context" "sync" + "github.com/edwarnicke/genericsync" "github.com/networkservicemesh/api/pkg/api/networkservice" ) type metaDataKey struct{} -func store(parent context.Context, id string, mdMap *metaDataMap) context.Context { +type metaData struct { + client sync.Map + server sync.Map +} + +func store(parent context.Context, id string, mdMap *genericsync.Map[string, *metaData]) context.Context { if _, ok := parent.Value(metaDataKey{}).(*metaData); !ok { md, _ := mdMap.LoadOrStore(id, &metaData{}) return context.WithValue(parent, metaDataKey{}, md) @@ -35,7 +41,7 @@ func store(parent context.Context, id string, mdMap *metaDataMap) context.Contex return parent } -func del(parent context.Context, id string, mdMap *metaDataMap) context.Context { +func del(parent context.Context, id string, mdMap *genericsync.Map[string, *metaData]) context.Context { if _, ok := parent.Value(metaDataKey{}).(*metaData); !ok { if md, ok := mdMap.LoadAndDelete(id); ok { return context.WithValue(parent, metaDataKey{}, md) diff --git a/pkg/networkservice/utils/metadata/gen.go b/pkg/networkservice/utils/metadata/gen.go deleted file mode 100644 index ab8b09257..000000000 --- a/pkg/networkservice/utils/metadata/gen.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metadata - -import ( - "sync" -) - -//go:generate go-syncmap -output meta_data_map.gen.go -type metaDataMap - -type metaDataMap sync.Map - -type metaData struct { - client sync.Map - server sync.Map -} diff --git a/pkg/networkservice/utils/metadata/meta_data_map.gen.go b/pkg/networkservice/utils/metadata/meta_data_map.gen.go deleted file mode 100644 index 66d8f5ac4..000000000 --- a/pkg/networkservice/utils/metadata/meta_data_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output meta_data_map.gen.go -type metaDataMap -output meta_data_map.gen.go -type metaDataMap"; DO NOT EDIT. -// Install -output meta_data_map.gen.go -type metaDataMap by "go get -u github.com/searKing/golang/tools/-output meta_data_map.gen.go -type metaDataMap" - -package metadata - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert metaDataMap literal (type metaDataMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(metaDataMap{}) -} - -var _nil_metaDataMap_metaData_value = func() (val *metaData) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *metaDataMap) Load(key string) (*metaData, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_metaDataMap_metaData_value, ok - } - return value.(*metaData), ok -} - -// Store sets the value for a key. -func (m *metaDataMap) Store(key string, value *metaData) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *metaDataMap) LoadOrStore(key string, value *metaData) (*metaData, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_metaDataMap_metaData_value, loaded - } - return actual.(*metaData), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *metaDataMap) LoadAndDelete(key string) (value *metaData, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_metaDataMap_metaData_value, loaded - } - return actual.(*metaData), loaded -} - -// Delete deletes the value for a key. -func (m *metaDataMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *metaDataMap) Range(f func(key string, value *metaData) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*metaData)) - }) -} diff --git a/pkg/networkservice/utils/metadata/server.go b/pkg/networkservice/utils/metadata/server.go index 8193c5157..8146b3db3 100644 --- a/pkg/networkservice/utils/metadata/server.go +++ b/pkg/networkservice/utils/metadata/server.go @@ -1,6 +1,6 @@ // Copyright (c) 2021 Doc.ai and/or its affiliates. // -// Copyright (c) 2020-2022 Cisco and/or its affiliates. +// Copyright (c) 2020-2023 Cisco and/or its affiliates. // // SPDX-License-Identifier: Apache-2.0 // @@ -21,6 +21,8 @@ package metadata import ( "context" + "github.com/edwarnicke/genericsync" + "github.com/networkservicemesh/sdk/pkg/tools/log" "github.com/golang/protobuf/ptypes/empty" @@ -30,7 +32,7 @@ import ( ) type metadataServer struct { - Map metaDataMap + Map genericsync.Map[string, *metaData] } // NewServer - Enable per Connection.Id metadata for the server diff --git a/pkg/registry/common/begin/gen.go b/pkg/registry/common/begin/gen.go deleted file mode 100644 index 9e10b394d..000000000 --- a/pkg/registry/common/begin/gen.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2022 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package begin - -import ( - "sync" -) - -//go:generate go-syncmap -output nse_client_map.gen.go -type nseClientMap -//go:generate go-syncmap -output nse_server_map.gen.go -type nseServerMap - -//go:generate go-syncmap -output ns_client_map.gen.go -type nsClientMap -//go:generate go-syncmap -output ns_server_map.gen.go -type nsServerMap - -// nseClientMap - sync.Map with key == string and value == *eventNSEFactoryClient -type nseClientMap sync.Map - -// nseServerMap - sync.Map with key == string and value == *eventNSEFactoryClient -type nseServerMap sync.Map - -// nsClientMap - sync.Map with key == string and value == *eventNSFactoryClient -type nsClientMap sync.Map - -// nsServerMap - sync.Map with key == string and value == *eventNSFactoryClient -type nsServerMap sync.Map diff --git a/pkg/registry/common/begin/ns_client.go b/pkg/registry/common/begin/ns_client.go index 899209dd3..5454d3552 100644 --- a/pkg/registry/common/begin/ns_client.go +++ b/pkg/registry/common/begin/ns_client.go @@ -1,5 +1,7 @@ // Copyright (c) 2022 Cisco 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"); @@ -19,6 +21,7 @@ package begin import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" "github.com/pkg/errors" @@ -30,7 +33,7 @@ import ( ) type beginNSClient struct { - nsClientMap + genericsync.Map[string, *eventNSFactoryClient] } func (b *beginNSClient) Register(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*registry.NetworkService, error) { diff --git a/pkg/registry/common/begin/ns_client_map.gen.go b/pkg/registry/common/begin/ns_client_map.gen.go deleted file mode 100644 index 1ca9baef7..000000000 --- a/pkg/registry/common/begin/ns_client_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output ns_client_map.gen.go -type nsClientMap -output ns_client_map.gen.go -type nsClientMap"; DO NOT EDIT. -// Install -output ns_client_map.gen.go -type nsClientMap by "go get -u github.com/searKing/golang/tools/-output ns_client_map.gen.go -type nsClientMap" - -package begin - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert nsClientMap literal (type nsClientMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(nsClientMap{}) -} - -var _nil_nsClientMap_eventNSFactoryClient_value = func() (val *eventNSFactoryClient) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *nsClientMap) Load(key string) (*eventNSFactoryClient, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_nsClientMap_eventNSFactoryClient_value, ok - } - return value.(*eventNSFactoryClient), ok -} - -// Store sets the value for a key. -func (m *nsClientMap) Store(key string, value *eventNSFactoryClient) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *nsClientMap) LoadOrStore(key string, value *eventNSFactoryClient) (*eventNSFactoryClient, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_nsClientMap_eventNSFactoryClient_value, loaded - } - return actual.(*eventNSFactoryClient), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *nsClientMap) LoadAndDelete(key string) (value *eventNSFactoryClient, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_nsClientMap_eventNSFactoryClient_value, loaded - } - return actual.(*eventNSFactoryClient), loaded -} - -// Delete deletes the value for a key. -func (m *nsClientMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *nsClientMap) Range(f func(key string, value *eventNSFactoryClient) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*eventNSFactoryClient)) - }) -} diff --git a/pkg/registry/common/begin/ns_server.go b/pkg/registry/common/begin/ns_server.go index 35264f328..b59883bc1 100644 --- a/pkg/registry/common/begin/ns_server.go +++ b/pkg/registry/common/begin/ns_server.go @@ -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 // @@ -19,6 +19,7 @@ package begin import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" "github.com/pkg/errors" @@ -30,7 +31,7 @@ import ( ) type beginNSServer struct { - nsServerMap + genericsync.Map[string, *eventNSFactoryServer] } func (b *beginNSServer) Register(ctx context.Context, in *registry.NetworkService) (*registry.NetworkService, error) { diff --git a/pkg/registry/common/begin/ns_server_map.gen.go b/pkg/registry/common/begin/ns_server_map.gen.go deleted file mode 100644 index 379ef787b..000000000 --- a/pkg/registry/common/begin/ns_server_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output ns_server_map.gen.go -type nsServerMap -output ns_server_map.gen.go -type nsServerMap"; DO NOT EDIT. -// Install -output ns_server_map.gen.go -type nsServerMap by "go get -u github.com/searKing/golang/tools/-output ns_server_map.gen.go -type nsServerMap" - -package begin - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert nsServerMap literal (type nsServerMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(nsServerMap{}) -} - -var _nil_nsServerMap_eventNSFactoryServer_value = func() (val *eventNSFactoryServer) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *nsServerMap) Load(key string) (*eventNSFactoryServer, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_nsServerMap_eventNSFactoryServer_value, ok - } - return value.(*eventNSFactoryServer), ok -} - -// Store sets the value for a key. -func (m *nsServerMap) Store(key string, value *eventNSFactoryServer) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *nsServerMap) LoadOrStore(key string, value *eventNSFactoryServer) (*eventNSFactoryServer, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_nsServerMap_eventNSFactoryServer_value, loaded - } - return actual.(*eventNSFactoryServer), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *nsServerMap) LoadAndDelete(key string) (value *eventNSFactoryServer, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_nsServerMap_eventNSFactoryServer_value, loaded - } - return actual.(*eventNSFactoryServer), loaded -} - -// Delete deletes the value for a key. -func (m *nsServerMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *nsServerMap) Range(f func(key string, value *eventNSFactoryServer) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*eventNSFactoryServer)) - }) -} diff --git a/pkg/registry/common/begin/nse_client.go b/pkg/registry/common/begin/nse_client.go index 960574030..aad5d59e6 100644 --- a/pkg/registry/common/begin/nse_client.go +++ b/pkg/registry/common/begin/nse_client.go @@ -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 // @@ -19,6 +19,7 @@ package begin import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" "github.com/pkg/errors" @@ -30,7 +31,7 @@ import ( ) type beginNSEClient struct { - nseClientMap + genericsync.Map[string, *eventNSEFactoryClient] } func (b *beginNSEClient) Register(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) { diff --git a/pkg/registry/common/begin/nse_client_map.gen.go b/pkg/registry/common/begin/nse_client_map.gen.go deleted file mode 100644 index 393ea6b76..000000000 --- a/pkg/registry/common/begin/nse_client_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output nse_client_map.gen.go -type nseClientMap -output nse_client_map.gen.go -type nseClientMap"; DO NOT EDIT. -// Install -output nse_client_map.gen.go -type nseClientMap by "go get -u github.com/searKing/golang/tools/-output nse_client_map.gen.go -type nseClientMap" - -package begin - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert nseClientMap literal (type nseClientMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(nseClientMap{}) -} - -var _nil_nseClientMap_eventNSEFactoryClient_value = func() (val *eventNSEFactoryClient) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *nseClientMap) Load(key string) (*eventNSEFactoryClient, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_nseClientMap_eventNSEFactoryClient_value, ok - } - return value.(*eventNSEFactoryClient), ok -} - -// Store sets the value for a key. -func (m *nseClientMap) Store(key string, value *eventNSEFactoryClient) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *nseClientMap) LoadOrStore(key string, value *eventNSEFactoryClient) (*eventNSEFactoryClient, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_nseClientMap_eventNSEFactoryClient_value, loaded - } - return actual.(*eventNSEFactoryClient), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *nseClientMap) LoadAndDelete(key string) (value *eventNSEFactoryClient, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_nseClientMap_eventNSEFactoryClient_value, loaded - } - return actual.(*eventNSEFactoryClient), loaded -} - -// Delete deletes the value for a key. -func (m *nseClientMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *nseClientMap) Range(f func(key string, value *eventNSEFactoryClient) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*eventNSEFactoryClient)) - }) -} diff --git a/pkg/registry/common/begin/nse_server.go b/pkg/registry/common/begin/nse_server.go index 866d9f6ca..01bfd0cb9 100644 --- a/pkg/registry/common/begin/nse_server.go +++ b/pkg/registry/common/begin/nse_server.go @@ -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 // @@ -19,6 +19,7 @@ package begin import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" "github.com/pkg/errors" @@ -30,7 +31,7 @@ import ( ) type beginNSEServer struct { - nseServerMap + genericsync.Map[string, *eventNSEFactoryServer] } func (b *beginNSEServer) Register(ctx context.Context, in *registry.NetworkServiceEndpoint) (*registry.NetworkServiceEndpoint, error) { diff --git a/pkg/registry/common/begin/nse_server_map.gen.go b/pkg/registry/common/begin/nse_server_map.gen.go deleted file mode 100644 index 46d85070d..000000000 --- a/pkg/registry/common/begin/nse_server_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output nse_server_map.gen.go -type nseServerMap -output nse_server_map.gen.go -type nseServerMap"; DO NOT EDIT. -// Install -output nse_server_map.gen.go -type nseServerMap by "go get -u github.com/searKing/golang/tools/-output nse_server_map.gen.go -type nseServerMap" - -package begin - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert nseServerMap literal (type nseServerMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(nseServerMap{}) -} - -var _nil_nseServerMap_eventNSEFactoryServer_value = func() (val *eventNSEFactoryServer) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *nseServerMap) Load(key string) (*eventNSEFactoryServer, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_nseServerMap_eventNSEFactoryServer_value, ok - } - return value.(*eventNSEFactoryServer), ok -} - -// Store sets the value for a key. -func (m *nseServerMap) Store(key string, value *eventNSEFactoryServer) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *nseServerMap) LoadOrStore(key string, value *eventNSEFactoryServer) (*eventNSEFactoryServer, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_nseServerMap_eventNSEFactoryServer_value, loaded - } - return actual.(*eventNSEFactoryServer), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *nseServerMap) LoadAndDelete(key string) (value *eventNSEFactoryServer, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_nseServerMap_eventNSEFactoryServer_value, loaded - } - return actual.(*eventNSEFactoryServer), loaded -} - -// Delete deletes the value for a key. -func (m *nseServerMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *nseServerMap) Range(f func(key string, value *eventNSEFactoryServer) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*eventNSEFactoryServer)) - }) -} diff --git a/pkg/registry/common/clientconn/context.go b/pkg/registry/common/clientconn/context.go index d8ebe8ee0..53227830a 100644 --- a/pkg/registry/common/clientconn/context.go +++ b/pkg/registry/common/clientconn/context.go @@ -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 // @@ -19,6 +19,7 @@ package clientconn import ( "context" + "github.com/edwarnicke/genericsync" "google.golang.org/grpc" "github.com/networkservicemesh/sdk/pkg/tools/clienturlctx" @@ -27,7 +28,7 @@ import ( type mapKey struct{} type nameKey struct{} -func withClientConnMetadata(ctx context.Context, m *stringCCMap, key string) context.Context { +func withClientConnMetadata(ctx context.Context, m *genericsync.Map[string, grpc.ClientConnInterface], key string) context.Context { ctx = context.WithValue(ctx, nameKey{}, key) ctx = context.WithValue(ctx, mapKey{}, m) return ctx @@ -48,7 +49,7 @@ func nameFromContext(ctx context.Context) string { func LoadAndDelete(ctx context.Context) (grpc.ClientConnInterface, bool) { k := nameFromContext(ctx) - if v, ok := ctx.Value(mapKey{}).(*stringCCMap); ok && k != "" { + if v, ok := ctx.Value(mapKey{}).(*genericsync.Map[string, grpc.ClientConnInterface]); ok && k != "" { return v.LoadAndDelete(k) } @@ -59,7 +60,7 @@ func LoadAndDelete(ctx context.Context) (grpc.ClientConnInterface, bool) { func Store(ctx context.Context, cc grpc.ClientConnInterface) { k := nameFromContext(ctx) - if v, ok := ctx.Value(mapKey{}).(*stringCCMap); ok && k != "" { + if v, ok := ctx.Value(mapKey{}).(*genericsync.Map[string, grpc.ClientConnInterface]); ok && k != "" { v.Store(k, cc) } } @@ -68,7 +69,7 @@ func Store(ctx context.Context, cc grpc.ClientConnInterface) { func Delete(ctx context.Context) { k := nameFromContext(ctx) - if v, ok := ctx.Value(mapKey{}).(*stringCCMap); ok && k != "" { + if v, ok := ctx.Value(mapKey{}).(*genericsync.Map[string, grpc.ClientConnInterface]); ok && k != "" { v.Delete(k) } } @@ -79,7 +80,7 @@ func Delete(ctx context.Context) { func Load(ctx context.Context) (grpc.ClientConnInterface, bool) { k := nameFromContext(ctx) - if v, ok := ctx.Value(mapKey{}).(*stringCCMap); ok && k != "" { + if v, ok := ctx.Value(mapKey{}).(*genericsync.Map[string, grpc.ClientConnInterface]); ok && k != "" { return v.Load(k) } @@ -92,7 +93,7 @@ func Load(ctx context.Context) (grpc.ClientConnInterface, bool) { func LoadOrStore(ctx context.Context, cc grpc.ClientConnInterface) (grpc.ClientConnInterface, bool) { k := nameFromContext(ctx) - if v, ok := ctx.Value(mapKey{}).(*stringCCMap); ok && k != "" { + if v, ok := ctx.Value(mapKey{}).(*genericsync.Map[string, grpc.ClientConnInterface]); ok && k != "" { return v.LoadOrStore(k, cc) } diff --git a/pkg/registry/common/clientconn/gen.go b/pkg/registry/common/clientconn/gen.go deleted file mode 100644 index 792b22b80..000000000 --- a/pkg/registry/common/clientconn/gen.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2022 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientconn - -import ( - "sync" -) - -//go:generate go-syncmap -output map.gen.go -type stringCCMap - -// clientMap - sync.Map with key == url.URL and value == grpc.ClientConnInterface -type stringCCMap sync.Map diff --git a/pkg/registry/common/clientconn/map.gen.go b/pkg/registry/common/clientconn/map.gen.go deleted file mode 100644 index 0263b3f50..000000000 --- a/pkg/registry/common/clientconn/map.gen.go +++ /dev/null @@ -1,77 +0,0 @@ -// Code generated by "-output map.gen.go -type stringCCMap -output map.gen.go -type stringCCMap"; DO NOT EDIT. -// Install -output map.gen.go -type stringCCMap by "go get -u github.com/searKing/golang/tools/-output map.gen.go -type stringCCMap" - -package clientconn - -import ( - "sync" // Used by sync.Map. - - "google.golang.org/grpc" -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert stringCCMap literal (type stringCCMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(stringCCMap{}) -} - -var _nil_stringCCMap_grpc_ClientConnInterface_value = func() (val grpc.ClientConnInterface) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *stringCCMap) Load(key string) (grpc.ClientConnInterface, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_stringCCMap_grpc_ClientConnInterface_value, ok - } - return value.(grpc.ClientConnInterface), ok -} - -// Store sets the value for a key. -func (m *stringCCMap) Store(key string, value grpc.ClientConnInterface) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *stringCCMap) LoadOrStore(key string, value grpc.ClientConnInterface) (grpc.ClientConnInterface, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_stringCCMap_grpc_ClientConnInterface_value, loaded - } - return actual.(grpc.ClientConnInterface), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *stringCCMap) LoadAndDelete(key string) (value grpc.ClientConnInterface, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_stringCCMap_grpc_ClientConnInterface_value, loaded - } - return actual.(grpc.ClientConnInterface), loaded -} - -// Delete deletes the value for a key. -func (m *stringCCMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *stringCCMap) Range(f func(key string, value grpc.ClientConnInterface) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(grpc.ClientConnInterface)) - }) -} diff --git a/pkg/registry/common/clientconn/ns_client.go b/pkg/registry/common/clientconn/ns_client.go index 98564e2b5..7b421ab04 100644 --- a/pkg/registry/common/clientconn/ns_client.go +++ b/pkg/registry/common/clientconn/ns_client.go @@ -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 // @@ -20,6 +20,7 @@ package clientconn import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/google/uuid" "github.com/networkservicemesh/api/pkg/api/registry" @@ -29,21 +30,21 @@ import ( ) type clientConnNSClient struct { - stringCCMap + genericsync.Map[string, grpc.ClientConnInterface] } func (c *clientConnNSClient) Register(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*registry.NetworkService, error) { - ctx = withClientConnMetadata(ctx, &c.stringCCMap, in.GetName()) + ctx = withClientConnMetadata(ctx, &c.Map, in.GetName()) return next.NetworkServiceRegistryClient(ctx).Register(ctx, in, opts...) } func (c *clientConnNSClient) Unregister(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*empty.Empty, error) { - ctx = withClientConnMetadata(ctx, &c.stringCCMap, in.GetName()) + ctx = withClientConnMetadata(ctx, &c.Map, in.GetName()) return next.NetworkServiceRegistryClient(ctx).Unregister(ctx, in) } func (c *clientConnNSClient) Find(ctx context.Context, in *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) { - ctx = withClientConnMetadata(ctx, &c.stringCCMap, uuid.New().String()) + ctx = withClientConnMetadata(ctx, &c.Map, uuid.New().String()) return next.NetworkServiceRegistryClient(ctx).Find(ctx, in, opts...) } diff --git a/pkg/registry/common/clientconn/nse_client.go b/pkg/registry/common/clientconn/nse_client.go index 947c57eb7..569dfa42a 100644 --- a/pkg/registry/common/clientconn/nse_client.go +++ b/pkg/registry/common/clientconn/nse_client.go @@ -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 // @@ -20,6 +20,7 @@ package clientconn import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/google/uuid" "github.com/networkservicemesh/api/pkg/api/registry" @@ -29,21 +30,21 @@ import ( ) type clientConnNSEClient struct { - stringCCMap + genericsync.Map[string, grpc.ClientConnInterface] } func (c *clientConnNSEClient) Register(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) { - ctx = withClientConnMetadata(ctx, &c.stringCCMap, in.GetName()) + ctx = withClientConnMetadata(ctx, &c.Map, in.GetName()) return next.NetworkServiceEndpointRegistryClient(ctx).Register(ctx, in, opts...) } func (c *clientConnNSEClient) Unregister(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*empty.Empty, error) { - ctx = withClientConnMetadata(ctx, &c.stringCCMap, in.GetName()) + ctx = withClientConnMetadata(ctx, &c.Map, in.GetName()) return next.NetworkServiceEndpointRegistryClient(ctx).Unregister(ctx, in) } func (c *clientConnNSEClient) Find(ctx context.Context, in *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) { - ctx = withClientConnMetadata(ctx, &c.stringCCMap, uuid.New().String()) + ctx = withClientConnMetadata(ctx, &c.Map, uuid.New().String()) return next.NetworkServiceEndpointRegistryClient(ctx).Find(ctx, in, opts...) } diff --git a/pkg/registry/common/endpointurls/gen.go b/pkg/registry/common/endpointurls/gen.go deleted file mode 100644 index 27f65a723..000000000 --- a/pkg/registry/common/endpointurls/gen.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2020-2021 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package endpointurls - -import ( - "sync" -) - -//go:generate go-syncmap -output sync_map.gen.go -type Map - -// Map is like a Go map[url.URL]string but is safe for concurrent use -// by multiple goroutines without additional locking or coordination -type Map sync.Map diff --git a/pkg/registry/common/endpointurls/server.go b/pkg/registry/common/endpointurls/server.go index 5a58f1a8f..e6ad22467 100644 --- a/pkg/registry/common/endpointurls/server.go +++ b/pkg/registry/common/endpointurls/server.go @@ -1,5 +1,7 @@ // Copyright (c) 2020-2021 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"); @@ -21,6 +23,7 @@ import ( "context" "net/url" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" @@ -28,7 +31,7 @@ import ( ) type endpointURLsServer struct { - nses *Map + nses *genericsync.Map[url.URL, string] } func (e *endpointURLsServer) Register(ctx context.Context, endpoint *registry.NetworkServiceEndpoint) (*registry.NetworkServiceEndpoint, error) { @@ -50,6 +53,6 @@ func (e *endpointURLsServer) Unregister(ctx context.Context, endpoint *registry. } // NewNetworkServiceEndpointRegistryServer returns new registry.NetworkServiceEndpointRegistryServer with injected endpoint urls nses -func NewNetworkServiceEndpointRegistryServer(m *Map) registry.NetworkServiceEndpointRegistryServer { +func NewNetworkServiceEndpointRegistryServer(m *genericsync.Map[url.URL, string]) registry.NetworkServiceEndpointRegistryServer { return &endpointURLsServer{nses: m} } diff --git a/pkg/registry/common/endpointurls/sync_map.gen.go b/pkg/registry/common/endpointurls/sync_map.gen.go deleted file mode 100644 index 61b50e220..000000000 --- a/pkg/registry/common/endpointurls/sync_map.gen.go +++ /dev/null @@ -1,76 +0,0 @@ -// Code generated by "-output sync_map.gen.go -type Map -output sync_map.gen.go -type Map"; DO NOT EDIT. -// Install -output sync_map.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type Map" - -package endpointurls - -import ( - "net/url" - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert Map literal (type Map) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(Map{}) -} - -var _nil_Map_string_value = func() (val string) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *Map) Load(key url.URL) (string, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_Map_string_value, ok - } - return value.(string), ok -} - -// Store sets the value for a key. -func (m *Map) Store(key url.URL, value string) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *Map) LoadOrStore(key url.URL, value string) (string, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_Map_string_value, loaded - } - return actual.(string), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *Map) LoadAndDelete(key url.URL) (value string, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_Map_string_value, loaded - } - return actual.(string), loaded -} - -// Delete deletes the value for a key. -func (m *Map) Delete(key url.URL) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *Map) Range(f func(key url.URL, value string) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(url.URL), value.(string)) - }) -} diff --git a/pkg/registry/common/expire/gen.go b/pkg/registry/common/expire/gen.go deleted file mode 100644 index 508af29c9..000000000 --- a/pkg/registry/common/expire/gen.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2020-2022 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package expire - -import "sync" - -//go:generate go-syncmap -output sync_map.gen.go -type cancelsMap - -// cancelsMap is like a Go map[string]context.CancelFunc but is safe for concurrent use -// by multiple goroutines without additional locking or coordination -type cancelsMap sync.Map diff --git a/pkg/registry/common/expire/nse_server.go b/pkg/registry/common/expire/nse_server.go index 1de76265f..05a07414b 100644 --- a/pkg/registry/common/expire/nse_server.go +++ b/pkg/registry/common/expire/nse_server.go @@ -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"); @@ -20,6 +22,7 @@ import ( "context" "time" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "google.golang.org/protobuf/types/known/timestamppb" @@ -32,9 +35,9 @@ import ( ) type expireNSEServer struct { - ctx context.Context defaultExpiration time.Duration - cancelsMap + ctx context.Context + genericsync.Map[string, context.CancelFunc] } // NewNetworkServiceEndpointRegistryServer creates a new NetworkServiceServer chain element that implements unregister @@ -82,10 +85,10 @@ func (s *expireNSEServer) Register(ctx context.Context, nse *registry.NetworkSer } expireContext, cancel := context.WithCancel(s.ctx) - if v, ok := s.cancelsMap.LoadAndDelete(nse.GetName()); ok { + if v, ok := s.Map.LoadAndDelete(nse.GetName()); ok { v() } - s.cancelsMap.Store(nse.GetName(), cancel) + s.Map.Store(nse.GetName(), cancel) expireCh := timeClock.After(timeClock.Until(expirationTime.Local()) - requestTimeout) diff --git a/pkg/registry/common/expire/sync_map.gen.go b/pkg/registry/common/expire/sync_map.gen.go deleted file mode 100644 index 88bb39965..000000000 --- a/pkg/registry/common/expire/sync_map.gen.go +++ /dev/null @@ -1,76 +0,0 @@ -// Code generated by "-output sync_map.gen.go -type cancelsMap -output sync_map.gen.go -type cancelsMap"; DO NOT EDIT. -// Install -output sync_map.gen.go -type cancelsMap by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type cancelsMap" - -package expire - -import ( - "context" - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert cancelsMap literal (type cancelsMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(cancelsMap{}) -} - -var _nil_cancelsMap_context_CancelFunc_value = func() (val context.CancelFunc) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *cancelsMap) Load(key string) (context.CancelFunc, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_cancelsMap_context_CancelFunc_value, ok - } - return value.(context.CancelFunc), ok -} - -// Store sets the value for a key. -func (m *cancelsMap) Store(key string, value context.CancelFunc) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *cancelsMap) LoadOrStore(key string, value context.CancelFunc) (context.CancelFunc, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_cancelsMap_context_CancelFunc_value, loaded - } - return actual.(context.CancelFunc), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *cancelsMap) LoadAndDelete(key string) (value context.CancelFunc, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_cancelsMap_context_CancelFunc_value, loaded - } - return actual.(context.CancelFunc), loaded -} - -// Delete deletes the value for a key. -func (m *cancelsMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *cancelsMap) Range(f func(key string, value context.CancelFunc) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(context.CancelFunc)) - }) -} diff --git a/pkg/registry/common/heal/gen.go b/pkg/registry/common/heal/gen.go deleted file mode 100644 index dc1e6aec9..000000000 --- a/pkg/registry/common/heal/gen.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2021-2022 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package heal - -import ( - "sync" -) - -//go:generate go-syncmap -output sync_map.gen.go -type cancelsMap - -// cancelsMap is like a Go map[string]context.CancelFunc but is safe for concurrent use -// by multiple goroutines without additional locking or coordination -type cancelsMap sync.Map diff --git a/pkg/registry/common/heal/ns_client.go b/pkg/registry/common/heal/ns_client.go index 79aa25237..4805961c7 100644 --- a/pkg/registry/common/heal/ns_client.go +++ b/pkg/registry/common/heal/ns_client.go @@ -21,6 +21,7 @@ package heal import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" "google.golang.org/grpc" @@ -32,7 +33,7 @@ import ( type healNSClient struct { ctx context.Context - cancelsMap + genericsync.Map[string, context.CancelFunc] } // NewNetworkServiceRegistryClient returns a new NS registry client responsible for healing diff --git a/pkg/registry/common/heal/nse_client.go b/pkg/registry/common/heal/nse_client.go index de2c5ce7a..cd6e4b162 100644 --- a/pkg/registry/common/heal/nse_client.go +++ b/pkg/registry/common/heal/nse_client.go @@ -21,6 +21,7 @@ package heal import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" "google.golang.org/grpc" @@ -32,7 +33,7 @@ import ( type healNSEClient struct { ctx context.Context - cancelsMap + genericsync.Map[string, context.CancelFunc] } // NewNetworkServiceEndpointRegistryClient returns a new NSE registry client responsible for healing diff --git a/pkg/registry/common/heal/sync_map.gen.go b/pkg/registry/common/heal/sync_map.gen.go deleted file mode 100644 index dd20912eb..000000000 --- a/pkg/registry/common/heal/sync_map.gen.go +++ /dev/null @@ -1,76 +0,0 @@ -// Code generated by "-output sync_map.gen.go -type cancelsMap -output sync_map.gen.go -type cancelsMap"; DO NOT EDIT. -// Install -output sync_map.gen.go -type cancelsMap by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type cancelsMap" - -package heal - -import ( - "context" - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert cancelsMap literal (type cancelsMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(cancelsMap{}) -} - -var _nil_cancelsMap_context_CancelFunc_value = func() (val context.CancelFunc) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *cancelsMap) Load(key string) (context.CancelFunc, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_cancelsMap_context_CancelFunc_value, ok - } - return value.(context.CancelFunc), ok -} - -// Store sets the value for a key. -func (m *cancelsMap) Store(key string, value context.CancelFunc) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *cancelsMap) LoadOrStore(key string, value context.CancelFunc) (context.CancelFunc, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_cancelsMap_context_CancelFunc_value, loaded - } - return actual.(context.CancelFunc), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *cancelsMap) LoadAndDelete(key string) (value context.CancelFunc, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_cancelsMap_context_CancelFunc_value, loaded - } - return actual.(context.CancelFunc), loaded -} - -// Delete deletes the value for a key. -func (m *cancelsMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *cancelsMap) Range(f func(key string, value context.CancelFunc) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(context.CancelFunc)) - }) -} diff --git a/pkg/registry/common/interdomainbypass/server.go b/pkg/registry/common/interdomainbypass/server.go index 24da87fc2..38c7e7702 100644 --- a/pkg/registry/common/interdomainbypass/server.go +++ b/pkg/registry/common/interdomainbypass/server.go @@ -21,21 +21,21 @@ import ( "context" "net/url" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" "github.com/pkg/errors" "github.com/networkservicemesh/sdk/pkg/registry/core/next" - "github.com/networkservicemesh/sdk/pkg/tools/stringurl" ) type interdomainBypassNSEServer struct { - m *stringurl.Map + m *genericsync.Map[string, *url.URL] u *url.URL } type interdomainBypassNSEFindServer struct { - m *stringurl.Map + m *genericsync.Map[string, *url.URL] u *url.URL registry.NetworkServiceEndpointRegistry_FindServer } @@ -76,7 +76,7 @@ func (n *interdomainBypassNSEServer) Unregister(ctx context.Context, service *re // NewNetworkServiceEndpointRegistryServer creates new instance of interdomainbypass NSE server. // It simply stores into passed stringurl.Map all incoming nse.Name:nse.URL entries. // And sets passed URL for outgoing NSEs. -func NewNetworkServiceEndpointRegistryServer(m *stringurl.Map, u *url.URL) registry.NetworkServiceEndpointRegistryServer { +func NewNetworkServiceEndpointRegistryServer(m *genericsync.Map[string, *url.URL], u *url.URL) registry.NetworkServiceEndpointRegistryServer { if m == nil { panic("m can not be nil") } diff --git a/pkg/registry/common/localbypass/server.go b/pkg/registry/common/localbypass/server.go index f69439707..e24d663ee 100644 --- a/pkg/registry/common/localbypass/server.go +++ b/pkg/registry/common/localbypass/server.go @@ -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"); @@ -22,13 +24,13 @@ import ( "context" "net/url" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" "github.com/networkservicemesh/api/pkg/api/registry" "github.com/networkservicemesh/sdk/pkg/registry/core/next" - "github.com/networkservicemesh/sdk/pkg/tools/stringurl" ) type localBypassNSEFindServer struct { @@ -50,7 +52,7 @@ func (s *localBypassNSEFindServer) Send(nseResp *registry.NetworkServiceEndpoint type localBypassNSEServer struct { nsmgrURL string - nseURLs stringurl.Map + nseURLs genericsync.Map[string, *url.URL] } // NewNetworkServiceEndpointRegistryServer creates new instance of NetworkServiceEndpointRegistryServer which sets diff --git a/pkg/registry/common/memory/gen.go b/pkg/registry/common/memory/gen.go deleted file mode 100644 index 0b51c407f..000000000 --- a/pkg/registry/common/memory/gen.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package memory - -import "sync" - -//go:generate go-syncmap -output ns_sync_map.gen.go -type NetworkServiceSyncMap -//go:generate go-syncmap -output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap - -// NetworkServiceSyncMap is like a Go map[string]*registry.NetworkService but is safe for concurrent use -// by multiple goroutines without additional locking or coordination. -type NetworkServiceSyncMap sync.Map - -// NetworkServiceEndpointSyncMap is like a Go map[string]*registry.NetworkServiceEndpoint but is safe for concurrent use -// by multiple goroutines without additional locking or coordination. -type NetworkServiceEndpointSyncMap sync.Map diff --git a/pkg/registry/common/memory/ns_server.go b/pkg/registry/common/memory/ns_server.go index 84a357d00..4db145d8a 100644 --- a/pkg/registry/common/memory/ns_server.go +++ b/pkg/registry/common/memory/ns_server.go @@ -22,6 +22,7 @@ import ( "context" "io" + "github.com/edwarnicke/genericsync" "github.com/edwarnicke/serialize" "github.com/golang/protobuf/ptypes/empty" "github.com/google/uuid" @@ -34,7 +35,7 @@ import ( ) type memoryNSServer struct { - networkServices NetworkServiceSyncMap + networkServices genericsync.Map[string, *registry.NetworkService] executor serialize.Executor eventChannels map[string]chan *registry.NetworkService eventChannelSize int diff --git a/pkg/registry/common/memory/ns_sync_map.gen.go b/pkg/registry/common/memory/ns_sync_map.gen.go deleted file mode 100644 index 060e25cc3..000000000 --- a/pkg/registry/common/memory/ns_sync_map.gen.go +++ /dev/null @@ -1,77 +0,0 @@ -// Code generated by "-output ns_sync_map.gen.go -type NetworkServiceSyncMap -output ns_sync_map.gen.go -type NetworkServiceSyncMap"; DO NOT EDIT. -// Install -output ns_sync_map.gen.go -type NetworkServiceSyncMap by "go get -u github.com/searKing/golang/tools/-output ns_sync_map.gen.go -type NetworkServiceSyncMap" - -package memory - -import ( - "sync" // Used by sync.Map. - - "github.com/networkservicemesh/api/pkg/api/registry" -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert NetworkServiceSyncMap literal (type NetworkServiceSyncMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(NetworkServiceSyncMap{}) -} - -var _nil_NetworkServiceSyncMap_registry_NetworkService_value = func() (val *registry.NetworkService) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *NetworkServiceSyncMap) Load(key string) (*registry.NetworkService, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_NetworkServiceSyncMap_registry_NetworkService_value, ok - } - return value.(*registry.NetworkService), ok -} - -// Store sets the value for a key. -func (m *NetworkServiceSyncMap) Store(key string, value *registry.NetworkService) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *NetworkServiceSyncMap) LoadOrStore(key string, value *registry.NetworkService) (*registry.NetworkService, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_NetworkServiceSyncMap_registry_NetworkService_value, loaded - } - return actual.(*registry.NetworkService), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *NetworkServiceSyncMap) LoadAndDelete(key string) (value *registry.NetworkService, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_NetworkServiceSyncMap_registry_NetworkService_value, loaded - } - return actual.(*registry.NetworkService), loaded -} - -// Delete deletes the value for a key. -func (m *NetworkServiceSyncMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *NetworkServiceSyncMap) Range(f func(key string, value *registry.NetworkService) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*registry.NetworkService)) - }) -} diff --git a/pkg/registry/common/memory/nse_server.go b/pkg/registry/common/memory/nse_server.go index 00f0fb4d2..5da47c3a9 100644 --- a/pkg/registry/common/memory/nse_server.go +++ b/pkg/registry/common/memory/nse_server.go @@ -22,6 +22,7 @@ import ( "context" "io" + "github.com/edwarnicke/genericsync" "github.com/edwarnicke/serialize" "github.com/golang/protobuf/ptypes/empty" "github.com/google/uuid" @@ -34,7 +35,7 @@ import ( ) type memoryNSEServer struct { - networkServiceEndpoints NetworkServiceEndpointSyncMap + networkServiceEndpoints genericsync.Map[string, *registry.NetworkServiceEndpoint] executor serialize.Executor eventChannels map[string]chan *registry.NetworkServiceEndpointResponse eventChannelSize int diff --git a/pkg/registry/common/memory/nse_sync_map.gen.go b/pkg/registry/common/memory/nse_sync_map.gen.go deleted file mode 100644 index df0855994..000000000 --- a/pkg/registry/common/memory/nse_sync_map.gen.go +++ /dev/null @@ -1,77 +0,0 @@ -// Code generated by "-output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap -output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap"; DO NOT EDIT. -// Install -output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap by "go get -u github.com/searKing/golang/tools/-output nse_sync_map.gen.go -type NetworkServiceEndpointSyncMap" - -package memory - -import ( - "sync" // Used by sync.Map. - - "github.com/networkservicemesh/api/pkg/api/registry" -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert NetworkServiceEndpointSyncMap literal (type NetworkServiceEndpointSyncMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(NetworkServiceEndpointSyncMap{}) -} - -var _nil_NetworkServiceEndpointSyncMap_registry_NetworkServiceEndpoint_value = func() (val *registry.NetworkServiceEndpoint) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *NetworkServiceEndpointSyncMap) Load(key string) (*registry.NetworkServiceEndpoint, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_NetworkServiceEndpointSyncMap_registry_NetworkServiceEndpoint_value, ok - } - return value.(*registry.NetworkServiceEndpoint), ok -} - -// Store sets the value for a key. -func (m *NetworkServiceEndpointSyncMap) Store(key string, value *registry.NetworkServiceEndpoint) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *NetworkServiceEndpointSyncMap) LoadOrStore(key string, value *registry.NetworkServiceEndpoint) (*registry.NetworkServiceEndpoint, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_NetworkServiceEndpointSyncMap_registry_NetworkServiceEndpoint_value, loaded - } - return actual.(*registry.NetworkServiceEndpoint), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *NetworkServiceEndpointSyncMap) LoadAndDelete(key string) (value *registry.NetworkServiceEndpoint, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_NetworkServiceEndpointSyncMap_registry_NetworkServiceEndpoint_value, loaded - } - return actual.(*registry.NetworkServiceEndpoint), loaded -} - -// Delete deletes the value for a key. -func (m *NetworkServiceEndpointSyncMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *NetworkServiceEndpointSyncMap) Range(f func(key string, value *registry.NetworkServiceEndpoint) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*registry.NetworkServiceEndpoint)) - }) -} diff --git a/pkg/registry/common/querycache/cache.go b/pkg/registry/common/querycache/cache.go index ba44f1c0b..f9558dc42 100644 --- a/pkg/registry/common/querycache/cache.go +++ b/pkg/registry/common/querycache/cache.go @@ -1,5 +1,7 @@ // Copyright (c) 2021 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"); @@ -21,6 +23,7 @@ import ( "sync" "time" + "github.com/edwarnicke/genericsync" "github.com/networkservicemesh/api/pkg/api/registry" "github.com/networkservicemesh/sdk/pkg/tools/clock" @@ -28,7 +31,7 @@ import ( type cache struct { expireTimeout time.Duration - entries cacheEntryMap + entries genericsync.Map[string, *cacheEntry] clockTime clock.Clock } diff --git a/pkg/registry/common/querycache/cache_entry_map.gen.go b/pkg/registry/common/querycache/cache_entry_map.gen.go deleted file mode 100644 index 112ab6060..000000000 --- a/pkg/registry/common/querycache/cache_entry_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output cache_entry_map.gen.go -type cacheEntryMap -output cache_entry_map.gen.go -type cacheEntryMap"; DO NOT EDIT. -// Install -output cache_entry_map.gen.go -type cacheEntryMap by "go get -u github.com/searKing/golang/tools/-output cache_entry_map.gen.go -type cacheEntryMap" - -package querycache - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert cacheEntryMap literal (type cacheEntryMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(cacheEntryMap{}) -} - -var _nil_cacheEntryMap_cacheEntry_value = func() (val *cacheEntry) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *cacheEntryMap) Load(key string) (*cacheEntry, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_cacheEntryMap_cacheEntry_value, ok - } - return value.(*cacheEntry), ok -} - -// Store sets the value for a key. -func (m *cacheEntryMap) Store(key string, value *cacheEntry) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *cacheEntryMap) LoadOrStore(key string, value *cacheEntry) (*cacheEntry, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_cacheEntryMap_cacheEntry_value, loaded - } - return actual.(*cacheEntry), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *cacheEntryMap) LoadAndDelete(key string) (value *cacheEntry, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_cacheEntryMap_cacheEntry_value, loaded - } - return actual.(*cacheEntry), loaded -} - -// Delete deletes the value for a key. -func (m *cacheEntryMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *cacheEntryMap) Range(f func(key string, value *cacheEntry) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*cacheEntry)) - }) -} diff --git a/pkg/registry/common/querycache/gen.go b/pkg/registry/common/querycache/gen.go deleted file mode 100644 index 50583e818..000000000 --- a/pkg/registry/common/querycache/gen.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2020-2021 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package querycache - -import "sync" - -//go:generate go-syncmap -output cache_entry_map.gen.go -type cacheEntryMap - -type cacheEntryMap sync.Map diff --git a/pkg/registry/common/recvfd/client.go b/pkg/registry/common/recvfd/client.go index 8efe55ed0..ec76a276d 100644 --- a/pkg/registry/common/recvfd/client.go +++ b/pkg/registry/common/recvfd/client.go @@ -1,7 +1,7 @@ -// Copyright (c) 2021-2022 Cisco and/or its affiliates. -// // Copyright (c) 2021-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"); @@ -26,7 +26,9 @@ import ( "net/url" "os" + "github.com/edwarnicke/genericsync" "github.com/edwarnicke/grpcfd" + "github.com/edwarnicke/serialize" "github.com/golang/protobuf/ptypes/empty" "github.com/networkservicemesh/api/pkg/api/registry" "google.golang.org/grpc" @@ -34,8 +36,14 @@ import ( "github.com/networkservicemesh/sdk/pkg/registry/core/next" ) +type perEndpointFileMap struct { + executor serialize.Executor + filesByInodeURL map[string]*os.File + inodeURLbyFilename map[string]*url.URL +} + type recvfdNSEClient struct { - fileMaps perEndpointFileMapMap + fileMaps genericsync.Map[string, *perEndpointFileMap] } func (n *recvfdNSEClient) Register(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*registry.NetworkServiceEndpoint, error) { @@ -69,7 +77,7 @@ func NewNetworkServiceEndpointRegistryClient() registry.NetworkServiceEndpointRe type recvfdNSEFindClient struct { registry.NetworkServiceEndpointRegistry_FindClient transceiver grpcfd.FDTransceiver - fileMaps *perEndpointFileMapMap + fileMaps *genericsync.Map[string, *perEndpointFileMap] } func (x *recvfdNSEFindClient) Recv() (*registry.NetworkServiceEndpointResponse, error) { diff --git a/pkg/registry/common/recvfd/gen.go b/pkg/registry/common/recvfd/gen.go deleted file mode 100644 index a7a92651b..000000000 --- a/pkg/registry/common/recvfd/gen.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package recvfd - -import ( - "net/url" - "os" - "sync" - - "github.com/edwarnicke/serialize" -) - -//go:generate go-syncmap -output per_endpoint_file_map.gen.go -type perEndpointFileMapMap - -// PerConnectionFileMap - sync.Map with key == string and value == *perConnectionFileMap -type perEndpointFileMapMap sync.Map - -type perEndpointFileMap struct { - executor serialize.Executor - filesByInodeURL map[string]*os.File - inodeURLbyFilename map[string]*url.URL -} diff --git a/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go b/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go deleted file mode 100644 index f53d0835a..000000000 --- a/pkg/registry/common/recvfd/per_endpoint_file_map.gen.go +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated by "-output per_endpoint_file_map.gen.go -type perEndpointFileMapMap -output per_endpoint_file_map.gen.go -type perEndpointFileMapMap"; DO NOT EDIT. -// Install -output per_endpoint_file_map.gen.go -type perEndpointFileMapMap by "go get -u github.com/searKing/golang/tools/-output per_endpoint_file_map.gen.go -type perEndpointFileMapMap" - -package recvfd - -import ( - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert perEndpointFileMapMap literal (type perEndpointFileMapMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(perEndpointFileMapMap{}) -} - -var _nil_perEndpointFileMapMap_perEndpointFileMap_value = func() (val *perEndpointFileMap) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *perEndpointFileMapMap) Load(key string) (*perEndpointFileMap, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_perEndpointFileMapMap_perEndpointFileMap_value, ok - } - return value.(*perEndpointFileMap), ok -} - -// Store sets the value for a key. -func (m *perEndpointFileMapMap) Store(key string, value *perEndpointFileMap) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *perEndpointFileMapMap) LoadOrStore(key string, value *perEndpointFileMap) (*perEndpointFileMap, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_perEndpointFileMapMap_perEndpointFileMap_value, loaded - } - return actual.(*perEndpointFileMap), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *perEndpointFileMapMap) LoadAndDelete(key string) (value *perEndpointFileMap, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_perEndpointFileMapMap_perEndpointFileMap_value, loaded - } - return actual.(*perEndpointFileMap), loaded -} - -// Delete deletes the value for a key. -func (m *perEndpointFileMapMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *perEndpointFileMapMap) Range(f func(key string, value *perEndpointFileMap) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*perEndpointFileMap)) - }) -} diff --git a/pkg/registry/common/recvfd/server.go b/pkg/registry/common/recvfd/server.go index 0754b919e..2590e2d88 100644 --- a/pkg/registry/common/recvfd/server.go +++ b/pkg/registry/common/recvfd/server.go @@ -27,6 +27,7 @@ import ( "net/url" "os" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" @@ -38,7 +39,7 @@ import ( ) type recvfdNseServer struct { - fileMaps perEndpointFileMapMap + fileMaps genericsync.Map[string, *perEndpointFileMap] } // NewNetworkServiceEndpointRegistryServer - creates new NSE registry chain element that will: diff --git a/pkg/registry/common/refresh/gen.go b/pkg/registry/common/refresh/gen.go deleted file mode 100644 index 1ed4bfa1a..000000000 --- a/pkg/registry/common/refresh/gen.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2022 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package refresh - -import "sync" - -//go:generate go-syncmap -output sync_map.gen.go -type cancelsMap - -// cancelsMap is like a Go map[string]context.CancelFunc but is safe for concurrent use -// by multiple goroutines without additional locking or coordination -type cancelsMap sync.Map diff --git a/pkg/registry/common/refresh/nse_registry_client.go b/pkg/registry/common/refresh/nse_registry_client.go index 80a0f6054..4e56deeb1 100644 --- a/pkg/registry/common/refresh/nse_registry_client.go +++ b/pkg/registry/common/refresh/nse_registry_client.go @@ -19,6 +19,7 @@ package refresh import ( "context" + "github.com/edwarnicke/genericsync" "github.com/golang/protobuf/ptypes/empty" "google.golang.org/grpc" @@ -31,7 +32,7 @@ import ( type refreshNSEClient struct { ctx context.Context - cancelsMap + genericsync.Map[string, context.CancelFunc] } // NewNetworkServiceEndpointRegistryClient creates new NetworkServiceEndpointRegistryClient that will refresh expiration diff --git a/pkg/registry/common/refresh/sync_map.gen.go b/pkg/registry/common/refresh/sync_map.gen.go deleted file mode 100644 index 708746358..000000000 --- a/pkg/registry/common/refresh/sync_map.gen.go +++ /dev/null @@ -1,76 +0,0 @@ -// Code generated by "-output sync_map.gen.go -type cancelsMap -output sync_map.gen.go -type cancelsMap"; DO NOT EDIT. -// Install -output sync_map.gen.go -type cancelsMap by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type cancelsMap" - -package refresh - -import ( - "context" - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert cancelsMap literal (type cancelsMap) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(cancelsMap{}) -} - -var _nil_cancelsMap_context_CancelFunc_value = func() (val context.CancelFunc) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *cancelsMap) Load(key string) (context.CancelFunc, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_cancelsMap_context_CancelFunc_value, ok - } - return value.(context.CancelFunc), ok -} - -// Store sets the value for a key. -func (m *cancelsMap) Store(key string, value context.CancelFunc) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *cancelsMap) LoadOrStore(key string, value context.CancelFunc) (context.CancelFunc, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_cancelsMap_context_CancelFunc_value, loaded - } - return actual.(context.CancelFunc), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *cancelsMap) LoadAndDelete(key string) (value context.CancelFunc, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_cancelsMap_context_CancelFunc_value, loaded - } - return actual.(context.CancelFunc), loaded -} - -// Delete deletes the value for a key. -func (m *cancelsMap) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *cancelsMap) Range(f func(key string, value context.CancelFunc) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(context.CancelFunc)) - }) -} diff --git a/pkg/tools/clientmap/README.md b/pkg/tools/clientmap/README.md deleted file mode 100644 index 67fc5f408..000000000 --- a/pkg/tools/clientmap/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# clientmap.Map - -It is a `sync.Map` typed for the `string` keys and `networkservice.NetworkServiceClient` values. - -## Performance - -``` -BenchmarkMap -BenchmarkMap-4 20850049 54.7 ns/op -``` \ No newline at end of file diff --git a/pkg/tools/clientmap/bench_test.go b/pkg/tools/clientmap/bench_test.go deleted file mode 100644 index 2d69de1f9..000000000 --- a/pkg/tools/clientmap/bench_test.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2020-2021 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package clientmap_test - -import ( - "testing" - - "github.com/networkservicemesh/sdk/pkg/networkservice/common/null" - "github.com/networkservicemesh/sdk/pkg/tools/clientmap" -) - -const ( - parallelCount = 20 -) - -var ids = []string{ - "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", -} - -func BenchmarkMap(b *testing.B) { - var m clientmap.Map - client := null.NewClient() - b.SetParallelism(parallelCount) - - b.ResetTimer() - - b.RunParallel(func(pb *testing.PB) { - for i := 0; pb.Next(); i++ { - id := ids[i%len(ids)] - switch i % 6 { - case 0: - m.Store(id, client) - case 1: - _, _ = m.LoadOrStore(id, client) - case 2: - _, _ = m.Load(id) - case 3, 4, 5: - _, _ = m.LoadAndDelete(id) - } - } - }) -} diff --git a/pkg/tools/clientmap/clientmap.gen.go b/pkg/tools/clientmap/clientmap.gen.go deleted file mode 100644 index fea8ff871..000000000 --- a/pkg/tools/clientmap/clientmap.gen.go +++ /dev/null @@ -1,77 +0,0 @@ -// Code generated by "-output clientmap.gen.go -type Map -output clientmap.gen.go -type Map"; DO NOT EDIT. -// Install -output clientmap.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output clientmap.gen.go -type Map" - -package clientmap - -import ( - "sync" // Used by sync.Map. - - "github.com/networkservicemesh/api/pkg/api/networkservice" -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert Map literal (type Map) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(Map{}) -} - -var _nil_Map_networkservice_NetworkServiceClient_value = func() (val networkservice.NetworkServiceClient) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *Map) Load(key string) (networkservice.NetworkServiceClient, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_Map_networkservice_NetworkServiceClient_value, ok - } - return value.(networkservice.NetworkServiceClient), ok -} - -// Store sets the value for a key. -func (m *Map) Store(key string, value networkservice.NetworkServiceClient) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *Map) LoadOrStore(key string, value networkservice.NetworkServiceClient) (networkservice.NetworkServiceClient, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_Map_networkservice_NetworkServiceClient_value, loaded - } - return actual.(networkservice.NetworkServiceClient), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *Map) LoadAndDelete(key string) (value networkservice.NetworkServiceClient, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_Map_networkservice_NetworkServiceClient_value, loaded - } - return actual.(networkservice.NetworkServiceClient), loaded -} - -// Delete deletes the value for a key. -func (m *Map) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *Map) Range(f func(key string, value networkservice.NetworkServiceClient) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(networkservice.NetworkServiceClient)) - }) -} diff --git a/pkg/tools/clientmap/gen.go b/pkg/tools/clientmap/gen.go deleted file mode 100644 index 103baf060..000000000 --- a/pkg/tools/clientmap/gen.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2020 Cisco and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package clientmap provides a sync.Map for networkservicemesh.NetworkServiceClients and a refcounted sync.Map -package clientmap - -import ( - "sync" -) - -//go:generate go-syncmap -output clientmap.gen.go -type Map - -// Map - sync.Map with key == string and value == networkservice.NetworkServiceClient -type Map sync.Map diff --git a/pkg/tools/spire/spiffe_id_connection_map.gen.go b/pkg/tools/spire/spiffe_id_connection_map.gen.go index 2d87793ee..88cce6c68 100644 --- a/pkg/tools/spire/spiffe_id_connection_map.gen.go +++ b/pkg/tools/spire/spiffe_id_connection_map.gen.go @@ -6,8 +6,9 @@ package spire import ( "sync" // Used by sync.Map. - "github.com/networkservicemesh/sdk/pkg/tools/stringset" "github.com/spiffe/go-spiffe/v2/spiffeid" + + "github.com/networkservicemesh/sdk/pkg/tools/stringset" ) // Generate code that will fail if the constants change value. diff --git a/pkg/tools/stringurl/gen.go b/pkg/tools/stringurl/gen.go deleted file mode 100644 index ec0efef44..000000000 --- a/pkg/tools/stringurl/gen.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2020 Doc.ai and/or its affiliates. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package stringurl provides sync map like a Go map[string]*url.URL but is safe for concurrent using -package stringurl - -import "sync" - -//go:generate go-syncmap -output sync_map.gen.go -type Map - -// Map is like a Go map[string]*url.URL but is safe for concurrent use -// by multiple goroutines without additional locking or coordination -type Map sync.Map diff --git a/pkg/tools/stringurl/sync_map.gen.go b/pkg/tools/stringurl/sync_map.gen.go deleted file mode 100644 index 1f62c6c5e..000000000 --- a/pkg/tools/stringurl/sync_map.gen.go +++ /dev/null @@ -1,76 +0,0 @@ -// Code generated by "-output sync_map.gen.go -type Map -output sync_map.gen.go -type Map"; DO NOT EDIT. -// Install -output sync_map.gen.go -type Map by "go get -u github.com/searKing/golang/tools/-output sync_map.gen.go -type Map" - -package stringurl - -import ( - "net/url" - "sync" // Used by sync.Map. -) - -// Generate code that will fail if the constants change value. -func _() { - // An "cannot convert Map literal (type Map) to type sync.Map" compiler error signifies that the base type have changed. - // Re-run the go-syncmap command to generate them again. - _ = (sync.Map)(Map{}) -} - -var _nil_Map_url_URL_value = func() (val *url.URL) { return }() - -// Load returns the value stored in the map for a key, or nil if no -// value is present. -// The ok result indicates whether value was found in the map. -func (m *Map) Load(key string) (*url.URL, bool) { - value, ok := (*sync.Map)(m).Load(key) - if value == nil { - return _nil_Map_url_URL_value, ok - } - return value.(*url.URL), ok -} - -// Store sets the value for a key. -func (m *Map) Store(key string, value *url.URL) { - (*sync.Map)(m).Store(key, value) -} - -// LoadOrStore returns the existing value for the key if present. -// Otherwise, it stores and returns the given value. -// The loaded result is true if the value was loaded, false if stored. -func (m *Map) LoadOrStore(key string, value *url.URL) (*url.URL, bool) { - actual, loaded := (*sync.Map)(m).LoadOrStore(key, value) - if actual == nil { - return _nil_Map_url_URL_value, loaded - } - return actual.(*url.URL), loaded -} - -// LoadAndDelete deletes the value for a key, returning the previous value if any. -// The loaded result reports whether the key was present. -func (m *Map) LoadAndDelete(key string) (value *url.URL, loaded bool) { - actual, loaded := (*sync.Map)(m).LoadAndDelete(key) - if actual == nil { - return _nil_Map_url_URL_value, loaded - } - return actual.(*url.URL), loaded -} - -// Delete deletes the value for a key. -func (m *Map) Delete(key string) { - (*sync.Map)(m).Delete(key) -} - -// Range calls f sequentially for each key and value present in the map. -// If f returns false, range stops the iteration. -// -// Range does not necessarily correspond to any consistent snapshot of the Map's -// contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. -// -// Range may be O(N) with the number of elements in the map even if f returns -// false after a constant number of calls. -func (m *Map) Range(f func(key string, value *url.URL) bool) { - (*sync.Map)(m).Range(func(key, value interface{}) bool { - return f(key.(string), value.(*url.URL)) - }) -}