| 542 | } |
| 543 | |
| 544 | func (s *SyncClient) RemovePeer(id peer.ID) bool { |
| 545 | s.lock.Lock() |
| 546 | defer s.lock.Unlock() |
| 547 | pr, ok := s.peers[id] |
| 548 | if !ok { |
| 549 | s.lg.Debug("Cannot remove peer from sync duties, peer was not registered", "peer", id) |
| 550 | return false |
| 551 | } |
| 552 | pr.resCancel() // once loop exits |
| 553 | delete(s.peers, id) |
| 554 | s.removePeerFromTask(pr.shards) |
| 555 | s.metrics.DecPeerCount() |
| 556 | delete(s.idlerPeers, id) |
| 557 | for _, t := range s.tasks { |
| 558 | delete(t.statelessPeers, id) |
| 559 | } |
| 560 | return true |
| 561 | } |
| 562 | |
| 563 | // Close will shut down the sync client and all attached work, and block until shutdown is complete. |
| 564 | // This will block if the Start() has not created the main background loop. |