github.com/searKing/golang/go@v1.2.117/net/ice/stun.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
     6  package ice
     7  
     8  import (
     9  	"fmt"
    10  	"net/url"
    11  )
    12  
    13  // https://tools.ietf.org/html/rfc7064 3.  Definition of the "stun" or "stuns" URI
    14  // stunURI       = scheme ":" host [ ":" port ]
    15  // scheme        = "stun" / "stuns"
    16  func parseStunProto(scheme Scheme, rawQuery string) (Transport, error) {
    17  	// stunURI       = scheme ":" host [ ":" port ]
    18  	// scheme        = "stun" / "stuns"
    19  	qArgs, err := url.ParseQuery(rawQuery)
    20  	if err != nil {
    21  		return "", err
    22  	}
    23  	if len(qArgs) > 0 {
    24  		return "", fmt.Errorf("malformed query %v ", qArgs)
    25  	}
    26  	switch scheme {
    27  	case SchemeSTUN:
    28  		return TransportUDP, nil
    29  	case SchemeSTUNS:
    30  		return TransportTCP, nil
    31  	default:
    32  		return "", fmt.Errorf("malformed scheme %s ", scheme.String())
    33  	}
    34  }