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"
|
||||
"runtime"
|
||||
|
||||
"github.com/net-byte/vtun/util"
|
||||
"github.com/net-byte/vtun/common/cipher"
|
||||
"github.com/songgao/water"
|
||||
)
|
||||
|
||||
@ -24,7 +24,7 @@ func New(local *string, remote *string, port *int, key *string) {
|
||||
log.Fatal("Only support linux!")
|
||||
return
|
||||
}
|
||||
hashKey := util.CreateHash(*key)
|
||||
hashKey := cipher.CreateHash(*key)
|
||||
// create tun
|
||||
config := water.Config{
|
||||
DeviceType: water.TAP,
|
||||
@ -64,7 +64,7 @@ func New(local *string, remote *string, port *int, key *string) {
|
||||
}
|
||||
b := buf[:n]
|
||||
// decrypt data
|
||||
util.Decrypt(&b, hashKey)
|
||||
cipher.Decrypt(&b, hashKey)
|
||||
iface.Write(b)
|
||||
}
|
||||
}()
|
||||
@ -77,7 +77,7 @@ func New(local *string, remote *string, port *int, key *string) {
|
||||
}
|
||||
b := packet[:n]
|
||||
// encrypt data
|
||||
util.Encrypt(&b, hashKey)
|
||||
cipher.Encrypt(&b, hashKey)
|
||||
conn.WriteToUDP(b, remoteAddr)
|
||||
}
|
||||
}
|
||||
@ -95,6 +95,6 @@ func execCmd(c string, args ...string) {
|
||||
cmd.Stdin = os.Stdin
|
||||
err := cmd.Run()
|
||||
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 (
|
||||
"crypto/sha256"
|
Loading…
Reference in New Issue
Block a user