2020-04-07 08:59:10 +08:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/pion/datachannel"
|
2021-02-22 05:30:34 +08:00
|
|
|
"github.com/pion/webrtc/v3"
|
2020-04-07 12:30:27 +08:00
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/webtorrent"
|
2020-04-07 08:59:10 +08:00
|
|
|
)
|
|
|
|
|
2020-04-07 12:30:27 +08:00
|
|
|
const webrtcNetwork = "webrtc"
|
|
|
|
|
2020-04-07 08:59:10 +08:00
|
|
|
type webrtcNetConn struct {
|
|
|
|
datachannel.ReadWriteCloser
|
2020-04-07 12:30:27 +08:00
|
|
|
webtorrent.DataChannelContext
|
2020-04-07 08:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type webrtcNetAddr struct {
|
2020-04-07 12:30:27 +08:00
|
|
|
webrtc.SessionDescription
|
2020-04-07 08:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (webrtcNetAddr) Network() string {
|
2020-04-07 12:30:27 +08:00
|
|
|
return webrtcNetwork
|
2020-04-07 08:59:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-07 12:30:27 +08:00
|
|
|
func (me webrtcNetAddr) String() string {
|
|
|
|
// TODO: What can I show here that's more like other protocols?
|
|
|
|
return "<WebRTC>"
|
2020-04-07 08:59:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-07 12:30:27 +08:00
|
|
|
func (me webrtcNetConn) LocalAddr() net.Addr {
|
|
|
|
return webrtcNetAddr{me.Local}
|
2020-04-07 08:59:10 +08:00
|
|
|
}
|
|
|
|
|
2020-04-07 12:30:27 +08:00
|
|
|
func (me webrtcNetConn) RemoteAddr() net.Addr {
|
|
|
|
return webrtcNetAddr{me.Remote}
|
2020-04-07 08:59:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w webrtcNetConn) SetDeadline(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w webrtcNetConn) SetReadDeadline(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w webrtcNetConn) SetWriteDeadline(t time.Time) error {
|
|
|
|
return nil
|
|
|
|
}
|