Skip to content

Commit 9f39a5c

Browse files
committed
[WIP] Initial work on integrated refactored libSession networking
• Started work on integrating refactored libSession networking • Fixed a couple of issues with the libSession build script
1 parent a758139 commit 9f39a5c

File tree

23 files changed

+795
-362
lines changed

23 files changed

+795
-362
lines changed

Scripts/build_libSession_util.sh

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ function finish {
2222
}
2323
trap finish EXIT ERR SIGINT SIGTERM
2424

25+
# Robustly removes a directory, first clearing any immutable flags (work around Xcode's indexer file locking)
26+
remove_locked_dir() {
27+
local dir_to_remove="$1"
28+
if [ -d "${dir_to_remove}" ]; then
29+
echo "- Unlocking and removing ${dir_to_remove}"
30+
chflags -R nouchg "${dir_to_remove}" &>/dev/null || true
31+
rm -rf "${dir_to_remove}"
32+
fi
33+
}
34+
35+
sync_headers() {
36+
local source_dir="$1"
37+
echo "- Syncing headers from ${source_dir}"
38+
remove_locked_dir "${TARGET_BUILD_DIR}/include"
39+
remove_locked_dir "${INDEX_DIR}/include"
40+
41+
# Ensure destination parent directories exist
42+
mkdir -p "${TARGET_BUILD_DIR}/include"
43+
mkdir -p "${INDEX_DIR}/include"
44+
45+
rsync -rtc --delete --exclude='.DS_Store' "${source_dir}/" "${TARGET_BUILD_DIR}/include/"
46+
rsync -rtc --delete --exclude='.DS_Store' "${source_dir}/" "${INDEX_DIR}/include/"
47+
}
48+
2549
# Determine whether we want to build from source
2650
TARGET_ARCH_DIR=""
2751

@@ -35,11 +59,10 @@ else
3559
fi
3660

3761
if [ "${COMPILE_LIB_SESSION}" != "YES" ]; then
38-
echo "Restoring original headers to Xcode Indexer cache from backup..."
39-
rm -rf "${INDEX_DIR}/include"
40-
rsync -rt --exclude='.DS_Store' "${PRE_BUILT_FRAMEWORK_DIR}/${FRAMEWORK_DIR}/${TARGET_ARCH_DIR}/Headers/" "${INDEX_DIR}/include"
41-
4262
echo "Using pre-packaged SessionUtil"
63+
sync_headers "${PRE_BUILT_FRAMEWORK_DIR}/${FRAMEWORK_DIR}/${TARGET_ARCH_DIR}/Headers/"
64+
echo "- Revert to SPM complete."
65+
4366
exit 0
4467
fi
4568

@@ -83,20 +106,22 @@ fi
83106
echo "- Checking if libSession changed..."
84107
REQUIRES_BUILD=0
85108

86-
# Generate a hash to determine whether any source files have changed
87-
SOURCE_HASH=$(find "${LIB_SESSION_SOURCE_DIR}/src" -type f -not -name '.DS_Store' -exec md5 {} + | awk '{print $NF}' | sort | md5 | awk '{print $NF}')
88-
HEADER_HASH=$(find "${LIB_SESSION_SOURCE_DIR}/include" -type f -not -name '.DS_Store' -exec md5 {} + | awk '{print $NF}' | sort | md5 | awk '{print $NF}')
89-
EXTERNAL_HASH=$(find "${LIB_SESSION_SOURCE_DIR}/external" -type f -not -name '.DS_Store' -exec md5 {} + | awk '{print $NF}' | sort | md5 | awk '{print $NF}')
90-
MAKE_LISTS_HASH=$(md5 -q "${LIB_SESSION_SOURCE_DIR}/CMakeLists.txt")
91-
STATIC_BUNDLE_HASH=$(md5 -q "${LIB_SESSION_SOURCE_DIR}/utils/static-bundle.sh")
92-
93-
CURRENT_SOURCE_TREE_HASH=$( (
94-
echo "${SOURCE_HASH}"
95-
echo "${HEADER_HASH}"
96-
echo "${EXTERNAL_HASH}"
97-
echo "${MAKE_LISTS_HASH}"
98-
echo "${STATIC_BUNDLE_HASH}"
99-
) | sort | md5 -q)
109+
# Generate a hash to determine whether any source files have changed (by using git we automatically
110+
# respect .gitignore)
111+
CURRENT_SOURCE_TREE_HASH=$( \
112+
( \
113+
cd "${LIB_SESSION_SOURCE_DIR}" && git ls-files --recurse-submodules \
114+
) \
115+
| grep -vE '/(tests?|docs?|examples?)/|\.md$|/(\.DS_Store|\.gitignore)$' \
116+
| sort \
117+
| tr '\n' '\0' \
118+
| ( \
119+
cd "${LIB_SESSION_SOURCE_DIR}" && xargs -0 md5 -r \
120+
) \
121+
| awk '{print $1}' \
122+
| sort \
123+
| md5 -q \
124+
)
100125

101126
PREVIOUS_BUILT_FRAMEWORK_SLICE_DIR=""
102127
if [ -f "$LAST_BUILT_FRAMEWORK_SLICE_DIR_FILE" ]; then
@@ -217,6 +242,8 @@ if [ "${REQUIRES_BUILD}" == 1 ]; then
217242
-DBUILD_TESTS=OFF \
218243
-DBUILD_STATIC_DEPS=ON \
219244
-DENABLE_VISIBILITY=ON \
245+
-DLOKINET_FULL=OFF \
246+
-DLOKINET_DAEMON=OFF \
220247
-DSUBMODULE_CHECK=$submodule_check \
221248
-DCMAKE_BUILD_TYPE=$build_type \
222249
-DLOCAL_MIRROR=https://oxen.rocks/deps
@@ -318,15 +345,11 @@ fi
318345

319346
echo "- Replacing build dir files"
320347

321-
# Remove the current files (might be "newer")
322-
rm -rf "${TARGET_BUILD_DIR}/libsession-util.a"
323-
rm -rf "${TARGET_BUILD_DIR}/include"
324-
rm -rf "${INDEX_DIR}/include"
325-
326348
# Rsync the compiled ones (maintaining timestamps)
349+
rm -rf "${TARGET_BUILD_DIR}/libsession-util.a"
327350
rsync -rt "${COMPILE_DIR}/libsession-util.a" "${TARGET_BUILD_DIR}/libsession-util.a"
328-
rsync -rt --exclude='.DS_Store' "${COMPILE_DIR}/Headers/" "${TARGET_BUILD_DIR}/include"
329-
rsync -rt --exclude='.DS_Store' "${COMPILE_DIR}/Headers/" "${INDEX_DIR}/include"
351+
sync_headers "${COMPILE_DIR}/Headers/"
352+
echo "- Sync complete."
330353

331354
# Output to XCode just so the output is good
332355
echo "LibSession is Ready"

Session.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@
10071007
FDD20C162A09E64A003898FB /* GetExpiriesRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD20C152A09E64A003898FB /* GetExpiriesRequest.swift */; };
10081008
FDD20C182A09E7D3003898FB /* GetExpiriesResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD20C172A09E7D3003898FB /* GetExpiriesResponse.swift */; };
10091009
FDD20C1A2A0A03AC003898FB /* DeleteInboxResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD20C192A0A03AC003898FB /* DeleteInboxResponse.swift */; };
1010+
FDD23ADE2E44501E0057E853 /* RequestCategory.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD23ADD2E44501B0057E853 /* RequestCategory.swift */; };
10101011
FDD2506E283711D600198BDA /* DifferenceKit+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD2506D283711D600198BDA /* DifferenceKit+Utilities.swift */; };
10111012
FDD250722837234B00198BDA /* MediaGalleryNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD250712837234B00198BDA /* MediaGalleryNavigationController.swift */; };
10121013
FDD82C3F2A205D0A00425F05 /* ProcessResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD82C3E2A205D0A00425F05 /* ProcessResult.swift */; };
@@ -2267,6 +2268,7 @@
22672268
FDD20C152A09E64A003898FB /* GetExpiriesRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetExpiriesRequest.swift; sourceTree = "<group>"; };
22682269
FDD20C172A09E7D3003898FB /* GetExpiriesResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetExpiriesResponse.swift; sourceTree = "<group>"; };
22692270
FDD20C192A0A03AC003898FB /* DeleteInboxResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteInboxResponse.swift; sourceTree = "<group>"; };
2271+
FDD23ADD2E44501B0057E853 /* RequestCategory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestCategory.swift; sourceTree = "<group>"; };
22702272
FDD2506D283711D600198BDA /* DifferenceKit+Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DifferenceKit+Utilities.swift"; sourceTree = "<group>"; };
22712273
FDD250712837234B00198BDA /* MediaGalleryNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaGalleryNavigationController.swift; sourceTree = "<group>"; };
22722274
FDD383702AFDD0E1001367F2 /* BencodeResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BencodeResponse.swift; sourceTree = "<group>"; };
@@ -5044,6 +5046,7 @@
50445046
FDB5DAF22A96DD4F002C8721 /* PreparedRequest+Sending.swift */,
50455047
FD22729D2C33E336004D8A6C /* ProxiedContentDownloader.swift */,
50465048
FD2272A32C33E337004D8A6C /* Request.swift */,
5049+
FDD23ADD2E44501B0057E853 /* RequestCategory.swift */,
50475050
FD2272A52C33E337004D8A6C /* ResponseInfo.swift */,
50485051
FD2272A02C33E336004D8A6C /* SwarmDrainBehaviour.swift */,
50495052
FD2272962C33E335004D8A6C /* UpdatableTimestamp.swift */,
@@ -6192,6 +6195,7 @@
61926195
files = (
61936196
FD2272B12C33E337004D8A6C /* ProxiedContentDownloader.swift in Sources */,
61946197
FDF848C329405C5A007DCAE5 /* DeleteMessagesRequest.swift in Sources */,
6198+
FDD23ADE2E44501E0057E853 /* RequestCategory.swift in Sources */,
61956199
FDF8489129405C13007DCAE5 /* SnodeAPINamespace.swift in Sources */,
61966200
FD2272AB2C33E337004D8A6C /* ValidatableResponse.swift in Sources */,
61976201
FD2272B72C33E337004D8A6C /* Request.swift in Sources */,

Session/Settings/NukeDataModal.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ final class NukeDataModal: Modal {
202202
switch authMethod.info {
203203
case .community(let server, _, _, _, _):
204204
return try OpenGroupAPI.preparedClearInbox(
205-
requestAndPathBuildTimeout: Network.defaultTimeout,
205+
overallTimeout: Network.defaultTimeout,
206206
authMethod: authMethod,
207207
using: dependencies
208208
)
@@ -221,7 +221,7 @@ final class NukeDataModal: Modal {
221221
try SnodeAPI
222222
.preparedDeleteAllMessages(
223223
namespace: .all,
224-
requestAndPathBuildTimeout: Network.defaultTimeout,
224+
overallTimeout: Network.defaultTimeout,
225225
authMethod: authMethod,
226226
using: dependencies
227227
)

SessionMessagingKit/Jobs/ConfigurationSyncJob.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public enum ConfigurationSyncJob: JobExecutor {
132132
requireAllBatchResponses: (additionalTransientData?.requireAllBatchResponses == true),
133133
swarmPublicKey: swarmPublicKey,
134134
snodeRetrievalRetryCount: 0, // This job has it's own retry mechanism
135-
requestAndPathBuildTimeout: Network.defaultTimeout,
135+
overallTimeout: Network.defaultTimeout,
136136
using: dependencies
137137
).send(using: dependencies)
138138
}

SessionMessagingKit/Open Groups/OpenGroupAPI.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -806,11 +806,11 @@ public enum OpenGroupAPI {
806806
x25519PublicKey: publicKey,
807807
fileName: fileName
808808
),
809-
body: data
809+
body: data,
810+
requestTimeout: Network.fileUploadTimeout
810811
),
811812
responseType: FileUploadResponse.self,
812813
additionalSignatureData: AdditionalSigningData(authMethod),
813-
requestTimeout: Network.fileUploadTimeout,
814814
using: dependencies
815815
)
816816
.signed(with: OpenGroupAPI.signRequest, using: dependencies)
@@ -844,11 +844,11 @@ public enum OpenGroupAPI {
844844
return try Network.PreparedRequest(
845845
request: Request<NoBody, Endpoint>(
846846
endpoint: .roomFileIndividual(roomToken, fileId),
847-
authMethod: authMethod
847+
authMethod: authMethod,
848+
requestTimeout: Network.fileDownloadTimeout
848849
),
849850
responseType: Data.self,
850851
additionalSignatureData: AdditionalSigningData(authMethod),
851-
requestTimeout: Network.fileDownloadTimeout,
852852
using: dependencies
853853
)
854854
.signed(with: OpenGroupAPI.signRequest, using: dependencies)
@@ -898,20 +898,20 @@ public enum OpenGroupAPI {
898898
/// Remove all message requests from inbox, this methrod will return the number of messages deleted
899899
public static func preparedClearInbox(
900900
requestTimeout: TimeInterval = Network.defaultTimeout,
901-
requestAndPathBuildTimeout: TimeInterval? = nil,
901+
overallTimeout: TimeInterval? = nil,
902902
authMethod: AuthenticationMethod,
903903
using dependencies: Dependencies
904904
) throws -> Network.PreparedRequest<DeleteInboxResponse> {
905905
return try Network.PreparedRequest(
906906
request: Request<NoBody, Endpoint>(
907907
method: .delete,
908908
endpoint: .inbox,
909-
authMethod: authMethod
909+
authMethod: authMethod,
910+
requestTimeout: requestTimeout,
911+
overallTimeout: overallTimeout
910912
),
911913
responseType: DeleteInboxResponse.self,
912914
additionalSignatureData: AdditionalSigningData(authMethod),
913-
requestTimeout: requestTimeout,
914-
requestAndPathBuildTimeout: requestAndPathBuildTimeout,
915915
using: dependencies
916916
)
917917
.signed(with: OpenGroupAPI.signRequest, using: dependencies)

SessionMessagingKit/Open Groups/Types/Request+OpenGroupAPI.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public extension Request where Endpoint == OpenGroupAPI.Endpoint {
1414
queryParameters: [HTTPQueryParam: String] = [:],
1515
headers: [HTTPHeader: String] = [:],
1616
body: T? = nil,
17-
authMethod: AuthenticationMethod
17+
authMethod: AuthenticationMethod,
18+
requestTimeout: TimeInterval = Network.defaultTimeout,
19+
overallTimeout: TimeInterval? = nil
1820
) throws {
1921
guard case .community(let server, let publicKey, _, _, _) = authMethod.info else {
2022
throw CryptoError.signatureGenerationFailed
@@ -29,7 +31,9 @@ public extension Request where Endpoint == OpenGroupAPI.Endpoint {
2931
headers: headers,
3032
x25519PublicKey: publicKey
3133
),
32-
body: body
34+
body: body,
35+
requestTimeout: requestTimeout,
36+
overallTimeout: overallTimeout
3337
)
3438
}
3539
}

SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ public enum PushNotificationAPI {
186186
timestamp: (dependencies[cache: .snodeAPI].currentOffsetTimestampMs() / 1000) // Seconds
187187
)
188188
}
189-
)
189+
),
190+
retryCount: PushNotificationAPI.maxRetryCount
190191
),
191192
responseType: SubscribeResponse.self,
192-
retryCount: PushNotificationAPI.maxRetryCount,
193193
using: dependencies
194194
)
195195
.handleEvents(
@@ -233,10 +233,10 @@ public enum PushNotificationAPI {
233233
timestamp: (dependencies[cache: .snodeAPI].currentOffsetTimestampMs() / 1000) // Seconds
234234
)
235235
}
236-
)
236+
),
237+
retryCount: PushNotificationAPI.maxRetryCount
237238
),
238239
responseType: UnsubscribeResponse.self,
239-
retryCount: PushNotificationAPI.maxRetryCount,
240240
using: dependencies
241241
)
242242
.handleEvents(

SessionMessagingKit/Sending & Receiving/Notifications/Types/Request+PushNotificationAPI.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public extension Request where Endpoint == PushNotificationAPI.Endpoint {
1212
endpoint: Endpoint,
1313
queryParameters: [HTTPQueryParam: String] = [:],
1414
headers: [HTTPHeader: String] = [:],
15-
body: T? = nil
15+
body: T? = nil,
16+
retryCount: Int = 0
1617
) throws {
1718
self = try Request(
1819
endpoint: endpoint,
@@ -23,7 +24,8 @@ public extension Request where Endpoint == PushNotificationAPI.Endpoint {
2324
headers: headers,
2425
x25519PublicKey: PushNotificationAPI.serverPublicKey
2526
),
26-
body: body
27+
body: body,
28+
retryCount: retryCount
2729
)
2830
}
2931
}

SessionMessagingKit/Utilities/DisplayPictureManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public class DisplayPictureManager {
281281
guard
282282
let preparedUpload: Network.PreparedRequest<FileUploadResponse> = try? Network.preparedUpload(
283283
data: encryptedData,
284-
requestAndPathBuildTimeout: Network.fileUploadTimeout,
284+
overallTimeout: Network.fileUploadTimeout,
285285
using: dependencies
286286
)
287287
else {

SessionNetworkingKit/Database/Models/SnodeReceivedMessageInfo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public extension SnodeReceivedMessageInfo {
6060
expirationDateMs: Int64?
6161
) {
6262
self.swarmPublicKey = swarmPublicKey
63-
self.snodeAddress = snode.address
63+
self.snodeAddress = snode.omqAddress
6464
self.namespace = namespace.rawValue
6565
self.hash = hash
6666
self.expirationDateMs = (expirationDateMs ?? 0)
@@ -85,7 +85,7 @@ public extension SnodeReceivedMessageInfo {
8585
.filter(SnodeReceivedMessageInfo.Columns.wasDeletedOrInvalid == false)
8686
.filter(
8787
SnodeReceivedMessageInfo.Columns.swarmPublicKey == swarmPublicKey &&
88-
SnodeReceivedMessageInfo.Columns.snodeAddress == snode.address &&
88+
SnodeReceivedMessageInfo.Columns.snodeAddress == snode.omqAddress &&
8989
SnodeReceivedMessageInfo.Columns.namespace == namespace.rawValue
9090
)
9191
.filter(SnodeReceivedMessageInfo.Columns.expirationDateMs > currentOffsetTimestampMs)

0 commit comments

Comments
 (0)