🚀 feat: P2PBox/IntentBox実装 - NyaMesh通信基盤の第一歩

## 🎯 概要
NyaMeshプロジェクトの基盤となるP2PBox/IntentBoxを実装。
シンプルなsend/onインターフェースで通信ノード間のメッセージングを実現。

##  新機能
- **IntentBox**: 通信世界を定義するコンテナ
  - Transportトレイトで通信方式を抽象化
  - LocalTransport実装(プロセス内通信)
  - 将来のWebSocket/SharedMemory拡張に対応

- **P2PBox**: 通信ノードの実装
  - send(intent, data, target) - 特定ノードへ送信
  - broadcast(intent, data) - 全ノードへ配信
  - on(intent, callback) - リスナー登録
  - off(intent) - リスナー解除
  - 同一intentに複数リスナー登録可能

## 🔧 技術詳細
- Arc<Mutex>パターンで完全なスレッドセーフティ
- Arc<P2PBoxInner>構造でBox型システムとの整合性確保
- インタープリター完全統合(new/メソッド呼び出し)

## 🧪 テスト
- test_p2p_basic.nyash - 基本機能検証
- test_p2p_message_types.nyash - 各種データ型対応
- test_p2p_edge_cases.nyash - エラー処理
- test_p2p_callback_demo.nyash - 実用例

## 📝 TODO (将来拡張)
- WebSocket/SharedMemoryトランスポート
- コールバック実行(MethodBox統合待ち)
- ノード登録管理システム

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-11 05:11:52 +09:00
parent 832b2e5953
commit 21eceed324
11 changed files with 898 additions and 7 deletions

View File

@ -8,7 +8,7 @@
use super::*;
use crate::ast::UnaryOperator;
use crate::boxes::{buffer::BufferBox, JSONBox, HttpClientBox, StreamBox, RegexBox};
use crate::boxes::{buffer::BufferBox, JSONBox, HttpClientBox, StreamBox, RegexBox, IntentBox, P2PBox};
use crate::operator_traits::OperatorResolver;
// TODO: Fix NullBox import issue later
// use crate::NullBox;
@ -427,6 +427,16 @@ impl NyashInterpreter {
return self.execute_console_method(console_box, method, arguments);
}
// IntentBox method calls
if let Some(intent_box) = obj_value.as_any().downcast_ref::<IntentBox>() {
return self.execute_intent_box_method(intent_box, method, arguments);
}
// P2PBox method calls
if let Some(p2p_box) = obj_value.as_any().downcast_ref::<P2PBox>() {
return self.execute_p2p_box_method(p2p_box, method, arguments);
}
// EguiBox method calls (非WASM環境のみ)
#[cfg(not(target_arch = "wasm32"))]
if let Some(egui_box) = obj_value.as_any().downcast_ref::<crate::boxes::EguiBox>() {