MCPcopy Create free account
hub / github.com/PasarGuard/node / buildTargetPeerConfigs

Function buildTargetPeerConfigs

backend/wireguard/user_common.go:144–164  ·  view source on GitHub ↗

buildTargetPeerConfigs converts targetPeers into WireGuard peer configs. Peers that fail key/IP parsing are quarantined (logged and skipped). Returns the config slice AND the set of public keys that were successfully built, so callers can filter the peerStore upsert list accordingly — the store must

(targetPeers map[string]*PeerInfo, presharedKey *wgtypes.Key)

Source from the content-addressed store, hash-verified

142// built, so callers can filter the peerStore upsert list accordingly — the
143// store must only contain peers that were actually committed to the kernel.
144func buildTargetPeerConfigs(targetPeers map[string]*PeerInfo, presharedKey *wgtypes.Key) ([]wgtypes.PeerConfig, map[string]struct{}) {
145 keys := make([]string, 0, len(targetPeers))
146 for key := range targetPeers {
147 keys = append(keys, key)
148 }
149 sort.Strings(keys)
150
151 configs := make([]wgtypes.PeerConfig, 0, len(keys))
152 appliedKeys := make(map[string]struct{}, len(keys))
153 for _, key := range keys {
154 config, err := buildAddConfigFromPeerInfo(targetPeers[key], presharedKey)
155 if err != nil {
156 log.Printf("quarantining startup peer %s due to config error: %v", targetPeers[key].Email, err)
157 continue
158 }
159 configs = append(configs, config)
160 appliedKeys[key] = struct{}{}
161 }
162
163 return configs, appliedKeys
164}
165
166// filterUpsertsByAppliedKeys returns only the peers whose public key appears in appliedKeys.
167// This keeps the peerStore in sync with what was actually committed to the kernel;

Callers 2

newWithManagerFactoryFunction · 0.85
syncUsersFullMethod · 0.85

Calls 1

Tested by

no test coverage detected