Skip to content
This repository was archived by the owner on Feb 24, 2024. It is now read-only.

Commit 0f7a7c3

Browse files
committed
Add documentation to TUN library
1 parent 43d0df3 commit 0f7a7c3

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

cli/down.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func DownRun(r *cmd.Root, c *cmd.Sub) {
5252

5353
// Different types of systems may need the tun devices destroyed first or
5454
// the process to exit first don't worry as long as one of these two has
55-
// suceeded.
55+
// succeeded.
5656
if err0 != nil && err1 != nil {
5757
checkErr(err0)
5858
checkErr(err1)

cli/up.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ func createDaemon(cfg *config.Config) error {
301301
fmt.Println(line.Text)
302302
if strings.HasPrefix(line.Text, "[+] Connection to") {
303303
numConnected++
304+
if numConnected >= len(cfg.Peers) {
305+
break
306+
}
304307
}
305308
}
306309
out <- numConnected

tun/options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
package tun
22

3+
// Option defines a TUN device modifier option.
34
type Option func(tun *TUN) error
45

6+
// Address sets the local address and subnet for an interface.
7+
// On MacOS devices use this function to set the Src Address
8+
// for an interface and use DestAddress to set the destination ip.
59
func Address(address string) Option {
610
return func(tun *TUN) error {
711
return tun.setAddress(address)
812
}
913
}
1014

15+
// MTU sets the Maximum Transmission Unit size for an interface.
1116
func MTU(mtu int) Option {
1217
return func(tun *TUN) error {
1318
return tun.setMTU(mtu)
1419
}
1520
}
1621

22+
// DestAddress sets the destination address for a point-to-point interface.
23+
// Only use this option on MacOS devices.
1724
func DestAddress(address string) Option {
1825
return func(tun *TUN) error {
1926
return tun.setDestAddress(address)

tun/tun.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package tun
22

33
import "github.com/songgao/water"
44

5+
// TUN is a struct containing the fields necessary
6+
// to configure a system TUN device. Access the
7+
// internal TUN device through TUN.Iface
58
type TUN struct {
69
Iface *water.Interface
710
MTU int
811
Src string
912
Dst string
1013
}
1114

15+
// Apply configures the specified options for a TUN device.
1216
func (t *TUN) Apply(opts ...Option) error {
1317
for _, opt := range opts {
1418
if opt == nil {

0 commit comments

Comments
 (0)