yggdrasil-go/src/dummy/dummy.go

62 lines
1.7 KiB
Go
Raw Normal View History

2019-04-01 17:02:06 +00:00
package dummy
import (
"github.com/gologme/log"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
2019-04-01 17:02:06 +00:00
"github.com/yggdrasil-network/yggdrasil-go/src/config"
"github.com/yggdrasil-network/yggdrasil-go/src/defaults"
2019-04-01 17:02:06 +00:00
"github.com/yggdrasil-network/yggdrasil-go/src/util"
"github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
)
// DummyAdapter is a non-specific adapter that is used by the mobile APIs.
// You can also use it to send or receive custom traffic over Yggdrasil.
2019-04-01 17:02:06 +00:00
type DummyAdapter struct {
yggdrasil.Adapter
}
// Init initialises the dummy adapter.
2019-04-01 17:02:06 +00:00
func (m *DummyAdapter) Init(config *config.NodeState, log *log.Logger, send chan<- []byte, recv <-chan []byte, reject <-chan yggdrasil.RejectedPacket) {
m.Adapter.Init(config, log, send, recv, reject)
}
// Name returns the name of the adapter. This is always "dummy" for dummy
// adapters.
2019-04-01 17:02:06 +00:00
func (m *DummyAdapter) Name() string {
return "dummy"
}
// MTU gets the adapter's MTU. This returns your platform's maximum MTU for
// dummy adapters.
2019-04-01 17:02:06 +00:00
func (m *DummyAdapter) MTU() int {
return defaults.GetDefaults().MaximumIfMTU
2019-04-01 17:02:06 +00:00
}
// IsTAP always returns false for dummy adapters.
2019-04-01 17:02:06 +00:00
func (m *DummyAdapter) IsTAP() bool {
return false
}
// Recv waits for and returns for a packet from the router.
2019-04-01 17:02:06 +00:00
func (m *DummyAdapter) Recv() ([]byte, error) {
packet := <-m.Adapter.Recv
2019-04-01 17:02:06 +00:00
return packet, nil
}
// Send a packet to the router.
2019-04-01 17:02:06 +00:00
func (m *DummyAdapter) Send(buf []byte) error {
packet := append(util.GetBytes(), buf[:]...)
m.Adapter.Send <- packet
return nil
}
// Start is not implemented for dummy adapters.
func (m *DummyAdapter) Start(address.Address, address.Subnet) error {
return nil
}
// Close is not implemented for dummy adapters.
func (m *DummyAdapter) Close() error {
2019-04-01 17:02:06 +00:00
return nil
}