8 "github.com/anacrolix/torrent/webtorrent"
9 "github.com/pion/datachannel"
10 "github.com/pion/webrtc/v3"
13 const webrtcNetwork = "webrtc"
15 type webrtcNetConn struct {
16 datachannel.ReadWriteCloser
17 webtorrent.DataChannelContext
20 type webrtcNetAddr struct {
24 var _ net.Addr = webrtcNetAddr{}
26 func (webrtcNetAddr) Network() string {
27 // Now that we have the ICE candidate, we can tell if it's over udp or tcp. But should we use
28 // that for the network?
32 func (me webrtcNetAddr) String() string {
33 return net.JoinHostPort(me.Address, strconv.FormatUint(uint64(me.Port), 10))
36 func (me webrtcNetConn) LocalAddr() net.Addr {
37 // I'm not sure if this evolves over time. It might also be unavailable if the PeerConnection is
38 // closed or closes itself. The same concern applies to RemoteAddr.
39 pair, err := me.DataChannelContext.GetSelectedIceCandidatePair()
43 return webrtcNetAddr{pair.Local}
46 func (me webrtcNetConn) RemoteAddr() net.Addr {
47 // See comments on LocalAddr.
48 pair, err := me.DataChannelContext.GetSelectedIceCandidatePair()
52 return webrtcNetAddr{pair.Remote}
55 // Do we need these for WebRTC connections exposed as net.Conns? Can we set them somewhere inside
56 // PeerConnection or on the channel or some transport?
58 func (w webrtcNetConn) SetDeadline(t time.Time) error {
62 func (w webrtcNetConn) SetReadDeadline(t time.Time) error {
66 func (w webrtcNetConn) SetWriteDeadline(t time.Time) error {