From e52258edac55d82ff153755493d770bfbbc9a346 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Thu, 29 Oct 2015 14:09:34 +0000 Subject: Make establishing outgoing connections the transport's responsibility. ClientFactories now have a Dial() method instead of a WrapConn() method, so that it is possible to write something like meek-client using the obfs4proxy framework. This breaks the external interface if anyone is using obfs4proxy as a library, but the new way of doing things is a trivial modification, to a single routine that shouldn't have been very large to begin with. --- obfs4proxy/obfs4proxy.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'obfs4proxy/obfs4proxy.go') diff --git a/obfs4proxy/obfs4proxy.go b/obfs4proxy/obfs4proxy.go index a817583..5c23ba2 100644 --- a/obfs4proxy/obfs4proxy.go +++ b/obfs4proxy/obfs4proxy.go @@ -155,22 +155,13 @@ func clientHandler(f base.ClientFactory, conn net.Conn, proxyURI *url.URL) { } dialFn = dialer.Dial } - remoteConn, err := dialFn("tcp", socksReq.Target) // XXX: Allow UDP? + remote, err := f.Dial("tcp", socksReq.Target, dialFn, args) if err != nil { log.Errorf("%s(%s) - outgoing connection failed: %s", name, addrStr, log.ElideError(err)) socksReq.Reply(socks5.ErrorToReplyCode(err)) return } - defer remoteConn.Close() - - // Instantiate the client transport method, handshake, and start pushing - // bytes back and forth. - remote, err := f.WrapConn(remoteConn, args) - if err != nil { - log.Errorf("%s(%s) - handshake failed: %s", name, addrStr, log.ElideError(err)) - socksReq.Reply(socks5.ReplyGeneralFailure) - return - } + defer remote.Close() err = socksReq.Reply(socks5.ReplySucceeded) if err != nil { log.Errorf("%s(%s) - SOCKS reply failed: %s", name, addrStr, log.ElideError(err)) -- cgit v1.2.3