mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 15:20:30 +00:00
Fix Read, update sample
This commit is contained in:
parent
693bcc5713
commit
24281d4049
@ -283,7 +283,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
logger.Println("Accepted")
|
logger.Println("Accepted")
|
||||||
for {
|
for {
|
||||||
b := []byte{}
|
b := make([]byte, 100)
|
||||||
if n, err := conn.Read(b); err != nil {
|
if n, err := conn.Read(b); err != nil {
|
||||||
logger.Errorln("Read failed:", err)
|
logger.Errorln("Read failed:", err)
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
@ -319,7 +319,7 @@ func main() {
|
|||||||
logger.Errorln("Write failed:", err)
|
logger.Errorln("Write failed:", err)
|
||||||
} else {
|
} else {
|
||||||
logger.Println("Wrote", n, "bytes:", b)
|
logger.Println("Wrote", n, "bytes:", b)
|
||||||
b = b[:0]
|
b = make([]byte, 100)
|
||||||
if n, err := conn.Read(b); err != nil {
|
if n, err := conn.Read(b); err != nil {
|
||||||
logger.Errorln("Read failed:", err)
|
logger.Errorln("Read failed:", err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -88,8 +88,10 @@ func (c *Conn) Read(b []byte) (int, error) {
|
|||||||
util.PutBytes(bs)
|
util.PutBytes(bs)
|
||||||
return errors.New("packet dropped due to decryption failure")
|
return errors.New("packet dropped due to decryption failure")
|
||||||
}
|
}
|
||||||
b = b[:0]
|
copy(b, bs)
|
||||||
b = append(b, bs...)
|
if len(bs) < len(b) {
|
||||||
|
b = b[:len(bs)]
|
||||||
|
}
|
||||||
c.session.updateNonce(&p.Nonce)
|
c.session.updateNonce(&p.Nonce)
|
||||||
c.session.time = time.Now()
|
c.session.time = time.Now()
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user