Skip to content

Commit

Permalink
Create Utils class on iOS and move relevant methods there
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkabuki committed Oct 19, 2023
1 parent bedc2e3 commit c1132ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/mobile/ios/Quiet/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ - (void) spinupBackend:(BOOL)init {
// (1/6) Find ports to use in tor and backend configuration

FindFreePort *findFreePort = [FindFreePort new];
Utils *utils = [Utils new];

self.dataPort = [findFreePort getFirstStartingFromPort:11000];
if (self.socketIOSecret == nil) {
self.socketIOSecret = randomStringWithLength(20);
self.socketIOSecret = [utils generateRandomStringWithLength:(20)];
}

self.dataPort = [findFreePort getFirstStartingFromPort:11000];
uint16_t socksPort = [findFreePort getFirstStartingFromPort:12000];
uint16_t controlPort = [findFreePort getFirstStartingFromPort:14000];
uint16_t httpTunnelPort = [findFreePort getFirstStartingFromPort:16000];
Expand Down
17 changes: 17 additions & 0 deletions packages/mobile/ios/Utils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@objc(Utils)
class Utils: NSObject {

@objc
func generateRandomString(length: Int) -> String {
let letters = "0123456789"
var randomString = String()

for _ in 0..<length {
let rand = Int(arc4random_uniform(UInt32(letters.count)))
let character = letters[letters.index(letters.startIndex, offsetBy: rand)]
randomString.append(character)
}

return randomString
}
}

0 comments on commit c1132ce

Please sign in to comment.