mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Define module.Module interface, update admin/tuntap/multicast modules to comply with it, fix #581
This commit is contained in:
parent
fc71624919
commit
a072e063d8
6 changed files with 108 additions and 42 deletions
|
@ -56,6 +56,11 @@ type TunAdapter struct {
|
|||
isOpen bool
|
||||
}
|
||||
|
||||
type TunOptions struct {
|
||||
Listener *yggdrasil.Listener
|
||||
Dialer *yggdrasil.Dialer
|
||||
}
|
||||
|
||||
// Gets the maximum supported MTU for the platform based on the defaults in
|
||||
// defaults.GetDefaults().
|
||||
func getSupportedMTU(mtu int) int {
|
||||
|
@ -110,16 +115,21 @@ func MaximumMTU() int {
|
|||
|
||||
// Init initialises the TUN/TAP module. You must have acquired a Listener from
|
||||
// the Yggdrasil core before this point and it must not be in use elsewhere.
|
||||
func (tun *TunAdapter) Init(config *config.NodeState, log *log.Logger, listener *yggdrasil.Listener, dialer *yggdrasil.Dialer) {
|
||||
func (tun *TunAdapter) Init(core *yggdrasil.Core, config *config.NodeState, log *log.Logger, options interface{}) error {
|
||||
tunoptions, ok := options.(TunOptions)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid options supplied to TunAdapter module")
|
||||
}
|
||||
tun.config = config
|
||||
tun.log = log
|
||||
tun.listener = listener
|
||||
tun.dialer = dialer
|
||||
tun.listener = tunoptions.Listener
|
||||
tun.dialer = tunoptions.Dialer
|
||||
tun.addrToConn = make(map[address.Address]*tunConn)
|
||||
tun.subnetToConn = make(map[address.Subnet]*tunConn)
|
||||
tun.dials = make(map[string][][]byte)
|
||||
tun.writer.tun = tun
|
||||
tun.reader.tun = tun
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start the setup process for the TUN/TAP adapter. If successful, starts the
|
||||
|
@ -160,13 +170,6 @@ func (tun *TunAdapter) _start() error {
|
|||
return nil
|
||||
}
|
||||
tun.isOpen = true
|
||||
tun.reconfigure = make(chan chan error)
|
||||
go func() {
|
||||
for {
|
||||
e := <-tun.reconfigure
|
||||
e <- nil
|
||||
}
|
||||
}()
|
||||
go tun.handler()
|
||||
tun.reader.Act(nil, tun.reader._read) // Start the reader
|
||||
tun.icmpv6.Init(tun)
|
||||
|
@ -177,6 +180,11 @@ func (tun *TunAdapter) _start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// IsStarted returns true if the module has been started.
|
||||
func (tun *TunAdapter) IsStarted() bool {
|
||||
return tun.isOpen
|
||||
}
|
||||
|
||||
// Start the setup process for the TUN/TAP adapter. If successful, starts the
|
||||
// read/write goroutines to handle packets on that interface.
|
||||
func (tun *TunAdapter) Stop() error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue