Skip to content

Commit

Permalink
Fixes logger, adds some log messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Revertron committed Oct 25, 2023
1 parent 8afa737 commit 6873fd4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions contrib/mobile/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error {
logger.EnableLevel("error")
logger.EnableLevel("warn")
logger.EnableLevel("info")
m.logger = logger
m.config = config.GenerateConfig()
if err := m.config.UnmarshalHJSON(configjson); err != nil {
return err
Expand Down Expand Up @@ -87,6 +88,7 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error {
// Setup the multicast module.
if len(m.config.MulticastInterfaces) > 0 {
var err error
logger.Infof("Initializing multicast %s", "")
options := []multicast.SetupOption{}
for _, intf := range m.config.MulticastInterfaces {
options = append(options, multicast.MulticastInterface{
Expand All @@ -98,9 +100,10 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error {
Password: intf.Password,
})
}
logger.Infof("Starting multicast %s", "")
m.multicast, err = multicast.New(m.core, m.logger, options...)
if err != nil {
m.logger.Errorln("An error occurred starting multicast:", err)
logger.Errorln("An error occurred starting multicast:", err)
}
}

Expand Down Expand Up @@ -159,15 +162,20 @@ func (m *Yggdrasil) RecvBuffer(buf []byte) (int, error) {
func (m *Yggdrasil) Stop() error {
logger := log.New(m.log, "", 0)
logger.EnableLevel("info")
logger.Infof("Stop the mobile Yggdrasil instance %s", "")
if err := m.multicast.Stop(); err != nil {
return err
logger.Infof("Stopping the mobile Yggdrasil instance %s", "")
if m.multicast != nil {
logger.Infof("Stopping multicast %s", "")
if err := m.multicast.Stop(); err != nil {
return err
}
}
logger.Infof("Stopping TUN device %s", "")
if m.tun != nil {
if err := m.tun.Stop(); err != nil {
return err
}
}
logger.Infof("Stopping Yggdrasil core %s", "")
m.core.Stop()
return nil
}
Expand Down

0 comments on commit 6873fd4

Please sign in to comment.