nm-proxy.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package nmproxy
  2. import (
  3. "context"
  4. "log"
  5. "net"
  6. "github.com/gravitl/netmaker/nm-proxy/manager"
  7. "github.com/gravitl/netmaker/nm-proxy/server"
  8. "github.com/gravitl/netmaker/nm-proxy/stun"
  9. )
  10. /*
  11. TODO:
  12. 1. Mutex locks for maps
  13. 2. CRUD funcs on Maps
  14. 3. Comments
  15. */
  16. func Start(ctx context.Context, mgmChan chan *manager.ManagerAction, apiServerAddr string) {
  17. log.Println("Starting Proxy...")
  18. hInfo := stun.GetHostInfo(apiServerAddr)
  19. stun.Host = hInfo
  20. log.Printf("HOSTINFO: %+v", hInfo)
  21. if IsPublicIP(hInfo.PrivIp) {
  22. log.Println("Host is public facing!!!")
  23. }
  24. // start the netclient proxy server
  25. err := server.NmProxyServer.CreateProxyServer(0, 0, hInfo.PrivIp.String())
  26. if err != nil {
  27. log.Fatal("failed to create proxy: ", err)
  28. }
  29. go manager.StartProxyManager(mgmChan)
  30. server.NmProxyServer.Listen(ctx)
  31. }
  32. // IsPublicIP indicates whether IP is public or not.
  33. func IsPublicIP(ip net.IP) bool {
  34. if ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() || ip.IsPrivate() {
  35. return false
  36. }
  37. return true
  38. }