5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-09 16:20:26 +00:00

use TLS for multicast peers, fix TLS listener type in log output

This commit is contained in:
Arceliar 2021-06-19 10:42:38 -05:00
parent 5564de94ba
commit b7f57c0617
2 changed files with 8 additions and 4 deletions

View File

@ -185,17 +185,21 @@ func (t *tcp) listener(l *TcpListener, listenaddr string) {
l.Listener.Close()
return
}
callproto := "TCP"
if l.opts.upgrade != nil {
callproto = strings.ToUpper(l.opts.upgrade.name)
}
t.listeners[listenaddr] = l
t.mutex.Unlock()
// And here we go!
defer func() {
t.links.core.log.Infoln("Stopping TCP listener on:", l.Listener.Addr().String())
t.links.core.log.Infoln("Stopping", callproto, "listener on:", l.Listener.Addr().String())
l.Listener.Close()
t.mutex.Lock()
delete(t.listeners, listenaddr)
t.mutex.Unlock()
}()
t.links.core.log.Infoln("Listening for TCP on:", l.Listener.Addr().String())
t.links.core.log.Infoln("Listening for", callproto, "on:", l.Listener.Addr().String())
go func() {
<-l.stop
l.Listener.Close()

View File

@ -277,7 +277,7 @@ func (m *Multicast) _announce() {
var info *listenerInfo
if nfo, ok := m.listeners[iface.Name]; !ok || nfo.listener.Listener == nil {
// No listener was found - let's create one
urlString := fmt.Sprintf("tcp://[%s]:%d", addrIP, m.listenPort)
urlString := fmt.Sprintf("tls://[%s]:%d", addrIP, m.listenPort)
u, err := url.Parse(urlString)
if err != nil {
panic(err)
@ -370,7 +370,7 @@ func (m *Multicast) listen() {
if _, ok := interfaces[from.Zone]; ok {
addr.Zone = ""
pin := fmt.Sprintf("/?key=%s", hex.EncodeToString(key))
u, err := url.Parse("tcp://" + addr.String() + pin)
u, err := url.Parse("tls://" + addr.String() + pin)
if err != nil {
m.log.Debugln("Call from multicast failed, parse error:", addr.String(), err)
}