package mtproto

import (
	
	

	
	

	
	
	
	
	
	
	
)

// Options of Conn.
type Options struct {
	// DC is datacenter ID for key exchange.
	// Defaults to 2.
	DC int

	// PublicKeys of telegram.
	//
	// If not provided, embedded public keys will be used.
	PublicKeys []exchange.PublicKey

	// Random is random source. Defaults to crypto.
	Random io.Reader
	// Logger is instance of zap.Logger. No logs by default.
	Logger *zap.Logger
	// Handler will be called on received message.
	Handler Handler

	// AckBatchSize is maximum ack-s to buffer.
	AckBatchSize int
	// AckInterval is maximum time to buffer ack.
	AckInterval time.Duration

	// RetryInterval is duration between retries.
	RetryInterval time.Duration
	// MaxRetries is max retry count until rpc request failure.
	MaxRetries int

	// DialTimeout is timeout of creating connection.
	DialTimeout time.Duration
	// ExchangeTimeout is timeout of every key exchange request.
	ExchangeTimeout time.Duration
	// SaltFetchInterval is duration between get_future_salts request.
	SaltFetchInterval time.Duration
	// PingTimeout sets ping_delay_disconnect timeout.
	PingTimeout time.Duration
	// PingInterval is duration between ping_delay_disconnect request.
	PingInterval time.Duration
	// RequestTimeout is function which returns request timeout for given type ID.
	RequestTimeout func(req uint32) time.Duration

	// CompressThreshold is a threshold in bytes to determine that message
	// is large enough to be compressed using GZIP.
	// If < 0, compression will be disabled.
	// If == 0, default value will be used.
	CompressThreshold int
	// MessageID is message id source. Share source between connection to
	// reduce collision probability.
	MessageID MessageIDSource
	// Clock is current time source. Defaults to system time.
	Clock clock.Clock
	// Types map, used in verbose logging of incoming message.
	Types *tmap.Map
	// Key that can be used to restore previous connection.
	Key crypto.AuthKey
	// Salt from server that can be used to restore previous connection.
	Salt int64

	// Tracer for OTEL.
	Tracer trace.Tracer

	// Private options.

	// Cipher defines message crypto.
	Cipher Cipher
	// engine for replacing RPC engine.
	engine *rpc.Engine
}

type nopHandler struct{}

func (nopHandler) ( *bin.Buffer) error   { return nil }
func (nopHandler) ( Session) error { return nil }

func ( *Options) () {
	// Using public keys that are included with distribution if not
	// provided.
	//
	// This should never fail and keys should be valid for recent
	// library versions.
	.PublicKeys = vendoredKeys()
}

func ( *Options) () {
	if .DC == 0 {
		.DC = 2
	}
	if .Random == nil {
		.Random = crypto.DefaultRand()
	}
	if .Logger == nil {
		.Logger = zap.NewNop()
	}
	if .AckBatchSize == 0 {
		.AckBatchSize = 20
	}
	if .AckInterval == 0 {
		.AckInterval = 15 * time.Second
	}
	if .RetryInterval == 0 {
		.RetryInterval = 5 * time.Second
	}
	if .MaxRetries == 0 {
		.MaxRetries = 5
	}
	if .DialTimeout == 0 {
		.DialTimeout = 35 * time.Second
	}
	if .ExchangeTimeout == 0 {
		.ExchangeTimeout = exchange.DefaultTimeout
	}
	if .SaltFetchInterval == 0 {
		.SaltFetchInterval = 1 * time.Hour
	}
	if .PingTimeout == 0 {
		.PingTimeout = 15 * time.Second
	}
	if .PingInterval == 0 {
		.PingInterval = 1 * time.Minute
	}
	if .RequestTimeout == nil {
		.RequestTimeout = func( uint32) time.Duration {
			return 15 * time.Second
		}
	}
	if .CompressThreshold == 0 {
		.CompressThreshold = 1024
	}
	if .Clock == nil {
		.Clock = clock.System
	}
	if .MessageID == nil {
		.MessageID = proto.NewMessageIDGen(.Clock.Now)
	}
	if len(.PublicKeys) == 0 {
		.setDefaultPublicKeys()
	}
	if .Handler == nil {
		.Handler = nopHandler{}
	}
	if .Cipher == nil {
		.Cipher = crypto.NewClientCipher(.Random)
	}
}