github.com/searKing/golang/go@v1.2.117/net/ice/transport.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // https://tools.ietf.org/html/rfc7064 3.2.  URI Scheme Semantics
     6  // https://tools.ietf.org/html/rfc7065 3.2.  URI Scheme Semantics
     7  package ice
     8  
     9  import (
    10  	"errors"
    11  )
    12  
    13  // Transport indicates the transport protocol type that is used in the ice.URL
    14  // structure.
    15  type Transport string
    16  
    17  const (
    18  	// TransportUDP indicates the URL uses:
    19  	// a UDP transport for turn|stun.
    20  	// a DTLS-over-UDP transport for turns|stuns.
    21  	TransportUDP Transport = "udp"
    22  
    23  	// TransportTCP indicates the URL uses:
    24  	// a TCP transport for turn|stun.
    25  	// a TLS-over-TCP transport for turns|stuns.
    26  	TransportTCP = "tcp"
    27  )
    28  
    29  func ParseProto(s string) (Transport, error) {
    30  	if s == "" {
    31  		return "", errors.New("empty proto")
    32  	}
    33  	return Transport(s), nil
    34  }
    35  
    36  // https://tools.ietf.org/html/rfc7065
    37  // transport-ext = 1*unreserved
    38  func (t Transport) String() string {
    39  	if t == "" {
    40  		return errors.New("empty proto").Error()
    41  	}
    42  	return string(t)
    43  }