From 902cf087aaed1d68e22e0dc6bf8ce68ed4630eb7 Mon Sep 17 00:00:00 2001 From: Konstantin Itskov Date: Tue, 28 Aug 2018 00:31:28 -0400 Subject: [PATCH] Add corrections to comply with govet, golint, etc. --- errors.go | 63 +++++++++++++++++++++++++++++++-------- media.go | 4 +-- pkg/ice/errors.go | 15 +++++----- pkg/ice/url.go | 53 +++++++++++++++++++------------- pkg/ice/url_test.go | 26 ++++++++-------- rtcbundlepolicy.go | 2 +- rtccertificate.go | 26 +++++++++++----- rtcdatachannel.go | 14 ++++----- rtcicecredentialtype.go | 2 +- rtciceserver.go | 8 ++--- rtciceserver_test.go | 8 ++--- rtcicetransportpolicy.go | 2 +- rtcpeerconnection.go | 24 +++++++-------- rtcpeerconnection_test.go | 18 +++++------ rtcpeerconnectionstate.go | 2 +- rtcrtcpmuxpolicy.go | 2 +- rtcsdptype.go | 2 +- rtcsignalingstate.go | 2 +- 18 files changed, 166 insertions(+), 107 deletions(-) diff --git a/errors.go b/errors.go index 100ae753..e07b699b 100644 --- a/errors.go +++ b/errors.go @@ -6,20 +6,57 @@ import ( ) var ( - ErrUnknownType = errors.New("unknown") - ErrConnectionClosed = errors.New("connection closed") - ErrCertificateExpired = errors.New("x509Cert expired") - ErrNoTurnCredencials = errors.New("turn server credentials required") - ErrTurnCredencials = errors.New("invalid turn server credentials") - ErrExistingTrack = errors.New("track aready exists") - ErrPrivateKeyType = errors.New("private key type not supported") - ErrModifyingPeerIdentity = errors.New("peerIdentity cannot be modified") - ErrModifyingCertificates = errors.New("certificates cannot be modified") - ErrModifyingBundlePolicy = errors.New("bundle policy cannot be modified") - ErrModifyingRtcpMuxPolicy = errors.New("rtcp mux policy cannot be modified") + // ErrUnknownType indicates an error with Unknown info. + ErrUnknownType = errors.New("unknown") + + // ErrConnectionClosed indicates an operation executed after connection + // has already been closed. + ErrConnectionClosed = errors.New("connection closed") + + // ErrCertificateExpired indicates that an x509 certificate has expired. + ErrCertificateExpired = errors.New("x509Cert expired") + + // ErrNoTurnCredencials indicates that a TURN server URL was provided + // without required credentials. + ErrNoTurnCredencials = errors.New("turn server credentials required") + + // ErrTurnCredencials indicates that provided TURN credentials are partial + // or malformed. + ErrTurnCredencials = errors.New("invalid turn server credentials") + + // ErrExistingTrack indicates that a track already exists. + ErrExistingTrack = errors.New("track aready exists") + + // ErrPrivateKeyType indicates that a particular private key encryption + // chosen to generate a certificate is not supported. + ErrPrivateKeyType = errors.New("private key type not supported") + + // ErrModifyingPeerIdentity indicates that an attempt to modify + // PeerIdentity was made after RTCPeerConnection has been initialized. + ErrModifyingPeerIdentity = errors.New("peerIdentity cannot be modified") + + // ErrModifyingCertificates indicates that an attempt to modify + // Certificates was made after RTCPeerConnection has been initialized. + ErrModifyingCertificates = errors.New("certificates cannot be modified") + + // ErrModifyingBundlePolicy indicates that an attempt to modify + // BundlePolicy was made after RTCPeerConnection has been initialized. + ErrModifyingBundlePolicy = errors.New("bundle policy cannot be modified") + + // ErrModifyingRtcpMuxPolicy indicates that an attempt to modify + // RtcpMuxPolicy was made after RTCPeerConnection has been initialized. + ErrModifyingRtcpMuxPolicy = errors.New("rtcp mux policy cannot be modified") + + // ErrModifyingIceCandidatePoolSize indicates that an attempt to modify + // IceCandidatePoolSize was made after RTCPeerConnection has been initialized. ErrModifyingIceCandidatePoolSize = errors.New("ice candidate pool size cannot be modified") - ErrInvalidValue = errors.New("invalid value") - ErrMaxDataChannels = errors.New("maximum number of datachannels reached") + + // ErrInvalidValue indicates that an invalid value was provided. + ErrInvalidValue = errors.New("invalid value") + + // ErrMaxDataChannels indicates that the maximum number of data channels + // was reached. + ErrMaxDataChannels = errors.New("maximum number of datachannels reached") ) // InvalidStateError indicates the object is in an invalid state. diff --git a/media.go b/media.go index 769eebc1..f44b5d53 100644 --- a/media.go +++ b/media.go @@ -181,14 +181,14 @@ func (pc *RTCPeerConnection) NewRTCTrack(payloadType uint8, id, label string) (* // AddTrack adds a RTCTrack to the RTCPeerConnection func (pc *RTCPeerConnection) AddTrack(track *RTCTrack) (*RTCRtpSender, error) { if pc.IsClosed { - return nil, &InvalidStateError{ErrConnectionClosed} + return nil, &InvalidStateError{Err: ErrConnectionClosed} } for _, transceiver := range pc.rtpTransceivers { if transceiver.Sender.Track == nil { continue } if track.ID == transceiver.Sender.Track.ID { - return nil, &InvalidAccessError{ErrExistingTrack} + return nil, &InvalidAccessError{Err: ErrExistingTrack} } } var transceiver *RTCRtpTransceiver diff --git a/pkg/ice/errors.go b/pkg/ice/errors.go index 8b03c1ab..e2eac02d 100644 --- a/pkg/ice/errors.go +++ b/pkg/ice/errors.go @@ -5,27 +5,26 @@ import ( "github.com/pkg/errors" ) -// Types of InvalidStateErrors var ( - // ErrUnknownType indicates a Unknown info + // ErrUnknownType indicates an error with Unknown info. ErrUnknownType = errors.New("Unknown") - // ErrServerType indicates the scheme type could not be parsed + // ErrSchemeType indicates the scheme type could not be parsed. ErrSchemeType = errors.New("unknown scheme type") - // ErrSTUNQuery indicates query arguments are provided in a STUN URL + // ErrSTUNQuery indicates query arguments are provided in a STUN URL. ErrSTUNQuery = errors.New("queries not supported in stun address") - // ErrInvalidQuery indicates an malformed query is provided + // ErrInvalidQuery indicates an malformed query is provided. ErrInvalidQuery = errors.New("invalid query") - // ErrHost indicates malformed hostname is provided + // ErrHost indicates malformed hostname is provided. ErrHost = errors.New("invalid hostname") - // ErrPort indicates malformed port is provided + // ErrPort indicates malformed port is provided. ErrPort = errors.New("invalid port") - // ErrProtoType indicates an unsupported transport type was provided + // ErrProtoType indicates an unsupported transport type was provided. ErrProtoType = errors.New("invalid transport protocol type") ) diff --git a/pkg/ice/url.go b/pkg/ice/url.go index 2f7a0452..a784d435 100644 --- a/pkg/ice/url.go +++ b/pkg/ice/url.go @@ -8,20 +8,26 @@ import ( // TODO: Migrate address parsing to STUN/TURN packages? -// Scheme indicates the type of server used +// SchemeType indicates the type of server used in the ice.URL structure. type SchemeType int const ( - // SchemeTypeSTUN indicates the URL represents a STUN server + // SchemeTypeSTUN indicates the URL represents a STUN server. SchemeTypeSTUN SchemeType = iota + 1 + + // SchemeTypeSTUNS indicates the URL represents a STUNS (secure) server. SchemeTypeSTUNS - // SchemeTypeTURN indicates the URL represents a TURN server + // SchemeTypeTURN indicates the URL represents a TURN server. SchemeTypeTURN + + // SchemeTypeTURNS indicates the URL represents a TURNS (secure) server. SchemeTypeTURNS ) -func NewSchemeType(raw string) (unknown SchemeType) { +// NewSchemeType defines a procedure for creating a new SchemeType from a raw +// string naming the scheme type. +func NewSchemeType(raw string) (SchemeType) { switch raw { case "stun": return SchemeTypeSTUN @@ -32,7 +38,7 @@ func NewSchemeType(raw string) (unknown SchemeType) { case "turns": return SchemeTypeTURNS default: - return unknown + return SchemeType(Unknown) } } @@ -51,25 +57,28 @@ func (t SchemeType) String() string { } } -// Proto indicates the transport that is used +// ProtoType indicates the transport protocol type that is used in the ice.URL +// structure. type ProtoType int const ( - // ProtoTypeUDP indicates the URL uses a UDP transport + // ProtoTypeUDP indicates the URL uses a UDP transport. ProtoTypeUDP ProtoType = iota + 1 - // ProtoTypeTCP indicates the URL uses a TCP transport + // ProtoTypeTCP indicates the URL uses a TCP transport. ProtoTypeTCP ) -func NewProtoType(raw string) (unknown ProtoType) { +// NewProtoType defines a procedure for creating a new ProtoType from a raw +// string naming the transport protocol type. +func NewProtoType(raw string) (ProtoType) { switch raw { case "udp": return ProtoTypeUDP case "tcp": return ProtoTypeTCP default: - return unknown + return ProtoType(Unknown) } } @@ -92,16 +101,19 @@ type URL struct { Proto ProtoType } +// ParseURL parses a STUN or TURN urls following the ABNF syntax described in +// https://tools.ietf.org/html/rfc7064 and https://tools.ietf.org/html/rfc7065 +// respectively. func ParseURL(raw string) (*URL, error) { rawParts, err := url.Parse(raw) if err != nil { - return nil, &UnknownError{err} + return nil, &UnknownError{Err: err} } var u URL u.Scheme = NewSchemeType(rawParts.Scheme) if u.Scheme == SchemeType(Unknown) { - return nil, &SyntaxError{ErrSchemeType} + return nil, &SyntaxError{Err: ErrSchemeType} } var rawPort string @@ -125,28 +137,28 @@ func ParseURL(raw string) (*URL, error) { } } } - return nil, &UnknownError{err} + return nil, &UnknownError{Err: err} } if u.Host == "" { - return nil, &SyntaxError{ErrHost} + return nil, &SyntaxError{Err: ErrHost} } if u.Port, err = strconv.Atoi(rawPort); err != nil { - return nil, &SyntaxError{ErrPort} + return nil, &SyntaxError{Err: ErrPort} } switch { case u.Scheme == SchemeTypeSTUN: qArgs, err := url.ParseQuery(rawParts.RawQuery) if err != nil || (err == nil && len(qArgs) > 0) { - return nil, &SyntaxError{ErrSTUNQuery} + return nil, &SyntaxError{Err: ErrSTUNQuery} } u.Proto = ProtoTypeUDP case u.Scheme == SchemeTypeSTUNS: qArgs, err := url.ParseQuery(rawParts.RawQuery) if err != nil || (err == nil && len(qArgs) > 0) { - return nil, &SyntaxError{ErrSTUNQuery} + return nil, &SyntaxError{Err: ErrSTUNQuery} } u.Proto = ProtoTypeTCP case u.Scheme == SchemeTypeTURN: @@ -177,19 +189,19 @@ func ParseURL(raw string) (*URL, error) { func parseProto(raw string) (ProtoType, error) { qArgs, err := url.ParseQuery(raw) if err != nil || len(qArgs) > 1 { - return ProtoType(Unknown), &SyntaxError{ErrInvalidQuery} + return ProtoType(Unknown), &SyntaxError{Err: ErrInvalidQuery} } var proto ProtoType if rawProto := qArgs.Get("transport"); rawProto != "" { if proto = NewProtoType(rawProto); proto == ProtoType(0) { - return ProtoType(Unknown), &NotSupportedError{ErrProtoType} + return ProtoType(Unknown), &NotSupportedError{Err: ErrProtoType} } return proto, nil } if len(qArgs) > 0 { - return ProtoType(Unknown), &SyntaxError{ErrInvalidQuery} + return ProtoType(Unknown), &SyntaxError{Err: ErrInvalidQuery} } return proto, nil @@ -203,6 +215,7 @@ func (u URL) String() string { return rawURL } +// IsSecure returns whether the this URL's scheme describes secure scheme or not. func (u URL) IsSecure() bool { return u.Scheme == SchemeTypeSTUNS || u.Scheme == SchemeTypeTURNS } diff --git a/pkg/ice/url_test.go b/pkg/ice/url_test.go index cd6edbb4..90044c24 100644 --- a/pkg/ice/url_test.go +++ b/pkg/ice/url_test.go @@ -47,19 +47,19 @@ func TestParseURL(t *testing.T) { rawURL string expectedErr error }{ - {"", &SyntaxError{ErrSchemeType}}, - {":::", &UnknownError{errors.New("parse :::: missing protocol scheme")}}, - {"stun:[::1]:123:", &UnknownError{errors.New("address [::1]:123:: too many colons in address")}}, - {"stun:[::1]:123a", &SyntaxError{ErrPort}}, - {"google.de", &SyntaxError{ErrSchemeType}}, - {"stun:", &SyntaxError{ErrHost}}, - {"stun:google.de:abc", &SyntaxError{ErrPort}}, - {"stun:google.de?transport=udp", &SyntaxError{ErrSTUNQuery}}, - {"stuns:google.de?transport=udp", &SyntaxError{ErrSTUNQuery}}, - {"turn:google.de?trans=udp", &SyntaxError{ErrInvalidQuery}}, - {"turns:google.de?trans=udp", &SyntaxError{ErrInvalidQuery}}, - {"turns:google.de?transport=udp&another=1", &SyntaxError{ErrInvalidQuery}}, - {"turn:google.de?transport=ip", &NotSupportedError{ErrProtoType}}, + {"", &SyntaxError{Err: ErrSchemeType}}, + {":::", &UnknownError{Err: errors.New("parse :::: missing protocol scheme")}}, + {"stun:[::1]:123:", &UnknownError{Err: errors.New("address [::1]:123:: too many colons in address")}}, + {"stun:[::1]:123a", &SyntaxError{Err: ErrPort}}, + {"google.de", &SyntaxError{Err: ErrSchemeType}}, + {"stun:", &SyntaxError{Err: ErrHost}}, + {"stun:google.de:abc", &SyntaxError{Err: ErrPort}}, + {"stun:google.de?transport=udp", &SyntaxError{Err: ErrSTUNQuery}}, + {"stuns:google.de?transport=udp", &SyntaxError{Err: ErrSTUNQuery}}, + {"turn:google.de?trans=udp", &SyntaxError{Err: ErrInvalidQuery}}, + {"turns:google.de?trans=udp", &SyntaxError{Err: ErrInvalidQuery}}, + {"turns:google.de?transport=udp&another=1", &SyntaxError{Err: ErrInvalidQuery}}, + {"turn:google.de?transport=ip", &NotSupportedError{Err: ErrProtoType}}, } for i, testCase := range testCases { diff --git a/rtcbundlepolicy.go b/rtcbundlepolicy.go index 7c9c2cbc..1d510235 100644 --- a/rtcbundlepolicy.go +++ b/rtcbundlepolicy.go @@ -24,7 +24,7 @@ const ( RTCBundlePolicyMaxBundle ) -// NewRTCBundlePolicy defines a proceedure for creating a new RTCBundlePolicy +// NewRTCBundlePolicy defines a procedure for creating a new RTCBundlePolicy // from a raw string naming the bundle policy. func NewRTCBundlePolicy(raw string) RTCBundlePolicy { switch raw { diff --git a/rtccertificate.go b/rtccertificate.go index 745b770b..b0bd173c 100644 --- a/rtccertificate.go +++ b/rtccertificate.go @@ -18,6 +18,10 @@ type RTCCertificate struct { x509Cert *x509.Certificate } +// NewRTCCertificate generates a new x509 compliant RTCCertificate to be used +// by DTLS for encrypting data sent over the wire. This method differs from +// GenerateCertificate by allowing to specify a template x509.Certificate to +// be used in order to define certificate parameters. func NewRTCCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*RTCCertificate, error) { var err error var certDER []byte @@ -27,28 +31,29 @@ func NewRTCCertificate(key crypto.PrivateKey, tpl x509.Certificate) (*RTCCertifi tpl.SignatureAlgorithm = x509.SHA256WithRSA certDER, err = x509.CreateCertificate(rand.Reader, &tpl, &tpl, pk, sk) if err != nil { - return nil, &UnknownError{err} + return nil, &UnknownError{Err: err} } case *ecdsa.PrivateKey: pk := sk.Public() tpl.SignatureAlgorithm = x509.ECDSAWithSHA256 certDER, err = x509.CreateCertificate(rand.Reader, &tpl, &tpl, pk, sk) if err != nil { - return nil, &UnknownError{err} + return nil, &UnknownError{Err: err} } default: - return nil, &NotSupportedError{ErrPrivateKeyType} + return nil, &NotSupportedError{Err: ErrPrivateKeyType} } cert, err := x509.ParseCertificate(certDER) if err != nil { - return nil, &UnknownError{err} + return nil, &UnknownError{Err: err} } return &RTCCertificate{secretKey: key, x509Cert: cert}, nil } -// Equals determines if two certificates are identical +// Equals determines if two certificates are identical by comparing both the +// secretKeys and x509Certificates. func (c RTCCertificate) Equals(o RTCCertificate) bool { switch cSK := c.secretKey.(type) { case *rsa.PrivateKey: @@ -72,6 +77,7 @@ func (c RTCCertificate) Equals(o RTCCertificate) bool { } } +// Expires returns the timestamp after which this certificate is no longer valid. func (c RTCCertificate) Expires() time.Time { if c.x509Cert == nil { return time.Time{} @@ -79,14 +85,18 @@ func (c RTCCertificate) Expires() time.Time { return c.x509Cert.NotAfter } +// GetFingerprints returns the list of certificate fingerprints, one of which +// is computed with the digest algorithm used in the certificate signature. func (c RTCCertificate) GetFingerprints() { - + panic("not implemented yet.") } +// GenerateCertificate causes the creation of an X.509 certificate and +// corresponding private key. func GenerateCertificate(secretKey crypto.PrivateKey) (*RTCCertificate, error) { origin := make([]byte, 16) if _, err := rand.Read(origin); err != nil { - return nil, &UnknownError{err} + return nil, &UnknownError{Err: err} } // Max random value, a 130-bits integer, i.e 2^130 - 1 @@ -94,7 +104,7 @@ func GenerateCertificate(secretKey crypto.PrivateKey) (*RTCCertificate, error) { maxBigInt.Exp(big.NewInt(2), big.NewInt(130), nil).Sub(maxBigInt, big.NewInt(1)) serialNumber, err := rand.Int(rand.Reader, maxBigInt) if err != nil { - return nil, &UnknownError{err} + return nil, &UnknownError{Err: err} } return NewRTCCertificate(secretKey, x509.Certificate{ diff --git a/rtcdatachannel.go b/rtcdatachannel.go index bf57c7dd..25acc259 100644 --- a/rtcdatachannel.go +++ b/rtcdatachannel.go @@ -65,11 +65,11 @@ type RTCDataChannelInit struct { // CreateDataChannel creates a new RTCDataChannel object with the given label and optitional options. func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataChannelInit) (*RTCDataChannel, error) { if pc.IsClosed { - return nil, &InvalidStateError{ErrConnectionClosed} + return nil, &InvalidStateError{Err: ErrConnectionClosed} } if len(label) > 65535 { - return nil, &TypeError{ErrInvalidValue} + return nil, &TypeError{Err: ErrInvalidValue} } // Defaults @@ -95,12 +95,12 @@ func (pc *RTCPeerConnection) CreateDataChannel(label string, options *RTCDataCha } if id > 65534 { - return nil, &TypeError{ErrInvalidValue} + return nil, &TypeError{Err: ErrInvalidValue} } if pc.sctp.State == RTCSctpTransportStateConnected && id >= pc.sctp.MaxChannels { - return nil, &OperationError{ErrMaxDataChannels} + return nil, &OperationError{Err: ErrMaxDataChannels} } _ = ordered // TODO @@ -132,13 +132,13 @@ func (pc *RTCPeerConnection) generateDataChannelID(client bool) (uint16, error) return id, nil } } - return 0, &OperationError{ErrMaxDataChannels} + return 0, &OperationError{Err: ErrMaxDataChannels} } // SendOpenChannelMessage is a test to send OpenChannel manually func (d *RTCDataChannel) SendOpenChannelMessage() error { if err := d.rtcPeerConnection.networkManager.SendOpenChannelMessage(d.ID, d.Label); err != nil { - return &UnknownError{err} + return &UnknownError{Err: err} } return nil @@ -147,7 +147,7 @@ func (d *RTCDataChannel) SendOpenChannelMessage() error { // Send sends the passed message to the DataChannel peer func (d *RTCDataChannel) Send(p datachannel.Payload) error { if err := d.rtcPeerConnection.networkManager.SendDataChannelMessage(p, d.ID); err != nil { - return &UnknownError{err} + return &UnknownError{Err: err} } return nil } diff --git a/rtcicecredentialtype.go b/rtcicecredentialtype.go index 7148fd9b..4acde431 100644 --- a/rtcicecredentialtype.go +++ b/rtcicecredentialtype.go @@ -14,7 +14,7 @@ const ( RTCIceCredentialTypeOauth ) -// NewRTCIceCredentialType defines a proceedure for creating a new +// NewRTCIceCredentialType defines a procedure for creating a new // RTCIceCredentialType from a raw string naming the ice credential type. func NewRTCIceCredentialType(raw string) RTCIceCredentialType { switch raw { diff --git a/rtciceserver.go b/rtciceserver.go index 4055e5de..ff35d63a 100644 --- a/rtciceserver.go +++ b/rtciceserver.go @@ -27,23 +27,23 @@ func (s RTCIceServer) validate() error { if url.Scheme == ice.SchemeTypeTURN || url.Scheme == ice.SchemeTypeTURNS { // https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.2) if s.Username == "" || s.Credential == nil { - return &InvalidAccessError{ErrNoTurnCredencials} + return &InvalidAccessError{Err: ErrNoTurnCredencials} } switch s.CredentialType { case RTCIceCredentialTypePassword: // https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.3) if _, ok := s.Credential.(string); !ok { - return &InvalidAccessError{ErrTurnCredencials} + return &InvalidAccessError{Err: ErrTurnCredencials} } case RTCIceCredentialTypeOauth: // https://www.w3.org/TR/webrtc/#set-the-configuration (step #11.3.4) if _, ok := s.Credential.(RTCOAuthCredential); !ok { - return &InvalidAccessError{ErrTurnCredencials} + return &InvalidAccessError{Err: ErrTurnCredencials} } default: - return &InvalidAccessError{ErrTurnCredencials} + return &InvalidAccessError{Err: ErrTurnCredencials} } } } diff --git a/rtciceserver_test.go b/rtciceserver_test.go index 1cf8f715..5de2c3cb 100644 --- a/rtciceserver_test.go +++ b/rtciceserver_test.go @@ -40,25 +40,25 @@ func TestRTCIceServer_validate(t *testing.T) { }{ {RTCIceServer{ URLs: []string{"turn:192.158.29.39?transport=udp"}, - }, &InvalidAccessError{ErrNoTurnCredencials}}, + }, &InvalidAccessError{Err: ErrNoTurnCredencials}}, {RTCIceServer{ URLs: []string{"turn:192.158.29.39?transport=udp"}, Username: "unittest", Credential: false, CredentialType: RTCIceCredentialTypePassword, - }, &InvalidAccessError{ErrTurnCredencials}}, + }, &InvalidAccessError{Err: ErrTurnCredencials}}, {RTCIceServer{ URLs: []string{"turn:192.158.29.39?transport=udp"}, Username: "unittest", Credential: false, CredentialType: RTCIceCredentialTypeOauth, - }, &InvalidAccessError{ErrTurnCredencials}}, + }, &InvalidAccessError{Err: ErrTurnCredencials}}, {RTCIceServer{ URLs: []string{"turn:192.158.29.39?transport=udp"}, Username: "unittest", Credential: false, CredentialType: Unknown, - }, &InvalidAccessError{ErrTurnCredencials}}, + }, &InvalidAccessError{Err: ErrTurnCredencials}}, {RTCIceServer{ URLs: []string{"stun:google.de?transport=udp"}, Username: "unittest", diff --git a/rtcicetransportpolicy.go b/rtcicetransportpolicy.go index 6045ddee..e600ef34 100644 --- a/rtcicetransportpolicy.go +++ b/rtcicetransportpolicy.go @@ -13,7 +13,7 @@ const ( RTCIceTransportPolicyAll ) -// NewRTCIceTransportPolicy defines a proceedure for creating a new +// NewRTCIceTransportPolicy defines a procedure for creating a new // RTCIceTransportPolicy from a raw string naming the ice transport policy. func NewRTCIceTransportPolicy(raw string) RTCIceTransportPolicy { switch raw { diff --git a/rtcpeerconnection.go b/rtcpeerconnection.go index 8404013e..13f00ce3 100644 --- a/rtcpeerconnection.go +++ b/rtcpeerconnection.go @@ -138,14 +138,14 @@ func (pc *RTCPeerConnection) initConfiguration(configuration RTCConfiguration) e now := time.Now() for _, x509Cert := range configuration.Certificates { if !x509Cert.Expires().IsZero() && now.After(x509Cert.Expires()) { - return &InvalidAccessError{ErrCertificateExpired} + return &InvalidAccessError{Err: ErrCertificateExpired} } pc.configuration.Certificates = append(pc.configuration.Certificates, x509Cert) } } else { sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) if err != nil { - return &UnknownError{err} + return &UnknownError{Err: err} } certificate, err := GenerateCertificate(sk) if err != nil { @@ -185,13 +185,13 @@ func (pc *RTCPeerConnection) initConfiguration(configuration RTCConfiguration) e func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) error { // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-setconfiguration (step #2) if pc.IsClosed { - return &InvalidStateError{ErrConnectionClosed} + return &InvalidStateError{Err: ErrConnectionClosed} } // https://www.w3.org/TR/webrtc/#set-the-configuration (step #3) if configuration.PeerIdentity != "" { if configuration.PeerIdentity != pc.configuration.PeerIdentity { - return &InvalidModificationError{ErrModifyingPeerIdentity} + return &InvalidModificationError{Err: ErrModifyingPeerIdentity} } pc.configuration.PeerIdentity = configuration.PeerIdentity } @@ -199,12 +199,12 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er // https://www.w3.org/TR/webrtc/#set-the-configuration (step #4) if len(configuration.Certificates) > 0 { if len(configuration.Certificates) != len(pc.configuration.Certificates) { - return &InvalidModificationError{ErrModifyingCertificates} + return &InvalidModificationError{Err: ErrModifyingCertificates} } for i, certificate := range configuration.Certificates { if !pc.configuration.Certificates[i].Equals(certificate) { - return &InvalidModificationError{ErrModifyingCertificates} + return &InvalidModificationError{Err: ErrModifyingCertificates} } } pc.configuration.Certificates = configuration.Certificates @@ -213,7 +213,7 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er // https://www.w3.org/TR/webrtc/#set-the-configuration (step #5) if configuration.BundlePolicy != RTCBundlePolicy(Unknown) { if configuration.BundlePolicy != pc.configuration.BundlePolicy { - return &InvalidModificationError{ErrModifyingBundlePolicy} + return &InvalidModificationError{Err: ErrModifyingBundlePolicy} } pc.configuration.BundlePolicy = configuration.BundlePolicy } @@ -221,7 +221,7 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er // https://www.w3.org/TR/webrtc/#set-the-configuration (step #6) if configuration.RtcpMuxPolicy != RTCRtcpMuxPolicy(Unknown) { if configuration.RtcpMuxPolicy != pc.configuration.RtcpMuxPolicy { - return &InvalidModificationError{ErrModifyingRtcpMuxPolicy} + return &InvalidModificationError{Err: ErrModifyingRtcpMuxPolicy} } pc.configuration.RtcpMuxPolicy = configuration.RtcpMuxPolicy } @@ -230,7 +230,7 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er if configuration.IceCandidatePoolSize != 0 { if pc.configuration.IceCandidatePoolSize != configuration.IceCandidatePoolSize && pc.LocalDescription() != nil { - return &InvalidModificationError{ErrModifyingIceCandidatePoolSize} + return &InvalidModificationError{Err: ErrModifyingIceCandidatePoolSize} } pc.configuration.IceCandidatePoolSize = configuration.IceCandidatePoolSize } @@ -256,7 +256,7 @@ func (pc *RTCPeerConnection) SetConfiguration(configuration RTCConfiguration) er // GetConfiguration returns an RTCConfiguration object representing the current // configuration of this RTCPeerConnection object. The returned object is a // copy and direct mutation on it will not take affect until SetConfiguration -// has been called with RTCConfiguration passed as its only arguement. +// has been called with RTCConfiguration passed as its only argument. // https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-getconfiguration func (pc *RTCPeerConnection) GetConfiguration() RTCConfiguration { return pc.configuration @@ -452,7 +452,7 @@ func (pc *RTCPeerConnection) CreateOffer(options *RTCOfferOptions) (RTCSessionDe } else if useIdentity { return RTCSessionDescription{}, errors.Errorf("TODO handle identity provider") } else if pc.IsClosed { - return RTCSessionDescription{}, &InvalidStateError{ErrConnectionClosed} + return RTCSessionDescription{}, &InvalidStateError{Err: ErrConnectionClosed} } d := sdp.NewJSEPSessionDescription(pc.networkManager.DTLSFingerprint(), useIdentity) @@ -491,7 +491,7 @@ func (pc *RTCPeerConnection) CreateAnswer(options *RTCAnswerOptions) (RTCSession } else if useIdentity { return RTCSessionDescription{}, errors.Errorf("TODO handle identity provider") } else if pc.IsClosed { - return RTCSessionDescription{}, &InvalidStateError{ErrConnectionClosed} + return RTCSessionDescription{}, &InvalidStateError{Err: ErrConnectionClosed} } candidates := pc.generateLocalCandidates() diff --git a/rtcpeerconnection_test.go b/rtcpeerconnection_test.go index f8c30f62..440f570f 100644 --- a/rtcpeerconnection_test.go +++ b/rtcpeerconnection_test.go @@ -64,7 +64,7 @@ func TestNew(t *testing.T) { return New(RTCConfiguration{ Certificates: []RTCCertificate{*certificate}, }) - }, &InvalidAccessError{ErrCertificateExpired}}, + }, &InvalidAccessError{Err: ErrCertificateExpired}}, {func() (*RTCPeerConnection, error) { return New(RTCConfiguration{ IceServers: []RTCIceServer{ @@ -77,7 +77,7 @@ func TestNew(t *testing.T) { }, }, }) - }, &InvalidAccessError{ErrNoTurnCredencials}}, + }, &InvalidAccessError{Err: ErrNoTurnCredencials}}, } for i, testCase := range testCases { @@ -140,14 +140,14 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) { return pc, err }, func() RTCConfiguration { return RTCConfiguration{} - }, &InvalidStateError{ErrConnectionClosed}}, + }, &InvalidStateError{Err: ErrConnectionClosed}}, {func() (*RTCPeerConnection, error) { return New(RTCConfiguration{}) }, func() RTCConfiguration { return RTCConfiguration{ PeerIdentity: "unittest", } - }, &InvalidModificationError{ErrModifyingPeerIdentity}}, + }, &InvalidModificationError{Err: ErrModifyingPeerIdentity}}, {func() (*RTCPeerConnection, error) { return New(RTCConfiguration{}) }, func() RTCConfiguration { @@ -166,7 +166,7 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) { return RTCConfiguration{ Certificates: []RTCCertificate{*certificate1, *certificate2}, } - }, &InvalidModificationError{ErrModifyingCertificates}}, + }, &InvalidModificationError{Err: ErrModifyingCertificates}}, {func() (*RTCPeerConnection, error) { return New(RTCConfiguration{}) }, func() RTCConfiguration { @@ -179,21 +179,21 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) { return RTCConfiguration{ Certificates: []RTCCertificate{*certificate}, } - }, &InvalidModificationError{ErrModifyingCertificates}}, + }, &InvalidModificationError{Err: ErrModifyingCertificates}}, {func() (*RTCPeerConnection, error) { return New(RTCConfiguration{}) }, func() RTCConfiguration { return RTCConfiguration{ BundlePolicy: RTCBundlePolicyMaxCompat, } - }, &InvalidModificationError{ErrModifyingBundlePolicy}}, + }, &InvalidModificationError{Err: ErrModifyingBundlePolicy}}, {func() (*RTCPeerConnection, error) { return New(RTCConfiguration{}) }, func() RTCConfiguration { return RTCConfiguration{ RtcpMuxPolicy: RTCRtcpMuxPolicyNegotiate, } - }, &InvalidModificationError{ErrModifyingRtcpMuxPolicy}}, + }, &InvalidModificationError{Err: ErrModifyingRtcpMuxPolicy}}, // TODO Unittest for IceCandidatePoolSize cannot be done now needs pc.LocalDescription() {func() (*RTCPeerConnection, error) { return New(RTCConfiguration{}) @@ -209,7 +209,7 @@ func TestRTCPeerConnection_SetConfiguration(t *testing.T) { }, }, } - }, &InvalidAccessError{ErrNoTurnCredencials}}, + }, &InvalidAccessError{Err: ErrNoTurnCredencials}}, } for i, testCase := range testCases { diff --git a/rtcpeerconnectionstate.go b/rtcpeerconnectionstate.go index 08f112c6..4bb0b34d 100644 --- a/rtcpeerconnectionstate.go +++ b/rtcpeerconnectionstate.go @@ -34,7 +34,7 @@ const ( RTCPeerConnectionStateClosed ) -// NewRTCPeerConnectionState defines a proceedure for creating a new +// NewRTCPeerConnectionState defines a procedure for creating a new // RTCPeerConnectionState from a raw string naming the peer connection state. func NewRTCPeerConnectionState(raw string) RTCPeerConnectionState { switch raw { diff --git a/rtcrtcpmuxpolicy.go b/rtcrtcpmuxpolicy.go index acaf398b..fa3930da 100644 --- a/rtcrtcpmuxpolicy.go +++ b/rtcrtcpmuxpolicy.go @@ -17,7 +17,7 @@ const ( RTCRtcpMuxPolicyRequire ) -// NewRTCRtcpMuxPolicy defines a proceedure for creating a new RTCRtcpMuxPolicy +// NewRTCRtcpMuxPolicy defines a procedure for creating a new RTCRtcpMuxPolicy // from a raw string naming the rtcp multiplexing policy. func NewRTCRtcpMuxPolicy(raw string) RTCRtcpMuxPolicy { switch raw { diff --git a/rtcsdptype.go b/rtcsdptype.go index 2874a8e2..f48307f5 100644 --- a/rtcsdptype.go +++ b/rtcsdptype.go @@ -28,7 +28,7 @@ const ( RTCSdpTypeRollback ) -// NewRTCSdpType defines a proceedure for creating a new RTCSdpType from a raw +// NewRTCSdpType defines a procedure for creating a new RTCSdpType from a raw // string naming the session description protocol type. func NewRTCSdpType(raw string) RTCSdpType { switch raw { diff --git a/rtcsignalingstate.go b/rtcsignalingstate.go index 5f8a9dee..0732c0c4 100644 --- a/rtcsignalingstate.go +++ b/rtcsignalingstate.go @@ -31,7 +31,7 @@ const ( RTCSignalingStateClosed ) -// NewRTCSignalingState defines a proceedure for creating a new +// NewRTCSignalingState defines a procedure for creating a new // RTCSignalingState from a raw string naming the signaling state. func NewRTCSignalingState(raw string) RTCSignalingState { switch raw {