Merge pull request #2 from sairajzero/master
This commit is contained in:
commit
7bef8ac826
3
.config
Normal file
3
.config
Normal file
@ -0,0 +1,3 @@
|
||||
SERVER_PWD=<server_password>
|
||||
BROWSER=firefox
|
||||
PORT=7130
|
||||
87
README.md
87
README.md
@ -1,80 +1,23 @@
|
||||
# Standard_Operations
|
||||
Standard operations required for FLO Crypto, Blockchain API, Supernode WS, IndexedDB
|
||||
|
||||
This template contains standard operations that can be used for the following:
|
||||
1. FLO Globals
|
||||
2. FLO Crypto Operations
|
||||
3. FLO Blockchain API Operations
|
||||
4. FLO SuperNode Websocket Operations
|
||||
5. compact IndexedDB Operations
|
||||
# SuperNodeStorage
|
||||
FLO Supernode Storage is a Cloud Storage progam for FLO Dapps
|
||||
|
||||
## FLO Globals
|
||||
`floGlobals` object contains the global variables and constants required for the operations. Make sure to add this object before any other scripts.
|
||||
`floGlobals` contains the following properties :
|
||||
1. `blockchain` : Indicates the blockchain (`"FLO"` or `"FLO_TEST"`).
|
||||
2. `apiURL` : Indicates the URL for blockchain API calls.
|
||||
3. `adminID` : Indicates the master admin FLO ID for the project.
|
||||
4. `sendAmt` : Indicates the default flo amount to be sent while sending transactions into the blockchain
|
||||
5. `fee` : Indicates the default fee amount to be deduced while sending transactions into the blockchain
|
||||
6. `supernodes` : Holder for the supernode list. Can be updated in runtime while retriving data from blockchain using API. Stored in the Object format,
|
||||
## Installation
|
||||
1. Download or clone the [repo](https://github.com/ranchimall/SuperNodeStorage):
|
||||
|
||||
{
|
||||
<supernodeFLOID> : {
|
||||
uri : <supernodeURI>
|
||||
...(otherProperties)
|
||||
}
|
||||
...(Other Supernodes)
|
||||
}
|
||||
git clone https://github.com/ranchimall/SuperNodeStorage
|
||||
2. Add a strong <server_password> in `.config` file
|
||||
3. Change other configurations (if needed)
|
||||
4. Host and publish the domain name or IP with port
|
||||
|
||||
## FLO Crypto Operations
|
||||
`floCrypto` operations can be used to perform blockchain-cryptography methods. `floCrypto` operations are synchronized and return a value. Contains the following Operations.
|
||||
#### Generate New FLO ID pair
|
||||
floCrypto.generateNewID()
|
||||
`generateNewID` generates a new flo ID and returns private-key, public-key and floID
|
||||
## Usage
|
||||
1. Start the app using the following command in terminal. The server WSS will be started and the supernode html-js will be opened in the browser.
|
||||
|
||||
#### Calculate Public Key Hex
|
||||
`getPubKeyHex` returns public-key from given private-key
|
||||
floCrypto.getPubKeyHex(privateKey)
|
||||
1. privateKey - private key in WIF format (Hex)
|
||||
./start_supernode.sh
|
||||
2. (Only for first time login) Enter the <server_password> and <private_key> when prompted
|
||||
|
||||
#### Calculate FLO ID
|
||||
floCrypto.getFloIDfromPubkeyHex(publicKey)
|
||||
`getFloIDfromPubkeyHex` returns flo-ID from public-key
|
||||
1. publicKey - public key hex value
|
||||
The Supernode storage will automatically start
|
||||
|
||||
#### Verify Private Key
|
||||
floCrypto.verifyPrivKey(privateKey, pubKey_floID, *isfloID)
|
||||
`verifyPrivKey` verify the private-key for the given public-key or flo-ID
|
||||
1. privateKey - private key in WIF format (Hex)
|
||||
2. pubKey_floID - public Key or flo ID
|
||||
3. isfloID - boolean value (true - compare as flo ID, false - compare as public key) (optional, default is true)
|
||||
NOTE: The <server_password> and <private_key> will be stored securedly in IndexedDB of the browser
|
||||
|
||||
#### Validate FLO ID
|
||||
floCrypto.validateAddr(floID)
|
||||
`validateAddr` check if the given Address is valid or not
|
||||
1. floID - flo ID to validate
|
||||
|
||||
#### Data Encryption
|
||||
floCrypto.encryptData(data, publicKey)
|
||||
`encryptData` encrypts the given data using public-key
|
||||
1. data - data to encrypt
|
||||
2. publicKey - public key of the recipient
|
||||
|
||||
#### Data Decryption
|
||||
floCrypto.decryptData(data, privateKey)
|
||||
`decryptData` decrypts the given data using private-key
|
||||
1. data - encrypted data to decrypt (Object that was returned from encryptData)
|
||||
2. privateKey - private key of the recipient
|
||||
|
||||
#### Sign Data
|
||||
floCrypto.signData(data, privateKey)
|
||||
`signData` signs the data using the private key
|
||||
1. data - data to sign
|
||||
2. privateKey - private key of the signer
|
||||
|
||||
#### Verify Signature
|
||||
floCrypto.decryptData(data, signature, publicKey)
|
||||
`decryptData` verifies signatue of the data using public-key
|
||||
1. data - data of the given signature
|
||||
2. signature - signature of the data
|
||||
3. publicKey - public key of the signer
|
||||
NOTE: Users may add `start_supernode` to bootup process to automatically start the supernode during boot up
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
BIN
app/supernodeWSS.bin
Executable file
BIN
app/supernodeWSS.bin
Executable file
Binary file not shown.
19
start_supernode.sh
Executable file
19
start_supernode.sh
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
current_date=$(date)
|
||||
echo "$current_date : Starting Supernode" >> logs/app.log
|
||||
|
||||
#Read configurations
|
||||
IFS="="
|
||||
while read -r var value
|
||||
do
|
||||
export "$var"="${value}"
|
||||
done < .config
|
||||
|
||||
#Start the app
|
||||
echo $current_date >> logs/server.log
|
||||
app/supernodeWSS.bin $PORT $SERVER_PWD >> logs/server.log &
|
||||
echo $current_date >> logs/browser.log
|
||||
$BROWSER app/index.html >> logs/browser.log &
|
||||
wait
|
||||
|
||||
BIN
supernodeWSS
BIN
supernodeWSS
Binary file not shown.
@ -6,9 +6,8 @@
|
||||
#include "mongoose.h"
|
||||
|
||||
static sig_atomic_t s_signal_received = 0;
|
||||
static const char *s_http_port = "7130";
|
||||
static struct mg_serve_http_opts s_http_server_opts;
|
||||
static char server_pwd[100];
|
||||
static char *s_http_port, *server_pwd;
|
||||
static struct mg_connection *supernode_client = NULL;
|
||||
|
||||
static void signal_handler(int sig_num) {
|
||||
@ -94,6 +93,10 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
case MG_EV_WEBSOCKET_HANDSHAKE_DONE: {
|
||||
/*New websocket connection*/
|
||||
display(nc, "+Connected+");
|
||||
if(supernode_client!=NULL)
|
||||
unicast(nc, mg_mk_str("$+"));
|
||||
else
|
||||
unicast(nc, mg_mk_str("$-"));
|
||||
break;
|
||||
}
|
||||
case MG_EV_WEBSOCKET_FRAME: {
|
||||
@ -106,6 +109,8 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
if(!strcmp(pass,server_pwd)){
|
||||
if(supernode_client!=NULL)
|
||||
unicast(supernode_client,mg_mk_str("$Another login is encountered! Please close/refresh this window"));
|
||||
else
|
||||
broadcast(nc, mg_mk_str("$+"));
|
||||
supernode_client = nc;
|
||||
unicast(supernode_client,mg_mk_str("$Access Granted!"));
|
||||
display(nc, "*Became SuperNode*");
|
||||
@ -129,6 +134,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
if(nc == supernode_client){
|
||||
supernode_client = NULL;
|
||||
display(nc,"!SuperNode Disconnected!");
|
||||
broadcast(nc, mg_mk_str("$-"));
|
||||
}else
|
||||
display(nc, "-Disconnected-");
|
||||
break;
|
||||
@ -138,12 +144,8 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
if(argc<=1){
|
||||
printf("Enter server password : ");
|
||||
scanf("%s",server_pwd);
|
||||
}
|
||||
else
|
||||
strcpy(server_pwd,argv[1]);
|
||||
s_http_port = argv[1];
|
||||
server_pwd = argv[2];
|
||||
|
||||
struct mg_mgr mgr;
|
||||
struct mg_connection *nc;
|
||||
@ -157,7 +159,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
nc = mg_bind(&mgr, s_http_port, ev_handler);
|
||||
mg_set_protocol_http_websocket(nc);
|
||||
s_http_server_opts.document_root = "."; // Serve current directory
|
||||
s_http_server_opts.document_root = "app/"; // Serve current directory
|
||||
s_http_server_opts.enable_directory_listing = "no";
|
||||
|
||||
printf("Started on port %s\n", s_http_port);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user