1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
//! Network types for Tenzro Network
//!
//! This module defines network topology, peer discovery, and node
//! information structures.
use crate::primitives::{Address, Timestamp};
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
/// The role of a node in the Tenzro Network
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum NetworkRole {
/// Full validator node
Validator,
/// Full node (non-validating)
FullNode,
/// Light client
LightClient,
/// TEE provider node
TeeProvider,
/// Model inference provider node
ModelProvider,
/// Storage provider node
StorageProvider,
/// Archive node (stores full history)
Archive,
/// Bootstrap/seed node
Bootstrap,
/// Micro node / participant — ultra-lightweight, no P2P required.
/// Humans or AI agents joining via MCP server, Claude, ClawBot,
/// or other agentic frameworks. Auto-provisioned DID + MPC wallet.
MicroNode,
}
impl NetworkRole {
/// Checks if this role can validate blocks
pub fn is_validator(&self) -> bool {
matches!(self, Self::Validator)
}
/// Checks if this role is a provider
pub fn is_provider(&self) -> bool {
matches!(
self,
Self::TeeProvider | Self::ModelProvider | Self::StorageProvider
)
}
/// Checks if this role maintains full state
pub fn is_full_node(&self) -> bool {
matches!(
self,
Self::Validator | Self::FullNode | Self::Archive | Self::Bootstrap
)
}
/// Checks if this role is a micro node (zero-install participant)
pub fn is_micro_node(&self) -> bool {
matches!(self, Self::MicroNode)
}
}
/// Information about a peer in the network
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PeerInfo {
/// Peer's unique identifier
pub peer_id: String,
/// Peer's network addresses
pub addresses: Vec<SocketAddr>,
/// Peer's role in the network
pub role: NetworkRole,
/// Protocol version
pub protocol_version: u32,
/// User agent string
pub user_agent: String,
/// Last seen timestamp
pub last_seen: Timestamp,
/// Peer reputation score
pub reputation: i64,
/// Connection status
pub status: PeerStatus,
}
impl PeerInfo {
/// Creates a new PeerInfo
pub fn new(peer_id: String, addresses: Vec<SocketAddr>, role: NetworkRole) -> Self {
Self {
peer_id,
addresses,
role,
protocol_version: 1,
user_agent: "tenzro/1.0".to_string(),
last_seen: Timestamp::now(),
reputation: 0,
status: PeerStatus::Disconnected,
}
}
/// Updates the last seen timestamp
pub fn update_last_seen(&mut self) {
self.last_seen = Timestamp::now();
}
/// Increases the reputation score
pub fn increase_reputation(&mut self, amount: i64) {
self.reputation = self.reputation.saturating_add(amount);
}
/// Decreases the reputation score
pub fn decrease_reputation(&mut self, amount: i64) {
self.reputation = self.reputation.saturating_sub(amount);
}
}
/// Peer connection status
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum PeerStatus {
/// Not connected
Disconnected,
/// Attempting to connect
Connecting,
/// Successfully connected
Connected,
/// Connection failed
Failed,
/// Peer is banned
Banned,
}
/// Information about the local node
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NodeInfo {
/// Node's unique identifier
pub node_id: String,
/// Node's account address (if applicable)
pub address: Option<Address>,
/// Node's role in the network
pub role: NetworkRole,
/// Listen addresses
pub listen_addresses: Vec<SocketAddr>,
/// Public addresses (for NAT traversal)
pub public_addresses: Vec<SocketAddr>,
/// Protocol version
pub protocol_version: u32,
/// User agent string
pub user_agent: String,
/// Node start time
pub start_time: Timestamp,
/// Node configuration
pub config: NodeConfiguration,
}
impl NodeInfo {
/// Creates a new NodeInfo
pub fn new(node_id: String, role: NetworkRole) -> Self {
Self {
node_id,
address: None,
role,
listen_addresses: Vec::new(),
public_addresses: Vec::new(),
protocol_version: 1,
user_agent: "tenzro/1.0".to_string(),
start_time: Timestamp::now(),
config: NodeConfiguration::default(),
}
}
/// Sets the node's account address
pub fn with_address(mut self, address: Address) -> Self {
self.address = Some(address);
self
}
/// Adds a listen address
pub fn add_listen_address(&mut self, addr: SocketAddr) {
if !self.listen_addresses.contains(&addr) {
self.listen_addresses.push(addr);
}
}
/// Adds a public address
pub fn add_public_address(&mut self, addr: SocketAddr) {
if !self.public_addresses.contains(&addr) {
self.public_addresses.push(addr);
}
}
/// Returns the node uptime in milliseconds
pub fn uptime(&self) -> i64 {
Timestamp::now().as_millis() - self.start_time.as_millis()
}
}
/// Node configuration parameters
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NodeConfiguration {
/// Maximum number of inbound peers
pub max_inbound_peers: u32,
/// Maximum number of outbound peers
pub max_outbound_peers: u32,
/// Enable peer discovery
pub enable_discovery: bool,
/// Enable metrics collection
pub enable_metrics: bool,
/// Enable RPC server
pub enable_rpc: bool,
/// RPC listen address
pub rpc_address: Option<SocketAddr>,
}
impl Default for NodeConfiguration {
fn default() -> Self {
Self {
max_inbound_peers: 50,
max_outbound_peers: 25,
enable_discovery: true,
enable_metrics: true,
enable_rpc: true,
rpc_address: None,
}
}
}
/// Network statistics
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct NetworkStats {
/// Total number of connected peers
pub connected_peers: u32,
/// Total bytes sent
pub bytes_sent: u64,
/// Total bytes received
pub bytes_received: u64,
/// Total messages sent
pub messages_sent: u64,
/// Total messages received
pub messages_received: u64,
}
impl NetworkStats {
/// Records a sent message
pub fn record_sent(&mut self, bytes: u64) {
self.messages_sent += 1;
self.bytes_sent = self.bytes_sent.saturating_add(bytes);
}
/// Records a received message
pub fn record_received(&mut self, bytes: u64) {
self.messages_received += 1;
self.bytes_received = self.bytes_received.saturating_add(bytes);
}
}
/// Full capabilities available to a micro node participant.
///
/// MicroNodes are zero-install full participants — they access everything
/// via JSON-RPC, MCP tools, A2A protocol, or agentic frameworks.
/// All capabilities default to `true` (full participant).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MicroNodeCapabilities {
/// AI model inference from network providers
pub inference: bool,
/// TNZO payments (send, receive, escrow)
pub payments: bool,
/// A2A agent-to-agent collaboration
pub agent_collaboration: bool,
/// MCP tool access (24 tools)
pub mcp_tools: bool,
/// Task marketplace — request tasks and complete tasks for others
pub task_execution: bool,
/// Chain state queries (blocks, transactions, balances)
pub chain_query: bool,
/// Smart contract interaction (EVM/SVM/DAML)
pub smart_contracts: bool,
/// TEE confidential compute and key management
pub tee_services: bool,
/// Cross-chain bridge (Ethereum, Solana, Canton)
pub bridge: bool,
/// Governance — proposals and voting
pub governance: bool,
}
impl Default for MicroNodeCapabilities {
fn default() -> Self {
// All capabilities enabled — full participant by default
Self {
inference: true,
payments: true,
agent_collaboration: true,
mcp_tools: true,
task_execution: true,
chain_query: true,
smart_contracts: true,
tee_services: true,
bridge: true,
governance: true,
}
}
}
/// Information about a registered micro node participant
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MicroNodeInfo {
/// TDIP decentralized identifier (did:tenzro:...)
pub did: String,
/// Auto-provisioned MPC wallet address
pub wallet_address: String,
/// Human-readable display name (optional)
pub display_name: String,
/// Timestamp when the micro node joined
pub joined_at: Timestamp,
/// Entry point: "mcp", "claude", "clawbot", "a2a", "sdk", "api", "cli", "app"
pub origin: String,
/// What kind of participant joined
pub participant_type: MicroNodeParticipantType,
/// Capabilities available to this micro node
pub capabilities: MicroNodeCapabilities,
}
impl MicroNodeInfo {
/// Creates a new MicroNodeInfo with full capabilities
pub fn new(
did: String,
wallet_address: String,
display_name: String,
origin: String,
participant_type: MicroNodeParticipantType,
) -> Self {
Self {
did,
wallet_address,
display_name,
joined_at: Timestamp::now(),
origin,
participant_type,
capabilities: MicroNodeCapabilities::default(),
}
}
}
/// The type of participant joining as a micro node
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MicroNodeParticipantType {
/// A human user (via Claude, ClawBot, CLI, desktop, SDK)
Human,
/// An AI agent (via A2A protocol, MCP, agentic framework)
Agent,
/// An automated bot or service
Bot,
}