feat(handshake): integra el broker con el ciclo de sesiones
ServerConfig acepta un Option<Arc<Mutex<Broker>>> compartido. Cuando está
presente, el servidor lo mantiene en sincronía con las sesiones:
- Tras un Hello aceptado, register_session indexa la Card en el broker
ANTES de insertar en el SessionRegistry y de emitir HelloAck.
- Al cerrar la sesión (Farewell, EOF, o error en run_post_handshake), un
cleanup() unificado llama unregister en el broker y remove en el
SessionRegistry. Garantizado por refactor de Session::handle a
do_handshake → run_post_handshake → cleanup.
Tests nuevos en handshake.rs:
- broker_registers_and_unregisters_with_session: confirma el ciclo
register → farewell → unregister.
- broker_matches_two_live_modules: dos clientes (productor + consumidor)
conectados; el broker resuelve find_producer_for(consumer.session, "in")
→ producer "dht". Tras farewell del productor, el match desaparece.
Fix colateral: brahman-card::TypeRef pasa de internally-tagged
(#[serde(tag = "kind")]) a externally-tagged (default). Postcard no
soporta internally-tagged en formatos no self-describing — sin este
cambio el wire de Hello con Cards que tengan flujos no codificaba.
JSON cambia de {"kind":"primitive","name":"x"} a
{"primitive":{"name":"x"}}. Documentado en el doc-comment de TypeRef.
26/26 tests verdes (broker 11 + card 8 + handshake codec 1 + integ 6).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -398,8 +398,17 @@ pub struct Flow {
|
||||
}
|
||||
|
||||
/// Referencia a un tipo, discriminada para distinguir primitivas de tipos WIT.
|
||||
///
|
||||
/// **Wire format (JSON / TOML / postcard):** externally-tagged. Ejemplo JSON:
|
||||
/// ```json
|
||||
/// { "primitive": { "name": "string" } }
|
||||
/// { "wit": { "package": "brahman:dht", "name": "entity-result" } }
|
||||
/// ```
|
||||
/// Se eligió externally-tagged por compatibilidad con postcard, que no
|
||||
/// soporta `#[serde(tag = "...")]` (internally-tagged) en formatos no
|
||||
/// self-describing.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(tag = "kind", rename_all = "lowercase")]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum TypeRef {
|
||||
/// Tipo primitivo del runtime.
|
||||
Primitive { name: String },
|
||||
@@ -674,11 +683,11 @@ mod tests {
|
||||
"priority": "high",
|
||||
"flow": {
|
||||
"input": [
|
||||
{ "name": "search-query", "type": { "kind": "primitive", "name": "string" } }
|
||||
{ "name": "search-query", "type": { "primitive": { "name": "string" } } }
|
||||
],
|
||||
"output": [
|
||||
{ "name": "dht-results",
|
||||
"type": { "kind": "wit", "package": "brahman:dht", "name": "entity-result" } }
|
||||
"type": { "wit": { "package": "brahman:dht", "name": "entity-result" } } }
|
||||
]
|
||||
},
|
||||
"genesis": []
|
||||
|
||||
Reference in New Issue
Block a user