feat(host): add IP-literal blocking TCP resource endpoint (P5)
- resource.open("tcp", ip:port, ["read","write"]) with exact IP grants,
project mode only, 5s connect/read/write timeouts; no DNS/TLS/UDP/server
sockets (ADR-0034).
- Add TCP stream storage/dispatch in the resource table; CLI --allow-net IP;
pure/strict preflight rejects the grant and the language endpoint.
- Host loopback echo/grant/DNS/strict tests and a .mq.md CLI echo test.
- Update specs, status, architecture, README, changelog and evidence.
Gate: fmt, clippy -D warnings, 426 tests passed.
This commit is contained in:
1 parent
1d87f98539
commit
00bdcad1ff
15 files changed
+435
-4
No files matched your search
@@ -5,6 +5,8 @@
|
||||
//! table validates run identity, slot identity and generation on every call.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::{Read, Write};
|
||||
use std::net::TcpStream;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
@@ -85,6 +87,10 @@ enum Stream {
|
||||
token: u64,
|
||||
closed: bool,
|
||||
},
|
||||
Tcp {
|
||||
stream: TcpStream,
|
||||
closed: bool,
|
||||
},
|
||||
}
|
||||
|
||||
struct Slot {
|
||||
@@ -99,6 +105,7 @@ impl Slot {
|
||||
Stream::File { closed, .. } => *closed,
|
||||
Stream::FileWriter { closed, .. } => *closed,
|
||||
Stream::Provider { closed, .. } => *closed,
|
||||
Stream::Tcp { closed, .. } => *closed,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,6 +162,14 @@ impl ResourceTable {
|
||||
})
|
||||
}
|
||||
|
||||
/// Register a connected TCP stream.
|
||||
pub fn open_tcp(&mut self, stream: TcpStream) -> ResourceHandle {
|
||||
self.insert(Stream::Tcp {
|
||||
stream,
|
||||
closed: false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Open a provider token and wrap it in a host-issued handle.
|
||||
pub fn open_provider(
|
||||
&mut self,
|
||||
@@ -272,6 +287,21 @@ impl ResourceTable {
|
||||
let mut provider = provider.lock().map_err(|_| provider_lock_error(span))?;
|
||||
provider.read(*token, max_bytes, span)
|
||||
}
|
||||
Stream::Tcp { stream, .. } => {
|
||||
let mut buffer = vec![0u8; max_bytes];
|
||||
let count = stream.read(&mut buffer).map_err(|error| {
|
||||
RuntimeError::new(
|
||||
ErrorCategory::HostError,
|
||||
span,
|
||||
format!("tcp read failed: {error}"),
|
||||
)
|
||||
})?;
|
||||
buffer.truncate(count);
|
||||
Ok(ResourceRead {
|
||||
bytes: buffer,
|
||||
eof: count == 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,6 +362,13 @@ impl ResourceTable {
|
||||
let mut provider = provider.lock().map_err(|_| provider_lock_error(span))?;
|
||||
provider.write(*token, bytes, span)
|
||||
}
|
||||
Stream::Tcp { stream, .. } => stream.write(bytes).map_err(|error| {
|
||||
RuntimeError::new(
|
||||
ErrorCategory::HostError,
|
||||
span,
|
||||
format!("tcp write failed: {error}"),
|
||||
)
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,6 +400,10 @@ impl ResourceTable {
|
||||
provider.close(*token, span)?;
|
||||
*closed = true;
|
||||
}
|
||||
Stream::Tcp { stream, closed } => {
|
||||
let _ = stream.shutdown(std::net::Shutdown::Both);
|
||||
*closed = true;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -400,6 +441,7 @@ impl ResourceTable {
|
||||
Stream::Stdout { .. } => "stdio".to_string(),
|
||||
Stream::File { .. } | Stream::FileWriter { .. } => "file".to_string(),
|
||||
Stream::Provider { kind, .. } => kind.clone(),
|
||||
Stream::Tcp { .. } => "tcp".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user