mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-17 16:20:26 +08:00
add more logs
This commit is contained in:
@@ -35,7 +35,7 @@ func (l *Link) Decode(teatype uint8, b []byte) (db []byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodePreshared 使用 chacha20poly1305 加密
|
// EncodePreshared 使用 xchacha20poly1305 加密
|
||||||
func (l *Link) EncodePreshared(additional uint16, b []byte) (eb []byte) {
|
func (l *Link) EncodePreshared(additional uint16, b []byte) (eb []byte) {
|
||||||
nsz := l.aead.NonceSize()
|
nsz := l.aead.NonceSize()
|
||||||
// Select a random nonce, and leave capacity for the ciphertext.
|
// Select a random nonce, and leave capacity for the ciphertext.
|
||||||
@@ -51,7 +51,7 @@ func (l *Link) EncodePreshared(additional uint16, b []byte) (eb []byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodePreshared 使用 chacha20poly1305 解密
|
// DecodePreshared 使用 xchacha20poly1305 解密
|
||||||
func (l *Link) DecodePreshared(additional uint16, b []byte) (db []byte) {
|
func (l *Link) DecodePreshared(additional uint16, b []byte) (db []byte) {
|
||||||
nsz := l.aead.NonceSize()
|
nsz := l.aead.NonceSize()
|
||||||
if len(b) < nsz { // ciphertext too short
|
if len(b) < nsz { // ciphertext too short
|
||||||
|
|||||||
@@ -60,18 +60,22 @@ func (l *Link) WriteAndPut(p *head.Packet, istransfer bool) (n int, err error) {
|
|||||||
|
|
||||||
func (l *Link) encrypt(p *head.Packet, sndcnt uint16, teatype uint8) {
|
func (l *Link) encrypt(p *head.Packet, sndcnt uint16, teatype uint8) {
|
||||||
p.FillHash()
|
p.FillHash()
|
||||||
|
logrus.Debugln("[send] data len before encrypt:", len(p.Data))
|
||||||
if l.usezstd {
|
if l.usezstd {
|
||||||
w := helper.SelectWriter()
|
w := helper.SelectWriter()
|
||||||
defer helper.PutWriter(w)
|
defer helper.PutWriter(w)
|
||||||
enc, _ := zstd.NewWriter(w, zstd.WithEncoderLevel(zstd.SpeedFastest))
|
enc, _ := zstd.NewWriter(w, zstd.WithEncoderLevel(zstd.SpeedFastest))
|
||||||
defer enc.Close()
|
|
||||||
_, _ = io.Copy(enc, bytes.NewReader(p.Data))
|
_, _ = io.Copy(enc, bytes.NewReader(p.Data))
|
||||||
|
enc.Close()
|
||||||
p.Data = w.Bytes()
|
p.Data = w.Bytes()
|
||||||
|
logrus.Debugln("[send] data len after zstd:", len(p.Data))
|
||||||
}
|
}
|
||||||
if l.aead != nil {
|
if l.aead != nil {
|
||||||
p.Data = l.EncodePreshared(sndcnt, p.Data)
|
p.Data = l.EncodePreshared(sndcnt, p.Data)
|
||||||
|
logrus.Debugln("[send] data len after xchacha20:", len(p.Data))
|
||||||
}
|
}
|
||||||
p.Data = l.Encode(teatype, p.Data)
|
p.Data = l.Encode(teatype, p.Data)
|
||||||
|
logrus.Debugln("[send] data len after tea:", len(p.Data))
|
||||||
}
|
}
|
||||||
|
|
||||||
// write 向 peer 发一个包
|
// write 向 peer 发一个包
|
||||||
|
|||||||
Reference in New Issue
Block a user