rename vtun to tungo
This commit is contained in:
@@ -57,15 +57,21 @@ func (l *tunListener) Init(md mdata.Metadata) (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
l.cqueue = make(chan net.Conn)
|
||||
l.cqueue = make(chan net.Conn, 1)
|
||||
l.closed = make(chan struct{})
|
||||
|
||||
go l.listenLoop()
|
||||
ctx, done := context.WithCancelCause(context.Background())
|
||||
go l.listenLoop(done)
|
||||
|
||||
<-ctx.Done()
|
||||
if err := context.Cause(ctx); err != ctx.Err() {
|
||||
return err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (l *tunListener) listenLoop() {
|
||||
func (l *tunListener) listenLoop(ready context.CancelCauseFunc) {
|
||||
for {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
err := func() error {
|
||||
@@ -116,6 +122,8 @@ func (l *tunListener) listenLoop() {
|
||||
cancel()
|
||||
}
|
||||
|
||||
ready(err)
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-l.closed:
|
||||
|
||||
+7
-4
@@ -2,11 +2,14 @@ package tun
|
||||
|
||||
import (
|
||||
"io"
|
||||
"math"
|
||||
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
)
|
||||
|
||||
const (
|
||||
maxBufSize = 16 * 1024
|
||||
)
|
||||
|
||||
type tunDevice struct {
|
||||
dev tun.Device
|
||||
packets int
|
||||
@@ -65,11 +68,11 @@ func (l *tunListener) createTunDevice() (dev io.ReadWriteCloser, name string, er
|
||||
return
|
||||
}
|
||||
|
||||
batchSize := 16
|
||||
batchSize := ifce.BatchSize()
|
||||
|
||||
rbufs := make([][]byte, batchSize)
|
||||
for i := 1; i < len(rbufs); i++ {
|
||||
rbufs[i] = make([]byte, math.MaxUint16)
|
||||
rbufs[i] = make([]byte, maxBufSize)
|
||||
}
|
||||
|
||||
dev = &tunDevice{
|
||||
@@ -77,7 +80,7 @@ func (l *tunListener) createTunDevice() (dev io.ReadWriteCloser, name string, er
|
||||
sizes: make([]int, batchSize),
|
||||
rbufs: rbufs,
|
||||
wbufs: make([][]byte, 1),
|
||||
wbuf: make([]byte, math.MaxUint16+writeOffset),
|
||||
wbuf: make([]byte, maxBufSize+writeOffset),
|
||||
}
|
||||
name, err = ifce.Name()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tun
|
||||
package tungo
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package tun
|
||||
package tungo
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.ListenerRegistry().Register("vtun", NewListener)
|
||||
registry.ListenerRegistry().Register("tungo", NewListener)
|
||||
}
|
||||
|
||||
type tunListener struct {
|
||||
@@ -50,15 +50,21 @@ func (l *tunListener) Init(md mdata.Metadata) (err error) {
|
||||
|
||||
l.addr = &Addr{Name: l.options.Addr}
|
||||
|
||||
l.cqueue = make(chan net.Conn)
|
||||
l.cqueue = make(chan net.Conn, 1)
|
||||
l.closed = make(chan struct{})
|
||||
|
||||
go l.listenLoop()
|
||||
ctx, done := context.WithCancelCause(context.Background())
|
||||
go l.listenLoop(done)
|
||||
|
||||
<-ctx.Done()
|
||||
if err := context.Cause(ctx); err != ctx.Err() {
|
||||
return err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (l *tunListener) listenLoop() {
|
||||
func (l *tunListener) listenLoop(ready context.CancelCauseFunc) {
|
||||
for {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
err := func() error {
|
||||
@@ -108,6 +114,8 @@ func (l *tunListener) listenLoop() {
|
||||
cancel()
|
||||
}
|
||||
|
||||
ready(err)
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-l.closed:
|
||||
@@ -1,4 +1,4 @@
|
||||
package tun
|
||||
package tungo
|
||||
|
||||
import (
|
||||
"net"
|
||||
@@ -12,7 +12,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultMTU = 1420
|
||||
defaultMTU = 1420
|
||||
defaultName = "tungo"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
@@ -28,6 +29,9 @@ func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
if config.MTU <= 0 {
|
||||
config.MTU = defaultMTU
|
||||
}
|
||||
if config.Name == "" {
|
||||
config.Name = "tungo"
|
||||
}
|
||||
if gw := mdutil.GetString(md, "gw", "tun.gw"); gw != "" {
|
||||
config.Gateway = net.ParseIP(gw)
|
||||
}
|
||||
@@ -1,13 +1,16 @@
|
||||
package tun
|
||||
package tungo
|
||||
|
||||
import (
|
||||
"io"
|
||||
"math"
|
||||
|
||||
"github.com/go-gost/core/logger"
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
)
|
||||
|
||||
const (
|
||||
maxBufSize = 16 * 1024
|
||||
)
|
||||
|
||||
type tunDevice struct {
|
||||
dev tun.Device
|
||||
|
||||
@@ -70,11 +73,11 @@ func (l *tunListener) createTunDevice() (dev io.ReadWriteCloser, name string, er
|
||||
return
|
||||
}
|
||||
|
||||
batchSize := 16
|
||||
batchSize := ifce.BatchSize()
|
||||
|
||||
rbufs := make([][]byte, batchSize)
|
||||
for i := 1; i < len(rbufs); i++ {
|
||||
rbufs[i] = make([]byte, math.MaxUint16)
|
||||
rbufs[i] = make([]byte, maxBufSize)
|
||||
}
|
||||
|
||||
dev = &tunDevice{
|
||||
@@ -82,7 +85,7 @@ func (l *tunListener) createTunDevice() (dev io.ReadWriteCloser, name string, er
|
||||
sizes: make([]int, batchSize),
|
||||
rbufs: rbufs,
|
||||
wbufs: make([][]byte, 1),
|
||||
wbuf: make([]byte, math.MaxUint16+writeOffset),
|
||||
wbuf: make([]byte, maxBufSize+writeOffset),
|
||||
log: l.log,
|
||||
}
|
||||
name, err = ifce.Name()
|
||||
@@ -1,4 +1,4 @@
|
||||
package tun
|
||||
package tungo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package tun
|
||||
package tungo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build !linux && !windows && !darwin
|
||||
|
||||
package tun
|
||||
package tungo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package tun
|
||||
package tungo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
Reference in New Issue
Block a user