Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

feat: Enable TURN proxying over WebSocket #384

Merged
merged 17 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename conn to dataChannelConn
  • Loading branch information
kylecarbs committed Jul 14, 2021
commit 0d32c1be7b5b18eeb8f7745e5645cd36b30dc39e
20 changes: 10 additions & 10 deletions wsnet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (t *turnProxyDialer) Dial(network, addr string) (c net.Conn, err error) {
return websocket.NetConn(ctx, conn, websocket.MessageBinary), nil
}

type conn struct {
type dataChannelConn struct {
addr *net.UnixAddr
dc *webrtc.DataChannel
rw datachannel.ReadWriteCloser
Expand All @@ -109,7 +109,7 @@ type conn struct {
writeMutex sync.Mutex
}

func (c *conn) init() {
func (c *dataChannelConn) init() {
c.sendMore = make(chan struct{}, 1)
c.dc.SetBufferedAmountLowThreshold(bufferedAmountLowThreshold)
c.dc.OnBufferedAmountLow(func() {
Expand All @@ -125,11 +125,11 @@ func (c *conn) init() {
})
}

func (c *conn) Read(b []byte) (n int, err error) {
func (c *dataChannelConn) Read(b []byte) (n int, err error) {
return c.rw.Read(b)
}

func (c *conn) Write(b []byte) (n int, err error) {
func (c *dataChannelConn) Write(b []byte) (n int, err error) {
c.writeMutex.Lock()
defer c.writeMutex.Unlock()
if len(b) > maxMessageLength {
Expand All @@ -148,7 +148,7 @@ func (c *conn) Write(b []byte) (n int, err error) {
return c.rw.Write(b)
}

func (c *conn) Close() error {
func (c *dataChannelConn) Close() error {
c.closedMutex.Lock()
defer c.closedMutex.Unlock()
if !c.closed {
Expand All @@ -158,22 +158,22 @@ func (c *conn) Close() error {
return c.dc.Close()
}

func (c *conn) LocalAddr() net.Addr {
func (c *dataChannelConn) LocalAddr() net.Addr {
return c.addr
}

func (c *conn) RemoteAddr() net.Addr {
func (c *dataChannelConn) RemoteAddr() net.Addr {
return c.addr
}

func (c *conn) SetDeadline(t time.Time) error {
func (c *dataChannelConn) SetDeadline(t time.Time) error {
return nil
}

func (c *conn) SetReadDeadline(t time.Time) error {
func (c *dataChannelConn) SetReadDeadline(t time.Time) error {
return nil
}

func (c *conn) SetWriteDeadline(t time.Time) error {
func (c *dataChannelConn) SetWriteDeadline(t time.Time) error {
return nil
}
2 changes: 1 addition & 1 deletion wsnet/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
return nil, ctx.Err()
}

c := &conn{
c := &dataChannelConn{
addr: &net.UnixAddr{
Name: address,
Net: network,
Expand Down
2 changes: 1 addition & 1 deletion wsnet/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (l *listener) handle(msg BrokerMessage) func(dc *webrtc.DataChannel) {
}
// Must wrap the data channel inside this connection
// for buffering from the dialed endpoint to the client.
co := &conn{
co := &dataChannelConn{
addr: nil,
dc: dc,
rw: rw,
Expand Down