netmaker/nm-proxy/nm-proxy.go

39 lines
975 B
Go

package nmproxy
import (
"log"
"net"
"github.com/gravitl/netmaker/nm-proxy/manager"
"github.com/gravitl/netmaker/nm-proxy/server"
"github.com/gravitl/netmaker/nm-proxy/stun"
)
// Comm Channel to configure proxy
/* Actions -
1. Add - new interface and its peers
2. Delete - remove close all conns for the interface,cleanup
*/
func Start(mgmChan chan *manager.ManagerAction) {
log.Println("Starting Proxy...")
go manager.StartProxyManager(mgmChan)
hInfo := stun.GetHostInfo()
stun.Host = hInfo
log.Printf("HOSTINFO: %+v", hInfo)
// start the netclient proxy server
err := server.NmProxyServer.CreateProxyServer(0, 0, hInfo.PrivIp.String())
if err != nil {
log.Fatal("failed to create proxy: ", err)
}
server.NmProxyServer.Listen()
}
// IsPublicIP indicates whether IP is public or not.
func IsPublicIP(ip net.IP) bool {
if ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() || ip.IsPrivate() {
return false
}
return true
}