Connect connects the node and makes its peerPool refer to the constructed pool and address (possibly updating ourselves from the old address.) (Unless pid is ourselves, in which case this does nothing.)
(pid uint64, addr string)
| 525 | // (possibly updating ourselves from the old address.) (Unless pid is ourselves, in which |
| 526 | // case this does nothing.) |
| 527 | func (n *Node) Connect(pid uint64, addr string) { |
| 528 | if pid == n.Id { |
| 529 | return |
| 530 | } |
| 531 | if paddr, ok := n.Peer(pid); ok && paddr == addr { |
| 532 | // Already connected. |
| 533 | return |
| 534 | } |
| 535 | // Here's what we do. Right now peerPool maps peer node id's to addr values. If |
| 536 | // a *pool can be created, good, but if not, we still create a peerPoolEntry with |
| 537 | // a nil *pool. |
| 538 | if addr == n.MyAddr { |
| 539 | // TODO: Note this fact in more general peer health info somehow. |
| 540 | glog.Infof("Peer %d claims same host as me\n", pid) |
| 541 | n.SetPeer(pid, addr) |
| 542 | return |
| 543 | } |
| 544 | GetPools().Connect(addr, n.tlsClientConfig) |
| 545 | n.SetPeer(pid, addr) |
| 546 | } |
| 547 | |
| 548 | // DeletePeer deletes the record of the peer with the given id. |
| 549 | func (n *Node) DeletePeer(pid uint64) { |