package libp2pwebrtcimport ()// clientSDP describes an SDP format string which can be used// to infer a client's SDP offer from the incoming STUN message.// The fingerprint used to render a client SDP is arbitrary since// it fingerprint verification is disabled in favour of a noise// handshake. The max message size is fixed to 16384 bytes.const clientSDP = `v=0o=- 0 0 IN %[1]s %[2]ss=-c=IN %[1]s %[2]st=0 0m=application %[3]d UDP/DTLS/SCTP webrtc-datachannela=mid:0a=ice-options:ice2a=ice-ufrag:%[4]sa=ice-pwd:%[4]sa=fingerprint:sha-256 ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ada=setup:actpassa=sctp-port:5000a=max-message-size:16384`func createClientSDP( *net.UDPAddr, string) string { := "IP4"if .IP.To4() == nil { = "IP6" }returnfmt.Sprintf(clientSDP, , .IP, .Port, , )}// serverSDP defines an SDP format string used by a dialer// to infer the SDP answer of a server based on the provided// multiaddr, and the locally set ICE credentials. The max// message size is fixed to 16384 bytes.const serverSDP = `v=0o=- 0 0 IN %[1]s %[2]ss=-t=0 0a=ice-litem=application %[3]d UDP/DTLS/SCTP webrtc-datachannelc=IN %[1]s %[2]sa=mid:0a=ice-options:ice2a=ice-ufrag:%[4]sa=ice-pwd:%[4]sa=fingerprint:%[5]sa=setup:passivea=sctp-port:5000a=max-message-size:16384a=candidate:1 1 UDP 1 %[2]s %[3]d typ hosta=end-of-candidates`func createServerSDP( *net.UDPAddr, string, multihash.DecodedMultihash) (string, error) { := "IP4"if .IP.To4() == nil { = "IP6" } , := getSupportedSDPString(.Code)if != nil {return"", }varstrings.Builder .Grow(len(.Digest)*3 + 8) .WriteString() .WriteByte(' ') .WriteString(encodeInterspersedHex(.Digest)) := .String()returnfmt.Sprintf(serverSDP, , .IP, .Port, , , ), nil}// getSupportedSDPHash converts a multihash code to the// corresponding crypto.Hash for supported protocols. If a// crypto.Hash cannot be found, it returns `(0, false)`func getSupportedSDPHash( uint64) (crypto.Hash, bool) {switch {casemultihash.MD5:returncrypto.MD5, truecasemultihash.SHA1:returncrypto.SHA1, truecasemultihash.SHA3_224:returncrypto.SHA3_224, truecasemultihash.SHA2_256:returncrypto.SHA256, truecasemultihash.SHA3_384:returncrypto.SHA3_384, truecasemultihash.SHA2_512:returncrypto.SHA512, truedefault:return0, false }}// getSupportedSDPString converts a multihash code// to a string format recognised by pion for fingerprint// algorithmsfunc getSupportedSDPString( uint64) (string, error) {// values based on (cryto.Hash).String()switch {casemultihash.MD5:return"md5", nilcasemultihash.SHA1:return"sha-1", nilcasemultihash.SHA3_224:return"sha3-224", nilcasemultihash.SHA2_256:return"sha-256", nilcasemultihash.SHA3_384:return"sha3-384", nilcasemultihash.SHA2_512:return"sha-512", nildefault:return"", fmt.Errorf("unsupported hash code (%d)", ) }}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.