func()

in conn.go [108:134]


func (c *Conn) authenticate() error {
	// create and encode request for zk server
	request := &proto.ConnectRequest{
		TimeOut: int32(c.sessionTimeout.Milliseconds()),
	}

	if err := WriteRecords(c.conn, request); err != nil {
		return fmt.Errorf("could not write authentication request: %w", err)
	}

	// receive bytes from same socket, reading the message length first
	dec, err := createDecoder(c.conn)
	if err != nil {
		return fmt.Errorf("could not read auth response: %w", err)
	}

	response := proto.ConnectResponse{}
	if err := response.Read(dec); err != nil {
		return fmt.Errorf("could not decode authentication response: %w", err)
	}

	if response.TimeOut > 0 {
		c.sessionTimeout = time.Duration(response.TimeOut) * time.Millisecond
	}

	return nil
}