mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-25 00:33:08 +01:00
add go fd test
This commit is contained in:
parent
776df87879
commit
bfd76ff76a
1
example_config/super_mode/.gitignore
vendored
Normal file
1
example_config/super_mode/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
n1_test_fd_mode2
|
@ -47,8 +47,10 @@ os.environ["EG_FD_TX"] = str(ew)
|
||||
|
||||
print(str(er), str(ew))
|
||||
|
||||
#p = subprocess.Popen('./etherguard-go -config example_config/super_mode/n1.yaml -mode edge'.split(" "),pass_fds=[er,ew])
|
||||
p = subprocess.Popen('python3 example_config/super_mode/n1_test_fd_mode2.py'.split(" "),pass_fds=[er,ew])
|
||||
#p = subprocess.Popen('./etherguard-go -config example_config/super_mode/n1_fd.yaml -mode edge'.split(" "),pass_fds=[er,ew])
|
||||
#p = subprocess.Popen('python3 example_config/super_mode/n1_test_fd_mode2.py'.split(" "),pass_fds=[er,ew])
|
||||
p = subprocess.Popen('example_config/super_mode/n1_test_fd_mode2'.split(" "),pass_fds=[er,ew])
|
||||
|
||||
os.close(er)
|
||||
os.close(ew)
|
||||
|
||||
|
77
example_config/super_mode/n1_test_fd_mode2.go
Normal file
77
example_config/super_mode/n1_test_fd_mode2.go
Normal file
@ -0,0 +1,77 @@
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"errors"
|
||||
"time"
|
||||
"syscall"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
||||
func ReadLoop(fileRX *os.File) {
|
||||
buf := make([]byte,65535)
|
||||
for {
|
||||
size, err := fileRX.Read(buf)
|
||||
if err != nil{
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("Go read fd" , fileRX.Fd() , ":" ,buf[:size])
|
||||
}
|
||||
}
|
||||
func WriteLoop(fileTX *os.File) {
|
||||
t := 0
|
||||
packet := ":gogogogogogogogogogogogo\n"
|
||||
for {
|
||||
fmt.Println("Go write fd:" , fileTX.Fd())
|
||||
_, err := fileTX.Write([]byte( strconv.Itoa(t) + packet))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
t += 1
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func cleanup(ftx *os.File,frx *os.File) {
|
||||
fmt.Println("Ctrl + C, exit")
|
||||
ftx.Close()
|
||||
frx.Close()
|
||||
}
|
||||
|
||||
func main() {
|
||||
fdRXstr, has := os.LookupEnv("EG_FD_RX")
|
||||
if !has {
|
||||
fmt.Println(errors.New("Need Environment Variable EG_FD_RX"))
|
||||
return
|
||||
}
|
||||
fdRX, err := strconv.Atoi(fdRXstr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fdTxstr, has := os.LookupEnv("EG_FD_TX")
|
||||
if !has {
|
||||
fmt.Println(errors.New("Need Environment Variable EG_FD_TX"))
|
||||
return
|
||||
}
|
||||
fdTX, err := strconv.Atoi(fdTxstr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fileRX := os.NewFile(uintptr(fdRX), "pipeRX")
|
||||
fileTX := os.NewFile(uintptr(fdTX), "pipeTX")
|
||||
go ReadLoop(fileRX)
|
||||
go WriteLoop(fileTX)
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
<-c
|
||||
cleanup(fileRX,fileTX)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func (tap *FdTap) Read(buf []byte, offset int) (int, error) {
|
||||
} // read a packet from the device (without any additional headers)
|
||||
func (tap *FdTap) Write(buf []byte, offset int) (size int, err error) {
|
||||
packet := buf[offset:]
|
||||
size, err = tap.fileRX.Write(packet)
|
||||
size, err = tap.fileTX.Write(packet)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user