move some potentially blocking operations out of session pool workers, minor cleanup

This commit is contained in:
Arceliar 2019-08-04 16:29:58 -05:00
parent c55d7b4705
commit 979c3d4c07
2 changed files with 8 additions and 7 deletions

View File

@ -172,7 +172,6 @@ func BoxOpen(shared *BoxSharedKey,
boxed []byte, boxed []byte,
nonce *BoxNonce) ([]byte, bool) { nonce *BoxNonce) ([]byte, bool) {
out := util.GetBytes() out := util.GetBytes()
//return append(out, boxed...), true //FIXME disabled crypto for benchmarking
s := (*[BoxSharedKeyLen]byte)(shared) s := (*[BoxSharedKeyLen]byte)(shared)
n := (*[BoxNonceLen]byte)(nonce) n := (*[BoxNonceLen]byte)(nonce)
unboxed, success := box.OpenAfterPrecomputation(out, boxed, n, s) unboxed, success := box.OpenAfterPrecomputation(out, boxed, n, s)
@ -185,7 +184,6 @@ func BoxSeal(shared *BoxSharedKey, unboxed []byte, nonce *BoxNonce) ([]byte, *Bo
} }
nonce.Increment() nonce.Increment()
out := util.GetBytes() out := util.GetBytes()
//return append(out, unboxed...), nonce // FIXME disabled crypto for benchmarking
s := (*[BoxSharedKeyLen]byte)(shared) s := (*[BoxSharedKeyLen]byte)(shared)
n := (*[BoxNonceLen]byte)(nonce) n := (*[BoxNonceLen]byte)(nonce)
boxed := box.SealAfterPrecomputation(out, unboxed, n, s) boxed := box.SealAfterPrecomputation(out, unboxed, n, s)

View File

@ -463,8 +463,8 @@ func (sinfo *sessionInfo) recvWorker() {
ch := make(chan func(), 1) ch := make(chan func(), 1)
poolFunc := func() { poolFunc := func() {
bs, isOK = crypto.BoxOpen(&k, p.Payload, &p.Nonce) bs, isOK = crypto.BoxOpen(&k, p.Payload, &p.Nonce)
util.PutBytes(p.Payload)
callback := func() { callback := func() {
util.PutBytes(p.Payload)
if !isOK { if !isOK {
util.PutBytes(bs) util.PutBytes(bs)
return return
@ -539,11 +539,14 @@ func (sinfo *sessionInfo) sendWorker() {
// Encrypt the packet // Encrypt the packet
p.Payload, _ = crypto.BoxSeal(&k, bs, &p.Nonce) p.Payload, _ = crypto.BoxSeal(&k, bs, &p.Nonce)
packet := p.encode() packet := p.encode()
// The callback will send the packet
callback := func() {
// Cleanup // Cleanup
util.PutBytes(bs) util.PutBytes(bs)
util.PutBytes(p.Payload) util.PutBytes(p.Payload)
// The callback will send the packet // Send the packet
callback := func() { sinfo.core.router.out(packet) } sinfo.core.router.out(packet)
}
ch <- callback ch <- callback
} }
// Send to the worker and wait for it to finish // Send to the worker and wait for it to finish