Skip to content

Commit 291078f

Browse files
committed
Add code to disable mysql protocol compression (no UI) to connect to Amazon Aurora (see #2122)
1 parent 26c821c commit 291078f

File tree

9 files changed

+49
-6
lines changed

9 files changed

+49
-6
lines changed

Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Copying.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ - (id)copyWithZone:(NSZone *)zone
6161
[copy setUseKeepAlive:useKeepAlive];
6262
[copy setRetryQueriesOnConnectionFailure:retryQueriesOnConnectionFailure];
6363
[copy setDelegateQueryLogging:delegateQueryLogging];
64+
[copy setClientFlags:clientFlags];
6465

6566
// Active connection state details, like selected database and encoding, are *not* copied.
6667

Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127

128128
// Queries
129129
BOOL retryQueriesOnConnectionFailure;
130+
131+
SPMySQLClientFlags clientFlags;
130132
}
131133

132134
#pragma mark -
@@ -164,6 +166,14 @@
164166

165167
@property (readwrite, assign) BOOL lastQueryWasCancelled;
166168

169+
/**
170+
* The mysql client capability flags to set when connecting.
171+
* See CLIENT_* in mysql.h
172+
*/
173+
@property (readwrite, assign, nonatomic) SPMySQLClientFlags clientFlags;
174+
- (void)addClientFlags:(SPMySQLClientFlags)opts;
175+
- (void)removeClientFlags:(SPMySQLClientFlags)opts;
176+
167177
#pragma mark -
168178
#pragma mark Connection and disconnection
169179

Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
#pragma mark Class constants
4242

4343
// The default connection options for MySQL connections
44-
const NSUInteger SPMySQLConnectionOptions =
45-
CLIENT_COMPRESS | // Enable protocol compression - almost always a win
46-
CLIENT_INTERACTIVE | // Mark ourselves as an interactive client
47-
CLIENT_MULTI_RESULTS; // Multiple result support (very basic, but present)
44+
const SPMySQLClientFlags SPMySQLConnectionOptions =
45+
SPMySQLClientFlagCompression | // Enable protocol compression - almost always a win
46+
SPMySQLClientFlagInteractive | // Mark ourselves as an interactive client
47+
SPMySQLClientFlagMultiResults; // Multiple result support (very basic, but present)
4848

4949
// List of permissible ciphers to use for SSL connections
5050
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
7373
@synthesize retryQueriesOnConnectionFailure;
7474
@synthesize delegateQueryLogging;
7575
@synthesize lastQueryWasCancelled;
76+
@synthesize clientFlags = clientFlags;
77+
78+
#pragma mark -
79+
#pragma mark Getters and Setters
80+
81+
- (void)addClientFlags:(SPMySQLClientFlags)opts
82+
{
83+
[self setClientFlags:([self clientFlags] | opts)];
84+
}
85+
86+
- (void)removeClientFlags:(SPMySQLClientFlags)opts
87+
{
88+
[self setClientFlags:([self clientFlags] & ~opts)];
89+
}
7690

7791
#pragma mark -
7892
#pragma mark Initialisation and teardown
@@ -188,6 +202,8 @@ - (id)init
188202

189203
// Start the ping keepalive timer
190204
keepAliveTimer = [[SPMySQLKeepAliveTimer alloc] initWithInterval:10 target:self selector:@selector(_keepAlive)];
205+
206+
[self setClientFlags:SPMySQLConnectionOptions];
191207
}
192208

193209
return self;
@@ -567,7 +583,7 @@ - (MYSQL *)_makeRawMySQLConnectionWithEncoding:(NSString *)encodingName isMaster
567583
mysql_ssl_set(theConnection, theSSLKeyFilePath, theSSLCertificatePath, theCACertificatePath, NULL, theSSLCiphers);
568584
}
569585

570-
MYSQL *connectionStatus = mysql_real_connect(theConnection, theHost, theUsername, thePassword, NULL, (unsigned int)port, theSocket, SPMySQLConnectionOptions);
586+
MYSQL *connectionStatus = mysql_real_connect(theConnection, theHost, theUsername, thePassword, NULL, (unsigned int)port, theSocket, [self clientFlags]);
571587

572588
// If the connection failed, return NULL
573589
if (theConnection != connectionStatus) {

Frameworks/SPMySQLFramework/Source/SPMySQLConstants.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@ typedef enum {
7474
SPMySQLResultAsLowMemStreamingResult = 2,
7575
SPMySQLResultAsStreamingResultStore = 3
7676
} SPMySQLResultType;
77+
78+
// Redeclared from mysql_com.h (private header)
79+
typedef NS_OPTIONS(unsigned long, SPMySQLClientFlags) {
80+
SPMySQLClientFlagCompression = 32, // CLIENT_COMPRESS
81+
SPMySQLClientFlagInteractive = 1024, // CLIENT_INTERACTIVE
82+
SPMySQLClientFlagMultiResults = (1UL << 17) // CLIENT_MULTI_RESULTS = 131072
83+
};

Source/SPConnectionController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
NSString *socket;
8080
NSString *port;
8181
NSInteger colorIndex;
82+
BOOL useCompression;
8283

8384
// SSL details
8485
NSInteger useSSL;
@@ -209,6 +210,7 @@
209210
@property (readwrite, retain) NSString *connectionKeychainItemAccount;
210211
@property (readwrite, retain) NSString *connectionSSHKeychainItemName;
211212
@property (readwrite, retain) NSString *connectionSSHKeychainItemAccount;
213+
@property (readwrite, assign) BOOL useCompression;
212214

213215
#ifdef SP_CODA
214216
@property (readwrite, assign) SPDatabaseDocument *dbDocument;

Source/SPConnectionController.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ @implementation SPConnectionController
132132
@synthesize sshKeyLocationEnabled;
133133
@synthesize sshKeyLocation;
134134
@synthesize sshPort;
135+
@synthesize useCompression;
135136

136137
#ifdef SP_CODA
137138
@synthesize dbDocument;
@@ -648,7 +649,8 @@ - (void)updateFavoriteSelection:(id)sender
648649
[self setColorIndex:([fav objectForKey:SPFavoriteColorIndexKey]? [[fav objectForKey:SPFavoriteColorIndexKey] integerValue] : -1)];
649650
[self setPort:([fav objectForKey:SPFavoritePortKey] ? [fav objectForKey:SPFavoritePortKey] : @"")];
650651
[self setDatabase:([fav objectForKey:SPFavoriteDatabaseKey] ? [fav objectForKey:SPFavoriteDatabaseKey] : @"")];
651-
652+
[self setUseCompression:([fav objectForKey:SPFavoriteUseCompressionKey] ? [[fav objectForKey:SPFavoriteUseCompressionKey] boolValue] : YES)];
653+
652654
// SSL details
653655
[self setUseSSL:([fav objectForKey:SPFavoriteUseSSLKey] ? [[fav objectForKey:SPFavoriteUseSSLKey] intValue] : NSOffState)];
654656
[self setSslKeyFileLocationEnabled:([fav objectForKey:SPFavoriteSSLKeyFileLocationEnabledKey] ? [[fav objectForKey:SPFavoriteSSLKeyFileLocationEnabledKey] intValue] : NSOffState)];

Source/SPConnectionHandler.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ - (void)initiateMySQLConnectionInBackground
157157
}
158158
}
159159

160+
if(![self useCompression])
161+
[mySQLConnection removeClientFlags:SPMySQLClientFlagCompression];
162+
160163
// Connection delegate must be set before actual connection attempt is made
161164
[mySQLConnection setDelegate:dbDocument];
162165

Source/SPConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ extern NSString *SPFavoriteSSLCertificateFileLocationEnabledKey;
489489
extern NSString *SPFavoriteSSLCertificateFileLocationKey;
490490
extern NSString *SPFavoriteSSLCACertFileLocationEnabledKey;
491491
extern NSString *SPFavoriteSSLCACertFileLocationKey;
492+
extern NSString *SPFavoriteUseCompressionKey;
492493
extern NSString *SPConnectionFavoritesChangedNotification;
493494

494495
// Favorites import/export

Source/SPConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
NSString *SPFavoriteSSLCertificateFileLocationKey = @"sslCertificateFileLocation";
300300
NSString *SPFavoriteSSLCACertFileLocationEnabledKey = @"sslCACertFileLocationEnabled";
301301
NSString *SPFavoriteSSLCACertFileLocationKey = @"sslCACertFileLocation";
302+
NSString *SPFavoriteUseCompressionKey = @"useCompression";
302303
NSString *SPConnectionFavoritesChangedNotification = @"SPConnectionFavoritesChanged";
303304

304305
// Favorites import/export

0 commit comments

Comments
 (0)