MCPcopy Index your code
hub / github.com/coder/coder / batchUpdateMappingLocked

Method batchUpdateMappingLocked

tailnet/peer.go:55–83  ·  view source on GitHub ↗

batchUpdateMapping updates the mappings for a list of peers linked to this one by a tunnel. This method is NOT threadsafe and must be called while holding the core lock.

(others []*peer, k proto.CoordinateResponse_PeerUpdate_Kind, reason string)

Source from the content-addressed store, hash-verified

53// batchUpdateMapping updates the mappings for a list of peers linked to this one by a tunnel. This
54// method is NOT threadsafe and must be called while holding the core lock.
55func (p *peer) batchUpdateMappingLocked(others []*peer, k proto.CoordinateResponse_PeerUpdate_Kind, reason string) error {
56 req := &proto.CoordinateResponse{}
57 for _, other := range others {
58 if other == nil || other.node == nil {
59 continue
60 }
61 update, err := p.storeMappingLocked(other.id, other.node, k, reason)
62 if xerrors.Is(err, errNoResp) {
63 continue
64 }
65 if err != nil {
66 return err
67 }
68 req.PeerUpdates = append(req.PeerUpdates, update)
69 }
70 if len(req.PeerUpdates) == 0 {
71 return nil
72 }
73 for _, chunk := range req.Chunked() {
74 select {
75 case p.resps <- chunk:
76 p.lastWrite = time.Now()
77 default:
78 return ErrWouldBlock
79 }
80 }
81 p.logger.Debug(context.Background(), "wrote batched update", slog.F("num_peer_updates", len(req.PeerUpdates)))
82 return nil
83}
84
85var errNoResp = xerrors.New("no response needed")
86

Callers 1

initPeerMethod · 0.80

Calls 3

storeMappingLockedMethod · 0.95
ChunkedMethod · 0.95
IsMethod · 0.45

Tested by

no test coverage detected