mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-29 22:31:37 +00:00
WARNING: CRYPTO DISABLED while speeding up stream writeMsg
This commit is contained in:
parent
1e6a6d2160
commit
f52955ee0f
@ -172,6 +172,7 @@ 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
|
||||||
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)
|
||||||
@ -184,6 +185,7 @@ 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
|
||||||
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)
|
||||||
|
@ -34,6 +34,15 @@ func PutBytes(bs []byte) {
|
|||||||
byteStore.Put(bs)
|
byteStore.Put(bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets a slice of the appropriate length, reusing existing slice capacity when possible
|
||||||
|
func ResizeBytes(bs []byte, length int) []byte {
|
||||||
|
if cap(bs) >= length {
|
||||||
|
return bs[:length]
|
||||||
|
} else {
|
||||||
|
return make([]byte, length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This is a workaround to go's broken timer implementation
|
// This is a workaround to go's broken timer implementation
|
||||||
func TimerStop(t *time.Timer) bool {
|
func TimerStop(t *time.Timer) bool {
|
||||||
stopped := t.Stop()
|
stopped := t.Stop()
|
||||||
|
@ -127,7 +127,6 @@ func (r *router) mainLoop() {
|
|||||||
r.core.switchTable.doMaintenance()
|
r.core.switchTable.doMaintenance()
|
||||||
r.core.dht.doMaintenance()
|
r.core.dht.doMaintenance()
|
||||||
r.core.sessions.cleanup()
|
r.core.sessions.cleanup()
|
||||||
util.GetBytes() // To slowly drain things
|
|
||||||
}
|
}
|
||||||
case f := <-r.admin:
|
case f := <-r.admin:
|
||||||
f()
|
f()
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
"github.com/yggdrasil-network/yggdrasil-go/src/util"
|
||||||
)
|
)
|
||||||
@ -12,10 +13,11 @@ import (
|
|||||||
var _ = linkInterfaceMsgIO(&stream{})
|
var _ = linkInterfaceMsgIO(&stream{})
|
||||||
|
|
||||||
type stream struct {
|
type stream struct {
|
||||||
rwc io.ReadWriteCloser
|
rwc io.ReadWriteCloser
|
||||||
inputBuffer []byte // Incoming packet stream
|
inputBuffer []byte // Incoming packet stream
|
||||||
frag [2 * streamMsgSize]byte // Temporary data read off the underlying rwc, on its way to the inputBuffer
|
frag [2 * streamMsgSize]byte // Temporary data read off the underlying rwc, on its way to the inputBuffer
|
||||||
outputBuffer [2 * streamMsgSize]byte // Temporary data about to be written to the rwc
|
//outputBuffer [2 * streamMsgSize]byte // Temporary data about to be written to the rwc
|
||||||
|
outputBuffer net.Buffers
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stream) close() error {
|
func (s *stream) close() error {
|
||||||
@ -35,14 +37,17 @@ func (s *stream) init(rwc io.ReadWriteCloser) {
|
|||||||
// writeMsg writes a message with stream padding, and is *not* thread safe.
|
// writeMsg writes a message with stream padding, and is *not* thread safe.
|
||||||
func (s *stream) writeMsg(bs []byte) (int, error) {
|
func (s *stream) writeMsg(bs []byte) (int, error) {
|
||||||
buf := s.outputBuffer[:0]
|
buf := s.outputBuffer[:0]
|
||||||
buf = append(buf, streamMsg[:]...)
|
buf = append(buf, streamMsg[:])
|
||||||
buf = wire_put_uint64(uint64(len(bs)), buf)
|
l := wire_put_uint64(uint64(len(bs)), util.GetBytes())
|
||||||
padLen := len(buf)
|
defer util.PutBytes(l)
|
||||||
buf = append(buf, bs...)
|
buf = append(buf, l)
|
||||||
|
padLen := len(buf[0]) + len(buf[1])
|
||||||
|
buf = append(buf, bs)
|
||||||
|
totalLen := padLen + len(bs)
|
||||||
var bn int
|
var bn int
|
||||||
for bn < len(buf) {
|
for bn < totalLen {
|
||||||
n, err := s.rwc.Write(buf[bn:])
|
n, err := buf.WriteTo(s.rwc)
|
||||||
bn += n
|
bn += int(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l := bn - padLen
|
l := bn - padLen
|
||||||
if l < 0 {
|
if l < 0 {
|
||||||
|
@ -820,7 +820,7 @@ func (t *switchTable) doWorker() {
|
|||||||
select {
|
select {
|
||||||
case bs := <-t.toRouter:
|
case bs := <-t.toRouter:
|
||||||
buf = append(buf, bs)
|
buf = append(buf, bs)
|
||||||
for len(buf) > 32 {
|
for len(buf) > 32768 { // FIXME realistically don't drop anything, just for testing
|
||||||
util.PutBytes(buf[0])
|
util.PutBytes(buf[0])
|
||||||
buf = buf[1:]
|
buf = buf[1:]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user