Skip to content

Commit

Permalink
feat: upgrade to katzenpost v0.0.38 and use client2
Browse files Browse the repository at this point in the history
- chore: upgrade to katzenpost v0.0.38
- feat(walletshield): use client2
- refactor(docker/Makefile): project specific targets, pass through others
- refactor: replace customized genconfig with Makefile target
- test: update test data output
- ci: add walletshield test probe to workflow
- feat(walletshield): add listen_client flag for client daemon network address
- feat(walletshield): Add delayed start option

---------

Co-authored-by: Xendarboh <[email protected]>
  • Loading branch information
david415 and xendarboh authored Oct 8, 2024
1 parent 207a681 commit e9ebb9c
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 1,052 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,24 @@ jobs:
- name: run ping
run: cd docker && sudo -E make run-ping

- name: Run Walletshield
- name: run walletshield test probe
run: cd docker && sudo -E make walletshield-probe

- name: Start walletshield
run: |
cd docker && sudo -E make run-walletshield
cd docker
sudo -E make walletshield-start
sleep 10
sudo -E make walletshield-logs
- name: Test Walletshield
- name: Test walletshield
run: ./tests/e2e/walletshield/test.sh

- name: Stop the Walletshield
- name: Stop walletshield
run: |
cd docker && sudo -E make stop-walletshield
cd docker
sudo -E make walletshield-logs
sudo -E make walletshield-stop
- name: Stop the mixnet
run: |
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
apps/walletshield/walletshield
docker/*.stamp
docker/cache
docker/katzenpost
docker/voting_mixnet
genconfig/genconfig
server_plugins/cbor_plugins/http_proxy/cmd/http_proxy/http_proxy
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.PHONY: all app-walletshield http_proxy clean


all: app-walletshield http_proxy

app-walletshield:
Expand Down
89 changes: 67 additions & 22 deletions apps/walletshield/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,60 @@ import (
"github.com/charmbracelet/log"
"github.com/fxamacker/cbor/v2"

"github.com/katzenpost/katzenpost/client"
"github.com/katzenpost/katzenpost/client/config"
"github.com/katzenpost/katzenpost/client/utils"
"github.com/katzenpost/hpqc/hash"
"github.com/katzenpost/hpqc/rand"

"github.com/katzenpost/katzenpost/client2"
"github.com/katzenpost/katzenpost/client2/config"
"github.com/katzenpost/katzenpost/client2/thin"
sConstants "github.com/katzenpost/katzenpost/core/sphinx/constants"

"github.com/0KnowledgeNetwork/opt/server_plugins/cbor_plugins/http_proxy"
)

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

func sendRequest(thin *thin.ThinClient, payload []byte) ([]byte, error) {
surbID := &[sConstants.SURBIDLength]byte{}
_, err := rand.Reader.Read(surbID[:])
if err != nil {
panic(err)
}

// Select a target service node and compute the DestinationIdHash
target, err := thin.GetService(ProxyHTTPService)
if err != nil {
panic(err)
}
nodeId := hash.Sum256(target.MixDescriptor.IdentityKey)

timeoutCtx, _ := context.WithTimeout(context.TODO(), timeout)
return thin.BlockingSendMessage(timeoutCtx, payload, &nodeId, target.RecipientQueueID)
}

type Server struct {
log *log.Logger
daemon *client2.Daemon
thin *thin.ThinClient
}

func main() {
var logLevel string
var listenAddr string
var listenAddrClient string
var configPath string
var delayStart int
var testProbe bool
var testProbeCount 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")
flag.StringVar(&logLevel, "log_level", "DEBUG", "logging level could be set to: DEBUG, INFO, WARNING, ERROR, CRITICAL")
flag.StringVar(&listenAddr, "listen", "", "local socket to listen HTTP on")
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.Parse()
Expand All @@ -56,30 +93,44 @@ func main() {
Level: level,
})

// mixnet client
if delayStart > 0 {
d := rand.NewMath().Intn(delayStart)
mylog.Infof("Delaying start for %d seconds...", d)
time.Sleep(time.Duration(d) * time.Second)
}

// start client2 daemon
cfg, err := config.LoadFile(configPath)
if err != nil {
panic(err)
}
c, err := client.New(cfg)

if listenAddrClient != "" {
cfg.ListenAddress = listenAddrClient
}

d, err := client2.NewDaemon(cfg)
if err != nil {
panic(err)
}
session, err := c.NewTOFUSession(context.Background())
err = d.Start()
if err != nil {
panic(err)
}
ProxyHTTPService := "http_proxy"
desc, err := session.GetService(ProxyHTTPService)

time.Sleep(time.Second * 3) // XXX ugly hack but works: FIXME

thin := thin.NewThinClient(cfg)
err = thin.Dial()
if err != nil {
panic(err)
}

// http server
server := &Server{
log: mylog,
session: session,
target: desc,
log: mylog,
thin: thin,
daemon: d,
}

if testProbe {
Expand All @@ -98,12 +149,6 @@ func main() {
}
}

type Server struct {
log *log.Logger
session *client.Session
target *utils.ServiceDescriptor
}

func (s *Server) Handler(w http.ResponseWriter, req *http.Request) {
s.log.Infof("Received HTTP request for %s", req.URL)

Expand All @@ -128,7 +173,7 @@ func (s *Server) Handler(w http.ResponseWriter, req *http.Request) {
panic(err)
}

rawReply, err := s.session.BlockingSendUnreliableMessage(s.target.Name, s.target.Provider, blob)
rawReply, err := sendRequest(s.thin, blob)
if err != nil {
s.log.Errorf("Failed to send message: %s", err)
http.Error(w, "custom 404", http.StatusNotFound)
Expand Down Expand Up @@ -176,7 +221,8 @@ func (s *Server) SendTestProbes(d time.Duration, testProbeCount int) {
for {
packetsTransmitted++
t := time.Now()
_, err := s.session.BlockingSendUnreliableMessage(s.target.Name, s.target.Provider, blob)

_, err = sendRequest(s.thin, blob)
elapsed := time.Since(t).Seconds()
if err != nil {
s.log.Errorf("Probe failed after %.2fs: %s", elapsed, err)
Expand All @@ -189,13 +235,12 @@ func (s *Server) SendTestProbes(d time.Duration, testProbeCount int) {
if elapsed > rttMax {
rttMax = elapsed
}
s.log.Infof("Probe response took %.2fs", elapsed)
}

packetLoss := float64(packetsTransmitted-packetsReceived) / float64(packetsTransmitted) * 100
rttAvg := rttTotal / float64(packetsReceived)
s.log.Infof("Probe packet transmitted/received/loss = %d/%d/%.1f%%", packetsTransmitted, packetsReceived, packetLoss)
s.log.Infof("Probe rtt min/avg/max = %.2f/%.2f/%.2f s", rttMin, rttAvg, rttMax)
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)

// probe indefinitely if testProbeCount is 0
if testProbeCount != 0 && packetsTransmitted >= testProbeCount {
Expand Down
Loading

0 comments on commit e9ebb9c

Please sign in to comment.