-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BugFix 🐛 Fix both latency and packet manipulation proxies connectivity
- Loading branch information
Showing
12 changed files
with
131 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,43 @@ | ||
package helper | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func ReqSimulator( | ||
targetAddr string, | ||
duration time.Duration, | ||
) error { | ||
endTime := time.Now().Add(duration) | ||
|
||
for time.Now().Before(endTime) { | ||
conn, err := net.Dial("tcp", ":"+targetAddr) | ||
if err != nil { | ||
log.Printf("Failed to connect to target: %v", err) | ||
return err | ||
} | ||
|
||
request := "GET / HTTP/1.1\r\n" + | ||
"Host: " + targetAddr + "\r\n" + | ||
"Connection: close\r\n" + | ||
"\r\n" | ||
func sendReq(client *http.Client, targetAddr string) { | ||
resp, err := client.Get("http://127.0.0.1:" + targetAddr) | ||
if err != nil { | ||
log.Printf("Failed to send request: %v", err) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
_, err = conn.Write([]byte(request)) | ||
if err != nil { | ||
log.Printf("Failed to write to target: %v", err) | ||
conn.Close() | ||
return err | ||
} | ||
if resp == nil { | ||
log.Println("Response is nil") | ||
return | ||
} | ||
|
||
buf := make([]byte, 1024) | ||
n, err := conn.Read(buf) | ||
if err != nil { | ||
log.Printf("Failed to read from target: %v", err) | ||
conn.Close() | ||
return err | ||
} | ||
log.Printf("Response status: %s", resp.Status) | ||
time.Sleep(2 * time.Second) | ||
} | ||
|
||
log.Printf("Received response: %s", string(buf[:n])) | ||
func ReqSimulator(targetAddr string, oneTime bool, duration time.Duration) error { | ||
client := &http.Client{} | ||
|
||
conn.Close() | ||
if oneTime { | ||
sendReq(client, targetAddr) | ||
} else { | ||
startTime := time.Now() | ||
endTime := startTime.Add(duration - 3*time.Second) | ||
|
||
time.Sleep(1 * time.Second) | ||
for time.Now().Before(endTime) { | ||
sendReq(client, targetAddr) | ||
} | ||
} | ||
|
||
fmt.Println("Timeout reached, stopping the requests.") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: my-express-app | ||
namespace: default | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: my-express-app | ||
template: | ||
metadata: | ||
labels: | ||
app: my-express-app | ||
spec: | ||
containers: | ||
- name: my-express | ||
image: lumbrjx/my-express:latest # Use the name and tag of your Docker image | ||
ports: | ||
- containerPort: 8080 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: my-express-app-service | ||
namespace: default | ||
spec: | ||
selector: | ||
app: my-express-app | ||
ports: | ||
- protocol: TCP | ||
port: 8080 | ||
targetPort: 8080 | ||
type: ClusterIP | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ spec: | |
- protocol: TCP | ||
port: 8080 | ||
targetPort: 8080 | ||
type: LoadBalancer | ||
type: NodePort | ||
|