-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send REFRESH_REQUESTED if vl3 dnsServerIP is updated
Signed-off-by: Artem Glazychev <[email protected]>
- Loading branch information
1 parent
f349173
commit ce2e962
Showing
4 changed files
with
279 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
pkg/networkservice/connectioncontext/dnscontext/vl3dns/metadata.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2023 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 vl3dns | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" | ||
) | ||
|
||
type key struct{} | ||
|
||
// storeNotifierCancelFunc sets the context.CancelFunc stored in per Connection.Id metadata. | ||
func storeNotifierCancelFunc(ctx context.Context, cancel context.CancelFunc) { | ||
metadata.Map(ctx, true).Store(key{}, cancel) | ||
} | ||
|
||
// loadAndDeleteNotifierCancelFunc deletes the context.CancelFunc stored in per Connection.Id metadata, | ||
// returning the previous value if any. The loaded result reports whether the key was present. | ||
func loadAndDeleteNotifierCancelFunc(ctx context.Context) (value context.CancelFunc, ok bool) { | ||
rawValue, ok := metadata.Map(ctx, true).LoadAndDelete(key{}) | ||
if !ok { | ||
return | ||
} | ||
value, ok = rawValue.(context.CancelFunc) | ||
return value, ok | ||
} |
68 changes: 68 additions & 0 deletions
68
pkg/networkservice/connectioncontext/dnscontext/vl3dns/notifier.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2023 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 vl3dns | ||
|
||
import ( | ||
"github.com/edwarnicke/serialize" | ||
) | ||
|
||
// notifier - notifies all subscribers of an event | ||
type vl3DNSNotifier struct { | ||
executor serialize.Executor | ||
channels map[string]chan struct{} | ||
} | ||
|
||
func newNotifier() *vl3DNSNotifier { | ||
return &vl3DNSNotifier{ | ||
channels: make(map[string]chan struct{}), | ||
} | ||
} | ||
|
||
func (n *vl3DNSNotifier) subscribe(id string) <-chan struct{} { | ||
if n == nil { | ||
return nil | ||
} | ||
var r chan struct{} | ||
<-n.executor.AsyncExec(func() { | ||
n.channels[id] = make(chan struct{}) | ||
r = n.channels[id] | ||
}) | ||
return r | ||
} | ||
|
||
func (n *vl3DNSNotifier) unsubscribe(id string) { | ||
if n == nil { | ||
return | ||
} | ||
<-n.executor.AsyncExec(func() { | ||
if v, ok := n.channels[id]; ok { | ||
close(v) | ||
} | ||
delete(n.channels, id) | ||
}) | ||
} | ||
|
||
func (n *vl3DNSNotifier) notify() { | ||
if n == nil { | ||
return | ||
} | ||
<-n.executor.AsyncExec(func() { | ||
for _, v := range n.channels { | ||
v <- struct{}{} | ||
} | ||
}) | ||
} |
Oops, something went wrong.