Connect first peer from config on demand.

This commit is contained in:
Revertron 2022-11-09 20:38:01 +01:00
parent 0da871f528
commit 30c83f5ec3
2 changed files with 26 additions and 0 deletions

View file

@ -169,6 +169,11 @@ func GenerateConfigJSON() []byte {
return nil return nil
} }
// Connects first peer from config, just to reconnect fast after network switch
func (m *Yggdrasil) ConnectFirstPeer() {
m.core.ConnectFirstPeer()
}
// GetAddressString gets the node's IPv6 address // GetAddressString gets the node's IPv6 address
func (m *Yggdrasil) GetAddressString() string { func (m *Yggdrasil) GetAddressString() string {
ip := m.core.Address() ip := m.core.Address()

View file

@ -121,6 +121,27 @@ func (c *Core) _addPeerLoop() {
}) })
} }
// Connects first peer from config, just to reconnect fast after network switch
// Used in mobile
func (c *Core) ConnectFirstPeer() {
select {
case <-c.ctx.Done():
return
default:
}
// Add peers from the Peers section
for peer := range c.config._peers {
u, err := url.Parse(peer.URI)
if err != nil {
c.log.Errorln("Failed to parse peer url:", peer, err)
}
if err := c.CallPeer(u, peer.SourceInterface); err != nil {
c.log.Errorln("Failed to add peer:", err)
}
break
}
}
// Stop shuts down the Yggdrasil node. // Stop shuts down the Yggdrasil node.
func (c *Core) Stop() { func (c *Core) Stop() {
phony.Block(c, func() { phony.Block(c, func() {