Remove UD websocket.

This commit is contained in:
Matthew Chen 2018-11-14 18:03:10 -05:00
parent 99d41256a9
commit dacccccf74
5 changed files with 21 additions and 74 deletions

View file

@ -119,12 +119,11 @@ public class RequestMaker: NSObject {
}
let isUDRequest: Bool = udAccessForRequest != nil
let request: TSRequest = requestFactoryBlock(udAccessForRequest?.udAccessKey)
let webSocketType: OWSWebSocketType = (isUDRequest ? .UD : .default)
let canMakeWebsocketRequests = (socketManager.canMakeRequests(of: webSocketType) && !skipWebsocket && !isUDRequest)
let canMakeWebsocketRequests = (socketManager.canMakeRequests() && !skipWebsocket && !isUDRequest)
if canMakeWebsocketRequests {
return Promise { resolver in
socketManager.make(request, webSocketType: webSocketType, success: { (responseObject: Any?) in
socketManager.make(request, success: { (responseObject: Any?) in
if self.udManager.isUDVerboseLoggingEnabled() {
if isUDRequest {
Logger.debug("UD websocket request '\(self.label)' succeeded.")

View file

@ -8,11 +8,6 @@ static void *OWSWebSocketStateObservationContext = &OWSWebSocketStateObservation
extern NSString *const kNSNotification_OWSWebSocketStateDidChange;
typedef NS_ENUM(NSUInteger, OWSWebSocketType) {
OWSWebSocketTypeDefault,
OWSWebSocketTypeUD,
};
typedef NS_ENUM(NSUInteger, OWSWebSocketState) {
OWSWebSocketStateClosed,
OWSWebSocketStateConnecting,
@ -29,8 +24,7 @@ typedef void (^TSSocketMessageFailure)(NSInteger statusCode, NSData *_Nullable r
@property (nonatomic, readonly) OWSWebSocketState state;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithWebSocketType:(OWSWebSocketType)webSocketType NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_DESIGNATED_INITIALIZER;
// If the app is in the foreground, we'll try to open the socket unless it's already
// open or connecting.

View file

@ -143,21 +143,9 @@ NSString *const kNSNotification_OWSWebSocketStateDidChange = @"kNSNotification_O
#pragma mark -
NSString *NSStringFromOWSWebSocketType(OWSWebSocketType type)
{
switch (type) {
case OWSWebSocketTypeDefault:
return @"Default";
case OWSWebSocketTypeUD:
return @"UD";
}
}
// OWSWebSocket's properties should only be accessed from the main thread.
@interface OWSWebSocket () <SRWebSocketDelegate>
@property (nonatomic) OWSWebSocketType webSocketType;
// This class has a few "tiers" of state.
//
// The first tier is the actual websocket and the timers used
@ -216,7 +204,7 @@ NSString *NSStringFromOWSWebSocketType(OWSWebSocketType type)
@implementation OWSWebSocket
- (instancetype)initWithWebSocketType:(OWSWebSocketType)webSocketType
- (instancetype)init
{
self = [super init];
@ -226,7 +214,6 @@ NSString *NSStringFromOWSWebSocketType(OWSWebSocketType type)
OWSAssertIsOnMainThread();
_webSocketType = webSocketType;
_state = OWSWebSocketStateClosed;
_socketMessageMap = [NSMutableDictionary new];
@ -573,12 +560,11 @@ NSString *NSStringFromOWSWebSocketType(OWSWebSocketType type)
[socketMessage didFailBeforeSending];
return;
}
OWSLogInfo(@"making request: %llu, %@: %@, jsonData.length: %zd, socketType: %@",
OWSLogInfo(@"making request: %llu, %@: %@, jsonData.length: %zd",
socketMessage.requestId,
request.HTTPMethod,
requestPath,
jsonData.length,
NSStringFromOWSWebSocketType(self.webSocketType));
jsonData.length);
const int64_t kSocketTimeoutSeconds = 10;
__weak TSSocketMessage *weakSocketMessage = socketMessage;
@ -650,7 +636,7 @@ NSString *NSStringFromOWSWebSocketType(OWSWebSocketType type)
[socketMessage didSucceedWithResponseObject:responseObject];
} else {
if (responseStatus == 403 && self.webSocketType == OWSWebSocketTypeDefault) {
if (responseStatus == 403) {
// This should be redundant with our check for the socket
// failing due to 403, but let's be thorough.
[self.tsAccountManager setIsDeregistered:YES];
@ -718,7 +704,7 @@ NSString *NSStringFromOWSWebSocketType(OWSWebSocketType type)
if ([error.domain isEqualToString:SRWebSocketErrorDomain] && error.code == 2132) {
NSNumber *_Nullable statusCode = error.userInfo[SRHTTPResponseErrorKey];
if (statusCode.unsignedIntegerValue == 403 && self.webSocketType == OWSWebSocketTypeDefault) {
if (statusCode.unsignedIntegerValue == 403) {
[self.tsAccountManager setIsDeregistered:YES];
}
}
@ -910,16 +896,9 @@ NSString *NSStringFromOWSWebSocketType(OWSWebSocketType type)
- (NSString *)webSocketAuthenticationString
{
switch (self.webSocketType) {
case OWSWebSocketTypeUD:
// UD socket is unauthenticated.
return @"";
case OWSWebSocketTypeDefault:
return
[NSString stringWithFormat:@"?login=%@&password=%@",
[[TSAccountManager localNumber] stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"],
[TSAccountManager serverAuthToken]];
}
return [NSString stringWithFormat:@"?login=%@&password=%@",
[[TSAccountManager localNumber] stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"],
[TSAccountManager serverAuthToken]];
}
#pragma mark - Socket LifeCycle
@ -1149,9 +1128,7 @@ NSString *NSStringFromOWSWebSocketType(OWSWebSocketType type)
{
OWSAssertIsOnMainThread();
if (self.webSocketType == OWSWebSocketTypeDefault) {
[self cycleSocket];
}
[self cycleSocket];
}
@end

View file

@ -39,10 +39,9 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Message Sending
- (BOOL)canMakeRequestsOfType:(OWSWebSocketType)webSocketType;
- (BOOL)canMakeRequests;
- (void)makeRequest:(TSRequest *)request
webSocketType:(OWSWebSocketType)webSocketType
success:(TSSocketMessageSuccess)success
failure:(TSSocketMessageFailure)failure;

View file

@ -9,8 +9,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface TSSocketManager ()
@property (nonatomic) OWSWebSocket *websocketDefault;
@property (nonatomic) OWSWebSocket *websocketUD;
@property (nonatomic) OWSWebSocket *websocket;
@end
@ -28,8 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssertIsOnMainThread();
_websocketDefault = [[OWSWebSocket alloc] initWithWebSocketType:OWSWebSocketTypeDefault];
_websocketUD = [[OWSWebSocket alloc] initWithWebSocketType:OWSWebSocketTypeUD];
_websocket = [[OWSWebSocket alloc] init];
OWSSingletonAssert();
@ -48,51 +46,31 @@ NS_ASSUME_NONNULL_BEGIN
return SSKEnvironment.shared.socketManager;
}
- (OWSWebSocket *)webSocketOfType:(OWSWebSocketType)webSocketType
- (BOOL)canMakeRequests
{
switch (webSocketType) {
case OWSWebSocketTypeDefault:
return self.websocketDefault;
case OWSWebSocketTypeUD:
return self.websocketUD;
}
}
- (BOOL)canMakeRequestsOfType:(OWSWebSocketType)webSocketType
{
return [self webSocketOfType:webSocketType].canMakeRequests;
return self.websocket.canMakeRequests;
}
- (void)makeRequest:(TSRequest *)request
webSocketType:(OWSWebSocketType)webSocketType
success:(TSSocketMessageSuccess)success
failure:(TSSocketMessageFailure)failure
{
[[self webSocketOfType:webSocketType] makeRequest:request success:success failure:failure];
[self.websocket makeRequest:request success:success failure:failure];
}
- (void)requestSocketOpen
{
[self.websocketDefault requestSocketOpen];
[self.websocketUD requestSocketOpen];
[self.websocket requestSocketOpen];
}
- (void)cycleSocket
{
[self.websocketDefault cycleSocket];
[self.websocketUD cycleSocket];
[self.websocket cycleSocket];
}
- (OWSWebSocketState)highestSocketState
{
if (self.websocketDefault.state == OWSWebSocketStateOpen || self.websocketUD.state == OWSWebSocketStateOpen) {
return OWSWebSocketStateOpen;
} else if (self.websocketDefault.state == OWSWebSocketStateConnecting
|| self.websocketUD.state == OWSWebSocketStateConnecting) {
return OWSWebSocketStateConnecting;
} else {
return OWSWebSocketStateClosed;
}
return self.websocket.state;
}
@end