retryInactivePeer try to connect peer in INACTIVITY state
()
| 379 | |
| 380 | //retryInactivePeer try to connect peer in INACTIVITY state |
| 381 | func (this *P2PServer) retryInactivePeer() { |
| 382 | np := this.network.GetNp() |
| 383 | np.Lock() |
| 384 | var ip net.IP |
| 385 | neighborPeers := make(map[uint64]*peer.Peer) |
| 386 | for _, p := range np.List { |
| 387 | addr, _ := p.GetAddr16() |
| 388 | ip = addr[:] |
| 389 | nodeAddr := ip.To16().String() + ":" + |
| 390 | strconv.Itoa(int(p.GetPort())) |
| 391 | if p.GetState() == common.INACTIVITY { |
| 392 | log.Debugf("[p2p] try reconnect %s", nodeAddr) |
| 393 | //add addr to retry list |
| 394 | this.addToRetryList(nodeAddr) |
| 395 | p.Close() |
| 396 | } else { |
| 397 | //add others to tmp node map |
| 398 | this.removeFromRetryList(nodeAddr) |
| 399 | neighborPeers[p.GetID()] = p |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | np.List = neighborPeers |
| 404 | np.Unlock() |
| 405 | |
| 406 | connCount := uint(this.network.GetOutConnRecordLen()) |
| 407 | if connCount >= config.DefConfig.P2PNode.MaxConnOutBound { |
| 408 | log.Warnf("[p2p]Connect: out connections(%d) reach the max limit(%d)", connCount, |
| 409 | config.DefConfig.P2PNode.MaxConnOutBound) |
| 410 | return |
| 411 | } |
| 412 | |
| 413 | //try connect |
| 414 | if len(this.RetryAddrs) > 0 { |
| 415 | this.ReconnectAddrs.Lock() |
| 416 | |
| 417 | list := make(map[string]int) |
| 418 | addrs := make([]string, 0, len(this.RetryAddrs)) |
| 419 | for addr, v := range this.RetryAddrs { |
| 420 | v += 1 |
| 421 | addrs = append(addrs, addr) |
| 422 | if v < common.MAX_RETRY_COUNT { |
| 423 | list[addr] = v |
| 424 | } |
| 425 | if v >= common.MAX_RETRY_COUNT { |
| 426 | this.network.RemoveFromConnectingList(addr) |
| 427 | remotePeer := this.network.GetPeerFromAddr(addr) |
| 428 | if remotePeer != nil { |
| 429 | if remotePeer.Link.GetAddr() == addr { |
| 430 | this.network.RemovePeerAddress(addr) |
| 431 | } |
| 432 | this.network.DelNbrNode(remotePeer.GetID()) |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | this.RetryAddrs = list |
| 438 | this.ReconnectAddrs.Unlock() |
no test coverage detected