-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
zenoh-kotlin/src/commonMain/kotlin/io/zenoh/scouting/Hello.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
package io.zenoh.scouting | ||
|
||
import io.zenoh.ZenohType | ||
import io.zenoh.protocol.ZenohID | ||
|
||
data class Hello(val whatAmI: WhatAmI, val zid: ZenohID, val locators: List<String>): ZenohType | ||
/** | ||
* Hello message received while scouting. | ||
* | ||
* @property whatAmI [WhatAmI] configuration: it indicates the role of the zenoh node sending the HELLO message. | ||
* @property zid [ZenohID] of the node sending the hello message. | ||
* @property locators The locators of this hello message. | ||
* @see Scout | ||
*/ | ||
data class Hello(val whatAmI: WhatAmI, val zid: ZenohID, val locators: List<String>): ZenohType |
38 changes: 35 additions & 3 deletions
38
zenoh-kotlin/src/commonMain/kotlin/io/zenoh/scouting/Scout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,51 @@ | ||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
package io.zenoh.scouting | ||
|
||
import io.zenoh.jni.JNIScout | ||
|
||
/** | ||
* Scout for routers and/or peers. | ||
* | ||
* Scout spawns a task that periodically sends scout messages and waits for Hello replies. | ||
* Drop the returned Scout to stop the scouting task. | ||
* | ||
* @param R The receiver type. | ||
* @param receiver Receiver to handle incoming hello messages. | ||
*/ | ||
class Scout<R> internal constructor( | ||
val receiver: R, | ||
private val jniScout: JNIScout? | ||
private var jniScout: JNIScout? | ||
) : AutoCloseable { | ||
|
||
/** | ||
* Stops the scouting. | ||
*/ | ||
fun stop() { | ||
jniScout?.close() | ||
jniScout = null | ||
} | ||
|
||
/** | ||
* Equivalent to [stop]. | ||
*/ | ||
override fun close() { | ||
stop() | ||
} | ||
} | ||
|
||
|
||
protected fun finalize() { | ||
stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
package io.zenoh.scouting | ||
|
||
/** | ||
* WhatAmI | ||
* | ||
* The role of the node sending the `hello` message. | ||
*/ | ||
enum class WhatAmI(internal val value: Int) { | ||
Router(1), | ||
Peer(2), | ||
|
@@ -8,4 +27,4 @@ enum class WhatAmI(internal val value: Int) { | |
companion object { | ||
internal fun fromInt(value: Int) = entries.first { value == it.value } | ||
} | ||
} | ||
} |