From 226c4bac9da529129ebb5bedc79f868e9a9992b4 Mon Sep 17 00:00:00 2001 From: xtaci Date: Tue, 2 Jul 2024 03:29:53 +0800 Subject: [PATCH] fix memory issue related to server-side QPP --- server/main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server/main.go b/server/main.go index df8c1fbbd..2d8b12979 100644 --- a/server/main.go +++ b/server/main.go @@ -38,7 +38,7 @@ const ( var VERSION = "SELFBUILD" // handle multiplex-ed connection -func handleMux(conn net.Conn, config *Config, seed []byte) { +func handleMux(_Q_ *qpp.QuantumPermutationPad, conn net.Conn, config *Config, seed []byte) { // check if target is unix domain socket var isUnix bool if _, _, err := net.SplitHostPort(config.Target); err != nil { @@ -60,12 +60,6 @@ func handleMux(conn net.Conn, config *Config, seed []byte) { } defer mux.Close() - // create shared QPP - var _Q_ *qpp.QuantumPermutationPad - if config.QPP { - _Q_ = qpp.NewQPP(seed, uint16(config.QPPCount), QUBIT) - } - for { stream, err := mux.AcceptStream() if err != nil { @@ -475,6 +469,12 @@ func main() { go http.ListenAndServe(":6060", nil) } + // create shared QPP + var _Q_ *qpp.QuantumPermutationPad + if config.QPP { + _Q_ = qpp.NewQPP(pass, uint16(config.QPPCount), QUBIT) + } + // main loop var wg sync.WaitGroup loop := func(lis *kcp.Listener) { @@ -500,9 +500,9 @@ func main() { conn.SetACKNoDelay(config.AckNodelay) if config.NoComp { - go handleMux(conn, &config, pass) + go handleMux(_Q_, conn, &config, pass) } else { - go handleMux(generic.NewCompStream(conn), &config, pass) + go handleMux(_Q_, generic.NewCompStream(conn), &config, pass) } } else { log.Printf("%+v", err)