diff --git a/Iroh.xcframework/ios-arm64/Iroh.framework/Headers/iroh_ffiFFI.h b/Iroh.xcframework/ios-arm64/Iroh.framework/Headers/iroh_ffiFFI.h index af9b90f6..2007e2a2 100644 --- a/Iroh.xcframework/ios-arm64/Iroh.framework/Headers/iroh_ffiFFI.h +++ b/Iroh.xcframework/ios-arm64/Iroh.framework/Headers/iroh_ffiFFI.h @@ -1806,7 +1806,7 @@ RustBuffer uniffi_iroh_ffi_fn_method_node_my_rpc_addr(void*_Nonnull ptr, RustCal #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IROH_FFI_FN_METHOD_NODE_SHUTDOWN #define UNIFFI_FFIDEF_UNIFFI_IROH_FFI_FN_METHOD_NODE_SHUTDOWN -uint64_t uniffi_iroh_ffi_fn_method_node_shutdown(void*_Nonnull ptr, int8_t force +uint64_t uniffi_iroh_ffi_fn_method_node_shutdown(void*_Nonnull ptr ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IROH_FFI_FN_METHOD_NODE_STATS diff --git a/Iroh.xcframework/ios-arm64_x86_64-simulator/Iroh.framework/Headers/iroh_ffiFFI.h b/Iroh.xcframework/ios-arm64_x86_64-simulator/Iroh.framework/Headers/iroh_ffiFFI.h index af9b90f6..2007e2a2 100644 --- a/Iroh.xcframework/ios-arm64_x86_64-simulator/Iroh.framework/Headers/iroh_ffiFFI.h +++ b/Iroh.xcframework/ios-arm64_x86_64-simulator/Iroh.framework/Headers/iroh_ffiFFI.h @@ -1806,7 +1806,7 @@ RustBuffer uniffi_iroh_ffi_fn_method_node_my_rpc_addr(void*_Nonnull ptr, RustCal #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IROH_FFI_FN_METHOD_NODE_SHUTDOWN #define UNIFFI_FFIDEF_UNIFFI_IROH_FFI_FN_METHOD_NODE_SHUTDOWN -uint64_t uniffi_iroh_ffi_fn_method_node_shutdown(void*_Nonnull ptr, int8_t force +uint64_t uniffi_iroh_ffi_fn_method_node_shutdown(void*_Nonnull ptr ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IROH_FFI_FN_METHOD_NODE_STATS diff --git a/Iroh.xcframework/macos-arm64/Iroh.framework/Headers/iroh_ffiFFI.h b/Iroh.xcframework/macos-arm64/Iroh.framework/Headers/iroh_ffiFFI.h index af9b90f6..2007e2a2 100644 --- a/Iroh.xcframework/macos-arm64/Iroh.framework/Headers/iroh_ffiFFI.h +++ b/Iroh.xcframework/macos-arm64/Iroh.framework/Headers/iroh_ffiFFI.h @@ -1806,7 +1806,7 @@ RustBuffer uniffi_iroh_ffi_fn_method_node_my_rpc_addr(void*_Nonnull ptr, RustCal #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IROH_FFI_FN_METHOD_NODE_SHUTDOWN #define UNIFFI_FFIDEF_UNIFFI_IROH_FFI_FN_METHOD_NODE_SHUTDOWN -uint64_t uniffi_iroh_ffi_fn_method_node_shutdown(void*_Nonnull ptr, int8_t force +uint64_t uniffi_iroh_ffi_fn_method_node_shutdown(void*_Nonnull ptr ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_IROH_FFI_FN_METHOD_NODE_STATS diff --git a/IrohLib/Sources/IrohLib/IrohLib.swift b/IrohLib/Sources/IrohLib/IrohLib.swift index 529b82b3..e4c752f8 100644 --- a/IrohLib/Sources/IrohLib/IrohLib.swift +++ b/IrohLib/Sources/IrohLib/IrohLib.swift @@ -8317,7 +8317,7 @@ public protocol NodeProtocol: AnyObject { /** * Shutdown this iroh node. */ - func shutdown(force: Bool) async throws + func shutdown() async throws /** * Get statistics of the running node. @@ -8400,13 +8400,12 @@ open class Node: /** * Shutdown this iroh node. */ - open func shutdown(force: Bool) async throws { + open func shutdown() async throws { return try await uniffiRustCallAsync( rustFutureFunc: { uniffi_iroh_ffi_fn_method_node_shutdown( - self.uniffiClonePointer(), - FfiConverterBool.lower(force) + self.uniffiClonePointer() ) }, pollFunc: ffi_iroh_ffi_rust_future_poll_void, @@ -18145,7 +18144,7 @@ private var initializationResult: InitializationResult = { if uniffi_iroh_ffi_checksum_method_node_my_rpc_addr() != 34751 { return InitializationResult.apiChecksumMismatch } - if uniffi_iroh_ffi_checksum_method_node_shutdown() != 21075 { + if uniffi_iroh_ffi_checksum_method_node_shutdown() != 49624 { return InitializationResult.apiChecksumMismatch } if uniffi_iroh_ffi_checksum_method_node_stats() != 13439 { diff --git a/iroh-js/__test__/blob.spec.mjs b/iroh-js/__test__/blob.spec.mjs index aa9ec552..69067dc8 100644 --- a/iroh-js/__test__/blob.spec.mjs +++ b/iroh-js/__test__/blob.spec.mjs @@ -38,7 +38,7 @@ test('add blob from path', async (t) => { t.truthy(allDone.tag) t.truthy(allDone.hash) - await node.node.shutdown(false) + await node.node.shutdown() }) test('hash basics', (t) => { @@ -104,7 +104,7 @@ test('collections', async (t) => { t.is(collectionList[0].hash, res.hash) t.is(collectionList[0].totalBlobsCount, BigInt(numFiles + 1)) - await node.node.shutdown(false) + await node.node.shutdown() }) test('share', async (t) => { @@ -119,7 +119,7 @@ test('share', async (t) => { t.is(ticket.hash, res.hash) t.deepEqual(ticket.nodeAddr, nodeAddr) - await node.node.shutdown(false) + await node.node.shutdown() }) test('provide events', async (t) => { @@ -174,6 +174,6 @@ test('provide events', async (t) => { t.is(events.length, 4) - await node1.node.shutdown(false) - await node2.node.shutdown(false) + await node1.node.shutdown() + await node2.node.shutdown() }) diff --git a/iroh-js/__test__/gossip.spec.mjs b/iroh-js/__test__/gossip.spec.mjs index 61b0b63f..eafb7d7e 100644 --- a/iroh-js/__test__/gossip.spec.mjs +++ b/iroh-js/__test__/gossip.spec.mjs @@ -68,8 +68,8 @@ test('gossip basic', async (t) => { await sink0.close() await sink1.close() - await n0.node.shutdown(false) - await n1.node.shutdown(false) + await n0.node.shutdown() + await n1.node.shutdown() t.pass() }) diff --git a/iroh-js/__test__/node.spec.mjs b/iroh-js/__test__/node.spec.mjs index 15a3f464..91f441d2 100644 --- a/iroh-js/__test__/node.spec.mjs +++ b/iroh-js/__test__/node.spec.mjs @@ -2,9 +2,9 @@ import test from 'ava' import { Iroh } from '../index.js' - test('create memory node', async (t) => { const node = await Iroh.memory() + await node.node.shutdown() t.pass() }) @@ -12,6 +12,7 @@ test('create memory node, with options', async (t) => { const node = await Iroh.memory({ gcIntervalMillis: 10000 }) + await node.node.shutdown() t.pass() }) @@ -20,6 +21,7 @@ test('node status', async (t) => { const status = await iroh.node.status() t.is(status.version, '0.28.1') + await iroh.node.shutdown() }) test('rpc client memory node', async (t) => { @@ -33,31 +35,32 @@ test('rpc client memory node', async (t) => { const clientId = await client.net.nodeId() t.is(nodeId, clientId) + + await node.node.shutdown() }) test('custom protocol', async (t) => { - t.plan(4) const alpn = Buffer.from('iroh-example/hello/0') const protocols = { [alpn]: (err, ep, client) => ({ accept: async (err, connecting) => { - console.log('accept') + // console.log('accept') t.falsy(err) const nodeId = await client.net.nodeId() - console.log(`accepting on node ${nodeId}`) + // console.log(`accepting on node ${nodeId}`) const alpn = await connecting.alpn() - console.log(`incoming on ${alpn.toString()}`) + // console.log(`incoming on ${alpn.toString()}`) const conn = await connecting.connect() const remote = await conn.getRemoteNodeId() - console.log(`connected id ${remote.toString()}`) + // console.log(`connected id ${remote.toString()}`) const bi = await conn.acceptBi() const bytes = await bi.recv.readToEnd(64) - console.log(`got: ${bytes.toString()}`) + // console.log(`got: ${bytes.toString()}`) t.is(bytes.toString(), 'yo') await bi.send.writeAll(Buffer.from('hello')) await bi.send.finish() @@ -65,11 +68,12 @@ test('custom protocol', async (t) => { }, shutdown: (err) => { if (err != null) { - if (!err.message.contains("closed by peer")) { + console.log('shutdown error', err) + if (!err.message.contains('closed')) { throw err } } - console.log('shutting down') + // console.log('shutting down') } }) } @@ -82,11 +86,11 @@ test('custom protocol', async (t) => { const node2 = await Iroh.memory({ protocols }) const endpoint = node2.node.endpoint() - console.log(`connecting to ${nodeAddr.nodeId}`) + // console.log(`connecting to ${nodeAddr.nodeId}`) const conn = await endpoint.connect(nodeAddr, alpn) const remote = await conn.getRemoteNodeId() - console.log(`connected to ${remote.toString()}`) + // console.log(`connected to ${remote.toString()}`) const bi = await conn.openBi() @@ -96,12 +100,13 @@ test('custom protocol', async (t) => { let out = Buffer.alloc(5) await bi.recv.readExact(out) - console.log(`read: ${out.toString()}`) + // console.log(`read: ${out.toString()}`) t.is(out.toString(), 'hello') - await node2.node.shutdown(false) - await node1.node.shutdown(false) + await node2.node.shutdown() + await node1.node.shutdown() + + // console.log('end') - console.log('end') t.pass() }) diff --git a/iroh-js/index.d.ts b/iroh-js/index.d.ts index 5d60dcdb..fc569060 100644 --- a/iroh-js/index.d.ts +++ b/iroh-js/index.d.ts @@ -431,7 +431,7 @@ export declare class Node { /** Get status information about a node */ status(): Promise /** Shutdown this iroh node. */ - shutdown(force: boolean): Promise + shutdown(): Promise /** Returns `Some(addr)` if an RPC endpoint is running, `None` otherwise. */ myRpcAddr(): string | null endpoint(): Endpoint | null diff --git a/iroh-js/src/node.rs b/iroh-js/src/node.rs index 1688a638..e38c1423 100644 --- a/iroh-js/src/node.rs +++ b/iroh-js/src/node.rs @@ -300,8 +300,12 @@ impl Node { /// Shutdown this iroh node. #[napi] - pub async fn shutdown(&self, force: bool) -> Result<()> { - self.node().shutdown(force).await?; + pub async fn shutdown(&self) -> Result<()> { + match self.node.0 { + InnerIroh::Fs(ref fs) => fs.clone().shutdown().await?, + InnerIroh::Memory(ref mem) => mem.clone().shutdown().await?, + InnerIroh::Client(ref client) => client.shutdown(false).await?, + } Ok(()) } diff --git a/kotlin/author_test.kts b/kotlin/author_test.kts index cbe3f583..e792fb10 100644 --- a/kotlin/author_test.kts +++ b/kotlin/author_test.kts @@ -31,4 +31,6 @@ kotlinx.coroutines.runBlocking { // check there is 1 author on the node assert(node.authors().list().size == 2) + + node.node().shutdown() } diff --git a/kotlin/blob_test.kts b/kotlin/blob_test.kts index d30b2e8c..462c8457 100644 --- a/kotlin/blob_test.kts +++ b/kotlin/blob_test.kts @@ -114,6 +114,8 @@ runBlocking { val gotBytes = node.blobs().readToBytes(hash) assert(gotBytes.size == blobSize) assert(gotBytes contentEquals bytes) + + node.node().shutdown() } // test functionality between reading bytes from a path and writing bytes to a path @@ -177,6 +179,8 @@ runBlocking { val gotBytesFile = java.io.File(outPath).readBytes() assert(gotBytesFile.size == blobSize) assert(gotBytesFile contentEquals bytes) + + node.node().shutdown() } // Collections @@ -250,6 +254,8 @@ runBlocking { // collections also create a metadata hash that is not accounted for // in the list of hashes assert(collectionHashes.size + 1 == gotHashes.size) + + node.node().shutdown() } // List and delete @@ -297,4 +303,6 @@ runBlocking { throw Exception(String.format("blob $removeHash should have been removed")) } } + + node.node().shutdown() } diff --git a/kotlin/doc_test.kts b/kotlin/doc_test.kts index 1058a923..6c01d08b 100644 --- a/kotlin/doc_test.kts +++ b/kotlin/doc_test.kts @@ -103,6 +103,13 @@ runBlocking { val entry = doc.getOne(query)!! assert(hash.equal(entry.contentHash())) assert(v.size.toULong() == entry.contentLen()) - val gotVal = entry.contentBytes(doc) + val gotVal: ByteArray = try { + entry.contentBytes(doc) + } catch (e: IrohException) { + println("failed content bytes ${e.message}") + throw e + } + assert(v contentEquals gotVal) + node.node().shutdown() } diff --git a/kotlin/gossip_test.kts b/kotlin/gossip_test.kts index 6d476f00..32be9204 100644 --- a/kotlin/gossip_test.kts +++ b/kotlin/gossip_test.kts @@ -14,7 +14,7 @@ class Callback : GossipMessageCallback { } runBlocking { - setLogLevel(LogLevel.DEBUG) + // setLogLevel(LogLevel.DEBUG) val n0 = Iroh.memory() val n1 = Iroh.memory() @@ -75,6 +75,6 @@ runBlocking { sink0.cancel() sink1.cancel() - n0.node().shutdown(false) - n1.node().shutdown(false) + n0.node().shutdown() + n1.node().shutdown() } diff --git a/kotlin/iroh/iroh_ffi.kt b/kotlin/iroh/iroh_ffi.kt index 0ea7563a..339b671f 100644 --- a/kotlin/iroh/iroh_ffi.kt +++ b/kotlin/iroh/iroh_ffi.kt @@ -2386,10 +2386,7 @@ internal interface UniffiLib : Library { uniffi_out_err: UniffiRustCallStatus, ): RustBuffer.ByValue - fun uniffi_iroh_ffi_fn_method_node_shutdown( - `ptr`: Pointer, - `force`: Byte, - ): Long + fun uniffi_iroh_ffi_fn_method_node_shutdown(`ptr`: Pointer): Long fun uniffi_iroh_ffi_fn_method_node_stats(`ptr`: Pointer): Long @@ -4118,7 +4115,7 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) { if (lib.uniffi_iroh_ffi_checksum_method_node_my_rpc_addr() != 34751.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_iroh_ffi_checksum_method_node_shutdown() != 21075.toShort()) { + if (lib.uniffi_iroh_ffi_checksum_method_node_shutdown() != 49624.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_iroh_ffi_checksum_method_node_stats() != 13439.toShort()) { @@ -18105,7 +18102,7 @@ public interface NodeInterface { /** * Shutdown this iroh node. */ - suspend fun `shutdown`(`force`: kotlin.Boolean) + suspend fun `shutdown`() /** * Get statistics of the running node. @@ -18239,12 +18236,11 @@ open class Node : */ @Throws(IrohException::class) @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE") - override suspend fun `shutdown`(`force`: kotlin.Boolean) = + override suspend fun `shutdown`() = uniffiRustCallAsync( callWithPointer { thisPtr -> UniffiLib.INSTANCE.uniffi_iroh_ffi_fn_method_node_shutdown( thisPtr, - FfiConverterBoolean.lower(`force`), ) }, { future, callback, continuation -> UniffiLib.INSTANCE.ffi_iroh_ffi_rust_future_poll_void(future, callback, continuation) }, diff --git a/kotlin/node_test.kts b/kotlin/node_test.kts index 391846c5..16b153f3 100644 --- a/kotlin/node_test.kts +++ b/kotlin/node_test.kts @@ -70,6 +70,9 @@ runBlocking { break } } + + node1.node().shutdown() + node0.node().shutdown() } class MyProtocol : ProtocolHandler { @@ -135,6 +138,6 @@ runBlocking { println(o.toString(Charsets.UTF_8)) assert("hello".toByteArray(Charsets.UTF_8) contentEquals o) - node2.node().shutdown(false) - node1.node().shutdown(false) + node2.node().shutdown() + node1.node().shutdown() } diff --git a/python/gossip_test.py b/python/gossip_test.py index b4b05cc3..6804bf2e 100644 --- a/python/gossip_test.py +++ b/python/gossip_test.py @@ -75,5 +75,5 @@ async def test_gossip_basic(): await sink0.cancel() await sink1.cancel() - await n0.node().shutdown(False) - await n1.node().shutdown(False) + await n0.node().shutdown() + await n1.node().shutdown() diff --git a/python/node_test.py b/python/node_test.py index 18cf354d..1afb602c 100644 --- a/python/node_test.py +++ b/python/node_test.py @@ -122,5 +122,5 @@ def create(self, endpoint, client): print("", out) assert b"hello", out - await node_2.node().shutdown(True) - await node_1.node().shutdown(True) + await node_2.node().shutdown() + await node_1.node().shutdown() diff --git a/src/node.rs b/src/node.rs index 0a599e8e..0b7df129 100644 --- a/src/node.rs +++ b/src/node.rs @@ -495,8 +495,12 @@ impl Node { /// Shutdown this iroh node. #[uniffi::method(async_runtime = "tokio")] - pub async fn shutdown(&self, force: bool) -> Result<(), IrohError> { - self.node().shutdown(force).await?; + pub async fn shutdown(&self) -> Result<(), IrohError> { + match self.node { + Iroh::Fs(ref fs) => fs.clone().shutdown().await?, + Iroh::Memory(ref mem) => mem.clone().shutdown().await?, + Iroh::Client(ref client) => client.shutdown(false).await?, + } Ok(()) }