mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
work-in-progress adding nodeinfo
This commit is contained in:
parent
2c7b22db92
commit
2e45e970c6
4 changed files with 211 additions and 9 deletions
|
@ -45,7 +45,9 @@ type TunAdapter struct {
|
|||
phony.Inbox // Currently only used for _handlePacket from the reader, TODO: all the stuff that currently needs a mutex below
|
||||
//mutex sync.RWMutex // Protects the below
|
||||
isOpen bool
|
||||
isEnabled bool // Used by the writer to drop sessionTraffic if not enabled
|
||||
gatekeeper func(pubkey ed25519.PublicKey, initiator bool) bool
|
||||
nodeinfo nodeinfo
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) SetSessionGatekeeper(gatekeeper func(pubkey ed25519.PublicKey, initiator bool) bool) {
|
||||
|
@ -107,6 +109,7 @@ func (tun *TunAdapter) Init(core *yggdrasil.Core, config *config.NodeState, log
|
|||
tun.store.init(tun)
|
||||
tun.config = config
|
||||
tun.log = log
|
||||
tun.nodeinfo.init(tun)
|
||||
if err := tun.core.SetOutOfBandHandler(tun.oobHandler); err != nil {
|
||||
return fmt.Errorf("tun.core.SetOutOfBandHander: %w", err)
|
||||
}
|
||||
|
@ -138,15 +141,8 @@ func (tun *TunAdapter) _start() error {
|
|||
addr := fmt.Sprintf("%s/%d", net.IP(tun.addr[:]).String(), 8*len(address.GetPrefix())-1)
|
||||
if current.IfName == "none" || current.IfName == "dummy" {
|
||||
tun.log.Debugln("Not starting TUN as ifname is none or dummy")
|
||||
go func() {
|
||||
bs := make([]byte, tun.core.PacketConn.MTU())
|
||||
for {
|
||||
// Dump traffic to nowhere
|
||||
if _, _, err := tun.core.PacketConn.ReadFrom(bs); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
tun.isEnabled = false
|
||||
go tun.write()
|
||||
return nil
|
||||
}
|
||||
mtu := current.IfMTU
|
||||
|
@ -160,6 +156,7 @@ func (tun *TunAdapter) _start() error {
|
|||
tun.log.Warnf("Warning: Interface MTU %d automatically adjusted to %d (supported range is 1280-%d)", current.IfMTU, tun.MTU(), MaximumMTU())
|
||||
}
|
||||
tun.isOpen = true
|
||||
tun.isEnabled = true
|
||||
go tun.read()
|
||||
go tun.write()
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue