Skip to content

Commit 226c4ba

Browse files
committed
fix memory issue related to server-side QPP
1 parent 5808892 commit 226c4ba

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

server/main.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const (
3838
var VERSION = "SELFBUILD"
3939

4040
// handle multiplex-ed connection
41-
func handleMux(conn net.Conn, config *Config, seed []byte) {
41+
func handleMux(_Q_ *qpp.QuantumPermutationPad, conn net.Conn, config *Config, seed []byte) {
4242
// check if target is unix domain socket
4343
var isUnix bool
4444
if _, _, err := net.SplitHostPort(config.Target); err != nil {
@@ -60,12 +60,6 @@ func handleMux(conn net.Conn, config *Config, seed []byte) {
6060
}
6161
defer mux.Close()
6262

63-
// create shared QPP
64-
var _Q_ *qpp.QuantumPermutationPad
65-
if config.QPP {
66-
_Q_ = qpp.NewQPP(seed, uint16(config.QPPCount), QUBIT)
67-
}
68-
6963
for {
7064
stream, err := mux.AcceptStream()
7165
if err != nil {
@@ -475,6 +469,12 @@ func main() {
475469
go http.ListenAndServe(":6060", nil)
476470
}
477471

472+
// create shared QPP
473+
var _Q_ *qpp.QuantumPermutationPad
474+
if config.QPP {
475+
_Q_ = qpp.NewQPP(pass, uint16(config.QPPCount), QUBIT)
476+
}
477+
478478
// main loop
479479
var wg sync.WaitGroup
480480
loop := func(lis *kcp.Listener) {
@@ -500,9 +500,9 @@ func main() {
500500
conn.SetACKNoDelay(config.AckNodelay)
501501

502502
if config.NoComp {
503-
go handleMux(conn, &config, pass)
503+
go handleMux(_Q_, conn, &config, pass)
504504
} else {
505-
go handleMux(generic.NewCompStream(conn), &config, pass)
505+
go handleMux(_Q_, generic.NewCompStream(conn), &config, pass)
506506
}
507507
} else {
508508
log.Printf("%+v", err)

0 commit comments

Comments
 (0)