diff --git a/Dockerfile b/Dockerfile index 38c5228..678c431 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,16 @@ -FROM golang:1.5 +FROM google/golang:1.4 -RUN cd /go/src/ && GOOS=linux GOARCH=386 ./make.bash --no-clean +RUN cd /goroot/src/ && GOOS=linux GOARCH=386 ./make.bash --no-clean RUN apt-get update && apt-get install ruby vim-common -y +# Install Java +# RUN apt-get install -y software-properties-common python-software-properties +# RUN add-apt-repository -y ppa:webupd8team/java +# RUN apt-get update -y +# RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections +# RUN apt-get install -y oracle-java8-installer + WORKDIR /gopath/src/github.com/buger/gor/ ADD . /gopath/src/github.com/buger/gor/ diff --git a/Makefile b/Makefile index 3addd1a..29de44d 100644 --- a/Makefile +++ b/Makefile @@ -37,10 +37,13 @@ dbench: # Used mainly for debugging, because docker container do not have access to parent machine ports drun: - docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-dummy=0 --output-http="http://localhost:9000" --input-raw :9000 --input-http :9000 --verbose --debug + docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-dummy=0 --output-http="http://localhost:9000" --input-raw :9000 --input-http :9000 --verbose --debug --middleware "./examples/middleware/echo.sh" + +drun-2: + docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-file="./fixtures/requests.gor" --output-dummy --verbose --debug --middleware "./examples/middleware/echo.sh" drecord: - docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose + docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-dummy=0 --output-file=requests.gor --verbose --debug dreplay: docker run -v `pwd`:$(SOURCE_PATH) -t -i gor go run $(SOURCE) --input-file=requests.bin --output-tcp=:9000 --verbose -h diff --git a/examples/middleware/echo.java b/examples/middleware/echo.java new file mode 100644 index 0000000..e37cf72 --- /dev/null +++ b/examples/middleware/echo.java @@ -0,0 +1,30 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.apache.commons.io.IOUtils; + +public class Echo { + public static void main(String[] args) { + if(args != null){ + for(String arg : args){ + System.out.println(arg); + } + + } + + BufferedReader stdin = new BufferedReader(new InputStreamReader( + System.in)); + String line = null; + + try { + while ((line = stdin.readLine()) != null) { + + System.out.println(line); + + } + } catch (IOException e) { + IOUtils.closeQuietly(stdin); + } + } +} \ No newline at end of file diff --git a/examples/middleware/echo_modifier.rb b/examples/middleware/echo.rb similarity index 100% rename from examples/middleware/echo_modifier.rb rename to examples/middleware/echo.rb diff --git a/examples/middleware/echo_modifier.sh b/examples/middleware/echo.sh similarity index 100% rename from examples/middleware/echo_modifier.sh rename to examples/middleware/echo.sh diff --git a/input_dummy.go b/input_dummy.go index 4c14830..17907d3 100644 --- a/input_dummy.go +++ b/input_dummy.go @@ -22,11 +22,9 @@ func NewDummyInput(options string) (di *DummyInput) { func (i *DummyInput) Read(data []byte) (int, error) { buf := <-i.data - header := payloadHeader(RequestPayload, uuid(), time.Now().UnixNano()) - copy(data[0:len(header)], header) - copy(data[len(header):], buf) + copy(data, buf) - return len(buf) + len(header), nil + return len(buf), nil } func (i *DummyInput) emit() { @@ -35,7 +33,12 @@ func (i *DummyInput) emit() { for { select { case <-ticker.C: - i.data <- []byte("POST /pub/WWW/å HTTP/1.1\nHost: www.w3.org\r\n\r\na=1&b=2") + uuid := uuid() + reqh := payloadHeader(RequestPayload, uuid, time.Now().UnixNano()) + i.data <- append(reqh, []byte("POST /pub/WWW/å HTTP/1.1\nHost: www.w3.org\r\nContent-Length: 7\r\n\r\na=1&b=2")...) + + resh := payloadHeader(ResponsePayload, uuid, 1) + i.data <- append(resh, []byte("HTTP/1.1 200 OK\r\n\r\n")...) } } } diff --git a/input_file.go b/input_file.go index 24ebd2d..60ec958 100644 --- a/input_file.go +++ b/input_file.go @@ -80,4 +80,6 @@ func (i *FileInput) emit() { i.data <- newBuf } + + log.Println("FileInput: end of file") } diff --git a/input_http.go b/input_http.go index 5150c4e..f7717c5 100644 --- a/input_http.go +++ b/input_http.go @@ -5,6 +5,7 @@ import ( "net" "net/http" "net/http/httputil" + "time" ) // HTTPInput used for sending requests to Gor via http @@ -27,9 +28,13 @@ func NewHTTPInput(address string) (i *HTTPInput) { func (i *HTTPInput) Read(data []byte) (int, error) { buf := <-i.data - copy(data, buf) - return len(buf), nil + header := payloadHeader(RequestPayload, uuid(), time.Now().UnixNano()) + + copy(data[0:len(header)], header) + copy(data[len(header):], buf) + + return len(buf) + len(header), nil } func (i *HTTPInput) handler(w http.ResponseWriter, r *http.Request) { diff --git a/input_raw.go b/input_raw.go index 7ce6a30..ed14707 100644 --- a/input_raw.go +++ b/input_raw.go @@ -10,10 +10,10 @@ import ( // RAWInput used for intercepting traffic for given address type RAWInput struct { - data chan *raw.TCPMessage - address string - expire time.Duration - quit chan bool + data chan *raw.TCPMessage + address string + expire time.Duration + quit chan bool listener *raw.Listener } diff --git a/input_raw_test.go b/input_raw_test.go index 4c7c1ad..fbe47e4 100644 --- a/input_raw_test.go +++ b/input_raw_test.go @@ -26,9 +26,8 @@ func TestRAWInput(t *testing.T) { defer origin.Close() originAddr := strings.Replace(origin.Listener.Addr().String(), "[::]", "127.0.0.1", -1) - var respCounter, reqCounter int64 - defer func(){ + defer func() { log.Println(reqCounter, respCounter) }() diff --git a/middleware_test.go b/middleware_test.go index c94154d..8474eeb 100644 --- a/middleware_test.go +++ b/middleware_test.go @@ -113,7 +113,7 @@ func TestEchoMiddleware(t *testing.T) { quit := make(chan int) - Settings.middleware = "./examples/middleware/echo_modifier.sh" + Settings.middleware = "./examples/middleware/echo.sh" // Catch traffic from one service input := NewRAWInput(from.Listener.Addr().String(), testRawExpire) diff --git a/output_http.go b/output_http.go index 0f57ea9..0528e38 100644 --- a/output_http.go +++ b/output_http.go @@ -41,9 +41,9 @@ type HTTPOutput struct { // aligned at 64bit. See https://github.com/golang/go/issues/599 activeWorkers int64 - address string - limit int - queue chan []byte + address string + limit int + queue chan []byte responses chan response @@ -173,7 +173,7 @@ func (o *HTTPOutput) Write(data []byte) (n int, err error) { func (o *HTTPOutput) Read(data []byte) (int, error) { resp := <-o.responses - Debug("[OUTPUT-HTTP] Received response", string(resp.payload)) + Debug("[OUTPUT-HTTP] Received response:", string(resp.payload)) header := payloadHeader(ReplayedResponsePayload, resp.uuid, resp.roundTripTime) copy(data[0:len(header)], header) diff --git a/raw_socket_listener/listener.go b/raw_socket_listener/listener.go index 5459019..4fe232d 100644 --- a/raw_socket_listener/listener.go +++ b/raw_socket_listener/listener.go @@ -19,8 +19,8 @@ import ( "net" "runtime/debug" "strconv" - "time" "strings" + "time" ) // Listener handle traffic capture diff --git a/raw_socket_listener/tcp_message.go b/raw_socket_listener/tcp_message.go index 5800534..cabac1d 100644 --- a/raw_socket_listener/tcp_message.go +++ b/raw_socket_listener/tcp_message.go @@ -7,8 +7,8 @@ import ( "github.com/buger/gor/proto" "log" "strconv" - "time" "sync" + "time" ) // TCPMessage ensure that all TCP packets for given request is received, and processed in right sequence