core

module
v0.0.0-...-449a9a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: Apache-2.0

README

LinkSelf Core

基本モジュール(Go)。PC / Android / iOS で共有するコア。Phase 1 で実装した DID・DHT・認証・Store-and-Forward の定義とパッケージ構成。

グループ: メッセージ・接続はグループ単位を想定している。グループ = メンバー DID の集合(2 人以上)。1 対 1 は 2 人グループのケース。詳細は docs/group-concept.md を参照。送信・接続 API は SendToGroup / ConnectToGroup への移行を計画している(現状実装は SendMessage / Connect のまま)。

パッケージ構成

core/
├── go.mod                 # module github.com/SeijiShii/link-self/core
├── internal/
│   ├── did/               # did:key 生成・パース・検証(Ed25519)
│   ├── dht/               # DHT の Provide/Find のラップ(DID ↔ AddrInfo)
│   ├── auth/              # チャレンジ・レスポンス認証
│   ├── node/              # ノード = Host + DHT + Auth + Store-and-Forward
│   └── storeforward/      # メッセージキューとオンライン検知時の送信
├── pkg/
│   └── linkself/          # 公開API(疎結合化のため作成)
│       ├── types.go       # Clientインターフェースと型定義
│       ├── client.go      # Client実装
│       └── README.md      # APIドキュメント
└── cmd/
    └── linkself-daemon/   # JSON-RPC daemon(Electronアプリ用)

公開API

pkg/linkselfパッケージは、LinkSelfコアライブラリの公開APIを提供します。

DID ↔ DHT キー・メッセージ形式

  • DID: did:key: + multibase(base58btc, multicodec(0xed) + raw Ed25519 公開鍵 32 バイト)。DID から PeerID は did.DIDToPeerID で導出可能(公開DHT用)。
  • DHT: 常に公開 DHT(ProtocolPrefix("/ipfs"))。PutDID は行わず、FindPeer(DIDToPeerID(did)) で相手を検索。bootstrap.libp2p.io 等と同一ネットワークに参加。
  • メッセージプロトコル: /linkself/msg/1.0.0。ペイロードは 4 バイト BigEndian 長 + 本体。

ビルド・テスト

cd core
go build ./...
go test ./...

internal/ の did・dht・storeforward の単体テスト、pkg/linkself のクライアントテスト、cmd/linkself-daemon の daemon テスト、test/integration の統合テストを含む。)

ローカル多ノードテスト(統合テスト)

go test ./test/integration/... で以下を網羅(公開DHT・bootstrap 経由):

  1. DID 生成・一致: 同一秘密鍵から同じ DID が得られること。
  2. DHT 発見: Node B が A を bootstrap し、FindPeer(DIDToPeerID(A.DID)) で A のアドレスを取得できること。
  3. 接続・認証: B が A の DID で接続し、チャレンジ・レスポンスで認証成功すること。
  4. メッセージ(オンライン): A と B がともにオンラインのとき、B→A のメッセージが A に届くこと(2 人グループのケース)。
  5. メッセージ(Store-and-Forward): B が A にメッセージを送るが A はオフライン → B がキューに保持 → A が起動して B が Connect でフラッシュ → A が受信すること。

注: グループ概念・オーナー・脱退などは docs/group-concept.md を参照。他計画は docs/phase1-design.mddocs/sync-db-plan.mddocs/sample-chat-app-plan.md を参照。

Directories

Path Synopsis
cmd
linkself-daemon command
poc-gsnode command
poc-gsnode is a throwaway harness for the Go↔TS groupshare interop test (ts/linkself/test/groupshare.interop.test.ts).
poc-gsnode is a throwaway harness for the Go↔TS groupshare interop test (ts/linkself/test/groupshare.interop.test.ts).
poc-wsnode command
poc-wsnode is a throwaway harness for the M1 browser-interop PoC (docs/spec/browser-pwa-support.md §7).
poc-wsnode is a throwaway harness for the M1 browser-interop PoC (docs/spec/browser-pwa-support.md §7).
internal
auth
Package auth implements challenge-response authentication over a libp2p stream.
Package auth implements challenge-response authentication over a libp2p stream.
dataroot
Package dataroot provides platform-specific data directory resolution for LinkSelf's storage hierarchy:
Package dataroot provides platform-specific data directory resolution for LinkSelf's storage hierarchy:
devicesync
Package devicesync provides transparent data replication between devices sharing the same DID (identity).
Package devicesync provides transparent data replication between devices sharing the same DID (identity).
dht
Package dht wraps libp2p Kademlia DHT to provide DID-based Provide/Find for LinkSelf.
Package dht wraps libp2p Kademlia DHT to provide DID-based Provide/Find for LinkSelf.
did
Package did implements did:key generation, parsing, and verification for LinkSelf.
Package did implements did:key generation, parsing, and verification for LinkSelf.
envelope
Package envelope provides a thin message type wrapper for multiplexing DeviceSync, GroupShare, and plain messages over the same transport.
Package envelope provides a thin message type wrapper for multiplexing DeviceSync, GroupShare, and plain messages over the same transport.
group
Package group implements the group concept: member set (2+), owner, leave, dissolve.
Package group implements the group concept: member set (2+), owner, leave, dissolve.
groupshare
Package groupshare provides API-like data sharing between different DIDs in a group.
Package groupshare provides API-like data sharing between different DIDs in a group.
node
Package node assembles a LinkSelf node: libp2p Host + DHT (DID Provide/Find) + auth.
Package node assembles a LinkSelf node: libp2p Host + DHT (DID Provide/Find) + auth.
pairing
Package pairing implements a simple device pairing protocol for LinkSelf.
Package pairing implements a simple device pairing protocol for LinkSelf.
permission
Package permission provides table-level access control using the role DAG.
Package permission provides table-level access control using the role DAG.
presence
Package presence implements the device-presence directory that an always-on node (relay / bootstrap) exposes so that a user's devices can find each other's current reachable address — the discovery piece of two-layer multi-device sync (browser leaves cannot accept inbound connections, so they publish their Circuit-Relay address here and look up their siblings).
Package presence implements the device-presence directory that an always-on node (relay / bootstrap) exposes so that a user's devices can find each other's current reachable address — the discovery piece of two-layer multi-device sync (browser leaves cannot accept inbound connections, so they publish their Circuit-Relay address here and look up their siblings).
role
Package role provides a role hierarchy as a directed acyclic graph (DAG).
Package role provides a role hierarchy as a directed acyclic graph (DAG).
roster
Package roster implements the device roster: the abstraction that unifies a user's devices under the two-layer identity model (data-sync-decisions §4.2 P3).
Package roster implements the device roster: the abstraction that unifies a user's devices under the two-layer identity model (data-sync-decisions §4.2 P3).
sqlproxy
Package sqlproxy provides a SQL query interface that wraps SQLite and captures write operations for sync.
Package sqlproxy provides a SQL query interface that wraps SQLite and captures write operations for sync.
storage/sqlite
Package sqlite provides SQLite3-backed implementations of all LinkSelf storage interfaces.
Package sqlite provides SQLite3-backed implementations of all LinkSelf storage interfaces.
storeforward
Package storeforward implements Store-and-Forward: queue messages by destination DID, flush when the peer is reported online (e.g.
Package storeforward implements Store-and-Forward: queue messages by destination DID, flush when the peer is reported online (e.g.
syncdb
Package syncdb implements the sync layer: meta attachment, immediate group delivery, last-write-wins apply.
Package syncdb implements the sync layer: meta attachment, immediate group delivery, last-write-wins apply.
pkg
linkself
Package linkself provides the public API for interacting with LinkSelf nodes.
Package linkself provides the public API for interacting with LinkSelf nodes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL