Reject invalid streaming key
This commit is contained in:
parent
ca622c85c7
commit
161aaeec8d
@ -20,8 +20,9 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type VideoSettings struct {
|
type VideoSettings struct {
|
||||||
ResolutionWidth int `yaml:"resolutionWidth"`
|
ResolutionWidth int `yaml:"resolutionWidth"`
|
||||||
ChunkLengthInSeconds int `yaml:"chunkLengthInSeconds"`
|
ChunkLengthInSeconds int `yaml:"chunkLengthInSeconds"`
|
||||||
|
StreamingKey string `yaml:"streamingKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxNumberOnDisk must be at least as large as MaxNumberInPlaylist
|
// MaxNumberOnDisk must be at least as large as MaxNumberInPlaylist
|
||||||
@ -39,7 +40,7 @@ func getConfig() Config {
|
|||||||
filePath := "config/config.yaml"
|
filePath := "config/config.yaml"
|
||||||
|
|
||||||
if !fileExists(filePath) {
|
if !fileExists(filePath) {
|
||||||
log.Fatal("ERROR: valid config/config.yaml is required")
|
log.Fatal("ERROR: valid config/config.yaml is required. Copy config/config-example.yaml to config/config.yaml and edit.")
|
||||||
}
|
}
|
||||||
|
|
||||||
yamlFile, err := ioutil.ReadFile(filePath)
|
yamlFile, err := ioutil.ReadFile(filePath)
|
||||||
|
@ -6,11 +6,12 @@ webServerPort: 8080
|
|||||||
videoSettings:
|
videoSettings:
|
||||||
resolutionWidth: 900
|
resolutionWidth: 900
|
||||||
chunkLengthInSeconds: 4
|
chunkLengthInSeconds: 4
|
||||||
|
streamingKey: abc123
|
||||||
|
|
||||||
files:
|
files:
|
||||||
maxNumberInPlaylist: 30
|
maxNumberInPlaylist: 30
|
||||||
maxNumberOnDisk: 60
|
maxNumberOnDisk: 60
|
||||||
|
|
||||||
ipfs:
|
ipfs:
|
||||||
enabled: true
|
enabled: false
|
||||||
gateway: https://ipfs.io
|
gateway: https://ipfs.io
|
@ -41,6 +41,12 @@ func (h *Handler) OnCreateStream(timestamp uint32, cmd *rtmpmsg.NetConnectionCre
|
|||||||
func (h *Handler) OnPublish(timestamp uint32, cmd *rtmpmsg.NetStreamPublish) error {
|
func (h *Handler) OnPublish(timestamp uint32, cmd *rtmpmsg.NetStreamPublish) error {
|
||||||
// log.Printf("OnPublish: %#v", cmd)
|
// log.Printf("OnPublish: %#v", cmd)
|
||||||
|
|
||||||
|
log.Println("Incoming stream connected.")
|
||||||
|
|
||||||
|
if cmd.PublishingName != configuration.VideoSettings.StreamingKey {
|
||||||
|
return errors.New("Invalid streaming key! Rejecting incoming stream.")
|
||||||
|
}
|
||||||
|
|
||||||
// (example) Reject a connection when PublishingName is empty
|
// (example) Reject a connection when PublishingName is empty
|
||||||
if cmd.PublishingName == "" {
|
if cmd.PublishingName == "" {
|
||||||
return errors.New("PublishingName is empty")
|
return errors.New("PublishingName is empty")
|
||||||
|
41
main.go
41
main.go
@ -1,15 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
icore "github.com/ipfs/interface-go-ipfs-core"
|
icore "github.com/ipfs/interface-go-ipfs-core"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/yutopp/go-rtmp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ipfs icore.CoreAPI
|
var ipfs icore.CoreAPI
|
||||||
@ -56,40 +52,3 @@ func startChatServer() {
|
|||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(configuration.WebServerPort), nil))
|
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(configuration.WebServerPort), nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func startRTMPService() {
|
|
||||||
port := 1935
|
|
||||||
log.Printf("RTMP server is listening for incoming stream on port %d.\n", port)
|
|
||||||
|
|
||||||
tcpAddr, err := net.ResolveTCPAddr("tcp", ":"+strconv.Itoa(port))
|
|
||||||
if err != nil {
|
|
||||||
log.Panicf("Failed: %+v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
listener, err := net.ListenTCP("tcp", tcpAddr)
|
|
||||||
if err != nil {
|
|
||||||
log.Panicf("Failed: %+v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
srv := rtmp.NewServer(&rtmp.ServerConfig{
|
|
||||||
OnConnect: func(conn net.Conn) (io.ReadWriteCloser, *rtmp.ConnConfig) {
|
|
||||||
l := log.StandardLogger()
|
|
||||||
l.SetLevel(logrus.WarnLevel)
|
|
||||||
|
|
||||||
h := &Handler{}
|
|
||||||
|
|
||||||
return conn, &rtmp.ConnConfig{
|
|
||||||
Handler: h,
|
|
||||||
|
|
||||||
ControlState: rtmp.StreamControlStateConfig{
|
|
||||||
DefaultBandwidthWindowSize: 6 * 1024 * 1024 / 8,
|
|
||||||
},
|
|
||||||
|
|
||||||
Logger: l,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err := srv.Serve(listener); err != nil {
|
|
||||||
log.Panicf("Failed: %+v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
48
rtmp.go
Normal file
48
rtmp.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/yutopp/go-rtmp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func startRTMPService() {
|
||||||
|
port := 1935
|
||||||
|
log.Printf("RTMP server is listening for incoming stream on port %d.\n", port)
|
||||||
|
|
||||||
|
tcpAddr, err := net.ResolveTCPAddr("tcp", ":"+strconv.Itoa(port))
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Failed: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
listener, err := net.ListenTCP("tcp", tcpAddr)
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Failed: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
srv := rtmp.NewServer(&rtmp.ServerConfig{
|
||||||
|
OnConnect: func(conn net.Conn) (io.ReadWriteCloser, *rtmp.ConnConfig) {
|
||||||
|
l := log.StandardLogger()
|
||||||
|
l.SetLevel(logrus.WarnLevel)
|
||||||
|
|
||||||
|
h := &Handler{}
|
||||||
|
|
||||||
|
return conn, &rtmp.ConnConfig{
|
||||||
|
Handler: h,
|
||||||
|
|
||||||
|
ControlState: rtmp.StreamControlStateConfig{
|
||||||
|
DefaultBandwidthWindowSize: 6 * 1024 * 1024 / 8,
|
||||||
|
},
|
||||||
|
|
||||||
|
Logger: l,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err := srv.Serve(listener); err != nil {
|
||||||
|
log.Panicf("Failed: %+v", err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user