-
Notifications
You must be signed in to change notification settings - Fork 0
/
webRtcNetConn.go
57 lines (43 loc) · 1.04 KB
/
webRtcNetConn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package gop2pt
import (
"net"
"time"
"github.com/mr-tron/base58"
"github.com/pion/datachannel"
"github.com/DaniilSokolyuk/gop2pt/webtorrent"
)
const webrtcNetwork = "webrtc"
type webrtcNetConn struct {
datachannel.ReadWriteCloser
webtorrent.DataChannelContext
}
func (c webrtcNetConn) LocalAddr() net.Addr {
return webrtcNetAddr{
peerIDBinary: c.PeerID,
}
}
func (c webrtcNetConn) RemoteAddr() net.Addr {
return webrtcNetAddr{
peerIDBinary: c.PeerID,
}
}
// Do we need these for WebRTC connections exposed as net.Conns? Can we set them somewhere inside
// PeerConnection or on the channel or some transport?
func (c webrtcNetConn) SetDeadline(_ time.Time) error {
return nil
}
func (c webrtcNetConn) SetReadDeadline(_ time.Time) error {
return nil
}
func (c webrtcNetConn) SetWriteDeadline(_ time.Time) error {
return nil
}
type webrtcNetAddr struct {
peerIDBinary string
}
func (webrtcNetAddr) Network() string {
return webrtcNetwork
}
func (a webrtcNetAddr) String() string {
return base58.Encode([]byte(a.peerIDBinary))
}