Skip to content

Commit

Permalink
fix memory issue related to server-side QPP
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Jul 1, 2024
1 parent 5808892 commit 226c4ba
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 226c4ba

Please sign in to comment.