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)
| 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. |
| 55 | func (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 | |
| 85 | var errNoResp = xerrors.New("no response needed") |
| 86 |
no test coverage detected