Chore: improve code architecture

This commit is contained in:
Dreamacro
2018-11-21 13:47:46 +08:00
parent 91e35f2f6a
commit 01a477bd3d
37 changed files with 926 additions and 990 deletions

View File

@ -4,7 +4,6 @@ import (
"net"
"github.com/Dreamacro/clash/adapters/inbound"
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/tunnel"
log "github.com/sirupsen/logrus"
@ -14,18 +13,14 @@ var (
tun = tunnel.Instance()
)
func NewRedirProxy(addr string) (*C.ProxySignal, error) {
func NewRedirProxy(addr string) (chan<- struct{}, <-chan struct{}, error) {
l, err := net.Listen("tcp", addr)
if err != nil {
return nil, err
return nil, nil, err
}
done := make(chan struct{})
closed := make(chan struct{})
signal := &C.ProxySignal{
Done: done,
Closed: closed,
}
go func() {
log.Infof("Redir proxy listening at: %s", addr)
@ -43,12 +38,11 @@ func NewRedirProxy(addr string) (*C.ProxySignal, error) {
go func() {
<-done
close(done)
l.Close()
closed <- struct{}{}
}()
return signal, nil
return done, closed, nil
}
func handleRedir(conn net.Conn) {