mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 03:41:37 +00:00
move some potentially blocking operations out of session pool workers, minor cleanup
This commit is contained in:
parent
c55d7b4705
commit
979c3d4c07
@ -172,7 +172,6 @@ func BoxOpen(shared *BoxSharedKey,
|
||||
boxed []byte,
|
||||
nonce *BoxNonce) ([]byte, bool) {
|
||||
out := util.GetBytes()
|
||||
//return append(out, boxed...), true //FIXME disabled crypto for benchmarking
|
||||
s := (*[BoxSharedKeyLen]byte)(shared)
|
||||
n := (*[BoxNonceLen]byte)(nonce)
|
||||
unboxed, success := box.OpenAfterPrecomputation(out, boxed, n, s)
|
||||
@ -185,7 +184,6 @@ func BoxSeal(shared *BoxSharedKey, unboxed []byte, nonce *BoxNonce) ([]byte, *Bo
|
||||
}
|
||||
nonce.Increment()
|
||||
out := util.GetBytes()
|
||||
//return append(out, unboxed...), nonce // FIXME disabled crypto for benchmarking
|
||||
s := (*[BoxSharedKeyLen]byte)(shared)
|
||||
n := (*[BoxNonceLen]byte)(nonce)
|
||||
boxed := box.SealAfterPrecomputation(out, unboxed, n, s)
|
||||
|
@ -463,8 +463,8 @@ func (sinfo *sessionInfo) recvWorker() {
|
||||
ch := make(chan func(), 1)
|
||||
poolFunc := func() {
|
||||
bs, isOK = crypto.BoxOpen(&k, p.Payload, &p.Nonce)
|
||||
util.PutBytes(p.Payload)
|
||||
callback := func() {
|
||||
util.PutBytes(p.Payload)
|
||||
if !isOK {
|
||||
util.PutBytes(bs)
|
||||
return
|
||||
@ -539,11 +539,14 @@ func (sinfo *sessionInfo) sendWorker() {
|
||||
// Encrypt the packet
|
||||
p.Payload, _ = crypto.BoxSeal(&k, bs, &p.Nonce)
|
||||
packet := p.encode()
|
||||
// Cleanup
|
||||
util.PutBytes(bs)
|
||||
util.PutBytes(p.Payload)
|
||||
// The callback will send the packet
|
||||
callback := func() { sinfo.core.router.out(packet) }
|
||||
callback := func() {
|
||||
// Cleanup
|
||||
util.PutBytes(bs)
|
||||
util.PutBytes(p.Payload)
|
||||
// Send the packet
|
||||
sinfo.core.router.out(packet)
|
||||
}
|
||||
ch <- callback
|
||||
}
|
||||
// Send to the worker and wait for it to finish
|
||||
|
Loading…
Reference in New Issue
Block a user