Skip to content

netboz/bbsvx

Repository files navigation

BBSvx

This project is under development and started as a proof of concept.

BBSvx is blockchain powered Virtual Reality engine.

Application logic is based on BBS

Integrating blockchain into BBS should permit to :

  • Have permanent ontologies
  • Have permanently running agents (agents being ontologies)
  • Keep consistency of ontologies in distributed environments as agents are interacting with them
  • Benefit from blockchain inherent characteristics: Enhanced security, transparency, traceability etc.

This blockchain is supported by a P2P overlay network formed by nodes following SPRAY protocol. This permits to bring up a network where each peer only have a partial view of the whole network, named neighnours. Regularly, each node exchange a part of its neighbours with one of them.

Nodes are exchanging messages following EPTO protocol. This permits to have a consistent ordering of events among the nodes.

To permit side effects to Prolog queries, a leader is elected among the nodes of an ontology.

Introduction - Quick Start with Docker

This tutorial will get you up and running with BBSvx in minutes using Docker Compose, demonstrating the distributed P2P network formation and monitoring capabilities.

Prerequisites

  • Docker and Docker Compose installed
  • Git (to clone the repository)

Step 1: Build and Start the BBSvx Cluster

# Clone and enter the repository
git clone https://github.com/netboz/bbsvx.git
cd bbsvx

# Build the BBSvx Docker image
docker build . -t bbsvx

# Build all required images including graph-visualizer
docker compose build

# Start BBSvx with 4 client nodes
docker compose up --scale bbsvx_client=4

This command starts:

  • 1 BBSvx server node (the root/seed node)
  • 4 BBSvx client nodes (joining the cluster)
  • Grafana for monitoring dashboards
  • Graph Visualizer for network topology visualization

Step 2: Monitor Network Formation

Once the containers are running, you can monitor the P2P network formation:

Grafana Dashboard (SPRAY Protocol Monitoring)

Open http://localhost:3000 in your browser to access Grafana dashboards:

  • Username: admin
  • Password: admin (default)
  • Navigate to the BBSvx SPRAY Dashboard to see:
    • Total connection slopes across the cluster
    • Arc exchange monitoring in real-time
    • Inview/outview connections per node
    • Network topology metrics

Graph Visualizer (Real-time Network Topology)

Open http://localhost:3400 in your browser to see:

  • Interactive network graph showing all nodes and connections
  • Real-time updates via WebSocket as nodes join/leave
  • Right-click any node to inspect its inview/outview connections
  • Visual representation of the SPRAY protocol overlay network

Step 3: Scale the Network

Now let's scale up to 10 client nodes to observe how the SPRAY protocol adapts:

# Scale up to 10 client nodes (keep existing containers running)
docker compose up --scale bbsvx_client=10 -d

Watch the monitoring dashboards as:

  1. New nodes join the network automatically
  2. SPRAY protocol exchanges redistribute connections
  3. Network topology evolves to maintain optimal connectivity
  4. Connection slopes adjust to accommodate the larger network

Step 4: Observe Network Behavior

In the Graph Visualizer (http://localhost:3400):

  • Watch new nodes appear and connect to existing ones
  • Observe how connections redistribute as the network grows
  • Right-click nodes to see how inview/outview connections balance

In the Grafana Dashboard (http://localhost:3000):

  • Monitor the "Total Connection Slopes" metric increasing
  • Watch "Arc Exchange" activity as nodes negotiate connections
  • Observe how the network maintains stability despite scaling

Step 5: API Interaction

The HTTP API is available at http://localhost:8085:

# View SPRAY network topology
curl -X GET http://localhost:8085/spray/nodes \
  -H "Content-Type: application/json" \
  -d '{"namespace": "bbsvx:root"}'

# View incoming connections (inview)
curl -X GET http://localhost:8085/spray/inview \
  -H "Content-Type: application/json" \
  -d '{"namespace": "bbsvx:root"}'

# View outgoing connections (outview)
curl -X GET http://localhost:8085/spray/outview \
  -H "Content-Type: application/json" \
  -d '{"namespace": "bbsvx:root"}'

# Create a new ontology
curl -X PUT http://localhost:8085/ontologies/my_test \
  -H "Content-Type: application/json" \
  -d '{"namespace": "my_test", "type": "local"}'

# Retrieve ontology facts and rules
curl -X GET http://localhost:8085/ontologies/bbsvx:root \
  -H "Content-Type: application/json" \
  -d '{"namespace": "bbsvx:root"}'

# Execute a Prolog goal/query
curl -X PUT http://localhost:8085/ontologies/prove \
  -H "Content-Type: application/json" \
  -d '{"namespace": "my_test", "goal": "your_prolog_query_here"}'

Step 6: Cleanup

# Stop all containers
docker compose down

# Remove volumes (optional, clears all data)
docker compose down -v

Features

  • P2P Network: SPRAY protocol implementation for overlay network formation
  • Consensus: EPTO protocol for consistent event ordering
  • Ontology Management: Prolog-based knowledge bases using Erlog
  • Transaction Processing: Blockchain-style transactions with validation pipeline
  • HTTP API: Cowboy-based REST API for external interactions
  • ASN.1 Protocol: High-performance binary protocol (102x faster than term encoding)

Quick Start

Build

export BUILD_WITHOUT_QUIC=true
rebar3 compile

Development

# Build release
rebar3 release

# Start development shell
rebar3 shell

# Run tests
rebar3 ct

Release Management

# Build release
export BUILD_WITHOUT_QUIC=true
rebar3 release

# Start node
_build/default/rel/bbsvx/bin/bbsvx start

# Node operations
_build/default/rel/bbsvx/bin/bbsvx stop
_build/default/rel/bbsvx/bin/bbsvx console
_build/default/rel/bbsvx/bin/bbsvx ping

Configuration

BBSvx supports intelligent configuration with automatic file location detection:

  • BBSVX_CONFIG_FILE=/path/to/config - Environment variable override
  • ~/.bbsvx/bbsvx.conf - User space config (recommended for development)
  • ./bbsvx.conf - Current directory config
  • etc/bbsvx.conf - Release default (production)

Smart Boot Modes

  • boot = root - Start new cluster (fresh data only)
  • boot = join <host> <port> - Join existing cluster
  • boot = auto - Automatic detection (restarts only)

Configuration Examples

# Initialize user config
./bin/bbsvx config init

# Start new cluster
echo "boot = root" >> _build/default/rel/bbsvx/etc/bbsvx.conf
_build/default/rel/bbsvx/bin/bbsvx start

# Join existing cluster
echo "boot = join existing.node.com 2304" >> _build/default/rel/bbsvx/etc/bbsvx.conf
_build/default/rel/bbsvx/bin/bbsvx start

# Environment variables for deployment
export BBSVX_NODE_NAME="[email protected]"
export BBSVX_P2P_PORT=2305
export BBSVX_BOOT="join cluster.internal 2304"
_build/default/rel/bbsvx/bin/bbsvx start

Runtime Management

# System status
_build/default/rel/bbsvx/bin/bbsvx rpc bbsvx_cli status
_build/default/rel/bbsvx/bin/bbsvx rpc bbsvx_cli status verbose

# Configuration management
_build/default/rel/bbsvx/bin/bbsvx rpc bbsvx_cli show
_build/default/rel/bbsvx/bin/bbsvx rpc bbsvx_cli show network.p2p_port
_build/default/rel/bbsvx/bin/bbsvx rpc bbsvx_cli set network.p2p_port 3000

# Ontology management
_build/default/rel/bbsvx/bin/bbsvx rpc bbsvx_cli ontology list
_build/default/rel/bbsvx/bin/bbsvx rpc bbsvx_cli ontology create my_namespace

Docker Development

# Build image
docker build . -t bbsvx

# Run with scaling
docker compose up --scale bbsvx_client=1    # Run with 1 client
docker compose up --scale bbsvx_client=N -d # Scale to N clients

Services

HTTP API Reference

BBSvx provides the following REST API endpoints (default port: 8085):

Ontology Management

Create or Update Ontology

PUT /ontologies/:namespace
Content-Type: application/json

{
  "namespace": "my_ont",
  "type": "local",           # or "shared" for distributed
  "version": "0.0.1",
  "contact_nodes": []
}

# Response: 201 (created) or 200 (already exists)

Retrieve Ontology

GET /ontologies/:namespace
Content-Type: application/json

{"namespace": "my_ont"}

# Response: List of Prolog clauses and facts in JSON format

Delete Ontology

DELETE /ontologies/:namespace
Content-Type: application/json

{"namespace": "my_ont"}

# Response: 204 (deleted)

Execute Prolog Goal/Query

PUT /ontologies/prove
Content-Type: application/json

{
  "namespace": "my_ont",
  "goal": "your_prolog_query_here"
}

# Response: {"status": "accepted", "id": "ulid"}

SPRAY Protocol Debugging

View Incoming Connections (Inview)

GET /spray/inview
Content-Type: application/json

{"namespace": "my_ont"}

# Response: Array of incoming arcs with source/target node details

View Outgoing Connections (Outview)

GET /spray/outview
Content-Type: application/json

{"namespace": "my_ont"}

# Response: Array of outgoing arcs with source/target node details

Get SPRAY Nodes Information

GET /spray/nodes
Content-Type: application/json

{"namespace": "my_ont"}

# Response: Node metadata

Stop SPRAY Agent

DELETE /spray/nodes
Content-Type: application/json

{"namespace": "my_ont"}

# Response: {"result": "ok"}

Real-time Updates

WebSocket Connection

WebSocket: ws://localhost:8085/websocket

- Sends initial ontology state on connection
- Pushes transaction diffs as they occur
- Auto-subscribes to bbsvx:root namespace

Static Files

Web console available at: http://localhost:8085/console/

Code Quality

# Type checking
rebar3 dialyzer
rebar3 eqwalizer

# Format code
rebar3 erlfmt

Architecture

BBSvx is built on a distributed architecture with the following key components:

  • Application Flow: bbsvx_appbbsvx_sup → service processes
  • Ontology Operations: bbsvx_ont_servicebbsvx_actor_ontologybbsvx_erlog_db_*
  • Network Layer: bbsvx_network_servicebbsvx_actor_spray ↔ connection handlers
  • Transaction Flow: HTTP API → bbsvx_ont_service:prove/2 → creates transaction → bbsvx_epto_service:broadcast/2bbsvx_actor_ontology

HTTP Handlers

  • bbsvx_cowboy_handler_ontology - Ontology CRUD and Prolog query execution
  • bbsvx_cowboy_handler_spray - SPRAY protocol debugging (inview/outview inspection)
  • bbsvx_cowboy_websocket_handler - Real-time ontology updates via WebSocket
  • cowboy_static - Static file serving for web console

Testing

# Run Common Test suites
rebar3 ct

# Run EUnit tests
rebar3 eunit

Performance

BBSvx uses ASN.1 encoding as the default protocol format:

  • Performance: 102x faster than Erlang term encoding
  • Size: 2.4x smaller messages
  • Interoperability: Standardized format for cross-language compatibility

License

See LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •