mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
Merge pull request #134 from Loyalsoldier/fix-go-vet
Fix according to go vet results
This commit is contained in:
commit
9466e5d09b
@ -50,8 +50,8 @@ func (p *Policy) overrideWith(another *Policy) {
|
|||||||
p.Timeout.overrideWith(another.Timeout)
|
p.Timeout.overrideWith(another.Timeout)
|
||||||
}
|
}
|
||||||
if another.Stats != nil && p.Stats == nil {
|
if another.Stats != nil && p.Stats == nil {
|
||||||
p.Stats = new(Policy_Stats)
|
p.Stats = &Policy_Stats{}
|
||||||
*p.Stats = *another.Stats
|
p.Stats = another.Stats
|
||||||
}
|
}
|
||||||
if another.Buffer != nil {
|
if another.Buffer != nil {
|
||||||
p.Buffer = &Policy_Buffer{
|
p.Buffer = &Policy_Buffer{
|
||||||
|
@ -44,17 +44,17 @@ func (p Port) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FromPort returns the beginning port of this PortRange.
|
// FromPort returns the beginning port of this PortRange.
|
||||||
func (p PortRange) FromPort() Port {
|
func (p *PortRange) FromPort() Port {
|
||||||
return Port(p.From)
|
return Port(p.From)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToPort returns the end port of this PortRange.
|
// ToPort returns the end port of this PortRange.
|
||||||
func (p PortRange) ToPort() Port {
|
func (p *PortRange) ToPort() Port {
|
||||||
return Port(p.To)
|
return Port(p.To)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contains returns true if the given port is within the range of a PortRange.
|
// 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()
|
return p.FromPort() <= port && port <= p.ToPort()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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))
|
dest := net.TCPDestination(spec.Address.AsAddress(), net.Port(spec.Port))
|
||||||
mUsers := make([]*MemoryUser, len(spec.User))
|
mUsers := make([]*MemoryUser, len(spec.User))
|
||||||
for idx, u := range spec.User {
|
for idx, u := range spec.User {
|
||||||
|
@ -135,7 +135,7 @@ func TestUDPDNSTunnel(t *testing.T) {
|
|||||||
m1.Id = dns.Id()
|
m1.Id = dns.Id()
|
||||||
m1.RecursionDesired = true
|
m1.RecursionDesired = true
|
||||||
m1.Question = make([]dns.Question, 1)
|
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)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m1, "127.0.0.1:"+strconv.Itoa(int(serverPort)))
|
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.Id = dns.Id()
|
||||||
m1.RecursionDesired = true
|
m1.RecursionDesired = true
|
||||||
m1.Question = make([]dns.Question, 1)
|
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 := new(dns.Client)
|
||||||
c.Timeout = 10 * time.Second
|
c.Timeout = 10 * time.Second
|
||||||
@ -176,7 +176,7 @@ func TestUDPDNSTunnel(t *testing.T) {
|
|||||||
m1.Id = dns.Id()
|
m1.Id = dns.Id()
|
||||||
m1.RecursionDesired = true
|
m1.RecursionDesired = true
|
||||||
m1.Question = make([]dns.Question, 1)
|
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)
|
c := new(dns.Client)
|
||||||
in, _, err := c.Exchange(m1, "127.0.0.1:"+strconv.Itoa(int(serverPort)))
|
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.Id = dns.Id()
|
||||||
m1.RecursionDesired = true
|
m1.RecursionDesired = true
|
||||||
m1.Question = make([]dns.Question, 1)
|
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{
|
c := &dns.Client{
|
||||||
Net: "tcp",
|
Net: "tcp",
|
||||||
@ -343,7 +343,7 @@ func TestUDP2TCPDNSTunnel(t *testing.T) {
|
|||||||
m1.Id = dns.Id()
|
m1.Id = dns.Id()
|
||||||
m1.RecursionDesired = true
|
m1.RecursionDesired = true
|
||||||
m1.Question = make([]dns.Question, 1)
|
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{
|
c := &dns.Client{
|
||||||
Net: "tcp",
|
Net: "tcp",
|
||||||
|
@ -39,12 +39,12 @@ func init() {
|
|||||||
type Handler struct {
|
type Handler struct {
|
||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
dns dns.Client
|
dns dns.Client
|
||||||
config Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes the Handler with necessary parameters.
|
// Init initializes the Handler with necessary parameters.
|
||||||
func (h *Handler) Init(config *Config, pm policy.Manager, d dns.Client) error {
|
func (h *Handler) Init(config *Config, pm policy.Manager, d dns.Client) error {
|
||||||
h.config = *config
|
h.config = config
|
||||||
h.policyManager = pm
|
h.policyManager = pm
|
||||||
h.dns = d
|
h.dns = d
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ var (
|
|||||||
func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
||||||
serverList := protocol.NewServerList()
|
serverList := protocol.NewServerList()
|
||||||
for _, rec := range config.Server {
|
for _, rec := range config.Server {
|
||||||
s, err := protocol.NewServerSpecFromPB(*rec)
|
s, err := protocol.NewServerSpecFromPB(rec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("failed to get server spec").Base(err)
|
return nil, newError("failed to get server spec").Base(err)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ type Client struct {
|
|||||||
func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
||||||
serverList := protocol.NewServerList()
|
serverList := protocol.NewServerList()
|
||||||
for _, rec := range config.Server {
|
for _, rec := range config.Server {
|
||||||
s, err := protocol.NewServerSpecFromPB(*rec)
|
s, err := protocol.NewServerSpecFromPB(rec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("failed to parse server spec").Base(err)
|
return nil, newError("failed to parse server spec").Base(err)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
config ServerConfig
|
config *ServerConfig
|
||||||
user *protocol.MemoryUser
|
user *protocol.MemoryUser
|
||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
|
|||||||
|
|
||||||
v := core.MustFromContext(ctx)
|
v := core.MustFromContext(ctx)
|
||||||
s := &Server{
|
s := &Server{
|
||||||
config: *config,
|
config: config,
|
||||||
user: mUser,
|
user: mUser,
|
||||||
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ type Client struct {
|
|||||||
func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
||||||
serverList := protocol.NewServerList()
|
serverList := protocol.NewServerList()
|
||||||
for _, rec := range config.Server {
|
for _, rec := range config.Server {
|
||||||
s, err := protocol.NewServerSpecFromPB(*rec)
|
s, err := protocol.NewServerSpecFromPB(rec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("failed to get server spec").Base(err)
|
return nil, newError("failed to get server spec").Base(err)
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
|
|||||||
|
|
||||||
serverList := protocol.NewServerList()
|
serverList := protocol.NewServerList()
|
||||||
for _, rec := range config.Receiver {
|
for _, rec := range config.Receiver {
|
||||||
s, err := protocol.NewServerSpecFromPB(*rec)
|
s, err := protocol.NewServerSpecFromPB(rec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("failed to parse server spec").Base(err).AtError()
|
return nil, newError("failed to parse server spec").Base(err).AtError()
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ type Handler struct {
|
|||||||
func New(ctx context.Context, config *Config) (*Handler, error) {
|
func New(ctx context.Context, config *Config) (*Handler, error) {
|
||||||
serverList := protocol.NewServerList()
|
serverList := protocol.NewServerList()
|
||||||
for _, rec := range config.Receiver {
|
for _, rec := range config.Receiver {
|
||||||
s, err := protocol.NewServerSpecFromPB(*rec)
|
s, err := protocol.NewServerSpecFromPB(rec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newError("failed to parse server spec").Base(err)
|
return nil, newError("failed to parse server spec").Base(err)
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ type Listener struct {
|
|||||||
server *http.Server
|
server *http.Server
|
||||||
handler internet.ConnHandler
|
handler internet.ConnHandler
|
||||||
local net.Addr
|
local net.Addr
|
||||||
config Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listener) Addr() net.Addr {
|
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(),
|
IP: address.IP(),
|
||||||
Port: int(port),
|
Port: int(port),
|
||||||
},
|
},
|
||||||
config: *httpSettings,
|
config: httpSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
var server *http.Server
|
var server *http.Server
|
||||||
|
Loading…
Reference in New Issue
Block a user