From de7727fd9aa7f84baeac0cda4a7f4408c3e551b3 Mon Sep 17 00:00:00 2001 From: Brandon Wiley Date: Wed, 22 Feb 2017 12:00:59 -0600 Subject: Removed obsolete client factories --- shapeshifter-dispatcher/shapeshifter-dispatcher.go | 68 ++-------------------- transports/transports.go | 52 +---------------- 2 files changed, 7 insertions(+), 113 deletions(-) diff --git a/shapeshifter-dispatcher/shapeshifter-dispatcher.go b/shapeshifter-dispatcher/shapeshifter-dispatcher.go index 00fd024..74b9027 100644 --- a/shapeshifter-dispatcher/shapeshifter-dispatcher.go +++ b/shapeshifter-dispatcher/shapeshifter-dispatcher.go @@ -143,10 +143,6 @@ func main() { if err = log.Init(*enableLogging, path.Join(stateDir, dispatcherLogFile), *unsafeLogging); err != nil { golog.Fatalf("[ERROR]: %s - failed to initialize logging", execName) } - if err = transports.Init(); err != nil { - log.Errorf("%s - failed to initialize transports: %s", execName, err) - os.Exit(-1) - } log.Noticef("%s - launched", getVersion()) fmt.Println("launching") @@ -162,15 +158,7 @@ func main() { log.Errorf("%s - transparent mode requires a target", execName) } else { fmt.Println("transparent udp client") - ptClientProxy, factories := getClientFactories(ptversion, transportsList, proxy) - - names := make([]string, len(factories)) - - i := 0 - for k := range factories { - names[i] = k - i++ - } + ptClientProxy, names := getClientNames(ptversion, transportsList, proxy) launched = transparent_udp.ClientSetup(termMon, *target, ptClientProxy, names, *options) } @@ -195,15 +183,7 @@ func main() { if *target == "" { log.Errorf("%s - transparent mode requires a target", execName) } else { - ptClientProxy, factories := getClientFactories(ptversion, transportsList, proxy) - - names := make([]string, len(factories)) - - i := 0 - for k := range factories { - names[i] = k - i++ - } + ptClientProxy, names := getClientNames(ptversion, transportsList, proxy) launched, clientListeners = transparent_tcp.ClientSetup(termMon, *target, ptClientProxy, names, *options) } @@ -227,15 +207,7 @@ func main() { log.Errorf("%s - STUN mode requires a target", execName) } else { fmt.Println("STUN udp client") - ptClientProxy, factories := getClientFactories(ptversion, transportsList, proxy) - - names := make([]string, len(factories)) - - i := 0 - for k := range factories { - names[i] = k - i++ - } + ptClientProxy, names := getClientNames(ptversion, transportsList, proxy) launched = stun_udp.ClientSetup(termMon, *target, ptClientProxy, names, *options) } @@ -255,15 +227,7 @@ func main() { log.Infof("%s - initializing PT 2.0 proxy", execName) if isClient { log.Infof("%s - initializing client transport listeners", execName) - ptClientProxy, factories := getClientFactories(ptversion, transportsList, proxy) - - names := make([]string, len(factories)) - - i := 0 - for k := range factories { - names[i] = k - i++ - } + ptClientProxy, names := getClientNames(ptversion, transportsList, proxy) launched, clientListeners = pt_socks5.ClientSetup(termMon, *target, ptClientProxy, names, *options) } else { @@ -334,7 +298,7 @@ func makeStateDir(statePath string) (string, error) { } } -func getClientFactories(ptversion *string, transportsList *string, proxy *string) (clientProxy *url.URL, factories map[string]base.ClientFactory) { +func getClientNames(ptversion *string, transportsList *string, proxy *string) (clientProxy *url.URL, names []string) { var ptClientInfo pt.ClientInfo var err error @@ -362,27 +326,7 @@ func getClientFactories(ptversion *string, transportsList *string, proxy *string pt_extras.PtProxyDone() } - factories = make(map[string]base.ClientFactory) - - // Launch each of the client listeners. - for _, name := range ptClientInfo.MethodNames { - t := transports.Get(name) - if t == nil { - pt.CmethodError(name, "no such transport is supported") - continue - } - - // FIXME - stateDir parameter must be moved to transport initializer - f := t.Dial - if err != nil { - pt.CmethodError(name, "failed to get ClientFactory") - continue - } - - factories[name] = f - } - - return ptClientProxy, factories + return ptClientProxy, ptClientInfo.MethodNames } func getServerInfo(ptversion *string, bindaddrList *string, options *string, transportList *string, orport *string, extorport *string, authcookie *string) pt.ServerInfo { diff --git a/transports/transports.go b/transports/transports.go index fefda45..f580770 100644 --- a/transports/transports.go +++ b/transports/transports.go @@ -29,57 +29,7 @@ // transports. package transports -import ( - "fmt" - "sync" - - "github.com/OperatorFoundation/shapeshifter-transports/transports/base" - "github.com/OperatorFoundation/shapeshifter-transports/transports/obfs2" -) - -var transportMapLock sync.Mutex -var transportMap map[string]base.Transport = make(map[string]base.Transport) - -// Register registers a transport protocol. -func Register(name string, transport base.Transport) error { - transportMapLock.Lock() - defer transportMapLock.Unlock() - - _, registered := transportMap[name] - if registered { - return fmt.Errorf("transport '%s' already registered", name) - } - transportMap[name] = transport - - return nil -} - // Transports returns the list of registered transport protocols. func Transports() []string { - transportMapLock.Lock() - defer transportMapLock.Unlock() - - var ret []string - for name := range transportMap { - ret = append(ret, name) - } - - return ret -} - -// Get returns a transport protocol implementation by name. -func Get(name string) base.Transport { - transportMapLock.Lock() - defer transportMapLock.Unlock() - - t := transportMap[name] - - return t -} - -// Init initializes all of the integrated transports. -func Init() error { - Register("obfs2", obfs2.NewObfs2Transport()) - - return nil + return []string{"obfs2", "meeklite", "obfs4"} } -- cgit v1.2.3