From 3ef95c19501d5ec95fa69160083fc7902f12ca53 Mon Sep 17 00:00:00 2001 From: marmei <43099631+mar-mei@users.noreply.github.com> Date: Mon, 4 Nov 2019 18:23:20 +0100 Subject: [PATCH] RV Proxy --- src/buffer.go | 12 ++++++++++++ src/config.go | 3 +++ src/webserver.go | 10 ++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/buffer.go b/src/buffer.go index 5e7c053..3cd7186 100644 --- a/src/buffer.go +++ b/src/buffer.go @@ -261,7 +261,9 @@ func bufferingStream(playlistID, streamingURL, channelName string, w http.Respon var oldSegments []string for { // Loop 2: Temporäre Datein sind vorhanden, Daten können zum Client gesendet werden + // HTTP Clientverbindung überwachen + cn, ok := w.(http.CloseNotifier) if ok { @@ -449,6 +451,9 @@ func getTmpFiles(stream *ThisStream) (tmpFiles []string) { func killClientConnection(streamID int, playlistID string, force bool) { + Lock.Lock() + defer Lock.Unlock() + if p, ok := BufferInformation.Load(playlistID); ok { var playlist = p.(Playlist) @@ -493,6 +498,8 @@ func killClientConnection(streamID int, playlistID string, force bool) { func clientConnection(stream ThisStream) (status bool) { status = true + Lock.Lock() + defer Lock.Unlock() if _, ok := BufferClients.Load(stream.PlaylistID + stream.MD5); !ok { @@ -901,6 +908,8 @@ func connectToStreamingServer(streamID int, playlistID string) { // Buffer auf die Festplatte speichern if fileSize >= tmpFileSize/2 || n == 0 { + Lock.Lock() + bandwidth.Stop = time.Now() bandwidth.Size += fileSize @@ -919,6 +928,7 @@ func connectToStreamingServer(streamID int, playlistID string) { stream.Status = true playlist.Streams[streamID] = stream BufferInformation.Store(playlistID, playlist) + Lock.Unlock() tmpSegment++ @@ -1551,9 +1561,11 @@ func thirdPartyBuffer(streamID int, playlistID string) { tmpSegment++ if stream.Status == false { + Lock.Lock() stream.Status = true playlist.Streams[streamID] = stream BufferInformation.Store(playlistID, playlist) + Lock.Unlock() } tmpFile = fmt.Sprintf("%s%d.ts", tmpFolder, tmpSegment) diff --git a/src/config.go b/src/config.go index 68eeadd..0c96a4f 100644 --- a/src/config.go +++ b/src/config.go @@ -29,6 +29,9 @@ var BufferInformation sync.Map // BufferClients : Anzahl der Clients die einen Stream über den Buffer abspielen var BufferClients sync.Map +// Lock : Lock Map +var Lock = sync.RWMutex{} + // Init : Systeminitialisierung func Init() (err error) { diff --git a/src/webserver.go b/src/webserver.go index e618db0..bfc5558 100644 --- a/src/webserver.go +++ b/src/webserver.go @@ -316,10 +316,12 @@ func WS(w http.ResponseWriter, r *http.Request) { var newToken string - if r.Header.Get("Origin") != "http://"+r.Host { - httpStatusError(w, r, 403) - return - } + /* + if r.Header.Get("Origin") != "http://"+r.Host { + httpStatusError(w, r, 403) + return + } + */ conn, err := websocket.Upgrade(w, r, w.Header(), 1024, 1024) if err != nil {