Permalink
Browse files

Add code to disable mysql protocol compression (no UI) to connect to …

…Amazon Aurora (see #2122)
  • Loading branch information...
dmoagx committed Jul 29, 2015
1 parent 26c821c commit 291078f1c4c28e5a2c69358a8aa9883862717e36
@@ -61,6 +61,7 @@ - (id)copyWithZone:(NSZone *)zone
[copy setUseKeepAlive:useKeepAlive];
[copy setRetryQueriesOnConnectionFailure:retryQueriesOnConnectionFailure];
[copy setDelegateQueryLogging:delegateQueryLogging];
[copy setClientFlags:clientFlags];
// Active connection state details, like selected database and encoding, are *not* copied.
@@ -127,6 +127,8 @@
// Queries
BOOL retryQueriesOnConnectionFailure;
SPMySQLClientFlags clientFlags;
}
#pragma mark -
@@ -164,6 +166,14 @@
@property (readwrite, assign) BOOL lastQueryWasCancelled;
/**
* The mysql client capability flags to set when connecting.
* See CLIENT_* in mysql.h
*/
@property (readwrite, assign, nonatomic) SPMySQLClientFlags clientFlags;
- (void)addClientFlags:(SPMySQLClientFlags)opts;
- (void)removeClientFlags:(SPMySQLClientFlags)opts;
#pragma mark -
#pragma mark Connection and disconnection
@@ -41,10 +41,10 @@
#pragma mark Class constants
// The default connection options for MySQL connections
const NSUInteger SPMySQLConnectionOptions =
CLIENT_COMPRESS | // Enable protocol compression - almost always a win
CLIENT_INTERACTIVE | // Mark ourselves as an interactive client
CLIENT_MULTI_RESULTS; // Multiple result support (very basic, but present)
const SPMySQLClientFlags SPMySQLConnectionOptions =
SPMySQLClientFlagCompression | // Enable protocol compression - almost always a win
SPMySQLClientFlagInteractive | // Mark ourselves as an interactive client
SPMySQLClientFlagMultiResults; // Multiple result support (very basic, but present)
// List of permissible ciphers to use for SSL connections
const char *SPMySQLSSLPermissibleCiphers = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RSA-AES128-SHA:AES128-SHA:AES256-RMD:AES128-RMD:DES-CBC3-RMD:DHE-RSA-AES256-RMD:DHE-RSA-AES128-RMD:DHE-RSA-DES-CBC3-RMD:RC4-SHA:RC4-MD5:DES-CBC3-SHA:DES-CBC-SHA:EDH-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC-SHA";
@@ -73,6 +73,20 @@ @implementation SPMySQLConnection
@synthesize retryQueriesOnConnectionFailure;
@synthesize delegateQueryLogging;
@synthesize lastQueryWasCancelled;
@synthesize clientFlags = clientFlags;
#pragma mark -
#pragma mark Getters and Setters
- (void)addClientFlags:(SPMySQLClientFlags)opts
{
[self setClientFlags:([self clientFlags] | opts)];
}
- (void)removeClientFlags:(SPMySQLClientFlags)opts
{
[self setClientFlags:([self clientFlags] & ~opts)];
}
#pragma mark -
#pragma mark Initialisation and teardown
@@ -188,6 +202,8 @@ - (id)init
// Start the ping keepalive timer
keepAliveTimer = [[SPMySQLKeepAliveTimer alloc] initWithInterval:10 target:self selector:@selector(_keepAlive)];
[self setClientFlags:SPMySQLConnectionOptions];
}
return self;
@@ -567,7 +583,7 @@ - (MYSQL *)_makeRawMySQLConnectionWithEncoding:(NSString *)encodingName isMaster
mysql_ssl_set(theConnection, theSSLKeyFilePath, theSSLCertificatePath, theCACertificatePath, NULL, theSSLCiphers);
}
MYSQL *connectionStatus = mysql_real_connect(theConnection, theHost, theUsername, thePassword, NULL, (unsigned int)port, theSocket, SPMySQLConnectionOptions);
MYSQL *connectionStatus = mysql_real_connect(theConnection, theHost, theUsername, thePassword, NULL, (unsigned int)port, theSocket, [self clientFlags]);
// If the connection failed, return NULL
if (theConnection != connectionStatus) {
@@ -74,3 +74,10 @@ typedef enum {
SPMySQLResultAsLowMemStreamingResult = 2,
SPMySQLResultAsStreamingResultStore = 3
} SPMySQLResultType;
// Redeclared from mysql_com.h (private header)
typedef NS_OPTIONS(unsigned long, SPMySQLClientFlags) {
SPMySQLClientFlagCompression = 32, // CLIENT_COMPRESS
SPMySQLClientFlagInteractive = 1024, // CLIENT_INTERACTIVE
SPMySQLClientFlagMultiResults = (1UL << 17) // CLIENT_MULTI_RESULTS = 131072
};
@@ -79,6 +79,7 @@
NSString *socket;
NSString *port;
NSInteger colorIndex;
BOOL useCompression;
// SSL details
NSInteger useSSL;
@@ -209,6 +210,7 @@
@property (readwrite, retain) NSString *connectionKeychainItemAccount;
@property (readwrite, retain) NSString *connectionSSHKeychainItemName;
@property (readwrite, retain) NSString *connectionSSHKeychainItemAccount;
@property (readwrite, assign) BOOL useCompression;
#ifdef SP_CODA
@property (readwrite, assign) SPDatabaseDocument *dbDocument;
@@ -132,6 +132,7 @@ @implementation SPConnectionController
@synthesize sshKeyLocationEnabled;
@synthesize sshKeyLocation;
@synthesize sshPort;
@synthesize useCompression;
#ifdef SP_CODA
@synthesize dbDocument;
@@ -648,7 +649,8 @@ - (void)updateFavoriteSelection:(id)sender
[self setColorIndex:([fav objectForKey:SPFavoriteColorIndexKey]? [[fav objectForKey:SPFavoriteColorIndexKey] integerValue] : -1)];
[self setPort:([fav objectForKey:SPFavoritePortKey] ? [fav objectForKey:SPFavoritePortKey] : @"")];
[self setDatabase:([fav objectForKey:SPFavoriteDatabaseKey] ? [fav objectForKey:SPFavoriteDatabaseKey] : @"")];
[self setUseCompression:([fav objectForKey:SPFavoriteUseCompressionKey] ? [[fav objectForKey:SPFavoriteUseCompressionKey] boolValue] : YES)];
// SSL details
[self setUseSSL:([fav objectForKey:SPFavoriteUseSSLKey] ? [[fav objectForKey:SPFavoriteUseSSLKey] intValue] : NSOffState)];
[self setSslKeyFileLocationEnabled:([fav objectForKey:SPFavoriteSSLKeyFileLocationEnabledKey] ? [[fav objectForKey:SPFavoriteSSLKeyFileLocationEnabledKey] intValue] : NSOffState)];
@@ -157,6 +157,9 @@ - (void)initiateMySQLConnectionInBackground
}
}
if(![self useCompression])
[mySQLConnection removeClientFlags:SPMySQLClientFlagCompression];
// Connection delegate must be set before actual connection attempt is made
[mySQLConnection setDelegate:dbDocument];
@@ -489,6 +489,7 @@ extern NSString *SPFavoriteSSLCertificateFileLocationEnabledKey;
extern NSString *SPFavoriteSSLCertificateFileLocationKey;
extern NSString *SPFavoriteSSLCACertFileLocationEnabledKey;
extern NSString *SPFavoriteSSLCACertFileLocationKey;
extern NSString *SPFavoriteUseCompressionKey;
extern NSString *SPConnectionFavoritesChangedNotification;
// Favorites import/export
@@ -299,6 +299,7 @@
NSString *SPFavoriteSSLCertificateFileLocationKey = @"sslCertificateFileLocation";
NSString *SPFavoriteSSLCACertFileLocationEnabledKey = @"sslCACertFileLocationEnabled";
NSString *SPFavoriteSSLCACertFileLocationKey = @"sslCACertFileLocation";
NSString *SPFavoriteUseCompressionKey = @"useCompression";
NSString *SPConnectionFavoritesChangedNotification = @"SPConnectionFavoritesChanged";
// Favorites import/export

0 comments on commit 291078f

Please sign in to comment.