Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/krypt0nn/bpn

Bit Points Network - your personal decentralized network in PHP 8
https://github.com/krypt0nn/bpn

decentralized network php

Last synced: 6 days ago
JSON representation

Bit Points Network - your personal decentralized network in PHP 8

Awesome Lists containing this project

README

        






🚀 BPN is a huge library which allows you to create your own decentralized network on PHP 8+

and provides various communication tools

## Installation

```
composer require krypt0nn/bpn
```

## Usage example

### Communication through events with unprotected UDP packets

client.php

```php
$keypair['public'],
'private_key' => $keypair['private']
]);

BPN::get()->send (
Endpoint::format('server address'),
Packet::performEvent('hello-world', 'Hello, World!')
);
```

server.php

```php
$keypair['public'],
'private_key' => $keypair['private']
]);

BPN::on('hello-world', fn (Packet $packet) => echo $packet->data['data'] . PHP_EOL);

while (true)
BPN::get()->update();
```

### Direct connection through protected TCP tunnel

client.php

```php
$keypair['public'],
'private_key' => $keypair['private']
]);

$tunnel = Tunnel::create(Endpoint::format('server address'));

if ($tunnel === null)
die ('Tunnel creation error');

else while (true)
{
$message = readline ('> ');

$tunnel->send ($message);
}
```

server.php

```php
$keypair['public'],
'private_key' => $keypair['private']
]);

while (!($tunnel = Tunnel::listen(Endpoint::local())));

while (true)
{
$tunnel->update (function ($data)
{
echo $data . PHP_EOL;
});
}
```

### Search client through BPN network by his UUID

```php
$keypair['public'],
'private_key' => $keypair['private']
]);

DNS::searchRecords ('client uuid', function (Record $record, Packet $packet)
{
echo 'Client with endpoint '. $packet->author_endpoint->toString() .
' found client we wanted to find'.
' and his endpoint is '. $record->endpoint()->toString() . PHP_EOL;

// if you want to not to receive another records
// you can return false from this callback
// return false;
});
```

### Broadcast data

```php
$keypair['public'],
'private_key' => $keypair['private']
]);

# Add broadcast handler for incoming data
BPN::onBroadcast(function ($data)
{
echo '['. $data['author'] .'] '. $data['message'] . PHP_EOL;
});

# Broadcast data
BPN::broadcast ([
'author' => 'aboba',
'message' => 'Hello, World!'
]);
```

## Documentation

Documentation will be added in future


Author: [Nikita Podvirnyy](https://vk.com/technomindlp)