Skip to content

Commit 1522bae

Browse files
refactor: align structure more closely with rust library (#167)
* refactor: align structure more closely with rust library - divide structures, `fn blob_` is now `blobs().` etc - workarounds for python reserved names `del` and `import` * update kotlin * update swift * python: apply ruff fixes
1 parent 4716933 commit 1522bae

File tree

25 files changed

+11641
-8864
lines changed

25 files changed

+11641
-8864
lines changed

Iroh.xcframework/ios-arm64/Iroh.framework/Headers/iroh_ffiFFI.h

Lines changed: 609 additions & 472 deletions
Large diffs are not rendered by default.

Iroh.xcframework/ios-arm64_x86_64-simulator/Iroh.framework/Headers/iroh_ffiFFI.h

Lines changed: 609 additions & 472 deletions
Large diffs are not rendered by default.

Iroh.xcframework/macos-arm64/Iroh.framework/Headers/iroh_ffiFFI.h

Lines changed: 609 additions & 472 deletions
Large diffs are not rendered by default.

IrohLib/Sources/IrohLib/IrohLib.swift

Lines changed: 3459 additions & 2801 deletions
Large diffs are not rendered by default.

IrohLib/Tests/IrohLibTests/IrohLibTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import XCTest
33

44
final class IrohLibTests: XCTestCase {
55
func testNodeId() async throws {
6-
let node = try await IrohLib.IrohNode.memory()
7-
let nodeId = try await node.nodeId()
6+
let node = try await IrohLib.Iroh.memory()
7+
let nodeId = try await node.node().nodeId()
88
print(nodeId)
99

1010
XCTAssertEqual(true, true)

kotlin/author_test.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ import iroh.*
33

44
kotlinx.coroutines.runBlocking {
55
// create node
6-
val node = IrohNode.memory()
6+
val node = Iroh.memory()
77

88
// creating a node also creates an author
9-
assert(node.authorList().size == 1)
9+
assert(node.authors().list().size == 1)
1010

1111
// create
12-
val authorId = node.authorCreate()
12+
val authorId = node.authors().create()
1313

1414
// list all authors on the node
15-
assert(node.authorList().size == 2)
15+
assert(node.authors().list().size == 2)
1616

1717
// export the author
18-
val author = node.authorExport(authorId)
18+
val author = node.authors().export(authorId)
1919
assert(authorId.equal(author.id()))
2020

2121
// remove that author from the node
22-
node.authorDelete(authorId)
22+
node.authors().delete(authorId)
2323

2424
// check there are 1 authors on the node
25-
assert(node.authorList().size == 1)
25+
assert(node.authors().list().size == 1)
2626

2727
// import the author back into the node
28-
node.authorImport(author)
28+
node.authors().import(author)
2929

3030
// check there is 1 author on the node
31-
assert(node.authorList().size == 2)
31+
assert(node.authors().list().size == 2)
3232
}

kotlin/blob_test.kts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,34 @@ runBlocking {
9292
runBlocking {
9393
// create node
9494
val irohDir = kotlin.io.path.createTempDirectory("doc-test")
95-
val node = IrohNode.persistent(irohDir.toString())
95+
val node = Iroh.persistent(irohDir.toString())
9696

9797
// create bytes
9898
val blobSize = 100
9999
val bytes = generateRandomByteArray(blobSize)
100100

101101
// add blob
102-
val addOutcome = node.blobsAddBytes(bytes)
102+
val addOutcome = node.blobs().addBytes(bytes)
103103

104104
// check outcome info is as expected
105105
assert(addOutcome.format == BlobFormat.RAW)
106106
assert(addOutcome.size == blobSize.toULong())
107107

108108
// check we get the expected size from the hash
109109
val hash = addOutcome.hash
110-
val gotSize = node.blobsSize(hash)
110+
val gotSize = node.blobs().size(hash)
111111
assert(gotSize == blobSize.toULong())
112112

113113
// get bytes
114-
val gotBytes = node.blobsReadToBytes(hash)
114+
val gotBytes = node.blobs().readToBytes(hash)
115115
assert(gotBytes.size == blobSize)
116116
assert(gotBytes contentEquals bytes)
117117
}
118118

119119
// test functionality between reading bytes from a path and writing bytes to a path
120120
runBlocking {
121121
val irohDir = kotlin.io.path.createTempDirectory("doc-test-read-bytes")
122-
val node = IrohNode.persistent(irohDir.toString())
122+
val node = Iroh.persistent(irohDir.toString())
123123

124124
// create bytes
125125
val blobSize = 100
@@ -154,24 +154,24 @@ runBlocking {
154154
}
155155
}
156156
val cb = Handler()
157-
node.blobsAddFromPath(path, false, tag, wrap, cb)
157+
node.blobs().addFromPath(path, false, tag, wrap, cb)
158158

159159
// check outcome info is as expected
160160
assert(cb.format == BlobFormat.RAW)
161161
assert(cb.hash != null)
162162

163163
// check we get the expected size from the hash
164-
val gotSize = node.blobsSize(cb.hash!!)
164+
val gotSize = node.blobs().size(cb.hash!!)
165165
assert(gotSize == blobSize.toULong())
166166

167167
// get bytes
168-
val gotBytes = node.blobsReadToBytes(cb.hash!!)
168+
val gotBytes = node.blobs().readToBytes(cb.hash!!)
169169
assert(gotBytes.size == blobSize)
170170
assert(gotBytes contentEquals bytes)
171171

172172
// write to file
173173
val outPath = dir.toString() + "out"
174-
node.blobsWriteToPath(cb.hash!!, outPath)
174+
node.blobs().writeToPath(cb.hash!!, outPath)
175175

176176
// open file
177177
val gotBytesFile = java.io.File(outPath).readBytes()
@@ -192,10 +192,10 @@ runBlocking {
192192
}
193193
// make node
194194
val irohDir = kotlin.io.path.createTempDirectory("doc-test-collection")
195-
val node = IrohNode.persistent(irohDir.toString())
195+
val node = Iroh.persistent(irohDir.toString())
196196

197197
// ensure zero blobs
198-
val blobs = node.blobsList()
198+
val blobs = node.blobs().list()
199199
assert(blobs.size == 0)
200200

201201
// create callback to get blobs and collection hash
@@ -226,13 +226,13 @@ runBlocking {
226226
val tag = SetTagOption.auto()
227227
val wrap = WrapOption.noWrap()
228228
// add from path
229-
node.blobsAddFromPath(collectionDir.toString(), false, tag, wrap, cb)
229+
node.blobs().addFromPath(collectionDir.toString(), false, tag, wrap, cb)
230230

231231
assert(cb.collectionHash != null)
232232
assert(cb.format == BlobFormat.HASH_SEQ)
233233

234234
// list collections
235-
val collections = node.blobsListCollections()
235+
val collections = node.blobs().listCollections()
236236
println("collection hash " + collections[0].hash)
237237
assert(collections.size == 1)
238238
assert(collections[0].hash.equal(cb.collectionHash!!))
@@ -241,9 +241,9 @@ runBlocking {
241241
// list blobs
242242
val collectionHashes = cb.blobHashes!!
243243
collectionHashes.add(cb.collectionHash!!)
244-
val gotHashes = node.blobsList()
244+
val gotHashes = node.blobs().list()
245245
for (hash in gotHashes) {
246-
val blob = node.blobsReadToBytes(hash)
246+
val blob = node.blobs().readToBytes(hash)
247247
println("hash " + hash + " has size " + blob.size)
248248
}
249249
hashesExist(collectionHashes, gotHashes)
@@ -256,7 +256,7 @@ runBlocking {
256256
runBlocking {
257257
val irohDir = kotlin.io.path.createTempDirectory("doc-test-list-del")
258258
val opts = NodeOptions(100UL)
259-
val node = IrohNode.persistentWithOptions(irohDir.toString(), opts)
259+
val node = Iroh.persistentWithOptions(irohDir.toString(), opts)
260260

261261
// create bytes
262262
val blobSize = 100
@@ -272,23 +272,23 @@ runBlocking {
272272
val hashes: MutableList<Hash> = arrayListOf()
273273
val tags: MutableList<ByteArray> = arrayListOf()
274274
for (blob in blobs) {
275-
val output = node.blobsAddBytes(blob)
275+
val output = node.blobs().addBytes(blob)
276276
hashes.add(output.hash)
277277
tags.add(output.tag)
278278
}
279279

280-
val gotHashes = node.blobsList()
280+
val gotHashes = node.blobs().list()
281281
assert(gotHashes.size == numBlobs)
282282
hashesExist(hashes, gotHashes)
283283

284284
val removeHash = hashes.removeAt(0)
285285
val removeTag = tags.removeAt(0)
286286
// delete the tag for the first blob
287-
node.tagsDelete(removeTag)
287+
node.tags().delete(removeTag)
288288
// wait for GC to clear the blob
289289
java.lang.Thread.sleep(250)
290290

291-
val clearedHashes = node.blobsList()
291+
val clearedHashes = node.blobs().list()
292292
assert(clearedHashes.size == numBlobs - 1)
293293
hashesExist(hashes, clearedHashes)
294294

kotlin/doc_test.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ runBlocking {
8585
runBlocking {
8686
// create node
8787
val irohDir = kotlin.io.path.createTempDirectory("doc-test")
88-
val node = IrohNode.persistent(irohDir.toString())
88+
val node = Iroh.persistent(irohDir.toString())
8989

9090
// create doc and author
91-
val doc = node.docCreate()
92-
val author = node.authorCreate()
91+
val doc = node.docs().create()
92+
val author = node.authors().create()
9393

9494
// create entry
9595
val v = "hello world!".toByteArray()

kotlin/gossip_test.kts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ class Callback: GossipMessageCallback {
1616
runBlocking {
1717
setLogLevel(LogLevel.DEBUG)
1818

19-
val n0 = IrohNode.memory()
20-
val n1 = IrohNode.memory()
19+
val n0 = Iroh.memory()
20+
val n1 = Iroh.memory()
2121

2222
// Create a topic
2323
val topic = ByteArray(32) { i -> 1 }
2424

2525
// Setup gossip on node 0
2626
val cb0 = Callback()
27-
val n1Id = n1.nodeId()
28-
val n1Addr = n1.nodeAddr()
29-
n0.addNodeAddr(n1Addr)
27+
val n1Id = n1.node().nodeId()
28+
val n1Addr = n1.node().nodeAddr()
29+
n0.node().addNodeAddr(n1Addr)
3030

3131
println("subscribe n0")
32-
val sink0 = n0.gossipSubscribe(topic, listOf(n1Id), cb0)
32+
val sink0 = n0.gossip().subscribe(topic, listOf(n1Id), cb0)
3333

3434
// Setup gossip on node 1
3535
val cb1 = Callback()
36-
val n0Id = n0.nodeId()
37-
val n0Addr = n0.nodeAddr()
38-
n1.addNodeAddr(n0Addr)
36+
val n0Id = n0.node().nodeId()
37+
val n0Addr = n0.node().nodeAddr()
38+
n1.node().addNodeAddr(n0Addr)
3939

4040
println("subscribe n1")
41-
val sink1 = n1.gossipSubscribe(topic, listOf(n0Id), cb1)
41+
val sink1 = n1.gossip().subscribe(topic, listOf(n0Id), cb1)
4242

4343
// Wait for n1 to show up for n0
4444
while (true) {

0 commit comments

Comments
 (0)