mirror of
https://github.com/net-byte/vtun
synced 2024-03-14 10:50:03 +08:00
refactor
This commit is contained in:
parent
2bc30e939c
commit
1033eafed9
10
cmd/vtun.go
10
cmd/vtun.go
@ -8,7 +8,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/net-byte/vtun/util"
|
"github.com/net-byte/vtun/common/cipher"
|
||||||
"github.com/songgao/water"
|
"github.com/songgao/water"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ func New(local *string, remote *string, port *int, key *string) {
|
|||||||
log.Fatal("Only support linux!")
|
log.Fatal("Only support linux!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hashKey := util.CreateHash(*key)
|
hashKey := cipher.CreateHash(*key)
|
||||||
// create tun
|
// create tun
|
||||||
config := water.Config{
|
config := water.Config{
|
||||||
DeviceType: water.TAP,
|
DeviceType: water.TAP,
|
||||||
@ -64,7 +64,7 @@ func New(local *string, remote *string, port *int, key *string) {
|
|||||||
}
|
}
|
||||||
b := buf[:n]
|
b := buf[:n]
|
||||||
// decrypt data
|
// decrypt data
|
||||||
util.Decrypt(&b, hashKey)
|
cipher.Decrypt(&b, hashKey)
|
||||||
iface.Write(b)
|
iface.Write(b)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -77,7 +77,7 @@ func New(local *string, remote *string, port *int, key *string) {
|
|||||||
}
|
}
|
||||||
b := packet[:n]
|
b := packet[:n]
|
||||||
// encrypt data
|
// encrypt data
|
||||||
util.Encrypt(&b, hashKey)
|
cipher.Encrypt(&b, hashKey)
|
||||||
conn.WriteToUDP(b, remoteAddr)
|
conn.WriteToUDP(b, remoteAddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,6 +95,6 @@ func execCmd(c string, args ...string) {
|
|||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if nil != err {
|
if nil != err {
|
||||||
log.Fatalln("Error running /sbin/ip:", err)
|
log.Fatalln("Exec /sbin/ip error:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package util
|
package cipher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
1
go.mod
1
go.mod
@ -5,5 +5,4 @@ go 1.16
|
|||||||
require (
|
require (
|
||||||
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
|
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
|
||||||
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
|
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
|
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user