mirror of https://github.com/v2ray/v2ray-core
comments and refactoring
parent
278fd7261e
commit
862f9a152e
|
@ -19,6 +19,7 @@ type Manager struct {
|
|||
running bool
|
||||
}
|
||||
|
||||
// New returns a new Manager for inbound handlers.
|
||||
func New(ctx context.Context, config *proxyman.InboundConfig) (*Manager, error) {
|
||||
m := &Manager{
|
||||
taggedHandlers: make(map[string]core.InboundHandler),
|
||||
|
@ -33,6 +34,7 @@ func New(ctx context.Context, config *proxyman.InboundConfig) (*Manager, error)
|
|||
return m, nil
|
||||
}
|
||||
|
||||
// AddHandler implements core.InboundHandlerManager.
|
||||
func (m *Manager) AddHandler(ctx context.Context, handler core.InboundHandler) error {
|
||||
m.access.Lock()
|
||||
defer m.access.Unlock()
|
||||
|
@ -51,6 +53,7 @@ func (m *Manager) AddHandler(ctx context.Context, handler core.InboundHandler) e
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetHandler returns core.InboundHandlerManager.
|
||||
func (m *Manager) GetHandler(ctx context.Context, tag string) (core.InboundHandler, error) {
|
||||
m.access.RLock()
|
||||
defer m.access.RUnlock()
|
||||
|
|
|
@ -152,7 +152,7 @@ func (*udpConn) SetWriteDeadline(time.Time) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type connId struct {
|
||||
type connID struct {
|
||||
src net.Destination
|
||||
dest net.Destination
|
||||
}
|
||||
|
@ -169,10 +169,10 @@ type udpWorker struct {
|
|||
dispatcher core.Dispatcher
|
||||
|
||||
done *signal.Done
|
||||
activeConn map[connId]*udpConn
|
||||
activeConn map[connID]*udpConn
|
||||
}
|
||||
|
||||
func (w *udpWorker) getConnection(id connId) (*udpConn, bool) {
|
||||
func (w *udpWorker) getConnection(id connID) (*udpConn, bool) {
|
||||
w.Lock()
|
||||
defer w.Unlock()
|
||||
|
||||
|
@ -202,7 +202,7 @@ func (w *udpWorker) getConnection(id connId) (*udpConn, bool) {
|
|||
}
|
||||
|
||||
func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest net.Destination) {
|
||||
id := connId{
|
||||
id := connID{
|
||||
src: source,
|
||||
dest: originalDest,
|
||||
}
|
||||
|
@ -235,14 +235,14 @@ func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest
|
|||
}
|
||||
}
|
||||
|
||||
func (w *udpWorker) removeConn(id connId) {
|
||||
func (w *udpWorker) removeConn(id connID) {
|
||||
w.Lock()
|
||||
delete(w.activeConn, id)
|
||||
w.Unlock()
|
||||
}
|
||||
|
||||
func (w *udpWorker) Start() error {
|
||||
w.activeConn = make(map[connId]*udpConn, 16)
|
||||
w.activeConn = make(map[connID]*udpConn, 16)
|
||||
w.done = signal.NewDone()
|
||||
h, err := udp.ListenUDP(w.address, w.port, udp.ListenOption{
|
||||
Callback: w.callback,
|
||||
|
|
Loading…
Reference in New Issue