diff --git a/app/policy/config.go b/app/policy/config.go index 4856e94db..adf09448a 100644 --- a/app/policy/config.go +++ b/app/policy/config.go @@ -50,8 +50,8 @@ func (p *Policy) overrideWith(another *Policy) { p.Timeout.overrideWith(another.Timeout) } if another.Stats != nil && p.Stats == nil { - p.Stats = new(Policy_Stats) - *p.Stats = *another.Stats + p.Stats = &Policy_Stats{} + p.Stats = another.Stats } if another.Buffer != nil { p.Buffer = &Policy_Buffer{ diff --git a/common/net/port.go b/common/net/port.go index e5f5cd349..2a0bf6370 100644 --- a/common/net/port.go +++ b/common/net/port.go @@ -44,17 +44,17 @@ func (p Port) String() string { } // FromPort returns the beginning port of this PortRange. -func (p PortRange) FromPort() Port { +func (p *PortRange) FromPort() Port { return Port(p.From) } // ToPort returns the end port of this PortRange. -func (p PortRange) ToPort() Port { +func (p *PortRange) ToPort() Port { return Port(p.To) } // Contains returns true if the given port is within the range of a PortRange. -func (p PortRange) Contains(port Port) bool { +func (p *PortRange) Contains(port Port) bool { return p.FromPort() <= port && port <= p.ToPort() } diff --git a/common/protocol/server_spec.go b/common/protocol/server_spec.go index bcf05d691..d462b4406 100644 --- a/common/protocol/server_spec.go +++ b/common/protocol/server_spec.go @@ -58,7 +58,7 @@ func NewServerSpec(dest net.Destination, valid ValidationStrategy, users ...*Mem } } -func NewServerSpecFromPB(spec ServerEndpoint) (*ServerSpec, error) { +func NewServerSpecFromPB(spec *ServerEndpoint) (*ServerSpec, error) { dest := net.TCPDestination(spec.Address.AsAddress(), net.Port(spec.Port)) mUsers := make([]*MemoryUser, len(spec.User)) for idx, u := range spec.User { diff --git a/proxy/dns/dns_test.go b/proxy/dns/dns_test.go index 441979433..7ac7d520d 100644 --- a/proxy/dns/dns_test.go +++ b/proxy/dns/dns_test.go @@ -135,7 +135,7 @@ func TestUDPDNSTunnel(t *testing.T) { m1.Id = dns.Id() m1.RecursionDesired = true m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{"google.com.", dns.TypeA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: "google.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET} c := new(dns.Client) in, _, err := c.Exchange(m1, "127.0.0.1:"+strconv.Itoa(int(serverPort))) @@ -159,7 +159,7 @@ func TestUDPDNSTunnel(t *testing.T) { m1.Id = dns.Id() m1.RecursionDesired = true m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{"ipv4only.google.com.", dns.TypeAAAA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: "ipv4only.google.com.", Qtype: dns.TypeAAAA, Qclass: dns.ClassINET} c := new(dns.Client) c.Timeout = 10 * time.Second @@ -176,7 +176,7 @@ func TestUDPDNSTunnel(t *testing.T) { m1.Id = dns.Id() m1.RecursionDesired = true m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{"notexist.google.com.", dns.TypeAAAA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: "notexist.google.com.", Qtype: dns.TypeAAAA, Qclass: dns.ClassINET} c := new(dns.Client) in, _, err := c.Exchange(m1, "127.0.0.1:"+strconv.Itoa(int(serverPort))) @@ -253,7 +253,7 @@ func TestTCPDNSTunnel(t *testing.T) { m1.Id = dns.Id() m1.RecursionDesired = true m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{"google.com.", dns.TypeA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: "google.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET} c := &dns.Client{ Net: "tcp", @@ -343,7 +343,7 @@ func TestUDP2TCPDNSTunnel(t *testing.T) { m1.Id = dns.Id() m1.RecursionDesired = true m1.Question = make([]dns.Question, 1) - m1.Question[0] = dns.Question{"google.com.", dns.TypeA, dns.ClassINET} + m1.Question[0] = dns.Question{Name: "google.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET} c := &dns.Client{ Net: "tcp", diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index b968a036f..d26ffe617 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -39,12 +39,12 @@ func init() { type Handler struct { policyManager policy.Manager dns dns.Client - config Config + config *Config } // Init initializes the Handler with necessary parameters. func (h *Handler) Init(config *Config, pm policy.Manager, d dns.Client) error { - h.config = *config + h.config = config h.policyManager = pm h.dns = d diff --git a/proxy/http/client.go b/proxy/http/client.go index 31c402831..dd30ff360 100644 --- a/proxy/http/client.go +++ b/proxy/http/client.go @@ -48,7 +48,7 @@ var ( func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) { serverList := protocol.NewServerList() for _, rec := range config.Server { - s, err := protocol.NewServerSpecFromPB(*rec) + s, err := protocol.NewServerSpecFromPB(rec) if err != nil { return nil, newError("failed to get server spec").Base(err) } diff --git a/proxy/shadowsocks/client.go b/proxy/shadowsocks/client.go index ab5619c5e..3823f3ccb 100644 --- a/proxy/shadowsocks/client.go +++ b/proxy/shadowsocks/client.go @@ -29,7 +29,7 @@ type Client struct { func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) { serverList := protocol.NewServerList() for _, rec := range config.Server { - s, err := protocol.NewServerSpecFromPB(*rec) + s, err := protocol.NewServerSpecFromPB(rec) if err != nil { return nil, newError("failed to parse server spec").Base(err) } diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 20aebdb3e..46e8fc3eb 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -23,7 +23,7 @@ import ( ) type Server struct { - config ServerConfig + config *ServerConfig user *protocol.MemoryUser policyManager policy.Manager } @@ -41,7 +41,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) { v := core.MustFromContext(ctx) s := &Server{ - config: *config, + config: config, user: mUser, policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager), } diff --git a/proxy/socks/client.go b/proxy/socks/client.go index e303e5b32..a6a345b27 100644 --- a/proxy/socks/client.go +++ b/proxy/socks/client.go @@ -30,7 +30,7 @@ type Client struct { func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) { serverList := protocol.NewServerList() for _, rec := range config.Server { - s, err := protocol.NewServerSpecFromPB(*rec) + s, err := protocol.NewServerSpecFromPB(rec) if err != nil { return nil, newError("failed to get server spec").Base(err) } diff --git a/proxy/vless/outbound/outbound.go b/proxy/vless/outbound/outbound.go index 039e4fc6f..a5919f627 100644 --- a/proxy/vless/outbound/outbound.go +++ b/proxy/vless/outbound/outbound.go @@ -42,7 +42,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) { serverList := protocol.NewServerList() for _, rec := range config.Receiver { - s, err := protocol.NewServerSpecFromPB(*rec) + s, err := protocol.NewServerSpecFromPB(rec) if err != nil { return nil, newError("failed to parse server spec").Base(err).AtError() } diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index 5ab123bb0..5b5fdd0d9 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -36,7 +36,7 @@ type Handler struct { func New(ctx context.Context, config *Config) (*Handler, error) { serverList := protocol.NewServerList() for _, rec := range config.Receiver { - s, err := protocol.NewServerSpecFromPB(*rec) + s, err := protocol.NewServerSpecFromPB(rec) if err != nil { return nil, newError("failed to parse server spec").Base(err) } diff --git a/transport/internet/http/hub.go b/transport/internet/http/hub.go index 32fb30907..43a9039a4 100644 --- a/transport/internet/http/hub.go +++ b/transport/internet/http/hub.go @@ -25,7 +25,7 @@ type Listener struct { server *http.Server handler internet.ConnHandler local net.Addr - config Config + config *Config } func (l *Listener) Addr() net.Addr { @@ -102,7 +102,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti IP: address.IP(), Port: int(port), }, - config: *httpSettings, + config: httpSettings, } var server *http.Server