-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
53 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,7 @@ | |
0.3.1 | ||
重新添加tcpFastOpen功能 | ||
取消多个tls配置 | ||
|
||
0.3.2 | ||
修复tunnel握手后转为tls的情况下udp无法代理 | ||
优化TFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ func handleCmd() { | |
if help == true { | ||
fmt.Println(" /) /)\n" + | ||
"ฅ(՞•ﻌ•՞)ฅ\n" + | ||
"CuteBi Network Server 0.3.1\nAuthor: CuteBi(Mmmdbybyd)\nE-mail: [email protected]\n") | ||
"CuteBi Network Server 0.3.2\nAuthor: CuteBi(Mmmdbybyd)\nE-mail: [email protected]\n") | ||
flag.Usage() | ||
os.Exit(0) | ||
} | ||
|
@@ -90,6 +90,11 @@ func handleCmd() { | |
log.Println(err) | ||
os.Exit(1) | ||
} | ||
//有效uid不为0(root)的关闭tfo | ||
if config.Enable_TFO == true && os.Geteuid() != 0 { | ||
config.Enable_TFO = false | ||
fmt.Println("TFO cannot be opened: CNS effective UID isn't 0(root).") | ||
} | ||
if config.Pid_path != "" { | ||
pidSaveToFile(config.Pid_path) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,13 @@ | ||
// +build windows | ||
|
||
/* windows暂时不支持tcpFastOpen */ | ||
|
||
package tfo | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"net" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
const ( | ||
TCPFastOpen int = 23 | ||
ListenBacklog int = 23 | ||
) | ||
|
||
// tfoListener implement the RazorListener can also be used as the net.Listener | ||
type tfoListener struct { | ||
ServerAddr [16]byte | ||
ServerPort int | ||
fd syscall.Handle | ||
ctx context.Context | ||
} | ||
|
||
// Listen will listen given host and give back a Listener which implement the net.Listener | ||
func Listen(host string) (Listener, error) { | ||
r := &tfoListener{} | ||
|
||
addr, err := net.ResolveTCPAddr("tcp", host) | ||
if err != nil { | ||
return nil, err | ||
} | ||
r.ServerPort = addr.Port | ||
copy(r.ServerAddr[:], addr.IP) | ||
/* 如果为ipv4格式则转为ipv4映射ipv6格式 */ | ||
if bytes.HasSuffix(r.ServerAddr[:], []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) { | ||
copy(r.ServerAddr[12:], r.ServerAddr[:4]) | ||
copy(r.ServerAddr[:12], []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff}) | ||
} | ||
sa := &syscall.SockaddrInet6{Addr: r.ServerAddr, Port: r.ServerPort} | ||
|
||
fd, err := syscall.Socket(syscall.AF_INET6, syscall.SOCK_STREAM, 0) | ||
if err != nil { | ||
if err == syscall.ENOPROTOOPT { | ||
return nil, ErrTFONotSupport | ||
} | ||
return nil, err | ||
} | ||
r.fd = fd | ||
|
||
syscall.SetsockoptInt(r.fd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) | ||
|
||
err = syscall.Bind(r.fd, sa) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = syscall.SetsockoptInt(r.fd, syscall.IPPROTO_TCP, TCPFastOpen, 3) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = syscall.Listen(r.fd, ListenBacklog) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return r, nil | ||
} | ||
|
||
func (r *tfoListener) Accept() (net.Conn, error) { | ||
cfd, _, err := syscall.Accept(r.fd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
f := os.NewFile(uintptr(cfd), "") | ||
defer f.Close() | ||
return net.FileConn(f) | ||
} | ||
|
||
func (r *tfoListener) Close() error { | ||
err := syscall.Shutdown(r.fd, syscall.SHUT_RDWR) | ||
if err != nil { | ||
return err | ||
} | ||
err = syscall.Close(r.fd) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (r *tfoListener) Addr() net.Addr { | ||
return &net.TCPAddr{ | ||
IP: r.ServerAddr[:], | ||
Port: r.ServerPort, | ||
} | ||
return net.Listen("tcp", host) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters