Skip to content

Commit

Permalink
do not serve hls sub session if in ip black list
Browse files Browse the repository at this point in the history
  • Loading branch information
q191201771 committed May 20, 2024
1 parent 4a3282c commit d196a17
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/logic/server_manager__.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package logic
import (
"flag"
"fmt"
"net"
"net/http"
_ "net/http/pprof"
"os"
Expand Down Expand Up @@ -55,6 +56,8 @@ type ServerManager struct {
onHookSession func(uniqueKey string, streamName string) ICustomizeHookSessionContext

notifyHandlerThread taskpool.Pool

ipBlacklist IpBlacklist
}

func NewServerManager(modOption ...ModOption) *ServerManager {
Expand Down Expand Up @@ -812,6 +815,7 @@ func (sm *ServerManager) serveHls(writer http.ResponseWriter, req *http.Request)
Log.Errorf("parse url. err=%+v", err)
return
}

if urlCtx.GetFileType() == "m3u8" {
// TODO(chef): [refactor] 需要整理,这里使用 hls.PathStrategy 不太好 202207
streamName := hls.PathStrategy.GetRequestInfo(urlCtx, sm.config.HlsConfig.OutPath).StreamName
Expand All @@ -821,6 +825,21 @@ func (sm *ServerManager) serveHls(writer http.ResponseWriter, req *http.Request)
}
}

remoteIp, _, err := net.SplitHostPort(req.RemoteAddr)
if err != nil {
Log.Warnf("SplitHostPort failed. addr=%s, err=%+v", req.RemoteAddr, err)
return
}

if sm.ipBlacklist.Has(remoteIp) {
//Log.Warnf("found %s in ip blacklist, so do not serve this request.", remoteIp)

sm.hlsServerHandler.CloseSubSessionIfExist(req)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.20, ubuntu-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, windows-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

Check failure on line 837 in pkg/logic/server_manager__.go

View workflow job for this annotation

GitHub Actions / build (1.18, macos-latest)

sm.hlsServerHandler.CloseSubSessionIfExist undefined (type *hls.ServerHandler has no field or method CloseSubSessionIfExist)

writer.WriteHeader(http.StatusNotFound)
return
}

sm.hlsServerHandler.ServeHTTP(writer, req)
}

Expand Down

0 comments on commit d196a17

Please sign in to comment.