package mtproto

import (
	
	

	
	

	
)

func ( *Conn) ( int64) {
	.sessionMux.Lock()
	// Copy to log.
	 := .salt
	.salt = 
	.sessionMux.Unlock()

	if  !=  {
		.log.Info("Salt updated", zap.Int64("old", ), zap.Int64("new", ))
	}
}

func ( *Conn) () {
	,  := .salts.Get(.clock.Now().Add(time.Minute * 5))
	if ! {
		return
	}

	.storeSalt()
}

const defaultSaltsNum = 4

func ( *Conn) ( context.Context) error {
	 := &mt.GetFutureSaltsRequest{
		Num: defaultSaltsNum,
	}
	,  := context.WithTimeout(, .getTimeout(.TypeID()))
	defer ()

	if  := .writeServiceMessage(, );  != nil {
		return errors.Wrap(, "request salts")
	}

	return nil
}

func ( *Conn) ( context.Context) error {
	select {
	case <-.gotSession.Ready():
	case <-.Done():
		return .Err()
	}

	// Get salts first time.
	if  := .getSalts();  != nil {
		return 
	}

	 := .clock.Ticker(.saltFetchInterval)
	defer .Stop()
	for {
		select {
		case <-.C():
			if  := .getSalts();  != nil {
				return 
			}
		case <-.Done():
			return .Err()
		}
	}
}