mirror of https://github.com/v2ray/v2ray-core
fix lint warnings
parent
c5ccbe6b63
commit
a14fae4b35
|
@ -10,7 +10,8 @@
|
||||||
"--disable=gas",
|
"--disable=gas",
|
||||||
"--disable=gocyclo",
|
"--disable=gocyclo",
|
||||||
"--disable=gosec",
|
"--disable=gosec",
|
||||||
"--disable=interfacer"
|
"--disable=interfacer",
|
||||||
|
"--deadline=5m"
|
||||||
],
|
],
|
||||||
"go.formatTool": "goimports",
|
"go.formatTool": "goimports",
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,9 @@ func NewCommander(ctx context.Context, config *Config) (*Commander, error) {
|
||||||
tag: config.Tag,
|
tag: config.Tag,
|
||||||
}
|
}
|
||||||
|
|
||||||
core.RequireFeatures(ctx, func(om outbound.Manager) {
|
common.Must(core.RequireFeatures(ctx, func(om outbound.Manager) {
|
||||||
c.ohm = om
|
c.ohm = om
|
||||||
})
|
}))
|
||||||
|
|
||||||
for _, rawConfig := range config.Service {
|
for _, rawConfig := range config.Service {
|
||||||
config, err := rawConfig.GetInstance()
|
config, err := rawConfig.GetInstance()
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"v2ray.com/core/features"
|
"v2ray.com/core/features"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// StaticHosts represents static domain-ip mapping in DNS server.
|
||||||
type StaticHosts struct {
|
type StaticHosts struct {
|
||||||
ips map[uint32][]net.IP
|
ips map[uint32][]net.IP
|
||||||
matchers *strmatcher.MatcherGroup
|
matchers *strmatcher.MatcherGroup
|
||||||
|
@ -31,6 +32,7 @@ func toStrMatcher(t DomainMatchingType, domain string) (strmatcher.Matcher, erro
|
||||||
return matcher, nil
|
return matcher, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewStaticHosts creates a new StaticHosts instance.
|
||||||
func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDomain) (*StaticHosts, error) {
|
func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDomain) (*StaticHosts, error) {
|
||||||
g := new(strmatcher.MatcherGroup)
|
g := new(strmatcher.MatcherGroup)
|
||||||
sh := &StaticHosts{
|
sh := &StaticHosts{
|
||||||
|
@ -71,6 +73,7 @@ func NewStaticHosts(hosts []*Config_HostMapping, legacy map[string]*net.IPOrDoma
|
||||||
return sh, nil
|
return sh, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LookupIP returns IP address for the given domain, if exists in this StaticHosts.
|
||||||
func (h *StaticHosts) LookupIP(domain string) []net.IP {
|
func (h *StaticHosts) LookupIP(domain string) []net.IP {
|
||||||
id := h.matchers.Match(domain)
|
id := h.matchers.Match(domain)
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"v2ray.com/core/features/routing"
|
"v2ray.com/core/features/routing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Server is a DNS rely server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
hosts *StaticHosts
|
hosts *StaticHosts
|
||||||
|
@ -25,6 +26,7 @@ type Server struct {
|
||||||
domainIndexMap map[uint32]uint32
|
domainIndexMap map[uint32]uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates a new DNS server with given configuration.
|
||||||
func New(ctx context.Context, config *Config) (*Server, error) {
|
func New(ctx context.Context, config *Config) (*Server, error) {
|
||||||
server := &Server{
|
server := &Server{
|
||||||
servers: make([]NameServerInterface, 0, len(config.NameServers)+len(config.NameServer)),
|
servers: make([]NameServerInterface, 0, len(config.NameServers)+len(config.NameServer)),
|
||||||
|
@ -55,9 +57,9 @@ func New(ctx context.Context, config *Config) (*Server, error) {
|
||||||
idx := len(server.servers)
|
idx := len(server.servers)
|
||||||
server.servers = append(server.servers, nil)
|
server.servers = append(server.servers, nil)
|
||||||
|
|
||||||
core.RequireFeatures(ctx, func(d routing.Dispatcher) {
|
common.Must(core.RequireFeatures(ctx, func(d routing.Dispatcher) {
|
||||||
server.servers[idx] = NewClassicNameServer(dest, d, server.clientIP)
|
server.servers[idx] = NewClassicNameServer(dest, d, server.clientIP)
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return len(server.servers) - 1
|
return len(server.servers) - 1
|
||||||
|
|
|
@ -131,10 +131,10 @@ func (s *service) Register(server *grpc.Server) {
|
||||||
hs := &handlerServer{
|
hs := &handlerServer{
|
||||||
s: s.v,
|
s: s.v,
|
||||||
}
|
}
|
||||||
s.v.RequireFeatures(func(im inbound.Manager, om outbound.Manager) {
|
common.Must(s.v.RequireFeatures(func(im inbound.Manager, om outbound.Manager) {
|
||||||
hs.ihm = im
|
hs.ihm = im
|
||||||
hs.ohm = om
|
hs.ohm = om
|
||||||
})
|
}))
|
||||||
RegisterHandlerServiceServer(server, hs)
|
RegisterHandlerServiceServer(server, hs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,7 @@ func (m *Manager) RemoveHandler(ctx context.Context, tag string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select implements outbound.HandlerSelector.
|
||||||
func (m *Manager) Select(selectors []string) []string {
|
func (m *Manager) Select(selectors []string) []string {
|
||||||
m.access.RLock()
|
m.access.RLock()
|
||||||
defer m.access.RUnlock()
|
defer m.access.RUnlock()
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"v2ray.com/core/transport/pipe"
|
"v2ray.com/core/transport/pipe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Bridge is a component in reverse proxy, that relays connections from Portal to local address.
|
||||||
type Bridge struct {
|
type Bridge struct {
|
||||||
dispatcher routing.Dispatcher
|
dispatcher routing.Dispatcher
|
||||||
tag string
|
tag string
|
||||||
|
@ -22,6 +23,7 @@ type Bridge struct {
|
||||||
monitorTask *task.Periodic
|
monitorTask *task.Periodic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewBridge creates a new Bridge instance.
|
||||||
func NewBridge(config *BridgeConfig, dispatcher routing.Dispatcher) (*Bridge, error) {
|
func NewBridge(config *BridgeConfig, dispatcher routing.Dispatcher) (*Bridge, error) {
|
||||||
if len(config.Tag) == 0 {
|
if len(config.Tag) == 0 {
|
||||||
return nil, newError("bridge tag is empty")
|
return nil, newError("bridge tag is empty")
|
||||||
|
|
|
@ -61,13 +61,13 @@ func (p *Portal) Close() error {
|
||||||
return p.ohm.RemoveHandler(context.Background(), p.tag)
|
return p.ohm.RemoveHandler(context.Background(), p.tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Portal) HandleConnection(ctx context.Context, link *transport.Link) error {
|
func (p *Portal) HandleConnection(ctx context.Context, link *transport.Link) error {
|
||||||
outboundMeta := session.OutboundFromContext(ctx)
|
outboundMeta := session.OutboundFromContext(ctx)
|
||||||
if outboundMeta == nil {
|
if outboundMeta == nil {
|
||||||
return newError("outbound metadata not found").AtError()
|
return newError("outbound metadata not found").AtError()
|
||||||
}
|
}
|
||||||
|
|
||||||
if isDomain(outboundMeta.Target, s.domain) {
|
if isDomain(outboundMeta.Target, p.domain) {
|
||||||
muxClient, err := mux.NewClientWorker(*link, mux.ClientStrategy{})
|
muxClient, err := mux.NewClientWorker(*link, mux.ClientStrategy{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newError("failed to create mux client worker").Base(err).AtWarning()
|
return newError("failed to create mux client worker").Base(err).AtWarning()
|
||||||
|
@ -78,11 +78,11 @@ func (s *Portal) HandleConnection(ctx context.Context, link *transport.Link) err
|
||||||
return newError("failed to create portal worker").Base(err)
|
return newError("failed to create portal worker").Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.picker.AddWorker(worker)
|
p.picker.AddWorker(worker)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.client.Dispatch(ctx, link)
|
return p.client.Dispatch(ctx, link)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Outbound struct {
|
type Outbound struct {
|
||||||
|
|
|
@ -99,7 +99,7 @@ func (r *ReadVReader) readMulti() (MultiBuffer, error) {
|
||||||
if nBytes <= 0 {
|
if nBytes <= 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
end := int32(nBytes)
|
end := nBytes
|
||||||
if end > Size {
|
if end > Size {
|
||||||
end = Size
|
end = Size
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ToTypeMessage converts a proto Message into TypedMessage.
|
// ToTypedMessage converts a proto Message into TypedMessage.
|
||||||
func ToTypedMessage(message proto.Message) *TypedMessage {
|
func ToTypedMessage(message proto.Message) *TypedMessage {
|
||||||
if message == nil {
|
if message == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -21,10 +21,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func hashTimestamp(h hash.Hash, t protocol.Timestamp) []byte {
|
func hashTimestamp(h hash.Hash, t protocol.Timestamp) []byte {
|
||||||
serial.WriteUint64(h, uint64(t))
|
common.Must2(serial.WriteUint64(h, uint64(t)))
|
||||||
serial.WriteUint64(h, uint64(t))
|
common.Must2(serial.WriteUint64(h, uint64(t)))
|
||||||
serial.WriteUint64(h, uint64(t))
|
common.Must2(serial.WriteUint64(h, uint64(t)))
|
||||||
serial.WriteUint64(h, uint64(t))
|
common.Must2(serial.WriteUint64(h, uint64(t)))
|
||||||
return h.Sum(nil)
|
return h.Sum(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue