Skip to content

Commit

Permalink
fix windows compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
p4gefau1t committed Mar 21, 2020
1 parent 6fa87f8 commit f1bd6f4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
21 changes: 7 additions & 14 deletions proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/p4gefau1t/trojan-go/protocol/direct"
"github.com/p4gefau1t/trojan-go/protocol/trojan"
"github.com/p4gefau1t/trojan-go/stat"
"github.com/valyala/tcplisten"
"github.com/xtaci/smux"
)

Expand Down Expand Up @@ -135,19 +134,13 @@ func (s *Server) Run() error {
var listener net.Listener
var err error
if s.config.TCP.ReusePort || s.config.TCP.FastOpen || s.config.TCP.NoDelay {
cfg := tcplisten.Config{
ReusePort: s.config.TCP.ReusePort,
FastOpen: s.config.TCP.FastOpen,
DeferAccept: s.config.TCP.NoDelay,
}
network := "tcp6"
if s.config.LocalIP.To4() != nil {
network = "tcp4"
}
listener, err = cfg.NewListener(network, s.config.LocalAddr.String())
if err != nil {
return err
}
listener, err = ListenWithTCPOption(
s.config.TCP.FastOpen,
s.config.TCP.ReusePort,
s.config.TCP.NoDelay,
s.config.LocalIP,
s.config.LocalAddr.String(),
)
} else {
listener, err = net.Listen("tcp", s.config.LocalAddr.String())
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions proxy/tcp_option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build !windows

package proxy

import (
"net"

"github.com/valyala/tcplisten"
)

func ListenWithTCPOption(fastOpen, reusePort, noDelay bool, ip net.IP, addr string) (net.Listener, error) {
cfg := tcplisten.Config{
ReusePort: reusePort,
FastOpen: fastOpen,
DeferAccept: noDelay,
}
network := "tcp6"
if ip.To4() != nil {
network = "tcp4"
}
return cfg.NewListener(network, addr)
}
12 changes: 12 additions & 0 deletions proxy/tcp_option_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build windows

package proxy

import (
"net"
)

func ListenWithTCPOption(fastOpen, reusePort, noDelay bool, ip net.IP, addr string) (net.Listener, error) {
panic("os not support tcp option")
return nil, nil
}

0 comments on commit f1bd6f4

Please sign in to comment.