mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-27 21:55:07 +03:00
Continue refactoring
This commit is contained in:
parent
5616b9fc84
commit
4c889703b1
7 changed files with 82 additions and 60 deletions
|
@ -25,7 +25,7 @@ import (
|
|||
// functions. Note that in the case of iOS we handle reading/writing to/from TUN
|
||||
// in Swift therefore we use the "dummy" TUN interface instead.
|
||||
type Yggdrasil struct {
|
||||
core core.Core
|
||||
core *core.Core
|
||||
iprwc *ipv6rwc.ReadWriteCloser
|
||||
config *config.NodeConfig
|
||||
multicast multicast.Multicast
|
||||
|
@ -48,19 +48,42 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error {
|
|||
if err := json.Unmarshal(configjson, &m.config); err != nil {
|
||||
return err
|
||||
}
|
||||
m.config.IfName = "none"
|
||||
if err := m.core.Start(m.config, logger); err != nil {
|
||||
logger.Errorln("An error occured starting Yggdrasil:", err)
|
||||
return err
|
||||
// Setup the Yggdrasil node itself.
|
||||
sk, err := hex.DecodeString(m.config.PrivateKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
options := []core.SetupOption{
|
||||
core.IfName("none"),
|
||||
core.IfMTU(m.config.IfMTU),
|
||||
}
|
||||
for _, peer := range m.config.Peers {
|
||||
options = append(options, core.Peer{URI: peer})
|
||||
}
|
||||
for intf, peers := range m.config.InterfacePeers {
|
||||
for _, peer := range peers {
|
||||
options = append(options, core.Peer{URI: peer, SourceInterface: intf})
|
||||
}
|
||||
}
|
||||
for _, allowed := range m.config.AllowedPublicKeys {
|
||||
k, err := hex.DecodeString(allowed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
options = append(options, core.AllowedPublicKey(k[:]))
|
||||
}
|
||||
m.core, err = core.New(sk[:], options...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
mtu := m.config.IfMTU
|
||||
m.iprwc = ipv6rwc.NewReadWriteCloser(&m.core)
|
||||
m.iprwc = ipv6rwc.NewReadWriteCloser(m.core)
|
||||
if m.iprwc.MaxMTU() < mtu {
|
||||
mtu = m.iprwc.MaxMTU()
|
||||
}
|
||||
m.iprwc.SetMTU(mtu)
|
||||
if len(m.config.MulticastInterfaces) > 0 {
|
||||
if err := m.multicast.Init(&m.core, m.config, logger, nil); err != nil {
|
||||
if err := m.multicast.Init(m.core, m.config, logger, nil); err != nil {
|
||||
logger.Errorln("An error occurred initialising multicast:", err)
|
||||
return err
|
||||
}
|
||||
|
@ -139,18 +162,18 @@ func (m *Yggdrasil) GetCoordsString() string {
|
|||
|
||||
func (m *Yggdrasil) GetPeersJSON() (result string) {
|
||||
peers := []struct {
|
||||
core.Peer
|
||||
core.PeerInfo
|
||||
IP string
|
||||
}{}
|
||||
for _, v := range m.core.GetPeers() {
|
||||
a := address.AddrForKey(v.Key)
|
||||
ip := net.IP(a[:]).String()
|
||||
peers = append(peers, struct {
|
||||
core.Peer
|
||||
core.PeerInfo
|
||||
IP string
|
||||
}{
|
||||
Peer: v,
|
||||
IP: ip,
|
||||
PeerInfo: v,
|
||||
IP: ip,
|
||||
})
|
||||
}
|
||||
if res, err := json.Marshal(peers); err == nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue