package mtproto
import (
"github.com/go-faster/errors"
"go.uber.org/zap"
"github.com/gotd/td/bin"
"github.com/gotd/td/internal/crypto"
"github.com/gotd/td/internal/proto"
)
func (c *Conn ) newEncryptedMessage (id int64 , seq int32 , payload bin .Encoder , b *bin .Buffer ) error {
s := c .session ()
var (
d crypto .EncryptedMessageData
log = c .log
)
if c .compressThreshold <= 0 {
if obj , ok := payload .(interface { TypeID () uint32 }); ok {
log = c .logWithTypeID (obj .TypeID ())
}
d = crypto .EncryptedMessageData {
SessionID : s .ID ,
Salt : s .Salt ,
MessageID : id ,
SeqNo : seq ,
Message : payload ,
}
} else {
payloadBuf := bufPool .Get ()
defer bufPool .Put (payloadBuf )
if err := payload .Encode (payloadBuf ); err != nil {
return errors .Wrap (err , "encode payload" )
}
log = c .logWithType (payloadBuf )
if payloadBuf .Len () > c .compressThreshold {
d = crypto .EncryptedMessageData {
SessionID : s .ID ,
Salt : s .Salt ,
MessageID : id ,
SeqNo : seq ,
Message : proto .GZIP {Data : payloadBuf .Raw ()},
}
} else {
d = crypto .EncryptedMessageData {
SessionID : s .ID ,
Salt : s .Salt ,
MessageID : id ,
SeqNo : seq ,
MessageDataLen : int32 (payloadBuf .Len ()),
MessageDataWithPadding : payloadBuf .Buf ,
}
}
}
log .Debug ("Request" , zap .Int64 ("msg_id" , id ))
if err := c .cipher .Encrypt (s .Key , d , b ); err != nil {
return errors .Wrap (err , "encrypt" )
}
return nil
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .