comments and refactoring

pull/861/head
Darien Raymond 2018-02-08 22:09:55 +01:00
parent 278fd7261e
commit 862f9a152e
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 9 additions and 6 deletions

View File

@ -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()

View File

@ -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,