package tdesktop
import (
"github.com/go-faster/errors"
"github.com/gotd/td/bin"
"github.com/gotd/td/internal/crypto"
)
type MTPConfigEnvironment int32
func (e MTPConfigEnvironment ) valid () bool {
return e == 0 || e == 1
}
func (e MTPConfigEnvironment ) String () string {
switch e {
case 0 :
return "production"
case 1 :
return "test"
default :
return "unknown"
}
}
func (e MTPConfigEnvironment ) Test () bool {
return e == 1
}
type MTPConfig struct {
Environment MTPConfigEnvironment
DCOptions MTPDCOptions
ChatSizeMax int32
MegagroupSizeMax int32
ForwardedCountMax int32
OnlineUpdatePeriod int32
OfflineBlurTimeout int32
OfflineIdleTimeout int32
OnlineFocusTimeout int32
OnlineCloudTimeout int32
NotifyCloudDelay int32
NotifyDefaultDelay int32
SavedGifsLimit int32
EditTimeLimit int32
RevokeTimeLimit int32
RevokePrivateTimeLimit int32
RevokePrivateInbox bool
StickersRecentLimit int32
StickersFavedLimit int32
PinnedDialogsCountMax int32
PinnedDialogsInFolderMax int32
InternalLinksDomain string
ChannelsReadMediaPeriod int32
CallReceiveTimeoutMs int32
CallRingTimeoutMs int32
CallConnectTimeoutMs int32
CallPacketTimeoutMs int32
WebFileDCID int32
TxtDomainString string
PhoneCallsEnabled bool
BlockedMode bool
CaptionLengthMax int32
}
func readMTPConfig (tgf *tdesktopFile , localKey crypto .Key ) (MTPConfig , error ) {
encrypted , err := tgf .readArray ()
if err != nil {
return MTPConfig {}, errors .Wrap (err , "read encrypted data" )
}
decrypted , err := decryptLocal (encrypted , localKey )
if err != nil {
return MTPConfig {}, errors .Wrap (err , "decrypt data" )
}
decrypted = decrypted [4 :]
root := qtReader {buf : bin .Buffer {Buf : decrypted }}
cfgReader , err := root .subArray ()
if err != nil {
return MTPConfig {}, errors .Wrap (err , "read config array" )
}
var m MTPConfig
if err := m .deserialize (&cfgReader ); err != nil {
return MTPConfig {}, errors .Wrap (err , "deserialize MTPConfig" )
}
return m , err
}
func (m *MTPConfig ) deserialize (r *qtReader ) error {
version , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read version" )
}
if version != kVersion {
return errors .Errorf ("wrong version (expected %d, got %d)" , kVersion , version )
}
environment , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read environment" )
}
m .Environment = MTPConfigEnvironment (environment )
if !m .Environment .valid () {
return errors .Errorf ("invalid environment %d" , environment )
}
{
sub , err := r .subArray ()
if err != nil {
return err
}
if err := m .DCOptions .deserialize (&sub ); err != nil {
return errors .Wrap (err , "read DC options" )
}
}
chatSizeMax , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read chatSizeMax" )
}
m .ChatSizeMax = chatSizeMax
megagroupSizeMax , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read megagroupSizeMax" )
}
m .MegagroupSizeMax = megagroupSizeMax
forwardedCountMax , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read forwardedCountMax" )
}
m .ForwardedCountMax = forwardedCountMax
onlineUpdatePeriod , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read onlineUpdatePeriod" )
}
m .OnlineUpdatePeriod = onlineUpdatePeriod
offlineBlurTimeout , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read offlineBlurTimeout" )
}
m .OfflineBlurTimeout = offlineBlurTimeout
offlineIdleTimeout , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read offlineIdleTimeout" )
}
m .OfflineIdleTimeout = offlineIdleTimeout
onlineFocusTimeout , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read onlineFocusTimeout" )
}
m .OnlineFocusTimeout = onlineFocusTimeout
onlineCloudTimeout , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read onlineCloudTimeout" )
}
m .OnlineCloudTimeout = onlineCloudTimeout
notifyCloudDelay , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read notifyCloudDelay" )
}
m .NotifyCloudDelay = notifyCloudDelay
notifyDefaultDelay , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read notifyDefaultDelay" )
}
m .NotifyDefaultDelay = notifyDefaultDelay
savedGifsLimit , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read savedGifsLimit" )
}
m .SavedGifsLimit = savedGifsLimit
editTimeLimit , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read editTimeLimit" )
}
m .EditTimeLimit = editTimeLimit
revokeTimeLimit , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read revokeTimeLimit" )
}
m .RevokeTimeLimit = revokeTimeLimit
revokePrivateTimeLimit , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read revokePrivateTimeLimit" )
}
m .RevokePrivateTimeLimit = revokePrivateTimeLimit
revokePrivateInbox , err := r .readUint32 ()
if err != nil {
return errors .Wrap (err , "read revokePrivateInbox" )
}
m .RevokePrivateInbox = revokePrivateInbox == 1
stickersRecentLimit , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read stickersRecentLimit" )
}
m .StickersRecentLimit = stickersRecentLimit
stickersFavedLimit , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read stickersFavedLimit" )
}
m .StickersFavedLimit = stickersFavedLimit
pinnedDialogsCountMax , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read pinnedDialogsCountMax" )
}
m .PinnedDialogsCountMax = pinnedDialogsCountMax
pinnedDialogsInFolderMax , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read pinnedDialogsInFolderMax" )
}
m .PinnedDialogsInFolderMax = pinnedDialogsInFolderMax
internalLinksDomain , err := r .readString ()
if err != nil {
return errors .Wrap (err , "read internalLinksDomain" )
}
m .InternalLinksDomain = internalLinksDomain
channelsReadMediaPeriod , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read channelsReadMediaPeriod" )
}
m .ChannelsReadMediaPeriod = channelsReadMediaPeriod
callReceiveTimeoutMs , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read callReceiveTimeoutMs" )
}
m .CallReceiveTimeoutMs = callReceiveTimeoutMs
callRingTimeoutMs , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read callRingTimeoutMs" )
}
m .CallRingTimeoutMs = callRingTimeoutMs
callConnectTimeoutMs , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read callConnectTimeoutMs" )
}
m .CallConnectTimeoutMs = callConnectTimeoutMs
callPacketTimeoutMs , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read callPacketTimeoutMs" )
}
m .CallPacketTimeoutMs = callPacketTimeoutMs
webFileDCID , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read webFileDCID" )
}
m .WebFileDCID = webFileDCID
txtDomainString , err := r .readString ()
if err != nil {
return errors .Wrap (err , "read txtDomainString" )
}
m .TxtDomainString = txtDomainString
phoneCallsEnabled , err := r .readUint32 ()
if err != nil {
return errors .Wrap (err , "read phoneCallsEnabled" )
}
m .PhoneCallsEnabled = phoneCallsEnabled == 1
blockedMode , err := r .readUint32 ()
if err != nil {
return errors .Wrap (err , "read blockedMode" )
}
m .BlockedMode = blockedMode == 1
captionLengthMax , err := r .readInt32 ()
if err != nil {
return errors .Wrap (err , "read captionLengthMax" )
}
m .CaptionLengthMax = captionLengthMax
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 .