|
|
@ -26,7 +26,7 @@ func securityMaxSubSessionPerIp(info base.UpdateInfo) {
|
|
|
|
for _, sub := range g.StatSubs {
|
|
|
|
for _, sub := range g.StatSubs {
|
|
|
|
host, _, err := net.SplitHostPort(sub.RemoteAddr)
|
|
|
|
host, _, err := net.SplitHostPort(sub.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
nazalog.Warnf("split host port failed. remote addr=%s", sub.RemoteAddr)
|
|
|
|
nazalog.Warnf("securityMaxSubSessionPerIp. split host port failed. remote addr=%s", sub.RemoteAddr)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ip2SubSessions[host] = append(ip2SubSessions[host], sub)
|
|
|
|
ip2SubSessions[host] = append(ip2SubSessions[host], sub)
|
|
|
@ -34,20 +34,31 @@ func securityMaxSubSessionPerIp(info base.UpdateInfo) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastUnix := int64(-1)
|
|
|
|
|
|
|
|
lastId := ""
|
|
|
|
for ip, subs := range ip2SubSessions {
|
|
|
|
for ip, subs := range ip2SubSessions {
|
|
|
|
if len(subs) <= config.MaxSubSessionPerIp {
|
|
|
|
if len(subs) <= config.MaxSubSessionPerIp {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nazalog.Debugf("close session. ip=%s, session count=%d", ip, len(subs))
|
|
|
|
nazalog.Debugf("securityMaxSubSessionPerIp. close session. ip=%s, session count=%d", ip, len(subs))
|
|
|
|
|
|
|
|
|
|
|
|
for _, sub := range subs {
|
|
|
|
for _, sub := range subs {
|
|
|
|
//if sub.Protocol == base.SessionProtocolHlsStr {
|
|
|
|
st, err := base.ParseReadableTime(sub.StartTime)
|
|
|
|
// host, _, err := net.SplitHostPort(sub.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
nazalog.Warnf("securityMaxSubSessionPerIp. parse readable time failed. start time=%s, err=%+v", sub.StartTime, err)
|
|
|
|
// nazalog.Warnf("split host port failed. remote addr=%s", sub.RemoteAddr)
|
|
|
|
continue
|
|
|
|
// continue
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if st.UnixMilli() > lastUnix {
|
|
|
|
// addIpBlacklist(info.ServerId, host, 60)
|
|
|
|
lastUnix = st.UnixMilli()
|
|
|
|
//}
|
|
|
|
lastId = sub.SessionId
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, sub := range subs {
|
|
|
|
|
|
|
|
if sub.SessionId == lastId {
|
|
|
|
|
|
|
|
nazalog.Debugf("securityMaxSubSessionPerIp. skip kick. last id=%s", lastId)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
kickSession(info.ServerId, sessionId2StreamName[sub.SessionId], sub.SessionId)
|
|
|
|
kickSession(info.ServerId, sessionId2StreamName[sub.SessionId], sub.SessionId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|