Skip to content

Commit 7ab0cc5

Browse files
committed
chore: add enableTLS flag for b2bua.
1 parent ba478bf commit 7ab0cc5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

examples/b2bua/b2bua/b2bua.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func init() {
6262
}
6363

6464
//NewB2BUA .
65-
func NewB2BUA(disableAuth bool) *B2BUA {
65+
func NewB2BUA(disableAuth bool, enableTLS bool) *B2BUA {
6666
b := &B2BUA{
6767
registry: registry.Registry(registry.NewMemoryRegistry()),
6868
accounts: make(map[string]string),
@@ -95,14 +95,16 @@ func NewB2BUA(disableAuth bool) *B2BUA {
9595
logger.Panic(err)
9696
}
9797

98-
tlsOptions := &transport.TLSConfig{Cert: "certs/cert.pem", Key: "certs/key.pem"}
98+
if enableTLS {
99+
tlsOptions := &transport.TLSConfig{Cert: "certs/cert.pem", Key: "certs/key.pem"}
99100

100-
if err := stack.ListenTLS("tls", "0.0.0.0:5061", tlsOptions); err != nil {
101-
logger.Panic(err)
102-
}
101+
if err := stack.ListenTLS("tls", "0.0.0.0:5061", tlsOptions); err != nil {
102+
logger.Panic(err)
103+
}
103104

104-
if err := stack.ListenTLS("wss", "0.0.0.0:5081", tlsOptions); err != nil {
105-
logger.Panic(err)
105+
if err := stack.ListenTLS("wss", "0.0.0.0:5081", tlsOptions); err != nil {
106+
logger.Panic(err)
107+
}
106108
}
107109

108110
ua := ua.NewUserAgent(&ua.UserAgentConfig{

examples/b2bua/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ func consoleLoop(b2bua *b2bua.B2BUA) {
125125
func main() {
126126
noconsole := false
127127
disableAuth := false
128+
enableTLS := false
128129
h := false
129130
flag.BoolVar(&h, "h", false, "this help")
130131
flag.BoolVar(&noconsole, "nc", false, "no console mode")
131132
flag.BoolVar(&disableAuth, "da", false, "disable auth mode")
133+
flag.BoolVar(&enableTLS, "tls", false, "enable TLS")
132134
flag.Usage = usage
133135

134136
flag.Parse()
@@ -146,7 +148,7 @@ func main() {
146148
http.ListenAndServe(":6658", nil)
147149
}()
148150

149-
b2bua := b2bua.NewB2BUA(disableAuth)
151+
b2bua := b2bua.NewB2BUA(disableAuth, enableTLS)
150152

151153
// Add sample accounts.
152154
b2bua.AddAccount("100", "100")

0 commit comments

Comments
 (0)