forked from ckousik/go-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdp.go
89 lines (82 loc) · 1.37 KB
/
sdp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package libp2pwebrtc
import (
"fmt"
"net"
"github.com/multiformats/go-multihash"
)
type sdpArgs struct {
Addr *net.UDPAddr
Ufrag string
Fingerprint *multihash.DecodedMultihash
}
const clientSDP string = `
v=0
o=- 0 0 IN %s %s
s=-
c=IN %s %s
t=0 0
m=application %d UDP/DTLS/SCTP webrtc-datachannel
a=mid:0
a=ice-options:trickle
a=ice-ufrag:%s
a=ice-pwd:%s
a=fingerprint:%s
a=setup:actpass
a=sctp-port:5000
a=max-message-size:100000
`
func renderClientSdp(args sdpArgs) string {
ipVersion := "IP4"
if args.Addr.IP.To4() == nil {
ipVersion = "IP6"
}
return fmt.Sprintf(
clientSDP,
ipVersion,
args.Addr.IP,
ipVersion,
args.Addr.IP,
args.Addr.Port,
args.Ufrag,
args.Ufrag,
fingerprintToSDP(args.Fingerprint),
)
}
const serverSDP string = `
v=0
o=- 0 0 IN %s %s
s=-
t=0 0
a=ice-lite
m=application %d UDP/DTLS/SCTP webrtc-datachannel
c=IN %s %s
a=mid:0
a=ice-options:ice2
a=ice-ufrag:%s
a=ice-pwd:%s
a=fingerprint:%s
a=setup:passive
a=sctp-port:5000
a=max-message-size:100000
a=candidate:1 1 UDP 1 %s %d typ host
`
func renderServerSdp(args sdpArgs) string {
ipVersion := "IP4"
if args.Addr.IP.To4() == nil {
ipVersion = "IP6"
}
fp := fingerprintToSDP(args.Fingerprint)
return fmt.Sprintf(
serverSDP,
ipVersion,
args.Addr.IP,
args.Addr.Port,
ipVersion,
args.Addr.IP,
args.Ufrag,
args.Ufrag,
fp,
args.Addr.IP,
args.Addr.Port,
)
}