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: 9 months ago
JSON representation
Bit Points Network - your personal decentralized network in PHP 8
- Host: GitHub
- URL: https://github.com/krypt0nn/bpn
- Owner: krypt0nn
- License: gpl-3.0
- Created: 2021-08-17T12:45:39.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-08-28T12:30:29.000Z (almost 5 years ago)
- Last Synced: 2025-04-22T20:47:31.666Z (about 1 year ago)
- Topics: decentralized, network, php
- Language: PHP
- Homepage:
- Size: 76.2 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)