Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc #42

Merged
merged 5 commits into from
Oct 16, 2024
Merged

Misc #42

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/walletshield/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
warped?=true
ldflags="-X github.com/katzenpost/katzenpost/core/epochtime.WarpedEpoch=${warped}"

.PHONY: all
all:
sh -c 'go build -ldflags ${ldflags};'
go build -trimpath -ldflags ${ldflags}

.PHONY: clean
clean:
rm app-walletshield
rm -f walletshield
14 changes: 10 additions & 4 deletions apps/walletshield/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

var (
timeout = time.Second * 200
timeout = time.Second * 45
ProxyHTTPService = "http_proxy"
)

Expand Down Expand Up @@ -66,6 +66,7 @@ func main() {
var delayStart int
var testProbe bool
var testProbeCount int
var testProbeResponseDelay int

flag.StringVar(&configPath, "config", "", "file path of the client configuration TOML file")
flag.IntVar(&delayStart, "delay_start", 0, "max random seconds to delay start")
Expand All @@ -74,6 +75,7 @@ func main() {
flag.StringVar(&listenAddrClient, "listen_client", "", "local network address for the client daemon")
flag.BoolVar(&testProbe, "probe", false, "send test probes instead of handling requests")
flag.IntVar(&testProbeCount, "probe_count", 1, "number of test probes to send")
flag.IntVar(&testProbeResponseDelay, "probe_response_delay", 0, "test probe response deplay")
flag.Parse()

if listenAddr == "" && !testProbe {
Expand Down Expand Up @@ -134,7 +136,7 @@ func main() {
}

if testProbe {
server.SendTestProbes(10*time.Second, testProbeCount)
server.SendTestProbes(10*time.Second, testProbeCount, testProbeResponseDelay)
} else {
http.HandleFunc("/", server.Handler)
err := http.ListenAndServe(listenAddr, nil)
Expand Down Expand Up @@ -203,8 +205,9 @@ func (s *Server) Handler(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, string(response.Payload))
}

func (s *Server) SendTestProbes(d time.Duration, testProbeCount int) {
req, err := http.NewRequest("GET", "http://nowhere/_/probe", nil)
func (s *Server) SendTestProbes(d time.Duration, testProbeCount int, testProbeResponseDelay int) {
url := fmt.Sprintf("http://nowhere/_/probe/%d", testProbeResponseDelay)
req, err := http.NewRequest("GET", url, nil)
buf := new(bytes.Buffer)
req.Write(buf)
request := new(http_proxy.Request)
Expand Down Expand Up @@ -239,6 +242,9 @@ func (s *Server) SendTestProbes(d time.Duration, testProbeCount int) {

packetLoss := float64(packetsTransmitted-packetsReceived) / float64(packetsTransmitted) * 100
rttAvg := rttTotal / float64(packetsReceived)
if packetsReceived == 0 {
rttMin = math.NaN()
}
s.log.Infof("Probe packet transmitted/received/loss = %d/%d/%.1f%% | rtt min/avg/max = %.2f/%.2f/%.2f s",
packetsTransmitted, packetsReceived, packetLoss, rttMin, rttAvg, rttMax)

Expand Down
14 changes: 13 additions & 1 deletion server_plugins/cbor_plugins/http_proxy/cmd/http_proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"

"github.com/fxamacker/cbor/v2"
"gopkg.in/op/go-logging.v1"
Expand Down Expand Up @@ -151,7 +155,15 @@ func (s *proxyRequestHandler) OnCommand(cmd cborplugin.Command) error {
return s.sendError(r.ID, r.SURB, fmt.Sprintf("validateRequestURL failed: %s", err.Error()))
}

if request.URL.Path == "/_/probe" {
if match, _ := regexp.MatchString("^/_/probe.*", request.URL.Path); match {
segments := strings.Split(request.URL.Path, "/")
if len(segments) >= 4 {
responseDelay, err := strconv.Atoi(segments[3])
if err == nil && responseDelay > 0 {
s.log.Infof("probe: delaying response for %ds", responseDelay)
time.Sleep(time.Duration(responseDelay) * time.Second)
}
}
go s.write(&cborplugin.Response{ID: r.ID, SURB: r.SURB, Payload: nil})
return nil
}
Expand Down
Loading