Update Snowflake client library documentation

Follow best practices for documenting the exported pieces of the
Snowflake client library.
This commit is contained in:
Cecylia Bocovich 2021-09-09 16:01:38 -04:00
parent 99887cd05d
commit 638ec6c222
8 changed files with 83 additions and 50 deletions

View file

@ -12,10 +12,9 @@ import (
"github.com/pion/webrtc/v3"
)
// Remote WebRTC peer.
// WebRTCPeer represents a WebRTC connection to a remote snowflake proxy.
//
// Handles preparation of go-webrtc PeerConnection. Only ever has
// one DataChannel.
// Each WebRTCPeer only ever has one DataChannel that is used as the peer's transport.
type WebRTCPeer struct {
id string
pc *webrtc.PeerConnection
@ -35,7 +34,11 @@ type WebRTCPeer struct {
bytesLogger bytesLogger
}
// Construct a WebRTC PeerConnection.
// NewWebRTCPeer constructs a WebRTC PeerConnection to a snowflake proxy.
//
// The creation of the peer handles the signaling to the Snowflake broker, including
// the exchange of SDP information, the creation of a PeerConnection, and the establishment
// of a DataChannel to the Snowflake proxy.
func NewWebRTCPeer(config *webrtc.Configuration,
broker *BrokerChannel) (*WebRTCPeer, error) {
connection := new(WebRTCPeer)
@ -79,7 +82,7 @@ func (c *WebRTCPeer) Write(b []byte) (int, error) {
return len(b), nil
}
//Returns a boolean indicated whether the peer is closed
// Closed returns a boolean indicated whether the peer is closed.
func (c *WebRTCPeer) Closed() bool {
select {
case <-c.closed:
@ -89,6 +92,7 @@ func (c *WebRTCPeer) Closed() bool {
return false
}
// Close closes the connection the snowflake proxy.
func (c *WebRTCPeer) Close() error {
c.once.Do(func() {
close(c.closed)
@ -225,7 +229,7 @@ func (c *WebRTCPeer) preparePeerConnection(config *webrtc.Configuration) error {
return nil
}
// Close all channels and transports
// cleanup closes all channels and transports
func (c *WebRTCPeer) cleanup() {
// Close this side of the SOCKS pipe.
if c.writePipe != nil { // c.writePipe can be nil in tests.