]> Sergey Matveev's repositories - btrtrc.git/blobdiff - webtorrent/tracker-client.go
Use webrtc selected ICE candidate for peer addresses
[btrtrc.git] / webtorrent / tracker-client.go
index 9f02c7e785f38e7767e86e73f3304eb61a322ef8..1ec4b9d9c6f917200c2795665283a2ad8e286df9 100644 (file)
@@ -58,10 +58,17 @@ type outboundOffer struct {
 }
 
 type DataChannelContext struct {
+       // Can these be obtained by just calling the relevant methods on peerConnection?
        Local, Remote webrtc.SessionDescription
        OfferId       string
        LocalOffered  bool
        InfoHash      [20]byte
+       // This is private as some methods might not be appropriate with data channel context.
+       peerConnection *wrappedPeerConnection
+}
+
+func (me *DataChannelContext) GetSelectedIceCandidatePair() (*webrtc.ICECandidatePair, error) {
+       return me.peerConnection.SCTP().Transport().ICETransport().GetSelectedCandidatePair()
 }
 
 type onDataChannelOpen func(_ datachannel.ReadWriteCloser, dcc DataChannelContext)
@@ -318,11 +325,12 @@ func (tc *TrackerClient) handleOffer(
                        tc.stats.ConvertedInboundConns++
                        tc.mu.Unlock()
                        tc.OnConn(dc, DataChannelContext{
-                               Local:        answer,
-                               Remote:       offer,
-                               OfferId:      offerId,
-                               LocalOffered: false,
-                               InfoHash:     infoHash,
+                               Local:          answer,
+                               Remote:         offer,
+                               OfferId:        offerId,
+                               LocalOffered:   false,
+                               InfoHash:       infoHash,
+                               peerConnection: peerConnection,
                        })
                })
        })
@@ -345,11 +353,12 @@ func (tc *TrackerClient) handleAnswer(offerId string, answer webrtc.SessionDescr
                tc.stats.ConvertedOutboundConns++
                tc.mu.Unlock()
                tc.OnConn(dc, DataChannelContext{
-                       Local:        offer.originalOffer,
-                       Remote:       answer,
-                       OfferId:      offerId,
-                       LocalOffered: true,
-                       InfoHash:     offer.infoHash,
+                       Local:          offer.originalOffer,
+                       Remote:         answer,
+                       OfferId:        offerId,
+                       LocalOffered:   true,
+                       InfoHash:       offer.infoHash,
+                       peerConnection: offer.peerConnection,
                })
        })
        if err != nil {