From 9c3597bd11f624fccde0f4d0eee63e1416718d05 Mon Sep 17 00:00:00 2001 From: Haruue Icymoon Date: Thu, 8 Jul 2021 21:19:13 +0800 Subject: [PATCH] Allow build with CGO_ENABLED=0 by disable TUN Mode Run hysteria on your favorite OpenWRT router. --- pkg/tun/server.go | 2 ++ pkg/tun/server_fake.go | 44 ++++++++++++++++++++++++++++++++++++++++++ pkg/tun/tcp.go | 2 ++ pkg/tun/udp.go | 2 ++ 4 files changed, 50 insertions(+) create mode 100644 pkg/tun/server_fake.go diff --git a/pkg/tun/server.go b/pkg/tun/server.go index b66cc8b..bced82b 100644 --- a/pkg/tun/server.go +++ b/pkg/tun/server.go @@ -1,3 +1,5 @@ +// +build cgo + package tun import ( diff --git a/pkg/tun/server_fake.go b/pkg/tun/server_fake.go new file mode 100644 index 0000000..86b493a --- /dev/null +++ b/pkg/tun/server_fake.go @@ -0,0 +1,44 @@ +// +build !cgo + +package tun + +import ( + "errors" + "github.com/tobyxdd/hysteria/pkg/acl" + "github.com/tobyxdd/hysteria/pkg/core" + "github.com/tobyxdd/hysteria/pkg/transport" + "io" + "net" + "time" +) + +type Server struct { + HyClient *core.Client + Timeout time.Duration + TunDev io.ReadWriteCloser + Transport transport.Transport + ACLEngine *acl.Engine + + RequestFunc func(addr net.Addr, reqAddr string, action acl.Action, arg string) + ErrorFunc func(addr net.Addr, reqAddr string, err error) +} + +const ( + MTU = 1500 +) + +func NewServerWithTunDev(hyClient *core.Client, transport transport.Transport, + timeout time.Duration, + tunDev io.ReadWriteCloser) (*Server, error) { + return nil, errors.New("TUN mode is not available when build with CGO_ENABLED=0") +} + +func NewServer(hyClient *core.Client, transport transport.Transport, + timeout time.Duration, + name, address, gateway, mask string, dnsServers []string, persist bool) (*Server, error) { + return nil, errors.New("TUN mode is not available when build with CGO_ENABLED=0") +} + +func (s *Server) ListenAndServe() error { + panic("not implemented!") +} diff --git a/pkg/tun/tcp.go b/pkg/tun/tcp.go index 8a9ef9e..5ee9f6b 100644 --- a/pkg/tun/tcp.go +++ b/pkg/tun/tcp.go @@ -1,3 +1,5 @@ +// +build cgo + package tun import ( diff --git a/pkg/tun/udp.go b/pkg/tun/udp.go index 9c74e27..6053320 100644 --- a/pkg/tun/udp.go +++ b/pkg/tun/udp.go @@ -1,3 +1,5 @@ +// +build cgo + package tun import (