From fc4bf82171d7337c9db1ce91e553a3b9a97beb02 Mon Sep 17 00:00:00 2001 From: Brandon Wiley Date: Wed, 16 Nov 2016 15:10:16 -0600 Subject: Added new command line flags and refactored ClientSetup to use them --- modes/transparent_udp/transparent_udp.go | 61 ++++++++++++-------------------- 1 file changed, 22 insertions(+), 39 deletions(-) (limited to 'modes/transparent_udp') diff --git a/modes/transparent_udp/transparent_udp.go b/modes/transparent_udp/transparent_udp.go index d7ee938..f9c2efc 100644 --- a/modes/transparent_udp/transparent_udp.go +++ b/modes/transparent_udp/transparent_udp.go @@ -30,15 +30,15 @@ package transparent_udp import ( - "io" + "bytes" + "encoding/binary" "fmt" + "io" golog "log" "net" "net/url" "strconv" "strings" - "bytes" - "encoding/binary" "golang.org/x/net/proxy" @@ -50,15 +50,13 @@ import ( ) const ( - obfs4proxyVersion = "0.0.7-dev" - obfs4proxyLogFile = "obfs4proxy.log" - socksAddr = "127.0.0.1:1234" + socksAddr = "127.0.0.1:1234" ) var stateDir string type ConnState struct { - Conn *net.Conn + Conn *net.Conn Waiting bool } @@ -68,24 +66,9 @@ func NewConnState() ConnState { type ConnTracker map[string]ConnState -func ClientSetup(termMon *termmon.TermMonitor, target string) bool { - methodNames := [...]string{"obfs2"} - var ptClientProxy *url.URL = nil - +func ClientSetup(termMon *termmon.TermMonitor, target string, ptClientProxy *url.URL, factories map[string]base.ClientFactory) bool { // Launch each of the client listeners. - for _, name := range methodNames { - t := transports.Get(name) - if t == nil { - log.Errorf("no such transport is supported: %s", name) - continue - } - - f, err := t.ClientFactory(stateDir) - if err != nil { - log.Errorf("failed to get ClientFactory: %s", name) - continue - } - + for name, f := range factories { udpAddr, err := net.ResolveUDPAddr("udp", socksAddr) if err != nil { fmt.Println("Error resolving address", socksAddr) @@ -107,7 +90,7 @@ func ClientSetup(termMon *termmon.TermMonitor, target string) bool { } func clientHandler(target string, termMon *termmon.TermMonitor, f base.ClientFactory, conn *net.UDPConn, proxyURI *url.URL) { - var length16 uint16 + var length16 uint16 defer conn.Close() termMon.OnHandlerStart() @@ -115,24 +98,24 @@ func clientHandler(target string, termMon *termmon.TermMonitor, f base.ClientFac fmt.Println("@@@ handling...") - tracker := make(ConnTracker) + tracker := make(ConnTracker) name := f.Transport().Name() fmt.Println("Transport is", name) - buf := make([]byte, 1024) + buf := make([]byte, 1024) - // Receive UDP packets and forward them over transport connections forever + // Receive UDP packets and forward them over transport connections forever for { n, addr, err := conn.ReadFromUDP(buf) - fmt.Println("Received ",string(buf[0:n]), " from ",addr) + fmt.Println("Received ", string(buf[0:n]), " from ", addr) if err != nil { - fmt.Println("Error: ",err) + fmt.Println("Error: ", err) } - fmt.Println(tracker) + fmt.Println(tracker) if state, ok := tracker[addr.String()]; ok { // There is an open transport connection, or a connection attempt is in progress. @@ -158,11 +141,11 @@ func clientHandler(target string, termMon *termmon.TermMonitor, f base.ClientFac (*state.Conn).Write(buf) } } - } else { + } else { // There is not an open transport connection and a connection attempt is not in progress. // Open a transport connection. - fmt.Println("Opening connection to ", target) + fmt.Println("Opening connection to ", target) openConnection(&tracker, addr.String(), target, termMon, f, proxyURI) @@ -176,7 +159,7 @@ func openConnection(tracker *ConnTracker, addr string, target string, termMon *t fmt.Println("Making dialer...") newConn := NewConnState() - (*tracker)[addr]=newConn + (*tracker)[addr] = newConn go dialConn(tracker, addr, target, f, proxyURI) } @@ -219,7 +202,7 @@ func dialConn(tracker *ConnTracker, addr string, target string, f base.ClientFac fmt.Println("Success") - (*tracker)[addr]=ConnState{&remote, false} + (*tracker)[addr] = ConnState{&remote, false} } func ServerSetup(termMon *termmon.TermMonitor, bindaddrString string, target string) bool { @@ -357,7 +340,7 @@ func serverHandler(termMon *termmon.TermMonitor, f base.ServerFactory, conn net. return } - serverAddr, err := net.ResolveUDPAddr("udp",target) + serverAddr, err := net.ResolveUDPAddr("udp", target) if err != nil { golog.Fatal(err) } @@ -372,7 +355,7 @@ func serverHandler(termMon *termmon.TermMonitor, f base.ServerFactory, conn net. golog.Fatal(err) } - fmt.Println("pumping") + fmt.Println("pumping") defer dest.Close() @@ -381,7 +364,7 @@ func serverHandler(termMon *termmon.TermMonitor, f base.ServerFactory, conn net. for { fmt.Println("reading...") // Read the incoming connection into the buffer. - readLen, err := io.ReadFull(remote, lengthBuffer) + readLen, err := io.ReadFull(remote, lengthBuffer) if err != nil { fmt.Println("read error") break @@ -405,5 +388,5 @@ func serverHandler(termMon *termmon.TermMonitor, f base.ServerFactory, conn net. } dest.Write(readBuffer) - } + } } -- cgit v1.2.3