Level Connection Manager的IsAllowed方法有BUG
RT, 修复代码如下:
// IsAllowed return true if peer can connect to self. Otherwise, return false.
func (cm *LevelConnManager) IsAllowed(pid peer.ID) bool {
cm.cmLock.RLock()
defer cm.cmLock.RUnlock()
currentCount := 0
if s, idx := cm.getHighLevelConnections(pid); idx != -1 {
currentCount = currentCount + s.Size()
}
if s, idx := cm.getLowLevelConnections(pid); idx != -1 {
currentCount = currentCount + s.Size()
}
if currentCount > 0 {
return currentCount < cm.maxConnCountEachPeerAllowed
}
isHighLevel := cm.IsHighLevel(pid)
if cm.strategy == LIFO {
if isHighLevel {
return len(cm.highLevelConn) < cm.maxPeerCountAllowed
}
return len(cm.highLevelConn)+len(cm.lowLevelConn) < cm.maxPeerCountAllowed
}
if !isHighLevel {
return len(cm.highLevelConn) < cm.maxPeerCountAllowed
}
return true
}