File: network_store.go

package info (click to toggle)
docker.io 28.5.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 69,048 kB
  • sloc: sh: 5,867; makefile: 863; ansic: 184; python: 162; asm: 159
file content (66 lines) | stat: -rw-r--r-- 1,820 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.23

package libnetwork

import (
	"context"

	"github.com/docker/docker/internal/maputil"
)

// storeNetwork inserts or updates the network in the store and the in-memory
// cache maintained by the Controller.
//
// This method is thread-safe.
func (c *Controller) storeNetwork(ctx context.Context, n *Network) error {
	if err := c.updateToStore(ctx, n); err != nil {
		return err
	}
	c.cacheNetwork(n)
	return nil
}

// deleteStoredNetwork deletes the network from the store and the in-memory
// cache maintained by the Controller.
//
// This method is thread-safe.
func (c *Controller) deleteStoredNetwork(n *Network) error {
	if err := c.deleteFromStore(n); err != nil {
		return err
	}

	c.networksMu.Lock()
	defer c.networksMu.Unlock()
	delete(c.networks, n.id)

	return nil
}

// cacheNetwork caches the network in the in-memory cache of networks
// maintained by the Controller.
//
// This method is thread-safe.
func (c *Controller) cacheNetwork(n *Network) {
	c.networksMu.Lock()
	defer c.networksMu.Unlock()
	c.networks[n.ID()] = n
}

// findNetworks looks for all networks matching the filter from the in-memory
// cache of networks maintained by the Controller.
//
// This method is thread-safe, but do not use it unless you're sure your code
// uses the returned networks in thread-safe way (see the comment on
// Controller.networks).
func (c *Controller) findNetworks(filter func(nw *Network) bool) []*Network {
	c.networksMu.Lock()
	defer c.networksMu.Unlock()
	return maputil.FilterValues(c.networks, filter)
}

func filterNetworkByConfigFrom(expected string) func(nw *Network) bool {
	return func(nw *Network) bool {
		return nw.configFrom == expected
	}
}