func RegisterMixNodePresence(publicKey *sphinx.PublicKey, layer int, host ...string) error {
	b64Key := base64.URLEncoding.EncodeToString(publicKey.Bytes())
	values := map[string]interface{}{"pubKey": b64Key, "layer": layer}
	if len(host) == 1 {
		values["host"] = host[0]
	}
	jsonValue, err := json.Marshal(values)
	if err != nil {
		return err
	}
	endpoint := config.DirectoryServerMixPresenceURL
	if len(host) == 1 && len(host[0]) > 0 {
		ip, _, err := net.SplitHostPort(host[0])
		if err == nil && (ip == "localhost" || net.ParseIP(ip).IsLoopback()) {
			endpoint = config.LocalDirectoryServerMixPresenceURL
		} else if err != nil && err.Error() == "missing port in address" &&
			(host[0] == "localhost" || net.ParseIP(host[0]).IsLoopback()) {
			endpoint = config.LocalDirectoryServerMixPresenceURL
		}
	}
	resp, err := http.Post(endpoint, "application/json", bytes.NewBuffer(jsonValue))
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	_ = resp
	return nil
}
RegisterMixNodePresence registers server presence at the directory server.
package helpers
import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"errors"
	"net"
	"net/http"
	"github.com/nymtech/nym-directory/models"
	"github.com/nymtech/nym-mixnet/config"
	"github.com/nymtech/nym-mixnet/sphinx"
)
var (
	ErrInvalidLocalIP = errors.New("couldn't find a valid IP for your machine, check your internet connection")
)
func ResolveTCPAddress(host, port string) (*net.TCPAddr, error) {
	addr, err := net.ResolveTCPAddr("tcp", host+":"+port)
	if err != nil {
		return nil, err
	}
	return addr, nil
}
func GetLocalIP() (string, error) {
	ifaces, err := net.Interfaces()
	if err != nil {
		return "", err
	}
	for _, iface := range ifaces {
		addrs, err := iface.Addrs()
		if err != nil {
			return "", err
		}
		for _, addr := range addrs {
			var ip net.IP
			switch v := addr.(type) {
			case *net.IPNet:
				ip = v.IP
			case *net.IPAddr:
				ip = v.IP
			}
			if ip == nil || ip.IsLoopback() {
				continue
			}
			ip = ip.To4()
			if ip == nil {
				continue  
			}
			return ip.String(), nil
		}
	}
	return "", ErrInvalidLocalIP
}