(p *peer)
| 422 | } |
| 423 | |
| 424 | func (c *core) initPeer(p *peer) error { |
| 425 | c.mutex.Lock() |
| 426 | defer c.mutex.Unlock() |
| 427 | p.logger.Debug(context.Background(), "initPeer") |
| 428 | if c.closed { |
| 429 | return ErrClosed |
| 430 | } |
| 431 | if p.node != nil { |
| 432 | return xerrors.Errorf("peer (%s) must be initialized with nil node", p.id) |
| 433 | } |
| 434 | if old, ok := c.peers[p.id]; ok { |
| 435 | // rare and interesting enough to log at Info, but it isn't an error per se |
| 436 | old.logger.Info(context.Background(), "overwritten by new connection") |
| 437 | select { |
| 438 | case old.resps <- &proto.CoordinateResponse{Error: CloseErrOverwritten}: |
| 439 | default: |
| 440 | // pass |
| 441 | } |
| 442 | close(old.resps) |
| 443 | p.overwrites = old.overwrites + 1 |
| 444 | } |
| 445 | now := time.Now() |
| 446 | p.start = now |
| 447 | p.lastWrite = now |
| 448 | c.peers[p.id] = p |
| 449 | |
| 450 | tp := c.tunnels.findTunnelPeers(p.id) |
| 451 | p.logger.Debug(context.Background(), "initial tunnel peers", slog.F("tunnel_peers", tp)) |
| 452 | var others []*peer |
| 453 | for _, otherID := range tp { |
| 454 | // ok to append nil here because the batch call below filters them out |
| 455 | others = append(others, c.peers[otherID]) |
| 456 | } |
| 457 | return p.batchUpdateMappingLocked(others, proto.CoordinateResponse_PeerUpdate_NODE, "init") |
| 458 | } |
| 459 | |
| 460 | // removePeer removes and cleans up a lost peer. It updates all peers it shares a tunnel with, deletes |
| 461 | // all tunnels from which the removed peer is the source. |
no test coverage detected