Log ICE candidates to debug TCP connection issues. (#2658)
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
|
"github.com/livekit/protocol/logger"
|
||||||
"github.com/livekit/psrpc"
|
"github.com/livekit/psrpc"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/routing"
|
"github.com/livekit/livekit-server/pkg/routing"
|
||||||
@@ -254,6 +255,9 @@ func (p *ParticipantImpl) sendDisconnectUpdatesForReconnect() error {
|
|||||||
func (p *ParticipantImpl) sendICECandidate(c *webrtc.ICECandidate, target livekit.SignalTarget) error {
|
func (p *ParticipantImpl) sendICECandidate(c *webrtc.ICECandidate, target livekit.SignalTarget) error {
|
||||||
trickle := ToProtoTrickle(c.ToJSON())
|
trickle := ToProtoTrickle(c.ToJSON())
|
||||||
trickle.Target = target
|
trickle.Target = target
|
||||||
|
|
||||||
|
p.params.Logger.Debugw("sending ICE candidate", "transport", target, "trickle", logger.Proto(trickle))
|
||||||
|
|
||||||
return p.writeMessage(&livekit.SignalResponse{
|
return p.writeMessage(&livekit.SignalResponse{
|
||||||
Message: &livekit.SignalResponse_Trickle{
|
Message: &livekit.SignalResponse_Trickle{
|
||||||
Trickle: trickle,
|
Trickle: trickle,
|
||||||
|
|||||||
+23
-1
@@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
"github.com/bep/debounce"
|
"github.com/bep/debounce"
|
||||||
"github.com/pion/dtls/v2/pkg/crypto/elliptic"
|
"github.com/pion/dtls/v2/pkg/crypto/elliptic"
|
||||||
|
"github.com/pion/ice/v2"
|
||||||
"github.com/pion/interceptor"
|
"github.com/pion/interceptor"
|
||||||
"github.com/pion/interceptor/pkg/cc"
|
"github.com/pion/interceptor/pkg/cc"
|
||||||
"github.com/pion/interceptor/pkg/gcc"
|
"github.com/pion/interceptor/pkg/gcc"
|
||||||
@@ -702,6 +703,19 @@ func (t *PCTransport) SetPreferTCP(preferTCP bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *PCTransport) AddICECandidate(candidate webrtc.ICECandidateInit) {
|
func (t *PCTransport) AddICECandidate(candidate webrtc.ICECandidateInit) {
|
||||||
|
if !t.params.Config.UseMDNS {
|
||||||
|
candidateValue := strings.TrimPrefix(candidate.Candidate, "candidate:")
|
||||||
|
if candidateValue != "" {
|
||||||
|
candidate, err := ice.UnmarshalCandidate(candidateValue)
|
||||||
|
if err != nil {
|
||||||
|
t.params.Logger.Errorw("failed to parse ice candidate", err)
|
||||||
|
} else if strings.HasSuffix(candidate.Address(), ".local") {
|
||||||
|
t.params.Logger.Debugw("ignoring mDNS candidate", "candidate", candidateValue)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
t.postEvent(event{
|
t.postEvent(event{
|
||||||
signal: signalRemoteICECandidate,
|
signal: signalRemoteICECandidate,
|
||||||
data: &candidate,
|
data: &candidate,
|
||||||
@@ -1314,6 +1328,7 @@ func (t *PCTransport) localDescriptionSent() error {
|
|||||||
|
|
||||||
for _, c := range cachedLocalCandidates {
|
for _, c := range cachedLocalCandidates {
|
||||||
if err := t.params.Handler.OnICECandidate(c, t.params.Transport); err != nil {
|
if err := t.params.Handler.OnICECandidate(c, t.params.Transport); err != nil {
|
||||||
|
t.params.Logger.Warnw("failed to send cached ICE candidate", err, "candidate", c)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1347,7 +1362,12 @@ func (t *PCTransport) handleLocalICECandidate(e event) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.params.Handler.OnICECandidate(c, t.params.Transport)
|
if err := t.params.Handler.OnICECandidate(c, t.params.Transport); err != nil {
|
||||||
|
t.params.Logger.Warnw("failed to send ICE candidate", err, "candidate", c)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *PCTransport) handleRemoteICECandidate(e event) error {
|
func (t *PCTransport) handleRemoteICECandidate(e event) error {
|
||||||
@@ -1370,6 +1390,7 @@ func (t *PCTransport) handleRemoteICECandidate(e event) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := t.pc.AddICECandidate(*c); err != nil {
|
if err := t.pc.AddICECandidate(*c); err != nil {
|
||||||
|
t.params.Logger.Warnw("failed to add cached ICE candidate", err, "candidate", c)
|
||||||
return errors.Wrap(err, "add ice candidate failed")
|
return errors.Wrap(err, "add ice candidate failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1605,6 +1626,7 @@ func (t *PCTransport) setRemoteDescription(sd webrtc.SessionDescription) error {
|
|||||||
|
|
||||||
for _, c := range t.pendingRemoteCandidates {
|
for _, c := range t.pendingRemoteCandidates {
|
||||||
if err := t.pc.AddICECandidate(*c); err != nil {
|
if err := t.pc.AddICECandidate(*c); err != nil {
|
||||||
|
t.params.Logger.Warnw("failed to add cached ICE candidate", err, "candidate", c)
|
||||||
return errors.Wrap(err, "add ice candidate failed")
|
return errors.Wrap(err, "add ice candidate failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,9 @@ package rtc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math/bits"
|
"math/bits"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pion/ice/v2"
|
|
||||||
"github.com/pion/rtcp"
|
"github.com/pion/rtcp"
|
||||||
"github.com/pion/sdp/v3"
|
"github.com/pion/sdp/v3"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
@@ -372,19 +370,6 @@ func (t *TransportManager) HandleAnswer(answer webrtc.SessionDescription) {
|
|||||||
|
|
||||||
// AddICECandidate adds candidates for remote peer
|
// AddICECandidate adds candidates for remote peer
|
||||||
func (t *TransportManager) AddICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) {
|
func (t *TransportManager) AddICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) {
|
||||||
if !t.params.Config.UseMDNS {
|
|
||||||
candidateValue := strings.TrimPrefix(candidate.Candidate, "candidate:")
|
|
||||||
if candidateValue != "" {
|
|
||||||
candidate, err := ice.UnmarshalCandidate(candidateValue)
|
|
||||||
if err != nil {
|
|
||||||
t.params.Logger.Errorw("failed to parse ice candidate", err)
|
|
||||||
} else if strings.HasSuffix(candidate.Address(), ".local") {
|
|
||||||
t.params.Logger.Debugw("ignoring mDNS candidate", "candidate", candidateValue, "target", target)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch target {
|
switch target {
|
||||||
case livekit.SignalTarget_PUBLISHER:
|
case livekit.SignalTarget_PUBLISHER:
|
||||||
t.publisher.AddICECandidate(candidate)
|
t.publisher.AddICECandidate(candidate)
|
||||||
|
|||||||
Reference in New Issue
Block a user