mirror of https://github.com/v2ray/v2ray-core
fix lint warnings
parent
ceaf5d1178
commit
c3942fd5f0
|
@ -24,7 +24,7 @@ type DokodemoDoor struct {
|
||||||
port v2net.Port
|
port v2net.Port
|
||||||
packetDispatcher dispatcher.PacketDispatcher
|
packetDispatcher dispatcher.PacketDispatcher
|
||||||
tcpListener *internet.TCPHub
|
tcpListener *internet.TCPHub
|
||||||
udpHub *udp.UDPHub
|
udpHub *udp.Hub
|
||||||
udpServer *udp.Server
|
udpServer *udp.Server
|
||||||
meta *proxy.InboundHandlerMeta
|
meta *proxy.InboundHandlerMeta
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ type Server struct {
|
||||||
meta *proxy.InboundHandlerMeta
|
meta *proxy.InboundHandlerMeta
|
||||||
accepting bool
|
accepting bool
|
||||||
tcpHub *internet.TCPHub
|
tcpHub *internet.TCPHub
|
||||||
udpHub *udp.UDPHub
|
udpHub *udp.Hub
|
||||||
udpServer *udp.Server
|
udpServer *udp.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ type Server struct {
|
||||||
packetDispatcher dispatcher.PacketDispatcher
|
packetDispatcher dispatcher.PacketDispatcher
|
||||||
config *ServerConfig
|
config *ServerConfig
|
||||||
tcpListener *internet.TCPHub
|
tcpListener *internet.TCPHub
|
||||||
udpHub *udp.UDPHub
|
udpHub *udp.Hub
|
||||||
udpAddress v2net.Destination
|
udpAddress v2net.Destination
|
||||||
udpServer *udp.Server
|
udpServer *udp.Server
|
||||||
meta *proxy.InboundHandlerMeta
|
meta *proxy.InboundHandlerMeta
|
||||||
|
|
|
@ -83,7 +83,7 @@ type Listener struct {
|
||||||
running bool
|
running bool
|
||||||
sessions map[ConnectionID]*Connection
|
sessions map[ConnectionID]*Connection
|
||||||
awaitingConns chan *Connection
|
awaitingConns chan *Connection
|
||||||
hub *udp.UDPHub
|
hub *udp.Hub
|
||||||
tlsConfig *tls.Config
|
tlsConfig *tls.Config
|
||||||
config *Config
|
config *Config
|
||||||
reader PacketReader
|
reader PacketReader
|
||||||
|
@ -279,7 +279,7 @@ func (v *Listener) Put(internal.ConnectionId, net.Conn) {}
|
||||||
type Writer struct {
|
type Writer struct {
|
||||||
id ConnectionID
|
id ConnectionID
|
||||||
dest v2net.Destination
|
dest v2net.Destination
|
||||||
hub *udp.UDPHub
|
hub *udp.Hub
|
||||||
listener *Listener
|
listener *Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,9 @@ func (v *RawConnection) SysFd() (int, error) {
|
||||||
|
|
||||||
type Connection struct {
|
type Connection struct {
|
||||||
id internal.ConnectionId
|
id internal.ConnectionId
|
||||||
|
reusable bool
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
listener ConnectionManager
|
listener ConnectionManager
|
||||||
reusable bool
|
|
||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,31 +13,35 @@ import (
|
||||||
"v2ray.com/core/transport/internet/internal"
|
"v2ray.com/core/transport/internet/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UDPPayload struct {
|
// Payload represents a single UDP payload.
|
||||||
|
type Payload struct {
|
||||||
payload *buf.Buffer
|
payload *buf.Buffer
|
||||||
session *proxy.SessionInfo
|
session *proxy.SessionInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type UDPPayloadHandler func(*buf.Buffer, *proxy.SessionInfo)
|
// PayloadHandler is function to handle Payload.
|
||||||
|
type PayloadHandler func(*buf.Buffer, *proxy.SessionInfo)
|
||||||
|
|
||||||
type UDPPayloadQueue struct {
|
// PayloadQueue is a queue of Payload.
|
||||||
queue []chan UDPPayload
|
type PayloadQueue struct {
|
||||||
callback UDPPayloadHandler
|
queue []chan Payload
|
||||||
|
callback PayloadHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUDPPayloadQueue(option ListenOption) *UDPPayloadQueue {
|
// NewPayloadQueue returns a new PayloadQueue.
|
||||||
queue := &UDPPayloadQueue{
|
func NewPayloadQueue(option ListenOption) *PayloadQueue {
|
||||||
|
queue := &PayloadQueue{
|
||||||
callback: option.Callback,
|
callback: option.Callback,
|
||||||
queue: make([]chan UDPPayload, option.Concurrency),
|
queue: make([]chan Payload, option.Concurrency),
|
||||||
}
|
}
|
||||||
for i := range queue.queue {
|
for i := range queue.queue {
|
||||||
queue.queue[i] = make(chan UDPPayload, 64)
|
queue.queue[i] = make(chan Payload, 64)
|
||||||
go queue.Dequeue(queue.queue[i])
|
go queue.Dequeue(queue.queue[i])
|
||||||
}
|
}
|
||||||
return queue
|
return queue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *UDPPayloadQueue) Enqueue(payload UDPPayload) {
|
func (v *PayloadQueue) Enqueue(payload Payload) {
|
||||||
size := len(v.queue)
|
size := len(v.queue)
|
||||||
idx := 0
|
idx := 0
|
||||||
if size > 1 {
|
if size > 1 {
|
||||||
|
@ -53,33 +57,33 @@ func (v *UDPPayloadQueue) Enqueue(payload UDPPayload) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *UDPPayloadQueue) Dequeue(queue <-chan UDPPayload) {
|
func (v *PayloadQueue) Dequeue(queue <-chan Payload) {
|
||||||
for payload := range queue {
|
for payload := range queue {
|
||||||
v.callback(payload.payload, payload.session)
|
v.callback(payload.payload, payload.session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *UDPPayloadQueue) Close() {
|
func (v *PayloadQueue) Close() {
|
||||||
for _, queue := range v.queue {
|
for _, queue := range v.queue {
|
||||||
close(queue)
|
close(queue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListenOption struct {
|
type ListenOption struct {
|
||||||
Callback UDPPayloadHandler
|
Callback PayloadHandler
|
||||||
ReceiveOriginalDest bool
|
ReceiveOriginalDest bool
|
||||||
Concurrency int
|
Concurrency int
|
||||||
}
|
}
|
||||||
|
|
||||||
type UDPHub struct {
|
type Hub struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
cancel *signal.CancelSignal
|
cancel *signal.CancelSignal
|
||||||
queue *UDPPayloadQueue
|
queue *PayloadQueue
|
||||||
option ListenOption
|
option ListenOption
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*UDPHub, error) {
|
func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*Hub, error) {
|
||||||
if option.Concurrency < 1 {
|
if option.Concurrency < 1 {
|
||||||
option.Concurrency = 1
|
option.Concurrency = 1
|
||||||
}
|
}
|
||||||
|
@ -102,9 +106,9 @@ func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*UD
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hub := &UDPHub{
|
hub := &Hub{
|
||||||
conn: udpConn,
|
conn: udpConn,
|
||||||
queue: NewUDPPayloadQueue(option),
|
queue: NewPayloadQueue(option),
|
||||||
option: option,
|
option: option,
|
||||||
cancel: signal.NewCloseSignal(),
|
cancel: signal.NewCloseSignal(),
|
||||||
}
|
}
|
||||||
|
@ -112,7 +116,7 @@ func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*UD
|
||||||
return hub, nil
|
return hub, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *UDPHub) Close() {
|
func (v *Hub) Close() {
|
||||||
v.Lock()
|
v.Lock()
|
||||||
defer v.Unlock()
|
defer v.Unlock()
|
||||||
|
|
||||||
|
@ -122,14 +126,14 @@ func (v *UDPHub) Close() {
|
||||||
v.queue.Close()
|
v.queue.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *UDPHub) WriteTo(payload []byte, dest v2net.Destination) (int, error) {
|
func (v *Hub) WriteTo(payload []byte, dest v2net.Destination) (int, error) {
|
||||||
return v.conn.WriteToUDP(payload, &net.UDPAddr{
|
return v.conn.WriteToUDP(payload, &net.UDPAddr{
|
||||||
IP: dest.Address.IP(),
|
IP: dest.Address.IP(),
|
||||||
Port: int(dest.Port),
|
Port: int(dest.Port),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *UDPHub) start() {
|
func (v *Hub) start() {
|
||||||
v.cancel.WaitThread()
|
v.cancel.WaitThread()
|
||||||
defer v.cancel.FinishThread()
|
defer v.cancel.FinishThread()
|
||||||
|
|
||||||
|
@ -156,23 +160,23 @@ func (v *UDPHub) start() {
|
||||||
if v.option.ReceiveOriginalDest && noob > 0 {
|
if v.option.ReceiveOriginalDest && noob > 0 {
|
||||||
session.Destination = RetrieveOriginalDest(oobBytes[:noob])
|
session.Destination = RetrieveOriginalDest(oobBytes[:noob])
|
||||||
}
|
}
|
||||||
v.queue.Enqueue(UDPPayload{
|
v.queue.Enqueue(Payload{
|
||||||
payload: buffer,
|
payload: buffer,
|
||||||
session: session,
|
session: session,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *UDPHub) Running() bool {
|
func (v *Hub) Running() bool {
|
||||||
return !v.cancel.Cancelled()
|
return !v.cancel.Cancelled()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connection return the net.Conn underneath v hub.
|
// Connection return the net.Conn underneath this hub.
|
||||||
// Private: Visible for testing only
|
// Private: Visible for testing only
|
||||||
func (v *UDPHub) Connection() net.Conn {
|
func (v *Hub) Connection() net.Conn {
|
||||||
return v.conn
|
return v.conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *UDPHub) Addr() net.Addr {
|
func (v *Hub) Addr() net.Addr {
|
||||||
return v.conn.LocalAddr()
|
return v.conn.LocalAddr()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue