github.com/searKing/golang/go@v1.2.74/net/ice/turn.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/rfc7065 6 package ice 7 8 import ( 9 "fmt" 10 "net/url" 11 ) 12 13 //https://tools.ietf.org/html/rfc7065 3. Definitions of the "turn" and "turns" URI. 14 // turnURI = scheme ":" host [ ":" port ] 15 // [ "?transport=" transport ] 16 // scheme = "turn" / "turns" 17 // transport = "udp" / "tcp" / transport-ext 18 // transport-ext = 1*unreserved 19 func parseTurnProto(scheme Scheme, rawQuery string) (Transport, error) { 20 form, err := url.ParseQuery(rawQuery) 21 if err != nil { 22 return "", err 23 } 24 if len(form) > 1 { 25 return "", fmt.Errorf("malformed query:%v", form) 26 } 27 28 if proto := form.Get("transport"); proto != "" { 29 return Transport(proto), nil 30 } 31 form.Del("transport") 32 if len(form) > 0 { 33 return "", fmt.Errorf("malformed query:%v", form) 34 } 35 36 switch scheme { 37 case SchemeTURN: 38 return TransportUDP, nil 39 case SchemeTURNS: 40 return TransportTCP, nil 41 default: 42 return "", fmt.Errorf("malformed scheme %s ", scheme.String()) 43 } 44 45 }