Add documentation to TUN library

This commit is contained in:
Alec Scott
2022-02-03 09:17:23 -07:00
parent 43d0df3731
commit 0f7a7c336f
4 changed files with 15 additions and 1 deletions

View File

@@ -52,7 +52,7 @@ func DownRun(r *cmd.Root, c *cmd.Sub) {
// Different types of systems may need the tun devices destroyed first or
// the process to exit first don't worry as long as one of these two has
// suceeded.
// succeeded.
if err0 != nil && err1 != nil {
checkErr(err0)
checkErr(err1)

View File

@@ -301,6 +301,9 @@ func createDaemon(cfg *config.Config) error {
fmt.Println(line.Text)
if strings.HasPrefix(line.Text, "[+] Connection to") {
numConnected++
if numConnected >= len(cfg.Peers) {
break
}
}
}
out <- numConnected

View File

@@ -1,19 +1,26 @@
package tun
// Option defines a TUN device modifier option.
type Option func(tun *TUN) error
// Address sets the local address and subnet for an interface.
// On MacOS devices use this function to set the Src Address
// for an interface and use DestAddress to set the destination ip.
func Address(address string) Option {
return func(tun *TUN) error {
return tun.setAddress(address)
}
}
// MTU sets the Maximum Transmission Unit size for an interface.
func MTU(mtu int) Option {
return func(tun *TUN) error {
return tun.setMTU(mtu)
}
}
// DestAddress sets the destination address for a point-to-point interface.
// Only use this option on MacOS devices.
func DestAddress(address string) Option {
return func(tun *TUN) error {
return tun.setDestAddress(address)

View File

@@ -2,6 +2,9 @@ package tun
import "github.com/songgao/water"
// TUN is a struct containing the fields necessary
// to configure a system TUN device. Access the
// internal TUN device through TUN.Iface
type TUN struct {
Iface *water.Interface
MTU int
@@ -9,6 +12,7 @@ type TUN struct {
Dst string
}
// Apply configures the specified options for a TUN device.
func (t *TUN) Apply(opts ...Option) error {
for _, opt := range opts {
if opt == nil {