stream key checking

This commit is contained in:
Muaz Ahmad 2023-09-21 13:36:11 +05:00
parent cbf372b0f4
commit e1852b6ae0
2 changed files with 62 additions and 4 deletions

View file

@ -137,15 +137,31 @@ func (agent *SRTManager) create_conclusion_resp() (*Packet) {
}
func (agent *SRTManager) process_conclusion(packet *Packet) (*Packet) {
resp_packet := agent.create_conclusion_resp()
if packet.packet_type == HANDSHAKE {
hs_cif := packet.cif.(*HandshakeCIF)
if hs_cif.hs_type == 0xffffffff && hs_cif.syn_cookie == agent.syn_cookie {
for _, v := range hs_cif.hs_extensions {
switch v.ext_type {
case 5:
writer, ok := CheckStreamID(v.ext_contents.([]byte))
if !ok {
resp_packet.cif.(*HandshakeCIF).hs_type = 1003
return resp_packet
} else {
agent.output = writer
}
}
}
agent.pings[0][1] = time.Now()
agent.state = DATA_LOOP
return agent.create_conclusion_resp()
if agent.output != nil {
agent.state = DATA_LOOP
return resp_packet
}
}
}
return nil
resp_packet.cif.(*HandshakeCIF).hs_type = 1000
return resp_packet
}
func (agent *SRTManager) create_ack_report() (*Packet) {
@ -174,7 +190,6 @@ func (agent *SRTManager) create_ack_report() (*Packet) {
rtt_2_sum += uint32(math.Pow(float64(rtt), 2))
}
}
fmt.Println(rtt, rtt_sum, rtt_2_sum, rtt_n)
cif.rtt = rtt
cif.var_rtt = uint32(rtt_2_sum / rtt_n) - uint32(math.Pow(float64(rtt_sum / rtt_n), 2))

43
srt/stream_ids.go Normal file
View file

@ -0,0 +1,43 @@
package srt
import (
"os"
"io"
"strings"
)
func NewWriter(stream_key string) (io.WriteCloser, error) {
base_dir, _ := os.UserHomeDir()
file, err := os.Create(base_dir + "/live/" + stream_key + "/rawdump.ts")
if err != nil {
return nil, err
}
return file, nil
}
func CheckStreamID(stream_id []byte) (io.WriteCloser, bool) {
stream_key := make([]byte, 0)
for i := len(stream_id) - 1; i >= 0; i-- {
if stream_id[i] == 0 {
break
}
stream_key = append(stream_key, stream_id[i])
}
stream_key_string := strings.TrimSpace(string(stream_key))
if check_stream_key(stream_key_string) {
writer, err := NewWriter(stream_key_string)
if err != nil {
return nil, false
}
return writer, true
}
return nil, false
}
func check_stream_key(stream_key string) (bool) {
base_dir, _ := os.UserHomeDir()
if fileinfo, err := os.Stat(base_dir + "/live/" + stream_key); err == nil && fileinfo.IsDir() {
return true
}
return false
}