func (m *MixServer) Wait() {
	<-m.haltedCh
}
Wait waits till the mixserver is terminated for any reason.
package mixnode
import (
	"encoding/base64"
	"net"
	"sync"
	"time"
	"github.com/golang/protobuf/proto"
	"github.com/nymtech/nym-directory/models"
	"github.com/nymtech/nym-mixnet/config"
	"github.com/nymtech/nym-mixnet/flags"
	"github.com/nymtech/nym-mixnet/helpers"
	"github.com/nymtech/nym-mixnet/logger"
	"github.com/nymtech/nym-mixnet/networker"
	"github.com/nymtech/nym-mixnet/node"
	"github.com/nymtech/nym-mixnet/sphinx"
	"github.com/sirupsen/logrus"
)
const (
	metricsInterval  = time.Second
	presenceInterval = 2 * time.Second
	defaultLogFileLocation = ""
	defaultLogLevel = "trace"
)
type MixServerIt interface {
	networker.NetworkServer
	networker.NetworkClient
	GetConfig() config.MixConfig
	Start() error
}
type MixServer struct {
	*node.Mix
	id       string
	host     string
	port     string
	layer    int
	listener net.Listener
	config   config.MixConfig
	metrics  *metrics
	haltedCh chan struct{}
	haltOnce sync.Once
	log      *logrus.Logger
}
type metrics struct {
	sync.Mutex
	host             string
	b64Key           string
	receivedMessages uint
	sentMessages     map[string]uint
	log *logrus.Logger
}
func (m *metrics) reset() {
	m.Lock()
	defer m.Unlock()
	m.sentMessages = make(map[string]uint)
	m.receivedMessages = 0
}
func (m *metrics) incrementReceived() {
	m.Lock()
	defer m.Unlock()
	m.receivedMessages++
}
func (m *metrics) addMessage(hopAddress string) {
	m.Lock()
	defer m.Unlock()
	if _, ok := m.sentMessages[hopAddress]; ok {
		m.sentMessages[hopAddress]++
	} else {
		m.sentMessages[hopAddress] = 1
	}
}
func (m *metrics) sendToDirectoryServer() {
	m.Lock()
	defer m.Unlock()
	sentCopy := make(map[string]uint)
	for k, v := range m.sentMessages {
		sentCopy[k] = v
	}
	receivedCopy := m.receivedMessages
	go func(metricsCopy models.MixMetric) {
		if err := helpers.SendMixMetrics(metricsCopy, m.host); err != nil {
			m.log.Errorf("Failed to send metrics: %v", err)
		}
	}(models.MixMetric{
		PubKey:   m.b64Key,
		Sent:     sentCopy,
		Received: &receivedCopy,
	})
}
func newMetrics(log *logrus.Logger, publicKey *sphinx.PublicKey, host string) *metrics {
	b64key := base64.URLEncoding.EncodeToString(publicKey.Bytes())
	log.Infof("Our public key is: %v", b64key)
	return &metrics{
		log:          log,
		b64Key:       b64key,
		sentMessages: make(map[string]uint),
		host:         host,
	}
}