Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 291078f
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 6 deletions.
Expand Up @@ -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.

Expand Down
10 changes: 10 additions & 0 deletions Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h
Expand Up @@ -127,6 +127,8 @@

// Queries
BOOL retryQueriesOnConnectionFailure;

SPMySQLClientFlags clientFlags;
}

#pragma mark -
Expand Down Expand Up @@ -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

Expand Down
26 changes: 21 additions & 5 deletions Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h
Expand Up @@ -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
};
2 changes: 2 additions & 0 deletions Source/SPConnectionController.h
Expand Up @@ -79,6 +79,7 @@
NSString *socket;
NSString *port;
NSInteger colorIndex;
BOOL useCompression;

// SSL details
NSInteger useSSL;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion Source/SPConnectionController.m
Expand Up @@ -132,6 +132,7 @@ @implementation SPConnectionController
@synthesize sshKeyLocationEnabled;
@synthesize sshKeyLocation;
@synthesize sshPort;
@synthesize useCompression;

#ifdef SP_CODA
@synthesize dbDocument;
Expand Down Expand Up @@ -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)];
Expand Down
3 changes: 3 additions & 0 deletions Source/SPConnectionHandler.m
Expand Up @@ -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];

Expand Down
1 change: 1 addition & 0 deletions Source/SPConstants.h
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Source/SPConstants.m
Expand Up @@ -299,6 +299,7 @@
NSString *SPFavoriteSSLCertificateFileLocationKey = @"sslCertificateFileLocation";
NSString *SPFavoriteSSLCACertFileLocationEnabledKey = @"sslCACertFileLocationEnabled";
NSString *SPFavoriteSSLCACertFileLocationKey = @"sslCACertFileLocation";
NSString *SPFavoriteUseCompressionKey = @"useCompression";
NSString *SPConnectionFavoritesChangedNotification = @"SPConnectionFavoritesChanged";

// Favorites import/export
Expand Down

0 comments on commit 291078f

Please sign in to comment.