EtherGuard-VPN/tap/tap_dummy.go

50 lines
1.4 KiB
Go
Raw Normal View History

2021-08-16 20:58:15 +02:00
package tap
2021-08-25 10:13:53 +02:00
import "errors"
2021-08-16 20:58:15 +02:00
type DummyTap struct {
stopRead chan struct{}
events chan Event
}
// New creates and returns a new TUN interface for the application.
func CreateDummyTAP() (tapdev Device, err error) {
// Setup TUN Config
tapdev = &DummyTap{
stopRead: make(chan struct{}, 1<<5),
events: make(chan Event, 1<<5),
}
tapdev.Events() <- EventUp
return
}
// SetMTU sets the Maximum Tansmission Unit Size for a
// Packet on the interface.
func (tap *DummyTap) Read([]byte, int) (int, error) {
_ = <-tap.stopRead
2021-08-25 10:13:53 +02:00
return 0, errors.New("Device stopped")
2021-08-16 20:58:15 +02:00
} // read a packet from the device (without any additional headers)
func (tap *DummyTap) Write(packet []byte, size int) (int, error) {
return size, nil
} // writes a packet to the device (without any additional headers)
func (tap *DummyTap) Flush() error {
return nil
} // flush all previous writes to the device
func (tap *DummyTap) MTU() (int, error) {
return 1500, nil
} // returns the MTU of the device
func (tap *DummyTap) Name() (string, error) {
return "DummyDevice", nil
} // fetches and returns the current name
func (tap *DummyTap) Events() chan Event {
return tap.events
} // returns a constant channel of events related to the device
func (tap *DummyTap) Close() error {
tap.events <- EventDown
2021-08-25 10:13:53 +02:00
tap.stopRead <- struct{}{}
//close(tap.stopRead)
//close(tap.events)
2021-08-16 20:58:15 +02:00
return nil
} // stops the device and closes the event channel