mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-07 01:03:07 +08:00
Restore IPv6 support for API and RTSP #532
This commit is contained in:
@@ -4,14 +4,15 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/AlexxIT/go2rtc/internal/app"
|
|
||||||
"github.com/rs/zerolog"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/AlexxIT/go2rtc/internal/app"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@@ -30,7 +31,7 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default config
|
// default config
|
||||||
cfg.Mod.Listen = ":1984"
|
cfg.Mod.Listen = "0.0.0.0:1984"
|
||||||
|
|
||||||
// load config from YAML
|
// load config from YAML
|
||||||
app.LoadConfig(&cfg)
|
app.LoadConfig(&cfg)
|
||||||
@@ -49,7 +50,7 @@ func Init() {
|
|||||||
HandleFunc("api/exit", exitHandler)
|
HandleFunc("api/exit", exitHandler)
|
||||||
|
|
||||||
// ensure we can listen without errors
|
// ensure we can listen without errors
|
||||||
listener, err := net.Listen("tcp4", cfg.Mod.Listen)
|
listener, err := net.Listen("tcp", cfg.Mod.Listen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("[api] listen")
|
log.Fatal().Err(err).Msg("[api] listen")
|
||||||
return
|
return
|
||||||
@@ -87,7 +88,7 @@ func Init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tlsListener, err := net.Listen("tcp4", cfg.Mod.TLSListen)
|
tlsListener, err := net.Listen("tcp", cfg.Mod.TLSListen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Caller().Send()
|
log.Fatal().Err(err).Caller().Send()
|
||||||
return
|
return
|
||||||
@@ -169,7 +170,7 @@ func middlewareLog(next http.Handler) http.Handler {
|
|||||||
|
|
||||||
func middlewareAuth(username, password string, next http.Handler) http.Handler {
|
func middlewareAuth(username, password string, next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if !strings.HasPrefix(r.RemoteAddr, "127.") {
|
if !strings.HasPrefix(r.RemoteAddr, "127.") && !strings.HasPrefix(r.RemoteAddr, "[::1]") {
|
||||||
user, pass, ok := r.BasicAuth()
|
user, pass, ok := r.BasicAuth()
|
||||||
if !ok || user != username || pass != password {
|
if !ok || user != username || pass != password {
|
||||||
w.Header().Set("Www-Authenticate", `Basic realm="go2rtc"`)
|
w.Header().Set("Www-Authenticate", `Basic realm="go2rtc"`)
|
||||||
|
@@ -26,7 +26,7 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default config
|
// default config
|
||||||
conf.Mod.Listen = ":8554"
|
conf.Mod.Listen = "0.0.0.0:8554"
|
||||||
conf.Mod.DefaultQuery = "video&audio"
|
conf.Mod.DefaultQuery = "video&audio"
|
||||||
|
|
||||||
app.LoadConfig(&conf)
|
app.LoadConfig(&conf)
|
||||||
@@ -45,7 +45,7 @@ func Init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ln, err := net.Listen("tcp4", address)
|
ln, err := net.Listen("tcp", address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("[rtsp] listen")
|
log.Error().Err(err).Msg("[rtsp] listen")
|
||||||
return
|
return
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
package srtp
|
package srtp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/internal/app"
|
"github.com/AlexxIT/go2rtc/internal/app"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/srtp"
|
"github.com/AlexxIT/go2rtc/pkg/srtp"
|
||||||
"net"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
@@ -14,7 +15,7 @@ func Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// default config
|
// default config
|
||||||
cfg.Mod.Listen = ":8443"
|
cfg.Mod.Listen = "0.0.0.0:8443"
|
||||||
|
|
||||||
// load config from YAML
|
// load config from YAML
|
||||||
app.LoadConfig(&cfg)
|
app.LoadConfig(&cfg)
|
||||||
|
@@ -23,7 +23,7 @@ func Init() {
|
|||||||
} `yaml:"webrtc"`
|
} `yaml:"webrtc"`
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Mod.Listen = ":8555/tcp"
|
cfg.Mod.Listen = "0.0.0.0:8555/tcp"
|
||||||
cfg.Mod.IceServers = []pion.ICEServer{
|
cfg.Mod.IceServers = []pion.ICEServer{
|
||||||
{URLs: []string{"stun:stun.l.google.com:19302"}},
|
{URLs: []string{"stun:stun.l.google.com:19302"}},
|
||||||
}
|
}
|
||||||
|
@@ -62,7 +62,7 @@ func (c *Client) Dial() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.conn, err = net.DialTimeout("tcp4", u.Host, Timeout); err != nil {
|
if c.conn, err = net.DialTimeout("tcp", u.Host, Timeout); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,17 +1,18 @@
|
|||||||
package rtsp
|
package rtsp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTimeout(t *testing.T) {
|
func TestTimeout(t *testing.T) {
|
||||||
Timeout = time.Millisecond
|
Timeout = time.Millisecond
|
||||||
|
|
||||||
ln, err := net.Listen("tcp4", "localhost:0")
|
ln, err := net.Listen("tcp", "localhost:0")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
client := NewClient("rtsp://" + ln.Addr().String() + "/stream")
|
client := NewClient("rtsp://" + ln.Addr().String() + "/stream")
|
||||||
@@ -27,7 +28,7 @@ func TestTimeout(t *testing.T) {
|
|||||||
func TestMissedControl(t *testing.T) {
|
func TestMissedControl(t *testing.T) {
|
||||||
Timeout = time.Millisecond
|
Timeout = time.Millisecond
|
||||||
|
|
||||||
ln, err := net.Listen("tcp4", "localhost:0")
|
ln, err := net.Listen("tcp", "localhost:0")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
Reference in New Issue
Block a user