pub struct TPCPNode {
pub identity: AgentIdentity,
pub memory: Arc<RwLock<LWWMap>>,
pub dlq: Arc<DLQ>,
/* private fields */
}Expand description
Async TPCP node backed by tokio and tokio-tungstenite.
Fields§
§identity: AgentIdentity§memory: Arc<RwLock<LWWMap>>§dlq: Arc<DLQ>Implementations§
Source§impl TPCPNode
impl TPCPNode
Sourcepub fn new(identity: AgentIdentity) -> Self
pub fn new(identity: AgentIdentity) -> Self
Creates a new TPCPNode with the given identity and no signing key.
Examples found in repository?
examples/hello.rs (line 16)
7async fn main() {
8 // Server
9 let server_identity = AgentIdentity {
10 agent_id: "server-001".into(),
11 framework: "hello-server".into(),
12 capabilities: vec![],
13 public_key: "".into(),
14 modality: vec!["text".into()],
15 };
16 let server = Arc::new(TPCPNode::new(server_identity));
17
18 server.register_handler(Intent::Handshake, |env| {
19 println!("Server received HANDSHAKE from {}", env.header.sender_id);
20 println!("Payload: {}", env.payload);
21 }).await;
22
23 server.listen("127.0.0.1:9001").await.expect("failed to listen");
24 sleep(Duration::from_millis(100)).await; // let server bind
25
26 // Client
27 let client_identity = AgentIdentity {
28 agent_id: "client-001".into(),
29 framework: "hello-client".into(),
30 capabilities: vec![],
31 public_key: "".into(),
32 modality: vec!["text".into()],
33 };
34 let client = TPCPNode::new(client_identity);
35
36 client.send_message(
37 "ws://127.0.0.1:9001",
38 "server-001",
39 Intent::Handshake,
40 serde_json::json!({"payload_type": "text", "content": "hello from Rust client"}),
41 ).await.expect("send failed");
42
43 sleep(Duration::from_millis(200)).await;
44 println!("TPCP Rust SDK hello example completed.");
45}Sourcepub fn with_signing_key(identity: AgentIdentity, key: SigningKey) -> Self
pub fn with_signing_key(identity: AgentIdentity, key: SigningKey) -> Self
Creates a TPCPNode that signs all outbound messages.
Sourcepub async fn register_peer_key(&self, agent_id: &str, public_key_b64: &str)
pub async fn register_peer_key(&self, agent_id: &str, public_key_b64: &str)
Registers a peer’s public key for inbound signature verification.
Sourcepub async fn register_handler<F>(&self, intent: Intent, handler: F)
pub async fn register_handler<F>(&self, intent: Intent, handler: F)
Registers a handler for a specific intent.
Examples found in repository?
examples/hello.rs (lines 18-21)
7async fn main() {
8 // Server
9 let server_identity = AgentIdentity {
10 agent_id: "server-001".into(),
11 framework: "hello-server".into(),
12 capabilities: vec![],
13 public_key: "".into(),
14 modality: vec!["text".into()],
15 };
16 let server = Arc::new(TPCPNode::new(server_identity));
17
18 server.register_handler(Intent::Handshake, |env| {
19 println!("Server received HANDSHAKE from {}", env.header.sender_id);
20 println!("Payload: {}", env.payload);
21 }).await;
22
23 server.listen("127.0.0.1:9001").await.expect("failed to listen");
24 sleep(Duration::from_millis(100)).await; // let server bind
25
26 // Client
27 let client_identity = AgentIdentity {
28 agent_id: "client-001".into(),
29 framework: "hello-client".into(),
30 capabilities: vec![],
31 public_key: "".into(),
32 modality: vec!["text".into()],
33 };
34 let client = TPCPNode::new(client_identity);
35
36 client.send_message(
37 "ws://127.0.0.1:9001",
38 "server-001",
39 Intent::Handshake,
40 serde_json::json!({"payload_type": "text", "content": "hello from Rust client"}),
41 ).await.expect("send failed");
42
43 sleep(Duration::from_millis(200)).await;
44 println!("TPCP Rust SDK hello example completed.");
45}Sourcepub async fn connect(
&self,
url: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn connect( &self, url: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Connects as a WebSocket client to the given URL.
Sourcepub async fn listen(
&self,
addr: &str,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn listen( &self, addr: &str, ) -> Result<(), Box<dyn Error + Send + Sync>>
Starts listening on the given address (e.g. “127.0.0.1:9001”).
Examples found in repository?
examples/hello.rs (line 23)
7async fn main() {
8 // Server
9 let server_identity = AgentIdentity {
10 agent_id: "server-001".into(),
11 framework: "hello-server".into(),
12 capabilities: vec![],
13 public_key: "".into(),
14 modality: vec!["text".into()],
15 };
16 let server = Arc::new(TPCPNode::new(server_identity));
17
18 server.register_handler(Intent::Handshake, |env| {
19 println!("Server received HANDSHAKE from {}", env.header.sender_id);
20 println!("Payload: {}", env.payload);
21 }).await;
22
23 server.listen("127.0.0.1:9001").await.expect("failed to listen");
24 sleep(Duration::from_millis(100)).await; // let server bind
25
26 // Client
27 let client_identity = AgentIdentity {
28 agent_id: "client-001".into(),
29 framework: "hello-client".into(),
30 capabilities: vec![],
31 public_key: "".into(),
32 modality: vec!["text".into()],
33 };
34 let client = TPCPNode::new(client_identity);
35
36 client.send_message(
37 "ws://127.0.0.1:9001",
38 "server-001",
39 Intent::Handshake,
40 serde_json::json!({"payload_type": "text", "content": "hello from Rust client"}),
41 ).await.expect("send failed");
42
43 sleep(Duration::from_millis(200)).await;
44 println!("TPCP Rust SDK hello example completed.");
45}Sourcepub async fn send_message(
&self,
url: &str,
receiver_id: &str,
intent: Intent,
payload: Value,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn send_message( &self, url: &str, receiver_id: &str, intent: Intent, payload: Value, ) -> Result<(), Box<dyn Error + Send + Sync>>
Sends a message to the given WebSocket URL.
receiver_id is the target agent’s agent_id (not the URL).
Examples found in repository?
examples/hello.rs (lines 36-41)
7async fn main() {
8 // Server
9 let server_identity = AgentIdentity {
10 agent_id: "server-001".into(),
11 framework: "hello-server".into(),
12 capabilities: vec![],
13 public_key: "".into(),
14 modality: vec!["text".into()],
15 };
16 let server = Arc::new(TPCPNode::new(server_identity));
17
18 server.register_handler(Intent::Handshake, |env| {
19 println!("Server received HANDSHAKE from {}", env.header.sender_id);
20 println!("Payload: {}", env.payload);
21 }).await;
22
23 server.listen("127.0.0.1:9001").await.expect("failed to listen");
24 sleep(Duration::from_millis(100)).await; // let server bind
25
26 // Client
27 let client_identity = AgentIdentity {
28 agent_id: "client-001".into(),
29 framework: "hello-client".into(),
30 capabilities: vec![],
31 public_key: "".into(),
32 modality: vec!["text".into()],
33 };
34 let client = TPCPNode::new(client_identity);
35
36 client.send_message(
37 "ws://127.0.0.1:9001",
38 "server-001",
39 Intent::Handshake,
40 serde_json::json!({"payload_type": "text", "content": "hello from Rust client"}),
41 ).await.expect("send failed");
42
43 sleep(Duration::from_millis(200)).await;
44 println!("TPCP Rust SDK hello example completed.");
45}Auto Trait Implementations§
impl Freeze for TPCPNode
impl !RefUnwindSafe for TPCPNode
impl Send for TPCPNode
impl Sync for TPCPNode
impl Unpin for TPCPNode
impl UnsafeUnpin for TPCPNode
impl !UnwindSafe for TPCPNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more