github.com/searKing/golang/go@v1.2.117/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 // 16 // [ "?transport=" transport ] 17 // 18 // scheme = "turn" / "turns" 19 // transport = "udp" / "tcp" / transport-ext 20 // transport-ext = 1*unreserved 21 func parseTurnProto(scheme Scheme, rawQuery string) (Transport, error) { 22 form, err := url.ParseQuery(rawQuery) 23 if err != nil { 24 return "", err 25 } 26 if len(form) > 1 { 27 return "", fmt.Errorf("malformed query:%v", form) 28 } 29 30 if proto := form.Get("transport"); proto != "" { 31 return Transport(proto), nil 32 } 33 form.Del("transport") 34 if len(form) > 0 { 35 return "", fmt.Errorf("malformed query:%v", form) 36 } 37 38 switch scheme { 39 case SchemeTURN: 40 return TransportUDP, nil 41 case SchemeTURNS: 42 return TransportTCP, nil 43 default: 44 return "", fmt.Errorf("malformed scheme %s ", scheme.String()) 45 } 46 47 }