mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-23 02:55:39 +00:00
Define Adapter base type/interface
This commit is contained in:
parent
8045cb4dc3
commit
f9dc300787
25
src/yggdrasil/adapter.go
Normal file
25
src/yggdrasil/adapter.go
Normal file
@ -0,0 +1,25 @@
|
||||
package yggdrasil
|
||||
|
||||
// Defines the minimum required functions for an adapter type.
|
||||
type AdapterInterface interface {
|
||||
init(core *Core, send chan<- []byte, recv <-chan []byte)
|
||||
read() error
|
||||
write() error
|
||||
close() error
|
||||
}
|
||||
|
||||
// Defines the minimum required struct members for an adapter type (this is
|
||||
// now the base type for tunAdapter in tun.go)
|
||||
type Adapter struct {
|
||||
AdapterInterface
|
||||
core *Core
|
||||
send chan<- []byte
|
||||
recv <-chan []byte
|
||||
}
|
||||
|
||||
// Initialises the adapter.
|
||||
func (adapter *Adapter) init(core *Core, send chan<- []byte, recv <-chan []byte) {
|
||||
adapter.core = core
|
||||
adapter.send = send
|
||||
adapter.recv = recv
|
||||
}
|
@ -30,12 +30,6 @@ import (
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
|
||||
type adapter struct {
|
||||
core *Core
|
||||
send chan<- []byte
|
||||
recv <-chan []byte
|
||||
}
|
||||
|
||||
// The router struct has channels to/from the tun/tap device and a self peer (0), which is how messages are passed between this node and the peers/switch layer.
|
||||
// The router's mainLoop goroutine is responsible for managing all information related to the dht, searches, and crypto sessions.
|
||||
type router struct {
|
||||
@ -45,8 +39,8 @@ type router struct {
|
||||
in <-chan []byte // packets we received from the network, link to peer's "out"
|
||||
out func([]byte) // packets we're sending to the network, link to peer's "in"
|
||||
toRecv chan router_recvPacket // packets to handle via recvPacket()
|
||||
tun tunAdapter // TUN/TAP adapter
|
||||
adapters []adapter // Other adapters
|
||||
tun tunAdapter // TUN/TAP adapter
|
||||
adapters []Adapter // Other adapters
|
||||
recv chan<- []byte // place where the tun pulls received packets from
|
||||
send <-chan []byte // place where the tun puts outgoing packets
|
||||
reset chan struct{} // signal that coords changed (re-init sessions/dht)
|
||||
|
@ -18,7 +18,7 @@ const tun_ETHER_HEADER_LENGTH = 14
|
||||
|
||||
// Represents a running TUN/TAP interface.
|
||||
type tunAdapter struct {
|
||||
adapter
|
||||
Adapter
|
||||
icmpv6 icmpv6
|
||||
mtu int
|
||||
iface *water.Interface
|
||||
@ -35,10 +35,8 @@ func getSupportedMTU(mtu int) int {
|
||||
|
||||
// Initialises the TUN/TAP adapter.
|
||||
func (tun *tunAdapter) init(core *Core, send chan<- []byte, recv <-chan []byte) {
|
||||
tun.core = core
|
||||
tun.Adapter.init(core, send, recv)
|
||||
tun.icmpv6.init(tun)
|
||||
tun.send = send
|
||||
tun.recv = recv
|
||||
}
|
||||
|
||||
// Starts the setup process for the TUN/TAP adapter, and if successful, starts
|
||||
|
Loading…
Reference in New Issue
Block a user