Compare commits
128 Commits
p2prc-docs
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 36930be8e4 | |||
| be1f3308ca | |||
| b3fcc10cd8 | |||
|
|
301a87e758 | ||
| c9f4c8b5c7 | |||
| 10b3c6bae3 | |||
| d4e73e9d34 | |||
| 4c7deb948f | |||
| 54a675e0c0 | |||
| 3c3cfac5e2 | |||
| 6a24da74ef | |||
| 0fe1b0c622 | |||
| 7d3fc9b25f | |||
|
|
6281b0f532 | ||
| 1711b01979 | |||
| 438b4d0424 | |||
| 22c5d61082 | |||
| a1bf13cac3 | |||
| 616bf76bda | |||
| 539bceee7d | |||
| 69b9ea3527 | |||
| 27f4615cd1 | |||
| 01e19d9a8c | |||
| aafc0ebdd7 | |||
| 9de0b1b985 | |||
| 4c12d74789 | |||
| f06df58a8a | |||
| 30004d59c6 | |||
| 4c8cde8857 | |||
| 994c52faf0 | |||
| 5e65381377 | |||
| ff66d55153 | |||
| 50983dbb19 | |||
| 189edd73b1 | |||
| 27670f2408 | |||
| b301a54fba | |||
| 05e29aab0d | |||
| b883feb825 | |||
| 5059444d26 | |||
| be3be96987 | |||
| 682424074f | |||
| 9d0ec3eba4 | |||
| bf87217b9a | |||
| e4638232d3 | |||
| fb6c3ab091 | |||
| a59657a93b | |||
| 30ea1f810a | |||
| fe72625266 | |||
| d2030b7d74 | |||
| 73a283a545 | |||
| 623cfffb6a | |||
| 3669fdfad2 | |||
| f39fab04ce | |||
| 12ff0ceb37 | |||
| 99c62a8dca | |||
| ce5c80a10e | |||
| 46ef4e1db9 | |||
| 14743f7f9b | |||
| a461c2da64 | |||
| 99c9c41528 | |||
| 0e260cf8e4 | |||
| 02e58493f5 | |||
| a46ec3575c | |||
| 2d55643dd9 | |||
| 1ac0647d46 | |||
| a07a412c72 | |||
| e04e918328 | |||
| 0bb949a1e2 | |||
| cf6611087a | |||
| b1a69189d3 | |||
| ad76773111 | |||
| ec46f74c4e | |||
| 3fb225676f | |||
| 0e86459122 | |||
| 77ebb76838 | |||
| 85806ab035 | |||
| 9d92ecb202 | |||
| 5fa625160e | |||
| 403ad72ddb | |||
| 6446681719 | |||
| d50534e270 | |||
| 8a2dfb7b5b | |||
| 0f4f52cb8b | |||
| cd8bb2df8c | |||
| fa5b7a27d5 | |||
| 21f0fc79c1 | |||
| bebe2a02a0 | |||
| 7b0b2404b2 | |||
| 724daf5eda | |||
| c262e612e1 | |||
| 257d91a432 | |||
| 42cf9bd028 | |||
| 7c34c5385a | |||
| d79c28c32f | |||
|
|
7b0d36873b | ||
| 2283736cc6 | |||
| 51b253df15 | |||
| b9f5dec9de | |||
| 30b464449c | |||
| ffd711f448 | |||
| 0d01d70c2b | |||
| 6b1edd3d8a | |||
| 5cf1e144aa | |||
|
|
f605e2e06b | ||
| 873caa911c | |||
| 73a470e201 | |||
| 805514edfa | |||
|
|
5e3a4e8b7a | ||
| 5f8407a37f | |||
| a6939ec35e | |||
|
|
c445ac88c4 | ||
| 9075ab5967 | |||
| 125d113ade | |||
| e7e0641f31 | |||
| 05655e2da1 | |||
| ed8d2be205 | |||
|
|
30cd9c1901 | ||
| d9d5ebe475 | |||
| 23abbc8f90 | |||
|
|
5c0bcfd4cf | ||
| 9b255265c4 | |||
| 075d1850f6 | |||
| 38bef975d5 | |||
|
|
5cbc9842b4 | ||
| 4479a79912 | |||
| 88a4e02e30 | |||
| ddd6864741 | |||
|
|
3735ab87e0 |
49
.github/workflows/pages.yml
vendored
49
.github/workflows/pages.yml
vendored
@@ -1,49 +0,0 @@
|
|||||||
name: Deploy Jekyll with GitHub Pages dependencies preinstalled
|
|
||||||
|
|
||||||
on:
|
|
||||||
# Runs on pushes targeting the default branch
|
|
||||||
push:
|
|
||||||
branches: ["main", "master"]
|
|
||||||
|
|
||||||
# Allows you to run this workflow manually from the Actions tab
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
pages: write
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
# Allow one concurrent deployment
|
|
||||||
concurrency:
|
|
||||||
group: "pages"
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
# Build job
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Setup Pages
|
|
||||||
uses: actions/configure-pages@v2
|
|
||||||
- name: Build with Jekyll
|
|
||||||
uses: actions/jekyll-build-pages@v1
|
|
||||||
with:
|
|
||||||
source: ./
|
|
||||||
destination: ./_site
|
|
||||||
- name: Upload artifact
|
|
||||||
uses: actions/upload-pages-artifact@v1
|
|
||||||
|
|
||||||
# Deployment job
|
|
||||||
deploy:
|
|
||||||
environment:
|
|
||||||
name: github-pages
|
|
||||||
url: ${{ steps.deployment.outputs.page_url }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build
|
|
||||||
steps:
|
|
||||||
- name: Deploy to GitHub Pages
|
|
||||||
id: deployment
|
|
||||||
uses: actions/deploy-pages@v1
|
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -31,6 +31,7 @@ server/docker/containers/
|
|||||||
|
|
||||||
# generic folder to ignore
|
# generic folder to ignore
|
||||||
export/
|
export/
|
||||||
|
exports/
|
||||||
|
|
||||||
# Any testing file
|
# Any testing file
|
||||||
*test
|
*test
|
||||||
@@ -43,6 +44,9 @@ p2prc.PublicKeyBareMetal
|
|||||||
# Ignore pem files
|
# Ignore pem files
|
||||||
*.pem
|
*.pem
|
||||||
|
|
||||||
|
# ignore virtual env file
|
||||||
|
venv
|
||||||
|
|
||||||
# Nix and Nix flake files
|
# Nix and Nix flake files
|
||||||
result
|
result
|
||||||
result-*
|
result-*
|
||||||
|
|||||||
@@ -135,11 +135,29 @@ func EscapeFirewall(HostOutsideNATIP string, HostOutsideNATPort string, internal
|
|||||||
|
|
||||||
//export MapPort
|
//export MapPort
|
||||||
func MapPort(Port string, DomainName string, ServerAddress string) *C.char {
|
func MapPort(Port string, DomainName string, ServerAddress string) *C.char {
|
||||||
entireAddress, _, err := abstractions.MapPort(Port, DomainName, ServerAddress)
|
Address, err := abstractions.MapPort(Port, DomainName, ServerAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return C.CString(err.Error())
|
return C.CString(err.Error())
|
||||||
}
|
}
|
||||||
return C.CString(entireAddress)
|
return C.CString(Address.EntireAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
//export CustomInformation
|
||||||
|
func CustomInformation(CustomInformation string) *C.char {
|
||||||
|
err := abstractions.AddCustomInformation(CustomInformation)
|
||||||
|
if err != nil {
|
||||||
|
return C.CString(err.Error())
|
||||||
|
}
|
||||||
|
return C.CString("Success")
|
||||||
|
}
|
||||||
|
|
||||||
|
//export AddRootNode
|
||||||
|
func AddRootNode(IP string, Port string) *C.char {
|
||||||
|
err := abstractions.AddRootNode(IP, Port)
|
||||||
|
if err != nil {
|
||||||
|
return C.CString(err.Error())
|
||||||
|
}
|
||||||
|
return C.CString("Success")
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------- Controlling Server ----------------------------------------
|
// --------------------------------- Controlling Server ----------------------------------------
|
||||||
|
|||||||
2
Bindings/Haskell/.mhsi
Normal file
2
Bindings/Haskell/.mhsi
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
exit
|
||||||
|
Exit
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
|--------------|-----------------------------------------|
|
|--------------|-----------------------------------------|
|
||||||
| Copyright | Copyright (C) 2006-2024 John MacFarlane |
|
| Copyright | Copyright (C) 2006-2024 John MacFarlane |
|
||||||
| License | GNU GPL, version 2 or above |
|
| License | GNU GPL, version 2 or above |
|
||||||
| Maintainer | John MacFarlane \<jgm@berkeley.edu\> |
|
|
||||||
| Stability | alpha |
|
| Stability | alpha |
|
||||||
| Portability | portable |
|
| Portability | portable |
|
||||||
| Safe Haskell | Safe-Inferred |
|
| Safe Haskell | Safe-Inferred |
|
||||||
|
|||||||
66
Bindings/Haskell/flake.lock
generated
66
Bindings/Haskell/flake.lock
generated
@@ -18,23 +18,41 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"flake-utils_2": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems_2"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"gomod2nix": {
|
"gomod2nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": [
|
"flake-utils": [
|
||||||
"p2prc",
|
"p2prc-main",
|
||||||
"flake-utils"
|
"flake-utils"
|
||||||
],
|
],
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
"p2prc",
|
"p2prc-main",
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1733668782,
|
"lastModified": 1745875161,
|
||||||
"narHash": "sha256-tPsqU00FhgdFr0JiQUiBMgPVbl1jbPCY5gbFiJycL3I=",
|
"narHash": "sha256-0YkWCS13jpoo3+sX/3kcgdxBNt1VZTmvF+FhZb4rFKI=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "gomod2nix",
|
"repo": "gomod2nix",
|
||||||
"rev": "514283ec89c39ad0079ff2f3b1437404e4cba608",
|
"rev": "2cbd7fdd6eeab65c494cc426e18f4e4d2a5e35c0",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -57,11 +75,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1735834308,
|
"lastModified": 1748026106,
|
||||||
"narHash": "sha256-dklw3AXr3OGO4/XT1Tu3Xz9n/we8GctZZ75ZWVqAVhk=",
|
"narHash": "sha256-6m1Y3/4pVw1RWTsrkAK2VMYSzG4MMIj7sqUy7o8th1o=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "6df24922a1400241dae323af55f30e4318a6ca65",
|
"rev": "063f43f2dbdef86376cc29ad646c45c46e93234c",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -71,28 +89,28 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"p2prc": {
|
"p2prc-main": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils_2",
|
||||||
"gomod2nix": "gomod2nix",
|
"gomod2nix": "gomod2nix",
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 0,
|
"lastModified": 0,
|
||||||
"narHash": "sha256-f4e4JcQzBS+R+8HqJbQVeecInm2ggInJuSSymj6gtQo=",
|
"narHash": "sha256-5qbaxawuLsg8iu9076zlAbLtTFSNJaTz7WERS5rWRxU=",
|
||||||
"path": "/nix/store/hmk8v0lxifsscll054qsdnzxqfql1998-source",
|
"path": "/nix/store/lg694r23fzc6v5ai3qqcszq1fp44djg2-source",
|
||||||
"type": "path"
|
"type": "path"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"path": "/nix/store/hmk8v0lxifsscll054qsdnzxqfql1998-source",
|
"path": "/nix/store/lg694r23fzc6v5ai3qqcszq1fp44djg2-source",
|
||||||
"type": "path"
|
"type": "path"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"p2prc": "p2prc",
|
"p2prc-main": "p2prc-main"
|
||||||
"utils": "utils"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"systems": {
|
"systems": {
|
||||||
@@ -124,24 +142,6 @@
|
|||||||
"repo": "default",
|
"repo": "default",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"utils": {
|
|
||||||
"inputs": {
|
|
||||||
"systems": "systems_2"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1731533236,
|
|
||||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|||||||
@@ -1,24 +1,28 @@
|
|||||||
{
|
{
|
||||||
description = "Nix flake for P2PRC Haskell library";
|
description = "Nix flake for P2PRC Haskell library";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
p2prc.url = "../../";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
utils.url = "github:numtide/flake-utils";
|
p2prc-main.url = "../../";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, utils, p2prc }: utils.lib.eachDefaultSystem (system:
|
outputs = { nixpkgs, flake-utils, p2prc-main, ... }:
|
||||||
let
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
let
|
||||||
in
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
{
|
in
|
||||||
devShell = pkgs.mkShell {
|
{
|
||||||
buildInputs = with pkgs; [
|
|
||||||
cabal-install
|
packages.default = pkgs.haskellPackages.callPackage ./project.nix {};
|
||||||
haskell.compiler.ghc96
|
|
||||||
zlib.dev
|
devShell = pkgs.mkShell {
|
||||||
p2prc.outputs.packages.${system}.default
|
buildInputs = with pkgs; [
|
||||||
];
|
cabal2nix
|
||||||
};
|
cabal-install
|
||||||
}
|
ghc
|
||||||
);
|
zlib.dev
|
||||||
|
p2prc-main.packages.${system}.default
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ module API
|
|||||||
( P2PRCapi(..)
|
( P2PRCapi(..)
|
||||||
, MapPortRequest(..)
|
, MapPortRequest(..)
|
||||||
, p2prcAPI
|
, p2prcAPI
|
||||||
|
, P2PRCommands(..)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ import System.Process ( ProcessHandle )
|
|||||||
|
|
||||||
import Data.Aeson ( FromJSON )
|
import Data.Aeson ( FromJSON )
|
||||||
|
|
||||||
|
|
||||||
import Error
|
import Error
|
||||||
( IOEitherError
|
( IOEitherError
|
||||||
)
|
)
|
||||||
@@ -20,19 +22,21 @@ import Error
|
|||||||
import JSON
|
import JSON
|
||||||
( IPAddressTable(..)
|
( IPAddressTable(..)
|
||||||
, MapPortResponse(..)
|
, MapPortResponse(..)
|
||||||
, P2prcConfig
|
, P2PRCConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
import CLI
|
import CLI
|
||||||
( StdInput(..)
|
( StdInput(..)
|
||||||
, CLIOpt(..)
|
, CLIOpt(..)
|
||||||
, eitherErrDecode
|
, eitherErrDecode
|
||||||
, p2PrcCmdName
|
, p2prcCmdName
|
||||||
, eitherExecProcess
|
, eitherExecProcess
|
||||||
, eitherExecProcessParser
|
, eitherExecProcessParser
|
||||||
, spawnProcP2Prc
|
, spawnProcP2PRC
|
||||||
)
|
)
|
||||||
|
|
||||||
|
-- import System.Environment (lookupEnv)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- | Lower level P2PRC Haskell api that exposes basic functionality necessary to joint the network.
|
-- | Lower level P2PRC Haskell api that exposes basic functionality necessary to joint the network.
|
||||||
@@ -41,21 +45,32 @@ data P2PRCapi
|
|||||||
= MkP2PRCapi
|
= MkP2PRCapi
|
||||||
{ startServer :: IOEitherError ProcessHandle
|
{ startServer :: IOEitherError ProcessHandle
|
||||||
-- ^ Start server
|
-- ^ Start server
|
||||||
, execInitConfig :: IOEitherError P2prcConfig
|
-- , execInitConfig :: IOEitherError P2PRCConfig
|
||||||
-- ^ Instantiate server configuration
|
-- ^ Instantiate server configuration
|
||||||
, execListServers :: IOEitherError IPAddressTable
|
, execListServers :: IOEitherError IPAddressTable
|
||||||
-- ^ List servers in network
|
-- ^ List servers in network
|
||||||
, execMapPort :: MapPortRequest -> IOEitherError MapPortResponse
|
, execMapPort :: MapPortRequest -> IOEitherError MapPortResponse
|
||||||
-- ^ Exposes and associates a local TCP port with a remote DNS address
|
-- ^ Exposes and associates a local TCP port with a remote DNS address
|
||||||
|
, execMaybeMapPortAndAddCustomInformation :: Maybe MapPortRequest -> PassCustomInformation -> IOEitherError String
|
||||||
|
, execAddCustomInformation :: PassCustomInformation -> IOEitherError String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- | This defines the request required to create an association between a TCP socket port and a DNS server in the network. If successful, it makes a resource available in the network.
|
-- | This defines the request required to create an association between a TCP socket port and a DNS server in the network. If successful, it makes a resource available in the network.
|
||||||
data MapPortRequest =
|
data MapPortRequest =
|
||||||
MkMapPortRequest -- ^ P2PRC's port allocation request value
|
MkMapPortRequest -- ^ P2PRC's port allocation request value
|
||||||
Int -- ^ TCP socket number
|
Int -- ^ TCP socket number
|
||||||
String -- ^ Network domain name
|
String -- ^ Network domain name
|
||||||
|
|
||||||
|
-- | This defined the custom information required to be passed through.
|
||||||
|
newtype PassCustomInformation =
|
||||||
|
MkAddCustomInformation
|
||||||
|
String
|
||||||
|
|
||||||
|
data P2PRCommands
|
||||||
|
= MapPort MapPortRequest
|
||||||
|
| CustomInformation PassCustomInformation
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
This function intiates a pure P2PRC runtime state and builds up a 'P2PRCapi' API instance. It allows a developer to create computing orchestration algorithms using the API primitives.
|
This function intiates a pure P2PRC runtime state and builds up a 'P2PRCapi' API instance. It allows a developer to create computing orchestration algorithms using the API primitives.
|
||||||
@@ -92,16 +107,22 @@ main =
|
|||||||
|
|
||||||
{-# WARNING p2prcAPI "This function is currently unstable because the configuration reading is dependent on the following issue: https://github.com/Akilan1999/p2p-rendering-computation/issues/120" #-}
|
{-# WARNING p2prcAPI "This function is currently unstable because the configuration reading is dependent on the following issue: https://github.com/Akilan1999/p2p-rendering-computation/issues/120" #-}
|
||||||
p2prcAPI :: P2PRCapi
|
p2prcAPI :: P2PRCapi
|
||||||
p2prcAPI =
|
p2prcAPI = let
|
||||||
|
|
||||||
|
execTemp :: Maybe MapPortRequest -> PassCustomInformation -> IOEitherError String
|
||||||
|
execTemp mp ci = undefined
|
||||||
|
|
||||||
|
|
||||||
|
in
|
||||||
MkP2PRCapi
|
MkP2PRCapi
|
||||||
{ startServer = spawnProcP2Prc p2PrcCmdName [ MkOptAtomic "--s" ]
|
{ startServer = spawnProcP2PRC p2prcCmdName [ MkOptAtomic "-s" ]
|
||||||
|
|
||||||
, execListServers =
|
, execListServers =
|
||||||
execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput
|
execProcP2PRCParser [ MkOptAtomic "--ls" ] MkEmptyStdInput
|
||||||
|
|
||||||
, execMapPort =
|
, execMapPort =
|
||||||
\ (MkMapPortRequest portNumber domainName) ->
|
\ (MkMapPortRequest portNumber domainName) ->
|
||||||
execProcP2PrcParser
|
execProcP2PRCParser
|
||||||
[ MkOptTuple
|
[ MkOptTuple
|
||||||
( "--mp"
|
( "--mp"
|
||||||
, show portNumber
|
, show portNumber
|
||||||
@@ -113,39 +134,44 @@ p2prcAPI =
|
|||||||
]
|
]
|
||||||
MkEmptyStdInput
|
MkEmptyStdInput
|
||||||
|
|
||||||
, execInitConfig = do
|
, execMaybeMapPortAndAddCustomInformation = execTemp
|
||||||
|
, execAddCustomInformation = execTemp Nothing
|
||||||
|
|
||||||
confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput
|
-- , execInitConfig = do
|
||||||
|
|
||||||
case confInitRes of
|
-- confInitRes <- execProcP2PRC [ MkOptAtomic "--dc" ] MkEmptyStdInput
|
||||||
(Right _) -> do
|
|
||||||
|
|
||||||
-- TODO: get config file name dynamically
|
-- case confInitRes of
|
||||||
--
|
-- (Right _) -> do
|
||||||
currDirectory <- getCurrentDirectory
|
|
||||||
|
|
||||||
-- TODO: change values before loading file
|
-- maybeValue <- lookupEnv "P2PRC"
|
||||||
let fname = currDirectory ++ "/config.json" :: FilePath
|
|
||||||
|
-- -- TODO: get config file name dynamically
|
||||||
|
-- --
|
||||||
|
-- currDirectory <- getCurrentDirectory
|
||||||
|
|
||||||
|
-- -- TODO: change values before loading file
|
||||||
|
-- let fname = currDirectory ++ "/config.json" :: FilePath
|
||||||
|
|
||||||
|
|
||||||
-- TODO: read config check if file exists
|
-- -- TODO: read config check if file exists
|
||||||
configContent <- readFile fname
|
-- configContent <- readFile fname
|
||||||
|
|
||||||
pure $ eitherErrDecode configContent
|
-- pure $ eitherErrDecode configContent
|
||||||
|
|
||||||
(Left err) -> pure $ Left err
|
-- (Left err) -> pure $ Left err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
where
|
where
|
||||||
|
|
||||||
execProcP2PrcParser ::
|
execProcP2PRCParser ::
|
||||||
FromJSON a =>
|
FromJSON a =>
|
||||||
[CLIOpt] -> StdInput -> IOEitherError a
|
[CLIOpt] -> StdInput -> IOEitherError a
|
||||||
|
|
||||||
execProcP2PrcParser = eitherExecProcessParser p2PrcCmdName
|
execProcP2PRCParser = eitherExecProcessParser p2prcCmdName
|
||||||
-- TODO: GHC question, why does it scope down instead staying generic
|
-- TODO: GHC question, why does it scope down instead staying generic
|
||||||
|
|
||||||
execProcP2Prc = eitherExecProcess p2PrcCmdName
|
-- execProcP2PRC = eitherExecProcess p2prcCmdName
|
||||||
|
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ optsToCLI = concatMap _optToCLI
|
|||||||
_optToCLI (MkOptTuple (o, v)) = [o, v]
|
_optToCLI (MkOptTuple (o, v)) = [o, v]
|
||||||
|
|
||||||
|
|
||||||
spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IOEitherError ProcessHandle
|
spawnProcP2PRC :: CLICmd -> [CLIOpt] -> IOEitherError ProcessHandle
|
||||||
spawnProcP2Prc cmd opts =
|
spawnProcP2PRC cmd opts =
|
||||||
do
|
do
|
||||||
let prc = proc cmd $ optsToCLI opts
|
let prc = proc cmd $ optsToCLI opts
|
||||||
|
|
||||||
@@ -115,6 +115,6 @@ eitherErrorDecode esa =
|
|||||||
|
|
||||||
-- assumes the program is ran inside the haskell module in p2prc's repo
|
-- assumes the program is ran inside the haskell module in p2prc's repo
|
||||||
-- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation"
|
-- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation"
|
||||||
p2PrcCmdName :: String
|
p2prcCmdName :: String
|
||||||
p2PrcCmdName = "p2p-rendering-computation"
|
p2prcCmdName = "p2p-rendering-computation"
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
module Engine
|
module Engine
|
||||||
( runP2PRC
|
( runP2PRC
|
||||||
|
, fn
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ import System.Process ( terminateProcess )
|
|||||||
import API
|
import API
|
||||||
( P2PRCapi(..)
|
( P2PRCapi(..)
|
||||||
, MapPortRequest(..)
|
, MapPortRequest(..)
|
||||||
, p2prcAPI
|
, p2prcAPI, P2PRCommands
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -58,14 +59,10 @@ import API
|
|||||||
@
|
@
|
||||||
-}
|
-}
|
||||||
runP2PRC
|
runP2PRC
|
||||||
:: MapPortRequest -- ^ TCP Port Request
|
:: [P2PRCommands] -- ^ TCP Port Request
|
||||||
-> IO ()
|
-> IO ()
|
||||||
runP2PRC
|
runP2PRC [] = putStrLn ""
|
||||||
( MkMapPortRequest
|
runP2PRC nonEmpty@(_:_) =
|
||||||
portNumber
|
|
||||||
domainName
|
|
||||||
)
|
|
||||||
=
|
|
||||||
let
|
let
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -95,9 +92,10 @@ runP2PRC
|
|||||||
|
|
||||||
( MkP2PRCapi
|
( MkP2PRCapi
|
||||||
{ startServer = startServer
|
{ startServer = startServer
|
||||||
, execInitConfig = execInitConfig
|
-- , execInitConfig = execInitConfig
|
||||||
, execListServers = execListServers
|
, execListServers = execListServers
|
||||||
, execMapPort = execMapPort
|
, execMapPort = execMapPort
|
||||||
|
, execAddCustomInformation = _
|
||||||
}
|
}
|
||||||
) = p2prcAPI
|
) = p2prcAPI
|
||||||
|
|
||||||
@@ -105,18 +103,19 @@ runP2PRC
|
|||||||
let
|
let
|
||||||
|
|
||||||
|
|
||||||
configValue <- execInitConfig
|
-- configValue <- execInitConfig
|
||||||
|
|
||||||
-- TODO: get name of host server from config json
|
-- TODO: get name of host server from config json
|
||||||
|
|
||||||
print configValue
|
-- print configValue
|
||||||
putStrLn "\n\n\n"
|
-- putStrLn "\n\n\n"
|
||||||
|
|
||||||
eitherStartProcessHandle <- startServer
|
eitherStartProcessHandle <- startServer
|
||||||
|
|
||||||
|
|
||||||
case eitherStartProcessHandle of
|
case eitherStartProcessHandle of
|
||||||
(Right startProcessHandle) -> do
|
(Right startProcessHandle) ->
|
||||||
|
do
|
||||||
|
|
||||||
let sleepNSecs i = threadDelay (i * 1000000)
|
let sleepNSecs i = threadDelay (i * 1000000)
|
||||||
|
|
||||||
@@ -125,7 +124,8 @@ runP2PRC
|
|||||||
outputStr <- execListServers
|
outputStr <- execListServers
|
||||||
print outputStr
|
print outputStr
|
||||||
|
|
||||||
mapPortOut <- execMapPort $ MkMapPortRequest portNumber domainName
|
-- mapPortOut <- execMapPort $ MkMapPortRequest portNumber domainName
|
||||||
|
mapPortOut <- execMapPort $ MkMapPortRequest undefined undefined
|
||||||
|
|
||||||
case mapPortOut of
|
case mapPortOut of
|
||||||
(Right v) -> print v
|
(Right v) -> print v
|
||||||
@@ -159,3 +159,7 @@ runP2PRC
|
|||||||
when (toLower c /= 'q') $ exitOnQ exitF
|
when (toLower c /= 'q') $ exitOnQ exitF
|
||||||
exitF
|
exitF
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn :: undefined
|
||||||
|
fn = undefined
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module JSON
|
module JSON
|
||||||
( P2prcConfig(..)
|
( P2PRCConfig(..)
|
||||||
, IPAddressTable(..)
|
, IPAddressTable(..)
|
||||||
, IPAddress(..)
|
, IPAddress(..)
|
||||||
, ServerInfo(..)
|
, ServerInfo(..)
|
||||||
@@ -38,11 +38,11 @@ instance FromJSON MapPortResponse where
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
{-# WARNING P2prcConfig "This type is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-}
|
{-# WARNING P2PRCConfig "This type is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-}
|
||||||
|
|
||||||
-- | This represents the server configuration that defines its attributes and behaviours in the network, as well as, the location of the runtime persistence artifacts.
|
-- | This represents the server configuration that defines its attributes and behaviours in the network, as well as, the location of the runtime persistence artifacts.
|
||||||
newtype P2prcConfig
|
newtype P2PRCConfig
|
||||||
= MkP2prConfig
|
= MkP2PRCConfig
|
||||||
{ machineName :: String -- ^ Machine Name
|
{ machineName :: String -- ^ Machine Name
|
||||||
} deriving Show
|
} deriving Show
|
||||||
|
|
||||||
@@ -96,13 +96,13 @@ newtype P2prcConfig
|
|||||||
-- to have a dedicated port field
|
-- to have a dedicated port field
|
||||||
|
|
||||||
|
|
||||||
instance FromJSON P2prcConfig where
|
instance FromJSON P2PRCConfig where
|
||||||
parseJSON (Object o) = do
|
parseJSON (Object o) = do
|
||||||
|
|
||||||
machineName <- o .: "MachineName"
|
machineName <- o .: "MachineName"
|
||||||
|
|
||||||
pure
|
pure
|
||||||
$ MkP2prConfig
|
$ MkP2PRCConfig
|
||||||
{ machineName=machineName
|
{ machineName=machineName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,9 +49,10 @@ module P2PRC
|
|||||||
-- ** Interface data types
|
-- ** Interface data types
|
||||||
-- | This section gives an overview on the runtime and host machine interfaces.
|
-- | This section gives an overview on the runtime and host machine interfaces.
|
||||||
, P2PRCapi(..)
|
, P2PRCapi(..)
|
||||||
, P2prcConfig(..)
|
, P2PRCConfig(..)
|
||||||
, MapPortRequest(..)
|
, MapPortRequest(..)
|
||||||
, MapPortResponse(..)
|
, MapPortResponse(..)
|
||||||
|
, P2PRCommands(..)
|
||||||
|
|
||||||
-- ** Primitive data types
|
-- ** Primitive data types
|
||||||
-- | These types represent the core data that is communicated between requests and the runtime.
|
-- | These types represent the core data that is communicated between requests and the runtime.
|
||||||
@@ -76,13 +77,14 @@ import JSON
|
|||||||
, ServerInfo(..)
|
, ServerInfo(..)
|
||||||
, IPAddress(..)
|
, IPAddress(..)
|
||||||
, MapPortResponse(..)
|
, MapPortResponse(..)
|
||||||
, P2prcConfig(..)
|
, P2PRCConfig(..)
|
||||||
)
|
)
|
||||||
|
|
||||||
import API
|
import API
|
||||||
( MapPortRequest(..)
|
( MapPortRequest(..)
|
||||||
, P2PRCapi(..)
|
, P2PRCapi(..)
|
||||||
, p2prcAPI
|
, p2prcAPI
|
||||||
|
, P2PRCommands(..)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
Bindings/Haskell/project.nix
Normal file
13
Bindings/Haskell/project.nix
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{ mkDerivation, aeson, base, bytestring, directory, lib, process
|
||||||
|
, text
|
||||||
|
}:
|
||||||
|
mkDerivation {
|
||||||
|
pname = "p2prc";
|
||||||
|
version = "0.1.0.0";
|
||||||
|
src = ./.;
|
||||||
|
libraryHaskellDepends = [
|
||||||
|
aeson base bytestring directory process text
|
||||||
|
];
|
||||||
|
description = "P2PRC haskell library";
|
||||||
|
license = "unknown";
|
||||||
|
}
|
||||||
@@ -3,10 +3,14 @@ module Main where
|
|||||||
import P2PRC
|
import P2PRC
|
||||||
( runP2PRC
|
( runP2PRC
|
||||||
, MapPortRequest(MkMapPortRequest)
|
, MapPortRequest(MkMapPortRequest)
|
||||||
|
, P2PRCommands(MapPort)
|
||||||
)
|
)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main =
|
main =let
|
||||||
|
in
|
||||||
runP2PRC
|
runP2PRC
|
||||||
( MkMapPortRequest 8080 "jose.akilan.io"
|
[
|
||||||
)
|
( MapPort $ MkMapPortRequest 8080 "jose.akilan.io")
|
||||||
|
]
|
||||||
|
|
||||||
|
|||||||
BIN
Bindings/python/.DS_Store
vendored
BIN
Bindings/python/.DS_Store
vendored
Binary file not shown.
129
Bindings/python/library.py
Normal file
129
Bindings/python/library.py
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
import ctypes
|
||||||
|
from ctypes import Structure, c_char_p, c_int, cdll
|
||||||
|
from dataclasses import dataclass, astuple
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
from typing import List
|
||||||
|
import subprocess
|
||||||
|
import uuid
|
||||||
|
import dacite
|
||||||
|
import os
|
||||||
|
import sqlalchemy
|
||||||
|
import dataclasses
|
||||||
|
from typing import Union
|
||||||
|
import schedule
|
||||||
|
import threading
|
||||||
|
import requests
|
||||||
|
|
||||||
|
p2prc = ctypes.CDLL("SharedObjects/p2prc.so")
|
||||||
|
|
||||||
|
p2prc.Init("")
|
||||||
|
|
||||||
|
# Start running schedule
|
||||||
|
schedule.run_pending()
|
||||||
|
|
||||||
|
# # Create Sqlite database to track processes
|
||||||
|
# engine=sqlalchemy.create_engine(f'sqlite:///homeserver.db')
|
||||||
|
|
||||||
|
# Global variable
|
||||||
|
# A global variable will be populated on runtime.
|
||||||
|
# It is read from P2PRC directly or from a local
|
||||||
|
# database.
|
||||||
|
|
||||||
|
# Node information
|
||||||
|
# Generated using: https://jsonformatter.org/json-to-python
|
||||||
|
@dataclass
|
||||||
|
class Node:
|
||||||
|
Name: str
|
||||||
|
MachineUsername: str
|
||||||
|
IPV4: str
|
||||||
|
IPV6: str
|
||||||
|
Latency: int
|
||||||
|
Download: int
|
||||||
|
Upload: int
|
||||||
|
ServerPort: str
|
||||||
|
BareMetalSSHPort: str
|
||||||
|
NAT: bool
|
||||||
|
EscapeImplementation: str
|
||||||
|
ProxyServer: bool
|
||||||
|
UnSafeMode: bool
|
||||||
|
PublicKey: str
|
||||||
|
CustomInformation: str
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class IPAddress:
|
||||||
|
ip_address: List[Node]
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# ----------------------------- Helper functions -----------------------------
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def StartServer():
|
||||||
|
# Starting P2PRC as a server mode
|
||||||
|
p2prc.Server()
|
||||||
|
|
||||||
|
# Class to create string to pass as string function
|
||||||
|
# parameter to shared object file
|
||||||
|
class go_string(Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("p", c_char_p),
|
||||||
|
("n", c_int)]
|
||||||
|
|
||||||
|
# Ensuring local port can escape NAT and responds
|
||||||
|
# with the public ip and port no.
|
||||||
|
# If the domain name is specified then the public IP
|
||||||
|
# can be used as an A name entry.
|
||||||
|
def P2PRCMapPort(port="",domainname="",serveraddress=""):
|
||||||
|
port = go_string(c_char_p(port.encode('utf-8')), len(port))
|
||||||
|
domainname = go_string(c_char_p(domainname.encode('utf-8')), len(domainname))
|
||||||
|
serveraddress = go_string(c_char_p(serveraddress.encode('utf-8')), len(serveraddress))
|
||||||
|
|
||||||
|
# Defining the response type of the GoLang function
|
||||||
|
# function
|
||||||
|
p2prc.MapPort.restype = c_char_p
|
||||||
|
# Calling the Go function
|
||||||
|
address = p2prc.MapPort(port,domainname,serveraddress)
|
||||||
|
res = str(address).strip("b'")
|
||||||
|
return res
|
||||||
|
|
||||||
|
# Lists all avaliable nodes in the network
|
||||||
|
def ListNodes():
|
||||||
|
# View IP Table information
|
||||||
|
p2prc.ViewIPTable.restype = c_char_p
|
||||||
|
ipTable = p2prc.ViewIPTable()
|
||||||
|
# View IP Table as
|
||||||
|
ipTableObject = json.loads((str(ipTable).strip("b'")))
|
||||||
|
dat: IPAddress = dacite.from_dict(IPAddress,ipTableObject)
|
||||||
|
return dat
|
||||||
|
|
||||||
|
# Add a root node to P2RRC and overwrites all other nodes.
|
||||||
|
# To be only added before the network started and with
|
||||||
|
# the intention of a fresh protocol.
|
||||||
|
def AddRootNode(ip="", port="") -> bool:
|
||||||
|
ip = go_string(c_char_p(ip.encode('utf-8')), len(ip))
|
||||||
|
port = go_string(c_char_p(port.encode('utf-8')), len(port))
|
||||||
|
|
||||||
|
p2prc.AddRootNode.restype = c_char_p
|
||||||
|
res = p2prc.AddRootNode(ip, port)
|
||||||
|
if str(res).strip("b'") == "Success":
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# python function to pass-through custom
|
||||||
|
# information to interpret which can be
|
||||||
|
# interpreted as a DSL.
|
||||||
|
def AddCustomInformation(message="") -> bool:
|
||||||
|
message = go_string(c_char_p(message.encode('utf-8')), len(message))
|
||||||
|
|
||||||
|
p2prc.CustomInformation.restype = c_char_p
|
||||||
|
status = p2prc.CustomInformation(message)
|
||||||
|
if str(status).strip("b'") == "Success":
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import ctypes
|
|
||||||
|
|
||||||
p2prc = ctypes.CDLL("SharedOBjects/p2prc.so")
|
|
||||||
|
|
||||||
p2prc.Init("")
|
|
||||||
|
|
||||||
def StartServer():
|
|
||||||
# Starting P2PRC as a server mode
|
|
||||||
p2prc.Server()
|
|
||||||
for _ in iter(int, 1):
|
|
||||||
pass
|
|
||||||
4
Bindings/python/requirements.txt
Normal file
4
Bindings/python/requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
dacite
|
||||||
|
schedule
|
||||||
|
sqlalchemy
|
||||||
|
requests
|
||||||
14
Bindings/python/test.py
Normal file
14
Bindings/python/test.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from library import *
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
P2PRCNodes = ListNodes()
|
||||||
|
# Print nodes in the network
|
||||||
|
print(P2PRCNodes)
|
||||||
|
|
||||||
|
# Add custom information to the network
|
||||||
|
if AddCustomInformation("Test"):
|
||||||
|
print("It worked")
|
||||||
|
|
||||||
|
if AddRootNode("0.0.0.0", "8081"):
|
||||||
|
print("It worked for adding root node")
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
* Contributing
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: contributing
|
|
||||||
:END:
|
|
||||||
When contributing to this repository, please first discuss the change
|
|
||||||
you wish to make via issue, email, or any other method with the owners
|
|
||||||
of this repository before making a change.
|
|
||||||
|
|
||||||
Please note we have a code of conduct, please follow it in all your
|
|
||||||
interactions with the project.
|
|
||||||
|
|
||||||
** Pull Request Process
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: pull-request-process
|
|
||||||
:END:
|
|
||||||
1. Ensure any install or build dependencies are removed before the end
|
|
||||||
of the layer when doing a build.
|
|
||||||
2. Update the appropriate docs before stating the changes you did.
|
|
||||||
3. You may merge the Pull Request in once you have the approval of
|
|
||||||
CODEOWNER, or if you do not have permission to do that, you may
|
|
||||||
request the second reviewer to merge it for you.
|
|
||||||
|
|
||||||
** Code of conduct
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: code-of-conduct
|
|
||||||
:END:
|
|
||||||
All projects(including mailing lists) at HWTechClub is required to
|
|
||||||
follow [[https://lunduke.com/pages/codeofconduct/][The Lunduke Code of
|
|
||||||
Conduct]].
|
|
||||||
|
|
||||||
*** The Lunduke Code of Conduct
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: the-lunduke-code-of-conduct
|
|
||||||
:END:
|
|
||||||
|
|
||||||
#+begin_quote
|
|
||||||
**** "Be Excellent to Each Other."
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: be-excellent-to-each-other.
|
|
||||||
:END:
|
|
||||||
#+end_quote
|
|
||||||
|
|
||||||
***** FAQ
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: faq
|
|
||||||
:END:
|
|
||||||
*Q*: Wait. That's it?
|
|
||||||
|
|
||||||
A: Yup.
|
|
||||||
|
|
||||||
*Q*: But... but... it's only 5 words!
|
|
||||||
|
|
||||||
A: It is? Cool!
|
|
||||||
|
|
||||||
*Q*: Isn't that too short to be a viable Code of Conduct?
|
|
||||||
|
|
||||||
A: Nah.
|
|
||||||
|
|
||||||
*Q*: It's too vague! How would you enforce this?!?
|
|
||||||
|
|
||||||
A: By being excellent to each other.
|
|
||||||
|
|
||||||
*Q*: What if someone violates this Code of Conduct?
|
|
||||||
|
|
||||||
A: I trust you to figure it out.
|
|
||||||
|
|
||||||
*Q*: What if someone talks about politics I disagree with?!?!!?
|
|
||||||
|
|
||||||
A: I know a guy who votes for Papa Smurf in every Presidential election.
|
|
||||||
He's a pretty cool dude.
|
|
||||||
|
|
||||||
*Q*: I'm super angry about something! And a person likes the thing
|
|
||||||
making me angry! What do I do?
|
|
||||||
|
|
||||||
A: I dunno. Try /hugs/?
|
|
||||||
|
|
||||||
*Q*: Are virtual hugs (such as /"hugs"/ and animated .GIFs of teddy
|
|
||||||
bears hugging) excellent?
|
|
||||||
|
|
||||||
A: Most excellent.
|
|
||||||
|
|
||||||
*Q*: Huh. Seems so simple!
|
|
||||||
|
|
||||||
A: I know, right?
|
|
||||||
|
|
||||||
*Q*: I like you!
|
|
||||||
|
|
||||||
A: I like you, too!
|
|
||||||
|
|
||||||
/The Lunduke Code of Conduct is free for you to use however you like./
|
|
||||||
|
|
||||||
*Source*: [[https://lunduke.com/pages/codeofconduct/][The Lunduke Code
|
|
||||||
of Conduct]]
|
|
||||||
BIN
Docs/.DS_Store
vendored
BIN
Docs/.DS_Store
vendored
Binary file not shown.
1
Docs/.gitignore
vendored
1
Docs/.gitignore
vendored
@@ -13,7 +13,6 @@
|
|||||||
*.elc
|
*.elc
|
||||||
*.fn
|
*.fn
|
||||||
*.fns
|
*.fns
|
||||||
*.html
|
|
||||||
*.info
|
*.info
|
||||||
*.ky
|
*.ky
|
||||||
*.kys
|
*.kys
|
||||||
|
|||||||
BIN
Docs/Colored-On-Light-Image.png
Normal file
BIN
Docs/Colored-On-Light-Image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 276 KiB |
1517
Docs/index.html
Normal file
1517
Docs/index.html
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,16 +3,20 @@
|
|||||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/search.css"/>
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="https://fniessen.github.io/org-html-themes/src/readtheorg_theme/css/search.css"/>
|
||||||
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="style.css"/>
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="style.css"/>
|
||||||
|
|
||||||
|
#+attr_html: :width 300px
|
||||||
|
[[./Colored-On-Light-Image.png]]
|
||||||
|
|
||||||
|
* Guide through video
|
||||||
|
*** The video below shows the setup and usage of P2PRC.
|
||||||
|
#+attr_html: :class video
|
||||||
|
[[https://www.youtube.com/watch?v=OMwCpedu5cs][https://i3.ytimg.com/vi/OMwCpedu5cs/maxresdefault.jpg]]
|
||||||
|
|
||||||
|
*** Source code: https://github.com/Akilan1999/p2p-rendering-computation
|
||||||
|
|
||||||
* Introduction
|
* Introduction
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: chapter1-introduction
|
:CUSTOM_ID: chapter1-introduction
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
** Abstract
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: abstract
|
|
||||||
:END:
|
|
||||||
This project focuses on creating a framework for running heavy computational tasks that a regular
|
This project focuses on creating a framework for running heavy computational tasks that a regular
|
||||||
computer cannot handle easily. These tasks may include graphically demanding video games, rendering
|
computer cannot handle easily. These tasks may include graphically demanding video games, rendering
|
||||||
3D animations, and performing complex protein folding simulations. The major focus of this project
|
3D animations, and performing complex protein folding simulations. The major focus of this project
|
||||||
@@ -93,7 +97,7 @@ To set up the internal dependencies and build the entire go code into a
|
|||||||
single binary
|
single binary
|
||||||
|
|
||||||
#+begin_example
|
#+begin_example
|
||||||
make install
|
make
|
||||||
#+end_example
|
#+end_example
|
||||||
|
|
||||||
**** For Windows
|
**** For Windows
|
||||||
@@ -116,17 +120,6 @@ export P2PRC=/<PATH>/p2p-rendering-computation
|
|||||||
export PATH=/<PATH>/p2p-rendering-computation:${PATH}
|
export PATH=/<PATH>/p2p-rendering-computation:${PATH}
|
||||||
#+end_example
|
#+end_example
|
||||||
|
|
||||||
*** Set up configuration file
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: set-up-configuration-file
|
|
||||||
:END:
|
|
||||||
#+begin_example
|
|
||||||
make configfile
|
|
||||||
#+end_example
|
|
||||||
|
|
||||||
Open the config file =config.json= and add the IPv6 address if you have
|
|
||||||
one.
|
|
||||||
|
|
||||||
*** Test if binary works
|
*** Test if binary works
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: test-if-binary-works
|
:CUSTOM_ID: test-if-binary-works
|
||||||
@@ -189,6 +182,110 @@ GLOBAL OPTIONS:
|
|||||||
|
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
* Nix Flake
|
||||||
|
|
||||||
|
Nix is a growing ecosystem that allows flexibility on how you develop, build and package software and configurations. It brings all programming languages (and all other tooling) to an equal footing, despite deep design differences. More importantly, integrates all the "packaging" into the context of a "pure" function.
|
||||||
|
|
||||||
|
|
||||||
|
P2PRC aims to become a utility that can be used in various flexible manners and having Nix support is a good alternative to accomplish this goal.
|
||||||
|
|
||||||
|
|
||||||
|
Nix Flake is a format, within the Nix ecosystem, intentionally designed to encourage a standard in packaging distribution. The current packaging assumes that you have "nix flake" installed because it is currently an experimental feature of Nix.
|
||||||
|
|
||||||
|
|
||||||
|
** P2PRC core Go language repo
|
||||||
|
|
||||||
|
In case you want to develop, build or integrate using nix, you just need to run either "nix develop" or "nix run" from the command line locally in a cloned git repository or by running "nix run github:akilan1999/p2p-rendering-computation -- --help"
|
||||||
|
|
||||||
|
|
||||||
|
P2PRC library also is ready to be imported into other nix flakes. To accomplish that please make sure to override the target nixpkgs environment in the following manner;
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [
|
||||||
|
p2prc-flake.overlays.default
|
||||||
|
];
|
||||||
|
};
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
|
||||||
|
This will make the p2prc executable available in the environment of any application you use.
|
||||||
|
|
||||||
|
** P2PRC Haskell library
|
||||||
|
|
||||||
|
*** Nix:
|
||||||
|
The project is structured to provide language bindings to any programming language. The first one being supported in this manner is the Haskell programming language. It provides a bootstrapping script for a new Cabal project with p2prc binary available in the environment and, more relevantly, the Haskell library bindings available in the virtual environment cabal environment.
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
nix run git+https://github.com/akilan1999/p2p-rendering-computation#initHaskellProject -- <PROJECT_NAME>
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
|
||||||
|
This will generate a new haskell project setup to automatically work with the p2prc development and running environment.
|
||||||
|
|
||||||
|
|
||||||
|
Once completed, you should go into the project directory and copy the nix flake template, necessary to define the project's environment.
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
nix flake init -t github:akilan1999/p2p-rendering-computation#haskell
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
The previous command sets up the flake environment and its dependencies. It will look like the following
|
||||||
|
|
||||||
|
#+begin_example
|
||||||
|
{
|
||||||
|
description = "Start of Haskell P2PRC flake";
|
||||||
|
|
||||||
|
inputs =
|
||||||
|
{
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
|
||||||
|
flake-util.url = "github:numtide/flake-utils";
|
||||||
|
|
||||||
|
p2prc-flake.url = "github:akilan1999/p2p-rendering-computation";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { nixpkgs, p2prc-flake, flake-utils, ... }:
|
||||||
|
(flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [
|
||||||
|
p2prc-flake.overlays.default
|
||||||
|
p2prc-flake.overlays.bindings
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
in {
|
||||||
|
|
||||||
|
packages.default = pkgs.haskellPackages.callPackage ./cabal.nix { };
|
||||||
|
|
||||||
|
devShells.default = pkgs.haskellPackages.shellFor {
|
||||||
|
|
||||||
|
packages = p: [
|
||||||
|
(p.callPackage ./cabal.nix { })
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
p2prc-flake.packages.${system}.default
|
||||||
|
ghc
|
||||||
|
cabal2nix
|
||||||
|
cabal-install
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
cabal2nix . > ./cabal.nix
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
The template uses Cabal2Nix which manages the Haskell virtual environment automatically. It applies the system overlays, sets up the shell environment for the project (updating the Cabal2Nix configuration) and packages the main executable.
|
||||||
|
|
||||||
* Using basic commands
|
* Using basic commands
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: using-basic-commands
|
:CUSTOM_ID: using-basic-commands
|
||||||
@@ -351,12 +448,26 @@ p2prc --amd "custom metadata"
|
|||||||
#+end_example
|
#+end_example
|
||||||
|
|
||||||
*** MapPort and link to domain name
|
*** MapPort and link to domain name
|
||||||
|
Allows to expose remote ports from a machine in the P2P network.
|
||||||
#+begin_example
|
#+begin_example
|
||||||
p2prc --mp <port no to map> --dn <domain name to link Mapped port against>
|
p2prc --mp <port no to map> --dn <domain name to link Mapped port against>
|
||||||
#+end_example
|
#+end_example
|
||||||
|
**** MapPort in remote machine
|
||||||
|
This is to ensure ports on remote machines on the P2PRC can be easily opened.
|
||||||
|
#+begin_example
|
||||||
|
p2prc --mp <port no to map> --dn <domain name to link Mapped port against> --ra <remote server address>
|
||||||
|
#+end_example
|
||||||
|
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
*** Add root node
|
||||||
|
Adds a root node to P2RRC and overwrites all other nodes in the ip table.
|
||||||
|
To be only added before the network is started and with
|
||||||
|
the intention of a fresh instance.
|
||||||
|
#+begin_example
|
||||||
|
p2prc --arn --ip <root node ip address> -p <root node port no>
|
||||||
|
#+end_example
|
||||||
|
|
||||||
* P2P Module Implementation
|
* P2P Module Implementation
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: p2p-module-implementation
|
:CUSTOM_ID: p2p-module-implementation
|
||||||
@@ -368,7 +479,7 @@ to determine upload and download speeds. This valuable information enables users
|
|||||||
servers with optimal performance, enhancing their overall network experience.
|
servers with optimal performance, enhancing their overall network experience.
|
||||||
|
|
||||||
#+caption: UML diagram of P2P module
|
#+caption: UML diagram of P2P module
|
||||||
[[file:images/p2pmoduleArch.png]]
|
[[file:./images/p2pmoduleArch.png]
|
||||||
|
|
||||||
The peer to peer implementation was built from scratch. This is because
|
The peer to peer implementation was built from scratch. This is because
|
||||||
other peer to peer libraries were on the implementation of the
|
other peer to peer libraries were on the implementation of the
|
||||||
@@ -628,9 +739,9 @@ func <Function name> (output *C.char) {
|
|||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: current-languages-supported
|
:CUSTOM_ID: current-languages-supported
|
||||||
:END:
|
:END:
|
||||||
- Python
|
*** Python
|
||||||
|
|
||||||
*** Build sample python program
|
**** Build sample python program
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: build-sample-python-program
|
:CUSTOM_ID: build-sample-python-program
|
||||||
:END:
|
:END:
|
||||||
@@ -646,7 +757,7 @@ cd Bindings/python/export/
|
|||||||
# list files
|
# list files
|
||||||
ls
|
ls
|
||||||
# Expected output
|
# Expected output
|
||||||
SharedObjects/ p2prc.py
|
SharedObjects/ library.py requirements.txt
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Above shows a generated folder which consists of a folder called
|
Above shows a generated folder which consists of a folder called
|
||||||
@@ -657,6 +768,28 @@ folder can copied and created as a new git repo for P2PRC extensions
|
|||||||
scripted or used a reference point as proof of concept that P2PRC can be
|
scripted or used a reference point as proof of concept that P2PRC can be
|
||||||
called from other programming languages.
|
called from other programming languages.
|
||||||
|
|
||||||
|
*** Haskell
|
||||||
|
P2PRC officially supports Haskell bindings and will further support
|
||||||
|
project using Haskell to build orchestrators on top of P2PRC.
|
||||||
|
|
||||||
|
**** Local machine without Nix
|
||||||
|
On the local machine we just create a folder as exports which copies the p2prc haskell bindings
|
||||||
|
and the latest build of the p2prc binary. After the binary is copied it runs the --dc in p2prc to setup the
|
||||||
|
basic p2prc configurations. To do the following just do:
|
||||||
|
#+begin_example
|
||||||
|
make haskell
|
||||||
|
#+end_example
|
||||||
|
**** Directory to enter into
|
||||||
|
#+begin_example
|
||||||
|
cd Bindings/Haskell/exports
|
||||||
|
#+end_example
|
||||||
|
**** Run
|
||||||
|
#+begin_example
|
||||||
|
- cabal build
|
||||||
|
- cabal run
|
||||||
|
#+end_example
|
||||||
|
|
||||||
|
[[https://p2prc.akilan.io/haskell][Read more...]]
|
||||||
|
|
||||||
* Config Implementation
|
* Config Implementation
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
@@ -678,18 +811,28 @@ configuration file was generated using JSON format.
|
|||||||
|
|
||||||
#+begin_src json
|
#+begin_src json
|
||||||
{
|
{
|
||||||
"MachineName": "pc-74-120.customer.ask4.lan",
|
"MachineName": "Akilans-MacBook-Pro.local-975261X",
|
||||||
"IPTable": "/Users/akilan/Documents/p2p-rendering-computation/p2p/iptable/ip_table.json",
|
"IPTable": "/Users/akilan/Documents/p2p-rendering-computation/p2p/iptable/ip_table.json",
|
||||||
"DockerContainers": "/Users/akilan/Documents/p2p-rendering-computation/server/docker/containers/",
|
"DockerContainers": "/Users/akilan/Documents/p2p-rendering-computation/server/docker/containers/",
|
||||||
"DefaultDockerFile": "/Users/akilan/Documents/p2p-rendering-computation/server/docker/containers/docker-ubuntu-sshd/",
|
"DefaultDockerFile": "/Users/akilan/Documents/p2p-rendering-computation/server/docker/containers/docker-ubuntu-sshd/",
|
||||||
|
"DockerRunLogs": "/tmp/",
|
||||||
"SpeedTestFile": "/Users/akilan/Documents/p2p-rendering-computation/p2p/50.bin",
|
"SpeedTestFile": "/Users/akilan/Documents/p2p-rendering-computation/p2p/50.bin",
|
||||||
"IPV6Address": "",
|
"IPV6Address": "",
|
||||||
"PluginPath": "/Users/akilan/Documents/p2p-rendering-computation/plugin/deploy",
|
"PluginPath": "/Users/akilan/Documents/p2p-rendering-computation/plugin/deploy",
|
||||||
"TrackContainersPath": "/Users/akilan/Documents/p2p-rendering-computation/client/trackcontainers/trackcontainers.json",
|
"TrackContainersPath": "/Users/akilan/Documents/p2p-rendering-computation/client/trackcontainers/trackcontainers.json",
|
||||||
"ServerPort": "8088",
|
"ServerPort": "8088",
|
||||||
|
"ProxyPort": "",
|
||||||
"GroupTrackContainersPath": "/Users/akilan/Documents/p2p-rendering-computation/client/trackcontainers/grouptrackcontainers.json",
|
"GroupTrackContainersPath": "/Users/akilan/Documents/p2p-rendering-computation/client/trackcontainers/grouptrackcontainers.json",
|
||||||
"FRPServerPort": "True",
|
"FRPServerPort": true,
|
||||||
"BehindNAT": "True",
|
"BehindNAT": true,
|
||||||
|
"IPTableKey": "QH3yQrGRe2X4",
|
||||||
|
"PublicKeyFile": "/Users/akilan/Documents/p2p-rendering-computation/p2prc.publicKey",
|
||||||
|
"PrivateKeyFile": "/Users/akilan/Documents/p2p-rendering-computation/p2prc.privateKey",
|
||||||
|
"PemFile": "/Users/akilan/Documents/p2p-rendering-computation/cert.pem",
|
||||||
|
"KeyFile": "/Users/akilan/Documents/p2p-rendering-computation/key.pem",
|
||||||
|
"BareMetal": false,
|
||||||
|
"UnsafeMode": false,
|
||||||
|
"Test": false,
|
||||||
"CustomConfig": null
|
"CustomConfig": null
|
||||||
}
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
@@ -771,6 +914,127 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#+end_src
|
#+end_src
|
||||||
|
* Simulation
|
||||||
|
The simulation library is a really simple library to locally
|
||||||
|
run serveral instances of P2PRC to test the functionality
|
||||||
|
of sending information through the network and particularly
|
||||||
|
the Node discovery mechanism. There are current 5 commands
|
||||||
|
which can be used as shown below:
|
||||||
|
|
||||||
|
** Command
|
||||||
|
- ***P2PRC instances "number of instances"*** : Starts p2prc processes
|
||||||
|
based on the number of number instances provided. This includes
|
||||||
|
creating temporary folders with independent IPTables.
|
||||||
|
- ***Start all instances "number of instances"***: Starts the P2PRC instances
|
||||||
|
created. This function enters into the instance directory and runs
|
||||||
|
```p2prc -s &``` with a delay for approximately 3 seconds. This allows
|
||||||
|
each independent created node to learn about each other.
|
||||||
|
- ***IP Tables after Started number of instances"***: Prints the IPTable of
|
||||||
|
each independant node.
|
||||||
|
- ***Remove all test files***: Removes all test files created which needed for
|
||||||
|
testing the generated P2PRC instances.
|
||||||
|
- ***Kill all instances***: Kills all the background P2PRC instances created.
|
||||||
|
|
||||||
|
** Sample bash instructions
|
||||||
|
#+begin_src bash
|
||||||
|
# Unset default P2PRC env path
|
||||||
|
unset P2PRC
|
||||||
|
|
||||||
|
# Run with 2 nodes
|
||||||
|
P2PRC_instances 3
|
||||||
|
|
||||||
|
# Start instances
|
||||||
|
Start_all_instances 3
|
||||||
|
|
||||||
|
# List ip tables of nodes started
|
||||||
|
IP_Tables_after_Started 3
|
||||||
|
|
||||||
|
# Remove test files created
|
||||||
|
Remove_all_test_files
|
||||||
|
|
||||||
|
# Kill all instances
|
||||||
|
Kill_all_instances
|
||||||
|
#+end_src
|
||||||
|
Source code: https://github.com/Akilan1999/p2p-rendering-computation/blob/master/Simulation/simulation.sh
|
||||||
|
* Blog posts
|
||||||
|
** Self host within 5 minutes any program
|
||||||
|
|
||||||
|
- Author: [[http://akilan.io/][Akilan Selvacoumar]]
|
||||||
|
- Date: 28-01-2025
|
||||||
|
|
||||||
|
|
||||||
|
- Video tutorial:
|
||||||
|
#+attr_html: :class video
|
||||||
|
[[https://youtu.be/rN4SiVowg5E][https://i3.ytimg.com/vi/rN4SiVowg5E/maxresdefault.jpg]]
|
||||||
|
|
||||||
|
This is a fun expirement for anyone to try to quickly run a server and
|
||||||
|
quickly do a map port and domain name mapping in a single command.
|
||||||
|
|
||||||
|
*** 1. Find a program you want to run
|
||||||
|
Let's try to setup a really easy program (Let's do with Linkwarden
|
||||||
|
with docker compose :) ). This is under the assumption you have docker
|
||||||
|
compose installed on your local machine.
|
||||||
|
|
||||||
|
**** Let's run Linkwarden using docker compose and P2PRC
|
||||||
|
[[https://docs.linkwarden.app/self-hosting/installation][Installation instructions]]:
|
||||||
|
#+BEGIN_SRC
|
||||||
|
mkdir linkwarden && cd linkwarden
|
||||||
|
curl -O https://raw.githubusercontent.com/linkwarden/linkwarden/refs/heads/main/docker-compose.yml
|
||||||
|
curl -L https://raw.githubusercontent.com/linkwarden/linkwarden/refs/heads/main/.env.sample -o ".env"
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
Environment configuration
|
||||||
|
#+BEGIN_SRC
|
||||||
|
vim .env
|
||||||
|
|
||||||
|
# Change values
|
||||||
|
NEXTAUTH_URL=https://<DOMAIN NAME>/api/v1/auth
|
||||||
|
NEXTAUTH_SECRET=VERY_SENSITIVE_SECRET
|
||||||
|
POSTGRES_PASSWORD=CUSTOM_POSTGRES_PASSWORD
|
||||||
|
#+END_SRC
|
||||||
|
Run linkwarden!
|
||||||
|
#+BEGIN_SRC
|
||||||
|
docker compose up
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
If setup correctly linkwarden should
|
||||||
|
be running.
|
||||||
|
Local link: http://localhost:3000
|
||||||
|
|
||||||
|
Time to setup P2PRC
|
||||||
|
[[https://p2prc.akilan.io/Docs/#build-project-and-install-project][Installation Instructions]]
|
||||||
|
|
||||||
|
Run p2prc as a background
|
||||||
|
#+BEGIN_SRC
|
||||||
|
p2prc -s &
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
Run map port and domain mapping
|
||||||
|
#+BEGIN_SRC
|
||||||
|
p2prc --mp 3000 --dn <DOMAIN NAME>
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
Sample response
|
||||||
|
#+BEGIN_SRC
|
||||||
|
{
|
||||||
|
"IPAddress": "217.76.63.222",
|
||||||
|
"PortNo": "61582",
|
||||||
|
"EntireAddress": "217.76.63.222:61582"
|
||||||
|
}
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
Add DNS entry
|
||||||
|
#+BEGIN_SRC
|
||||||
|
A entry 217.76.63.222
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
Your done now just head to the DOMAIN NAME you added.
|
||||||
|
ex: https://linkwarden.akilan.io
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1
Docs/kill-docs.sh
Normal file
1
Docs/kill-docs.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
kill -9 $(lsof -t -i:8083)
|
||||||
1
Docs/run-docs.sh
Normal file
1
Docs/run-docs.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
go run staticServer.go &
|
||||||
28
Docs/staticServer.go
Normal file
28
Docs/staticServer.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
Serve is a very simple static file server in go
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
-p="8100": port to serve on
|
||||||
|
-d=".": the directory of static files to host
|
||||||
|
|
||||||
|
Navigating to http://localhost:8100 will display the index.html or directory
|
||||||
|
listing file.
|
||||||
|
*/
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
port := flag.String("p", "8083", "port to serve on")
|
||||||
|
directory := flag.String("d", ".", "the directory of static file to host")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
http.Handle("/", http.FileServer(http.Dir(*directory)))
|
||||||
|
|
||||||
|
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
|
||||||
|
log.Fatal(http.ListenAndServe(":"+*port, nil))
|
||||||
|
}
|
||||||
@@ -23,3 +23,7 @@ h4,h5,h6{
|
|||||||
color: #b96c29;
|
color: #b96c29;
|
||||||
font-weight:300;
|
font-weight:300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.video {
|
||||||
|
box-shadow: 10px 10px 25px rgba(0, 0, 0, 0.3);
|
||||||
|
}
|
||||||
|
|||||||
3
Makefile
3
Makefile
@@ -14,6 +14,9 @@ sharedObjects:
|
|||||||
python:
|
python:
|
||||||
sh build-python-package.sh
|
sh build-python-package.sh
|
||||||
|
|
||||||
|
haskell:
|
||||||
|
sh build-haskell.sh
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
go clean -modcache
|
go clean -modcache
|
||||||
rm -fr .go-build vendor result*
|
rm -fr .go-build vendor result*
|
||||||
|
|||||||
24
README.md
24
README.md
@@ -1,5 +1,5 @@
|
|||||||
> [!TIP]
|
> [!TIP]
|
||||||
> Haskell bindings supported!: [Bindings documentaton](https://p2prc.akilan.io/Docs/haskell/P2PRC.html)
|
> Haskell bindings supported!: [Bindings documentaton](https://p2prc.akilan.io/haskell/P2PRC.html)
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> Fixing documentation to latest changes. If you have any questions setting up P2PRC either [create an issue](https://github.com/Akilan1999/p2p-rendering-computation/issues/new/choose) or send me an email (me AT akilan dot io).
|
> Fixing documentation to latest changes. If you have any questions setting up P2PRC either [create an issue](https://github.com/Akilan1999/p2p-rendering-computation/issues/new/choose) or send me an email (me AT akilan dot io).
|
||||||
@@ -47,11 +47,27 @@ Networking details are completely abstracted, enabling users to focus on develop
|
|||||||
### Flexible Task Distribution
|
### Flexible Task Distribution
|
||||||
Users acting as clients retain full control over how tasks are batched and assigned to nodes, creating endless possibilities for optimising performance based on specific use cases.
|
Users acting as clients retain full control over how tasks are batched and assigned to nodes, creating endless possibilities for optimising performance based on specific use cases.
|
||||||
|
|
||||||
|
## Setup with Nix
|
||||||
|
- Ensure you have the nix package manager installed.
|
||||||
|
- Add the following to your .bashrc file.
|
||||||
|
```bash
|
||||||
|
alias p2prc='env P2PRC=<path you want the configs to exist in> nix run github:akilan1999/p2p-rendering-computation --'
|
||||||
|
```
|
||||||
|
- Check if it's successful
|
||||||
|
```bash
|
||||||
|
p2prc -h
|
||||||
|
```
|
||||||
|
Read more on command usage: https://p2prc.akilan.io/#using-basic-commands
|
||||||
|
|
||||||
## Latest tutorial
|
## Latest tutorial
|
||||||
[](https://www.youtube.com/watch?v=OMwCpedu5cs")
|
[](https://www.youtube.com/watch?v=OMwCpedu5cs")
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
### We have documented to our best effort the basics of p2prc: [Link](https://p2prc.akilan.io/)
|
||||||
|
|
||||||
<!-- ## Table of contents in the current README -->
|
<!-- ## Table of contents in the current README -->
|
||||||
<!-- 1. [Introduction](#Introduction)
|
<!-- 1. [Introduction](#Introduction)
|
||||||
2. [Installation](#extend-your-application-with-p2prc)
|
2. [Installation](#extend-your-application-with-p2prc)
|
||||||
@@ -98,7 +114,7 @@ This project aims to create a peer to peer (p2p) network, where a user can use t
|
|||||||
|
|
||||||
<!-- <br> -->
|
<!-- <br> -->
|
||||||
|
|
||||||
## Extend your application with P2PRC
|
<!-- ## Extend your application with P2PRC
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@@ -127,7 +143,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
``` -->
|
||||||
|
|
||||||
<!-- ### Export once this is added export P2PRC as environment paths
|
<!-- ### Export once this is added export P2PRC as environment paths
|
||||||
```
|
```
|
||||||
@@ -190,4 +206,4 @@ The programming language used for this project was Golang. The reason Go lang wa
|
|||||||
As we are working on the open source project p2prc (i.e p2p network designed for computation).If you are interested in participating as a contributor
|
As we are working on the open source project p2prc (i.e p2p network designed for computation).If you are interested in participating as a contributor
|
||||||
or just providing feedback on new features to build or even just curious about new features added to the project do file an Issue or send an email to me@akilan.io.
|
or just providing feedback on new features to build or even just curious about new features added to the project do file an Issue or send an email to me@akilan.io.
|
||||||
|
|
||||||
[](https://github.com/Gaurav-Gosain)
|
<!-- [](https://github.com/Gaurav-Gosain) -->
|
||||||
|
|||||||
252
README.md.org
252
README.md.org
@@ -1,252 +0,0 @@
|
|||||||
#+begin_quote
|
|
||||||
[!TIP] Haskell bindings supported!:
|
|
||||||
[[https://p2prc.akilan.io/Docs/haskell/P2PRC.html][Bindings
|
|
||||||
documentaton]]
|
|
||||||
|
|
||||||
#+end_quote
|
|
||||||
|
|
||||||
#+begin_quote
|
|
||||||
[!NOTE] Fixing documentation to latest changes. If you have any
|
|
||||||
questions setting up P2PRC either
|
|
||||||
[[https://github.com/Akilan1999/p2p-rendering-computation/issues/new/choose][create
|
|
||||||
an issue]] or send me an email (me AT akilan dot io). Currently HEAD is
|
|
||||||
always intended to stay on a working state. It is recommended to always
|
|
||||||
use HEAD in your go.mod file.
|
|
||||||
|
|
||||||
#+end_quote
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<h1 align="center">
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
</h1>
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!-- seperator -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!-- The main aim of this project was to create a custom peer to peer network. The user acting as the
|
|
||||||
client has total flexibility on how to batch the tasks and the user acting as the server has complete
|
|
||||||
flexibility on tracking the container's usages and killing the containers at any point of time. -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!-- The objective is to allow users to self host servers in easier
|
|
||||||
and abstracted manner. The main aim of this project was to create a custom peer to peer network for distributed computing. The user acting as the client has total flexibility on how to batch the tasks to any of nodes in networks. These nodes can anywhere from personal
|
|
||||||
computers behind NAT to custom hardware for running custom workload. The aim to provide
|
|
||||||
access to Heterogeneous set of nodes as a singular global list and abstract away the networking details giving the user focus on designing a custom orchestrator based
|
|
||||||
on the requirements of a user. -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
This project aims to simplify self-hosting servers and streamline the
|
|
||||||
creation of distributed systems. The primary focus is to enable users to
|
|
||||||
design custom peer-to-peer networks for distributed computing, offering
|
|
||||||
full flexibility and control while abstracting away the complexities of
|
|
||||||
networking.
|
|
||||||
|
|
||||||
** Key Features
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: key-features
|
|
||||||
:END:
|
|
||||||
Simplified Self-Hosting Empower users to easily host nodes, whether on
|
|
||||||
personal computers behind NAT, custom hardware, or cloud-based
|
|
||||||
infrastructure.
|
|
||||||
|
|
||||||
*** Custom Peer-to-Peer Networks
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: custom-peer-to-peer-networks
|
|
||||||
:END:
|
|
||||||
Build a decentralised network tailored to user requirements, enabling
|
|
||||||
distributed task execution without the need for in-depth networking
|
|
||||||
knowledge.
|
|
||||||
|
|
||||||
*** Heterogeneous Node Support
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: heterogeneous-node-support
|
|
||||||
:END:
|
|
||||||
Harness a diverse array of nodes from personal computers to specialised
|
|
||||||
hardware---seamlessly integrated into a global node list.
|
|
||||||
|
|
||||||
*** Abstracted Networking Layer
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: abstracted-networking-layer
|
|
||||||
:END:
|
|
||||||
Networking details are completely abstracted, enabling users to focus on
|
|
||||||
developing bespoke task orchestration systems. No more manual
|
|
||||||
configuration of IPs, ports, or connection logic.
|
|
||||||
|
|
||||||
*** Flexible Task Distribution
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: flexible-task-distribution
|
|
||||||
:END:
|
|
||||||
Users acting as clients retain full control over how tasks are batched
|
|
||||||
and assigned to nodes, creating endless possibilities for optimising
|
|
||||||
performance based on specific use cases.
|
|
||||||
|
|
||||||
** Latest tutorial
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: latest-tutorial
|
|
||||||
:END:
|
|
||||||
[[https://www.youtube.com/watch?v=OMwCpedu5cs%22][[[https://i.ytimg.com/vi/OMwCpedu5cs/hqdefault.jpg]]]]
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!-- ## Table of contents in the current README -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!-- 1. [Introduction](#Introduction)
|
|
||||||
2. [Installation](#extend-your-application-with-p2prc)
|
|
||||||
3. [Design Architecture](#Design-Architecture)
|
|
||||||
4. [Implementation](#Implementation)
|
|
||||||
5. [Find out more](#Find-out-more) -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!-- # Table of contents in the Docs folder
|
|
||||||
1. [Introduction](Docs/Introduction.md)
|
|
||||||
2. [Installation](Docs/Installation.md)
|
|
||||||
3. [Abstractions](Docs/Abstractions.md)
|
|
||||||
3. [Design Architecture](DesignArchtectureIntro.md)
|
|
||||||
1. [Client Module](ClientArchitecture.md)
|
|
||||||
2. [P2P Module](P2PArchitecture.md)
|
|
||||||
3. [Server Module](ServerArchitecture.md)
|
|
||||||
4. [Implementation](Docs/Implementation.md)
|
|
||||||
1. [Client Module](Docs/ClientImplementation.md)
|
|
||||||
2. [P2P Module](Docs/P2PImplementation.md)
|
|
||||||
3. [Server Module](Docs/ServerImplementation.md)
|
|
||||||
4. [Config Module](Docs/ConfigImplementation.md)
|
|
||||||
5. [Cli Module](Docs/CliImplementation.md)
|
|
||||||
6. [Plugin Module](Docs/PluginImplementation.md)
|
|
||||||
7. [Language bindings](Docs/Bindings.md)
|
|
||||||
8. [Domain name mappings](Docs/Bindings.md)
|
|
||||||
5. Language bindings
|
|
||||||
1. [Haskell](Docs/haskell/)
|
|
||||||
5. [Problems](https://github.com/Akilan1999/p2p-rendering-computation/issues) -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!--
|
|
||||||
## Introduction
|
|
||||||
This project aims to create a peer to peer (p2p) network, where a user can use the p2p network to act as a client (i.e sending tasks) or the server (i.e executing the tasks). A prototype application will be developed, which comes bundled with a p2p module and possible to execute docker containers or virtual environments across selected nodes.
|
|
||||||
|
|
||||||
### Objectives
|
|
||||||
- Background review on peer to peer network, virtual environments, decentralized rendering tools and tools to batch any sort of tasks.
|
|
||||||
- Creating p2p network
|
|
||||||
- Server to create a containerised environment
|
|
||||||
- The client node to run tasks on Server containerised node -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!-- [Read more on the introduction](Docs/Introduction.md) -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!-- <br> -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
** Extend your application with P2PRC
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: extend-your-application-with-p2prc
|
|
||||||
:END:
|
|
||||||
#+begin_src go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/abstractions"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
_, err := abstractions.Init(nil)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// start p2prc
|
|
||||||
_, err = abstractions.Start()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run server till termination
|
|
||||||
for {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
#+begin_html
|
|
||||||
<!-- ### Export once this is added export P2PRC as environment paths
|
|
||||||
```
|
|
||||||
export P2PRC=<PROJECT PATH>
|
|
||||||
export PATH=<PROJECT PATH>:${PATH}
|
|
||||||
```
|
|
||||||
[Read more](Docs/Abstractions.md) ...
|
|
||||||
|
|
||||||
## Installation from source
|
|
||||||
1. Ensure the Go compiler is installed
|
|
||||||
```
|
|
||||||
go version
|
|
||||||
```
|
|
||||||
3. Ensure docker is installed (Should run without sudo)
|
|
||||||
```
|
|
||||||
docker ps
|
|
||||||
```
|
|
||||||
3. Clone this repository
|
|
||||||
```
|
|
||||||
git clone https://github.com/Akilan1999/p2p-rendering-computation
|
|
||||||
```
|
|
||||||
4. Install and build the project
|
|
||||||
```
|
|
||||||
make install
|
|
||||||
```
|
|
||||||
- If you look closely you will get outputs such as:
|
|
||||||
```
|
|
||||||
// Add them to your .bashrc file
|
|
||||||
export P2PRC=/<path>/p2p-rendering-computation
|
|
||||||
export PATH=/<path>/p2p-rendering-computation:${PATH}
|
|
||||||
```
|
|
||||||
|
|
||||||
5. Test if it works
|
|
||||||
```
|
|
||||||
p2prc -h
|
|
||||||
```
|
|
||||||
or
|
|
||||||
```
|
|
||||||
./p2prc -h
|
|
||||||
```
|
|
||||||
[Read more on the installation and usage](Docs/Installation.md)
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
## Design Architecture
|
|
||||||
The design architecture was inspired and based on the linux kernel design. The project is segmented into various modules. Each module is responsible for certain tasks in the project. The modules are highly dependent on each other hence the entire codebase can be considered as a huge monolithic chuck which acts as its own library
|
|
||||||
|
|
||||||
[Read more on the Design Architecture](Docs/DesignArchtectureIntro.md)
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
## Implementation
|
|
||||||
The programming language used for this project was Golang. The reason Go lang was chosen was because it is a compiled language. The entire codebase is just a single binary file. When distributing to other linux distributing the only requirement would be the binary file to run the code. It is easy to write independant modules and be monolithic at the sametime using Go. Using Go.mod makes it very easy to handle external libraries and modularise code. The go.mod name for the project is git.sr.ht/~akilan1999/p2p-rendering-computation.
|
|
||||||
|
|
||||||
[Read more on the Implementation](Docs/Implementation.md)
|
|
||||||
|
|
||||||
<br> -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
** Find out more
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: find-out-more
|
|
||||||
:END:
|
|
||||||
As we are working on the open source project p2prc (i.e p2p network
|
|
||||||
designed for computation).If you are interested in participating as a
|
|
||||||
contributor or just providing feedback on new features to build or even
|
|
||||||
just curious about new features added to the project do file an Issue or
|
|
||||||
send an email to me@akilan.io.
|
|
||||||
|
|
||||||
[[https://github.com/Gaurav-Gosain][[[https://api.star-history.com/svg?repos=Akilan1999/p2p-rendering-computation&type=Date]]]]
|
|
||||||
132
Simulation/simulation.sh
Normal file
132
Simulation/simulation.sh
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
# Unset P2PRC
|
||||||
|
unset P2PRC
|
||||||
|
|
||||||
|
# Create P2PRC instances
|
||||||
|
# Parameters:
|
||||||
|
# 1. Number of nodes
|
||||||
|
P2PRC_instances() {
|
||||||
|
local rootPort=""
|
||||||
|
for (( counter=0; counter<$1; counter++ )); do
|
||||||
|
mkdir test-$counter/
|
||||||
|
cd test-$counter/
|
||||||
|
|
||||||
|
# Generate a new random port
|
||||||
|
NEW_PORT=$(shuf -i 2000-65000 -n 1)
|
||||||
|
|
||||||
|
# Initialize node
|
||||||
|
p2prc --dc
|
||||||
|
|
||||||
|
# Save rootPort from the first node
|
||||||
|
if [[ $counter -eq 0 ]]; then
|
||||||
|
rootPort=$NEW_PORT
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Root port: $rootPort"
|
||||||
|
echo "This node's port: $NEW_PORT"
|
||||||
|
|
||||||
|
# Set root port
|
||||||
|
p2prc --arn --ip 0.0.0.0 -p "$rootPort"
|
||||||
|
|
||||||
|
# add current node
|
||||||
|
p2prc --as 0.0.0.0 -p "$NEW_PORT"
|
||||||
|
|
||||||
|
# Replace the ServerPort in config
|
||||||
|
# test-$counter
|
||||||
|
sed -i.bak "s/\"ServerPort\": \"[0-9]*\"/\"ServerPort\": \"$NEW_PORT\"/" "./config.json"
|
||||||
|
sed -i.bak "s/\"Test\": false/\"Test\": true/" "./config.json"
|
||||||
|
sed -i.bak "s/\"BehindNAT\": true/\"BehindNAT\": false/" "./config.json"
|
||||||
|
# sed -i.bak "s/\"MachineName\": "Akilans-MacBook-Pro.local-J2UbbkF"/\"MachineName\": \"test-$counter\"/" "./config.json"
|
||||||
|
|
||||||
|
cat config.json
|
||||||
|
|
||||||
|
# List services
|
||||||
|
p2prc --ls
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
|
||||||
|
# remove all instances after testing (optional — might want to comment this during testing)
|
||||||
|
# rm -rf test-*
|
||||||
|
}
|
||||||
|
|
||||||
|
# Arrays of process IDs
|
||||||
|
pids=()
|
||||||
|
|
||||||
|
# Calls all the P2PRC instances created for testing
|
||||||
|
Start_all_instances() {
|
||||||
|
for (( counter=0; counter<$1; counter++ )); do
|
||||||
|
cd test-$counter/
|
||||||
|
# Start P2PRC as background process
|
||||||
|
p2prc -s &
|
||||||
|
pids+=($!)
|
||||||
|
sleep 3
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Kills all P2PRC instances
|
||||||
|
Kill_all_instances() {
|
||||||
|
for pid in "${pids[@]}"; do
|
||||||
|
kill "$pid"
|
||||||
|
echo "Killed process $pid"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Removes all test files created
|
||||||
|
Remove_all_test_files() {
|
||||||
|
rm -rf test-*
|
||||||
|
}
|
||||||
|
|
||||||
|
# List ip tables of all nodes started
|
||||||
|
IP_Tables_after_Started() {
|
||||||
|
for (( counter=0; counter<$1; counter++ )); do
|
||||||
|
cd test-$counter/
|
||||||
|
p2prc --ls
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
Update_All_IP_Tables() {
|
||||||
|
for (( counter=0; counter<$1; counter++ )); do
|
||||||
|
cd test-$counter/
|
||||||
|
p2prc --us
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Test function for the root to custom information
|
||||||
|
# through the network
|
||||||
|
Send_Information() {
|
||||||
|
ls
|
||||||
|
cd test-2/
|
||||||
|
p2prc --amd "test message"
|
||||||
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------- Work flow test ---------------
|
||||||
|
|
||||||
|
# Unset default P2PRC env path
|
||||||
|
unset P2PRC
|
||||||
|
|
||||||
|
# Run with 2 nodes
|
||||||
|
P2PRC_instances 3
|
||||||
|
|
||||||
|
## Start instances
|
||||||
|
Start_all_instances 3
|
||||||
|
|
||||||
|
|
||||||
|
# Send test information from node 1
|
||||||
|
sleep 10
|
||||||
|
Send_Information
|
||||||
|
|
||||||
|
sleep 10
|
||||||
|
## List ip tables of nodes started
|
||||||
|
IP_Tables_after_Started 3
|
||||||
|
#
|
||||||
|
## Remove test files created
|
||||||
|
Remove_all_test_files
|
||||||
|
|
||||||
|
## Kill all instances
|
||||||
|
Kill_all_instances
|
||||||
|
|
||||||
@@ -1,88 +1,108 @@
|
|||||||
package abstractions
|
package abstractions
|
||||||
|
|
||||||
import "C"
|
|
||||||
import (
|
import (
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/client"
|
"github.com/Akilan1999/p2p-rendering-computation/client"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
||||||
Config "github.com/Akilan1999/p2p-rendering-computation/config"
|
Config "github.com/Akilan1999/p2p-rendering-computation/config"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/server"
|
"github.com/Akilan1999/p2p-rendering-computation/server"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/server/docker"
|
"github.com/Akilan1999/p2p-rendering-computation/server/docker"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Init Initialises p2prc
|
// Init Initialises p2prc
|
||||||
func Init(customConfig interface{}) (config *Config.Config, err error) {
|
func Init(customConfig interface{}) (config *Config.Config, err error) {
|
||||||
|
|
||||||
// Get config file path
|
// Get config file path
|
||||||
// Checks P2PRC path initially
|
// Checks P2PRC path initially
|
||||||
// - Get PATH if environment varaible
|
// - Get PATH if environment varaible
|
||||||
path, err := Config.GetPathP2PRC("P2PRC")
|
path, err := Config.GetPathP2PRC("P2PRC")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// check if the config file exists
|
// check if the config file exists
|
||||||
if _, err = os.Stat(path + "config.json"); err != nil {
|
if _, err = os.Stat(path + "config.json"); err != nil {
|
||||||
// Initialize with base p2prc config files
|
// Initialize with base p2prc config files
|
||||||
// set the config file with default paths
|
// set the config file with default paths
|
||||||
config, err = generate.SetDefaults("P2PRC", false, customConfig, false)
|
config, err = generate.SetDefaults("P2PRC", false, customConfig, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If the configs are available then use them over generating new ones.
|
// If the configs are available then use them over generating new ones.
|
||||||
config, err = Config.ConfigInit(nil, nil)
|
config, err = Config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start p2prc in a server mode
|
// Start p2prc in a server mode
|
||||||
func Start() (*gin.Engine, error) {
|
func Start() (*gin.Engine, error) {
|
||||||
engine, err := server.Server()
|
engine, err := server.Server()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return engine, nil
|
return engine, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MapPort Creates a reverse proxy connection and maps the appropriate port
|
// MapPort Creates a reverse proxy connection and maps the appropriate port
|
||||||
func MapPort(port string, domainName string, serverAddress string) (entireAddress string, mapPort string, err error) {
|
func MapPort(port string, domainName string, serverAddress string) (response *client.ResponseMAPPort, err error) {
|
||||||
entireAddress, mapPort, err = server.MapPort(port, domainName, serverAddress)
|
response, err = client.MAPPort(port, domainName, serverAddress)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartContainer Starts docker container on the remote machine
|
// StartContainer Starts docker container on the remote machine
|
||||||
func StartContainer(IP string) (container *docker.DockerVM, err error) {
|
func StartContainer(IP string) (container *docker.DockerVM, err error) {
|
||||||
container, err = client.StartContainer(IP, 0, false, "", "")
|
container, err = client.StartContainer(IP, 0, false, "", "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveContainer Removes docker container based on the IP address and ID
|
// RemoveContainer Removes docker container based on the IP address and ID
|
||||||
// provided
|
// provided
|
||||||
func RemoveContainer(IP string, ID string) error {
|
func RemoveContainer(IP string, ID string) error {
|
||||||
return client.RemoveContianer(IP, ID)
|
return client.RemoveContianer(IP, ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSpecs Get spec information about the remote server
|
// GetSpecs Get spec information about the remote server
|
||||||
func GetSpecs(IP string) (specs *server.SysInfo, err error) {
|
func GetSpecs(IP string) (specs *server.SysInfo, err error) {
|
||||||
specs, err = client.GetSpecs(IP)
|
specs, err = client.GetSpecs(IP)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ViewIPTable View information of nodes in the network
|
// ViewIPTable View information of nodes in the network
|
||||||
func ViewIPTable() (table *p2p.IpAddresses, err error) {
|
func ViewIPTable() (table *p2p.IpAddresses, err error) {
|
||||||
table, err = p2p.ReadIpTable()
|
table, err = p2p.ReadIpTable()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateIPTable Force updates IP tables based on new
|
// UpdateIPTable Force updates IP tables based on new
|
||||||
// new nodes discovered in the network
|
// new nodes discovered in the network
|
||||||
func UpdateIPTable() (err error) {
|
func UpdateIPTable() (err error) {
|
||||||
return clientIPTable.UpdateIpTableListClient()
|
return clientIPTable.UpdateIpTableListClient()
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCustomInformation allows to pass custom information
|
||||||
|
// through the network to which can be listened on
|
||||||
|
// all peers in the network to execute a task.
|
||||||
|
func AddCustomInformation(information string) error {
|
||||||
|
return clientIPTable.AddCustomInformationToIPTable(information)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddRootNode Adds root node to the network by using defaults except for
|
||||||
|
// ip address and port no. Supports only IPV4 as of now.
|
||||||
|
func AddRootNode(rootIP string, portNo string) error {
|
||||||
|
var rootNode []p2p.IpAddress
|
||||||
|
|
||||||
|
rootNode = append(rootNode, p2p.IpAddress{
|
||||||
|
Name: "",
|
||||||
|
Ipv4: rootIP,
|
||||||
|
ServerPort: portNo,
|
||||||
|
NAT: false,
|
||||||
|
})
|
||||||
|
return generate.GenerateIPTableFile(rootNode)
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
artwork/.DS_Store
vendored
BIN
artwork/.DS_Store
vendored
Binary file not shown.
BIN
artwork/p2prc-logos/.DS_Store
vendored
BIN
artwork/p2prc-logos/.DS_Store
vendored
Binary file not shown.
BIN
artwork/p2prc-logos/P2PRCHaskell.png
Normal file
BIN
artwork/p2prc-logos/P2PRCHaskell.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 922 KiB |
31
build-haskell.sh
Normal file
31
build-haskell.sh
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# This bash script consists of the manaul build script of haskell
|
||||||
|
go build .
|
||||||
|
|
||||||
|
# Unset p2prc path
|
||||||
|
unset p2prc
|
||||||
|
|
||||||
|
# Enter the haskell project
|
||||||
|
cd Bindings/haskell
|
||||||
|
# Remove exsisting export build
|
||||||
|
rm -rf exports
|
||||||
|
# Create exports directory
|
||||||
|
mkdir exports
|
||||||
|
# Copy current haskell project into the folder
|
||||||
|
cp -rf . exports/
|
||||||
|
# Copy p2prc binary inside haskell folder
|
||||||
|
cp ../../p2p-rendering-computation exports/
|
||||||
|
|
||||||
|
cd exports
|
||||||
|
# remove exports directory copied inside exports
|
||||||
|
rm -rf exports/
|
||||||
|
|
||||||
|
# Set p2prc variable
|
||||||
|
echo export P2PRC=$PWD
|
||||||
|
|
||||||
|
export P2PRC=$PWD
|
||||||
|
|
||||||
|
./p2p-rendering-computation --dc
|
||||||
|
|
||||||
|
echo "Run the following commands in the directory: ${PWD}"
|
||||||
|
echo "To build: cabal build"
|
||||||
|
echo "To run sample program: cabal run"
|
||||||
@@ -6,12 +6,19 @@ mkdir Bindings/python/export
|
|||||||
# Creating SharedObjects directory for python
|
# Creating SharedObjects directory for python
|
||||||
mkdir Bindings/python/export/SharedObjects
|
mkdir Bindings/python/export/SharedObjects
|
||||||
|
|
||||||
|
# Builds p2prc.h and p2prc.so file
|
||||||
|
# as apart of Go FFI to interacted
|
||||||
|
# with later on.
|
||||||
sh build-bindings.sh
|
sh build-bindings.sh
|
||||||
|
|
||||||
|
# Copy the shared object files as well to ensure
|
||||||
|
# that python can interact with the latest snapshot
|
||||||
|
# of P2PRC
|
||||||
cp Bindings/p2prc.h Bindings/python/export/SharedObjects/
|
cp Bindings/p2prc.h Bindings/python/export/SharedObjects/
|
||||||
cp Bindings/p2prc.so Bindings/python/export/SharedObjects/
|
cp Bindings/p2prc.so Bindings/python/export/SharedObjects/
|
||||||
|
|
||||||
cp Bindings/python/p2prc.py Bindings/python/export/
|
# Copy python library and tests as export as well
|
||||||
|
cp Bindings/python/* Bindings/python/export/
|
||||||
|
|
||||||
echo "Output is in the Directory Bindings/python/export/"
|
echo "Output is in the Directory Bindings/python/export/"
|
||||||
|
|
||||||
|
|||||||
@@ -3,21 +3,30 @@ package client
|
|||||||
import (
|
import (
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResponseMAPPort struct {
|
type ResponseMAPPort struct {
|
||||||
IPAddress string
|
IPAddress string
|
||||||
|
PortNo string
|
||||||
|
EntireAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
func MAPPort(port string, domainName string) (*ResponseMAPPort, error) {
|
func MAPPort(port string, domainName string, ServerAddress string) (*ResponseMAPPort, error) {
|
||||||
Config, err := config.ConfigInit(nil, nil)
|
Config, err := config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
URL := "http://0.0.0.0:" + Config.ServerPort
|
||||||
|
|
||||||
|
if ServerAddress != "" {
|
||||||
|
URL = "http://" + ServerAddress
|
||||||
|
}
|
||||||
|
|
||||||
//if version == "version 6" {
|
//if version == "version 6" {
|
||||||
URL := "http://0.0.0.0:" + Config.ServerPort + "/MAPPort?port=" + port + "&domain_name=" + domainName
|
URL = URL + "/MAPPort?port=" + port + "&domain_name=" + domainName
|
||||||
//} else {
|
//} else {
|
||||||
// URL = "http://" + IP + ":" + serverPort + "/server_info"
|
// URL = "http://" + IP + ":" + serverPort + "/server_info"
|
||||||
//}
|
//}
|
||||||
@@ -32,8 +41,15 @@ func MAPPort(port string, domainName string) (*ResponseMAPPort, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host, Exposedport, err := net.SplitHostPort(string(byteValue))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var response ResponseMAPPort
|
var response ResponseMAPPort
|
||||||
response.IPAddress = string(byteValue)
|
response.IPAddress = host
|
||||||
|
response.PortNo = Exposedport
|
||||||
|
response.EntireAddress = string(byteValue)
|
||||||
|
|
||||||
return &response, nil
|
return &response, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,40 @@
|
|||||||
package clientIPTable
|
package clientIPTable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddCustomInformationToIPTable(text string) error {
|
func AddCustomInformationToIPTable(text string) error {
|
||||||
// Get config information
|
// Get config information
|
||||||
Config, err := config.ConfigInit(nil, nil)
|
Config, err := config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get IPTable information
|
// Get IPTable information
|
||||||
table, err := p2p.ReadIpTable()
|
table, err := p2p.ReadIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
|
|
||||||
for i, _ := range table.IpAddress {
|
for i, _ := range table.IpAddress {
|
||||||
if table.IpAddress[i].Name == Config.MachineName {
|
if table.IpAddress[i].Name == Config.MachineName {
|
||||||
table.IpAddress[i].CustomInformation = text
|
table.IpAddress[i].CustomInformation = text
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if found {
|
if found {
|
||||||
table.WriteIpTable()
|
table.WriteIpTable()
|
||||||
// update IPTable after modified entry
|
// update IPTable after modified entry
|
||||||
go UpdateIpTableListClient()
|
UpdateIpTableListClient()
|
||||||
} else {
|
} else {
|
||||||
return errors.New("start server with p2prc -s as the server is currently not running")
|
return errors.New("start server with p2prc -s as the server is currently not running")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package clientIPTable
|
package clientIPTable
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
@@ -18,146 +18,147 @@ var mu sync.Mutex
|
|||||||
// UpdateIpTable Does the following to update it's IP table
|
// UpdateIpTable Does the following to update it's IP table
|
||||||
func UpdateIpTable(IpAddress string, serverPort string, wg *sync.WaitGroup) error {
|
func UpdateIpTable(IpAddress string, serverPort string, wg *sync.WaitGroup) error {
|
||||||
|
|
||||||
config, err := config.ConfigInit(nil, nil)
|
config, err := config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
|
|
||||||
var resp []byte
|
var resp []byte
|
||||||
|
|
||||||
version := p2p.Ip4or6(IpAddress)
|
version := p2p.Ip4or6(IpAddress)
|
||||||
if version == "version 6" {
|
if version == "version 6" {
|
||||||
resp, err = UploadMultipartFile(client, "http://["+IpAddress+"]:"+serverPort+"/IpTable", "json", config.IPTable)
|
resp, err = UploadMultipartFile(client, "http://["+IpAddress+"]:"+serverPort+"/IpTable", "json", config.IPTable)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resp, err = UploadMultipartFile(client, "http://"+IpAddress+":"+serverPort+"/IpTable", "json", config.IPTable)
|
resp, err = UploadMultipartFile(client, "http://"+IpAddress+":"+serverPort+"/IpTable", "json", config.IPTable)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//resp, err := SendPostRequest("http://"+IpAddress+":8088/IpTable",
|
//resp, err := SendPostRequest("http://"+IpAddress+":8088/IpTable",
|
||||||
// config.IPTable,
|
// config.IPTable,
|
||||||
// "json")
|
// "json")
|
||||||
//
|
//
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return err
|
// return err
|
||||||
//}
|
//}
|
||||||
|
|
||||||
var ipStruct p2p.IpAddresses
|
var ipStruct p2p.IpAddresses
|
||||||
json.Unmarshal(resp, &ipStruct)
|
json.Unmarshal(resp, &ipStruct)
|
||||||
|
|
||||||
// Updates IP table based on information provided
|
// Updates IP table based on information provided
|
||||||
// by the server
|
// by the server
|
||||||
if len(ipStruct.IpAddress) > 0 {
|
if len(ipStruct.IpAddress) > 0 {
|
||||||
err = ipStruct.SpeedTestUpdatedIPTable()
|
err = ipStruct.SpeedTestUpdatedIPTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not required to update IP table as speed test updates the IP Table
|
// Not required to update IP table as speed test updates the IP Table
|
||||||
//err = ipStruct.WriteIpTable()
|
//err = ipStruct.WriteIpTable()
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return err
|
// return err
|
||||||
//}
|
//}
|
||||||
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateIpTableListClient updates IP tables (Default 3 hops) based on server information available
|
// UpdateIpTableListClient updates IP tables (Default 3 hops) based on server information available
|
||||||
// on the ip tables
|
// on the ip tables
|
||||||
func UpdateIpTableListClient() error {
|
func UpdateIpTableListClient() error {
|
||||||
// Get config information
|
// Get config information
|
||||||
Config, err := config.ConfigInit(nil, nil)
|
Config, err := config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the IP Table has Node pingable
|
// Ensure that the IP Table has Node pingable
|
||||||
err = p2p.LocalSpeedTestIpTable()
|
err = p2p.LocalSpeedTestIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// IP addresses to not append to struct due to
|
// IP addresses to not append to struct due to
|
||||||
// duplication
|
// duplication
|
||||||
|
|
||||||
Addresses, err := p2p.ReadIpTable()
|
Addresses, err := p2p.ReadIpTable()
|
||||||
var DoNotRead p2p.IpAddresses
|
var DoNotRead p2p.IpAddresses
|
||||||
|
|
||||||
currentIPV4, err := p2p.CurrentPublicIP()
|
currentIPV4, err := p2p.CurrentPublicIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var w sync.WaitGroup
|
var w sync.WaitGroup
|
||||||
|
|
||||||
// Run loop 2 times
|
// Run loop 2 times
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
// Gets information from IP table
|
// Gets information from IP table
|
||||||
Addresses, err = p2p.ReadIpTable()
|
Addresses, err = p2p.ReadIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//DoNotRead.IpAddress = append(DoNotRead.IpAddress, PublicIP)
|
//DoNotRead.IpAddress = append(DoNotRead.IpAddress, PublicIP)
|
||||||
|
|
||||||
// Updates IP table based on server IP table
|
// Updates IP table based on server IP table
|
||||||
for j := range Addresses.IpAddress {
|
for j := range Addresses.IpAddress {
|
||||||
|
|
||||||
Exists := false
|
Exists := false
|
||||||
// If the address is local then add to the local list
|
// If the address is local then add to the local list
|
||||||
if currentIPV4 == Addresses.IpAddress[j].Ipv4 && Addresses.IpAddress[j].ServerPort == Config.ServerPort {
|
if (currentIPV4 == Addresses.IpAddress[j].Ipv4 && !Config.Test) && Addresses.IpAddress[j].ServerPort == Config.ServerPort {
|
||||||
Exists = true
|
Exists = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if IP addresses is there in the struct DoNotRead
|
// Check if IP addresses is there in the struct DoNotRead
|
||||||
for k := range DoNotRead.IpAddress {
|
for k := range DoNotRead.IpAddress {
|
||||||
if (DoNotRead.IpAddress[k].Ipv4 == Addresses.IpAddress[j].Ipv4 && DoNotRead.IpAddress[k].ServerPort == Addresses.IpAddress[j].ServerPort) || (DoNotRead.IpAddress[k].Ipv6 != "" && Addresses.IpAddress[j].Ipv6 == DoNotRead.IpAddress[k].Ipv6) {
|
if (DoNotRead.IpAddress[k].Ipv4 == Addresses.IpAddress[j].Ipv4 && DoNotRead.IpAddress[k].ServerPort == Addresses.IpAddress[j].ServerPort) || (DoNotRead.IpAddress[k].Ipv6 != "" && Addresses.IpAddress[j].Ipv6 == DoNotRead.IpAddress[k].Ipv6) {
|
||||||
Exists = true
|
Exists = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the struct exists then continues
|
// If the struct exists then continues
|
||||||
if Exists {
|
if Exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Add(1)
|
w.Add(1)
|
||||||
if Addresses.IpAddress[j].Ipv6 != "" {
|
//if Addresses.IpAddress[j].Ipv6 != "" {
|
||||||
go UpdateIpTable(Addresses.IpAddress[j].Ipv6, Addresses.IpAddress[j].ServerPort, &w)
|
// go UpdateIpTable(Addresses.IpAddress[j].Ipv6, Addresses.IpAddress[j].ServerPort, &w)
|
||||||
} else if Addresses.IpAddress[j].Ipv4 != currentIPV4 {
|
//} else if Addresses.IpAddress[j].Ipv4 != currentIPV4 {
|
||||||
go UpdateIpTable(Addresses.IpAddress[j].Ipv4, Addresses.IpAddress[j].ServerPort, &w)
|
// //go UpdateIpTable(Addresses.IpAddress[j].Ipv4, Addresses.IpAddress[j].ServerPort, &w)
|
||||||
}
|
//}
|
||||||
w.Wait()
|
go UpdateIpTable(Addresses.IpAddress[j].Ipv4, Addresses.IpAddress[j].ServerPort, &w)
|
||||||
|
w.Wait()
|
||||||
|
|
||||||
//Appends server1 IP address to variable DoNotRead
|
//Appends server1 IP address to variable DoNotRead
|
||||||
DoNotRead.IpAddress = append(DoNotRead.IpAddress, Addresses.IpAddress[j])
|
DoNotRead.IpAddress = append(DoNotRead.IpAddress, Addresses.IpAddress[j])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveOfflineNodes() error {
|
func RemoveOfflineNodes() error {
|
||||||
// Ensure that the IP Table has Node pingable
|
// Ensure that the IP Table has Node pingable
|
||||||
err := p2p.LocalSpeedTestIpTable()
|
err := p2p.LocalSpeedTestIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendPostRequest Sends a file as a
|
// SendPostRequest Sends a file as a
|
||||||
@@ -207,58 +208,58 @@ func RemoveOfflineNodes() error {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
func UploadMultipartFile(client http.Client, uri, key, path string) ([]byte, error) {
|
func UploadMultipartFile(client http.Client, uri, key, path string) ([]byte, error) {
|
||||||
body, writer := io.Pipe()
|
body, writer := io.Pipe()
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodPost, uri, body)
|
req, err := http.NewRequest(http.MethodPost, uri, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
mwriter := multipart.NewWriter(writer)
|
mwriter := multipart.NewWriter(writer)
|
||||||
req.Header.Add("Content-Type", mwriter.FormDataContentType())
|
req.Header.Add("Content-Type", mwriter.FormDataContentType())
|
||||||
|
|
||||||
errchan := make(chan error)
|
errchan := make(chan error)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(errchan)
|
defer close(errchan)
|
||||||
defer writer.Close()
|
defer writer.Close()
|
||||||
defer mwriter.Close()
|
defer mwriter.Close()
|
||||||
|
|
||||||
w, err := mwriter.CreateFormFile(key, path)
|
w, err := mwriter.CreateFormFile(key, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errchan <- err
|
errchan <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
in, err := os.Open(path)
|
in, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errchan <- err
|
errchan <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer in.Close()
|
defer in.Close()
|
||||||
|
|
||||||
if written, err := io.Copy(w, in); err != nil {
|
if written, err := io.Copy(w, in); err != nil {
|
||||||
errchan <- fmt.Errorf("error copying %s (%d bytes written): %v", path, written, err)
|
errchan <- fmt.Errorf("error copying %s (%d bytes written): %v", path, written, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := mwriter.Close(); err != nil {
|
if err := mwriter.Close(); err != nil {
|
||||||
errchan <- err
|
errchan <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := ioutil.ReadAll(resp.Body)
|
content, err := ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return content, nil
|
return content, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
139
cmd/action.go
139
cmd/action.go
@@ -2,8 +2,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Akilan1999/p2p-rendering-computation/abstractions"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/client"
|
"github.com/Akilan1999/p2p-rendering-computation/client"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
||||||
|
Config "github.com/Akilan1999/p2p-rendering-computation/config"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/plugin"
|
"github.com/Akilan1999/p2p-rendering-computation/plugin"
|
||||||
@@ -87,11 +89,7 @@ var CliAction = func(ctx *cli.Context) error {
|
|||||||
// Displays all images available on the server side
|
// Displays all images available on the server side
|
||||||
if ViewImages != "" {
|
if ViewImages != "" {
|
||||||
imageRes, err := client.ViewContainers(ViewImages)
|
imageRes, err := client.ViewContainers(ViewImages)
|
||||||
|
standardOutput(err, imageRes)
|
||||||
if err != nil {
|
|
||||||
fmt.Print(err)
|
|
||||||
}
|
|
||||||
client.PrettyPrint(imageRes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function called to stop and remove server from Docker
|
// Function called to stop and remove server from Docker
|
||||||
@@ -100,9 +98,7 @@ var CliAction = func(ctx *cli.Context) error {
|
|||||||
fmt.Println("provide container ID via --ID or --id")
|
fmt.Println("provide container ID via --ID or --id")
|
||||||
} else {
|
} else {
|
||||||
err := client.RemoveContianer(RemoveVM, ID)
|
err := client.RemoveContianer(RemoveVM, ID)
|
||||||
if err != nil {
|
standardOutput(err, nil)
|
||||||
fmt.Print(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,58 +115,40 @@ var CliAction = func(ctx *cli.Context) error {
|
|||||||
// Calls function to do Api call to start the container on the server side
|
// Calls function to do Api call to start the container on the server side
|
||||||
imageRes, err := client.StartContainer(CreateVM, PortsInt, GPU, ContainerName, BaseImage)
|
imageRes, err := client.StartContainer(CreateVM, PortsInt, GPU, ContainerName, BaseImage)
|
||||||
|
|
||||||
if err != nil {
|
standardOutput(err, imageRes)
|
||||||
fmt.Print(err)
|
|
||||||
}
|
|
||||||
client.PrettyPrint(imageRes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Call if specs flag is called
|
//Call if specs flag is called
|
||||||
if Specs != "" {
|
if Specs != "" {
|
||||||
specs, err := client.GetSpecs(Specs)
|
specs, err := client.GetSpecs(Specs)
|
||||||
if err != nil {
|
standardOutput(err, specs)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretty print
|
|
||||||
client.PrettyPrint(specs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Sets default paths to the config file
|
//Sets default paths to the config file
|
||||||
if SetDefaultConfig {
|
if SetDefaultConfig {
|
||||||
_, err := generate.SetDefaults("P2PRC", false, nil, false)
|
_, err := generate.SetDefaults("P2PRC", false, nil, false)
|
||||||
if err != nil {
|
standardOutput(err, nil)
|
||||||
fmt.Print(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the network interface flag is called
|
//If the network interface flag is called
|
||||||
// Then all the network interfaces are displayed
|
// Then all the network interfaces are displayed
|
||||||
if NetworkInterface {
|
if NetworkInterface {
|
||||||
err := p2p.ViewNetworkInterface()
|
err := p2p.ViewNetworkInterface()
|
||||||
if err != nil {
|
standardOutput(err, nil)
|
||||||
fmt.Print(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the view plugin flag is called then display all
|
// If the view plugin flag is called then display all
|
||||||
// plugins available
|
// plugins available
|
||||||
if ViewPlugin {
|
if ViewPlugin {
|
||||||
plugins, err := plugin.DetectPlugins()
|
plugins, err := plugin.DetectPlugins()
|
||||||
if err != nil {
|
standardOutput(err, plugins)
|
||||||
fmt.Print(err)
|
|
||||||
}
|
|
||||||
client.PrettyPrint(plugins)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the flag Tracked Container is called or the flag
|
// If the flag Tracked Container is called or the flag
|
||||||
// --tc
|
// --tc
|
||||||
if TrackedContainers {
|
if TrackedContainers {
|
||||||
err, trackedContainers := client.ViewTrackedContainers()
|
err, trackedContainers := client.ViewTrackedContainers()
|
||||||
if err != nil {
|
standardOutput(err, trackedContainers)
|
||||||
fmt.Print(err)
|
|
||||||
}
|
|
||||||
client.PrettyPrint(trackedContainers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Executing plugin when the plugin flag is called
|
//Executing plugin when the plugin flag is called
|
||||||
@@ -179,14 +157,11 @@ var CliAction = func(ctx *cli.Context) error {
|
|||||||
// To execute plugin requires the container ID or group ID provided when being executed
|
// To execute plugin requires the container ID or group ID provided when being executed
|
||||||
if ID != "" {
|
if ID != "" {
|
||||||
err := plugin.CheckRunPlugin(ExecutePlugin, ID)
|
err := plugin.CheckRunPlugin(ExecutePlugin, ID)
|
||||||
if err != nil {
|
standardOutput(err, nil)
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Success")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("provide container ID via --ID or --id")
|
|
||||||
}
|
}
|
||||||
|
//else {
|
||||||
|
// fmt.Println("provide container ID via --ID or --id")
|
||||||
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,10 +169,7 @@ var CliAction = func(ctx *cli.Context) error {
|
|||||||
// Creates new group and outputs JSON file
|
// Creates new group and outputs JSON file
|
||||||
if CreateGroup {
|
if CreateGroup {
|
||||||
group, err := client.CreateGroup()
|
group, err := client.CreateGroup()
|
||||||
if err != nil {
|
standardOutput(err, group)
|
||||||
return err
|
|
||||||
}
|
|
||||||
client.PrettyPrint(group)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions to be performed when the
|
// Actions to be performed when the
|
||||||
@@ -208,26 +180,14 @@ var CliAction = func(ctx *cli.Context) error {
|
|||||||
// --rmcgroup --id <contianer id>
|
// --rmcgroup --id <contianer id>
|
||||||
if RemoveContainerGroup && ID != "" {
|
if RemoveContainerGroup && ID != "" {
|
||||||
group, err := client.RemoveContainerGroup(ID, Group)
|
group, err := client.RemoveContainerGroup(ID, Group)
|
||||||
if err != nil {
|
standardOutput(err, group)
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
client.PrettyPrint(group)
|
|
||||||
}
|
|
||||||
} else if ID != "" { // Add container to group based on group ID provided
|
} else if ID != "" { // Add container to group based on group ID provided
|
||||||
// --id <Container ID>
|
// --id <Container ID>
|
||||||
group, err := client.AddContainerToGroup(ID, Group)
|
group, err := client.AddContainerToGroup(ID, Group)
|
||||||
if err != nil {
|
standardOutput(err, group)
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
client.PrettyPrint(group)
|
|
||||||
}
|
|
||||||
} else { // View all information about current group
|
} else { // View all information about current group
|
||||||
group, err := client.GetGroup(Group)
|
group, err := client.GetGroup(Group)
|
||||||
if err != nil {
|
standardOutput(err, group)
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
client.PrettyPrint(group)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,63 +196,58 @@ var CliAction = func(ctx *cli.Context) error {
|
|||||||
// --rmgroup
|
// --rmgroup
|
||||||
if RemoveGroup != "" {
|
if RemoveGroup != "" {
|
||||||
err := client.RemoveGroup(RemoveGroup)
|
err := client.RemoveGroup(RemoveGroup)
|
||||||
if err != nil {
|
standardOutput(err, nil)
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Group Removed")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute Function to view all groups
|
// Execute Function to view all groups
|
||||||
if Groups {
|
if Groups {
|
||||||
groups, err := client.ReadGroup()
|
groups, err := client.ReadGroup()
|
||||||
if err != nil {
|
standardOutput(err, groups)
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
client.PrettyPrint(groups)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
if PullPlugin != "" {
|
if PullPlugin != "" {
|
||||||
err := plugin.DownloadPlugin(PullPlugin)
|
err := plugin.DownloadPlugin(PullPlugin)
|
||||||
if err != nil {
|
standardOutput(err, nil)
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Success")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if RemovePlugin != "" {
|
if RemovePlugin != "" {
|
||||||
err := plugin.DeletePlugin(RemovePlugin)
|
err := plugin.DeletePlugin(RemovePlugin)
|
||||||
if err != nil {
|
standardOutput(err, nil)
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Success")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if AddMetaData != "" {
|
if AddMetaData != "" {
|
||||||
err := clientIPTable.AddCustomInformationToIPTable(AddMetaData)
|
err := clientIPTable.AddCustomInformationToIPTable(AddMetaData)
|
||||||
if err != nil {
|
standardOutput(err, nil)
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Success")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if MAPPort != "" {
|
if MAPPort != "" {
|
||||||
address, err := client.MAPPort(MAPPort, DomainName)
|
address, err := client.MAPPort(MAPPort, DomainName, RemoteAddress)
|
||||||
if err != nil {
|
standardOutput(err, address)
|
||||||
return err
|
}
|
||||||
}
|
|
||||||
if err != nil {
|
// Action called to add root node to network
|
||||||
fmt.Println(err)
|
if AddRootNode && IP != "" && Ports != "" {
|
||||||
} else {
|
err := abstractions.AddRootNode(IP, Ports)
|
||||||
client.PrettyPrint(address)
|
standardOutput(err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// display configuration
|
||||||
|
if ViewConfig {
|
||||||
|
config, err := Config.ConfigInit(nil, nil)
|
||||||
|
standardOutput(err, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func standardOutput(err error, i interface{}) {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
} else if i == nil {
|
||||||
|
fmt.Println("Success")
|
||||||
|
} else {
|
||||||
|
client.PrettyPrint(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
33
cmd/flags.go
33
cmd/flags.go
@@ -30,6 +30,7 @@ var (
|
|||||||
RemoveContainerGroup bool
|
RemoveContainerGroup bool
|
||||||
RemoveGroup string
|
RemoveGroup string
|
||||||
MAPPort string
|
MAPPort string
|
||||||
|
RemoteAddress string
|
||||||
DomainName string
|
DomainName string
|
||||||
//FRPProxy bool
|
//FRPProxy bool
|
||||||
// Generate only allowed in dev release
|
// Generate only allowed in dev release
|
||||||
@@ -40,10 +41,12 @@ var (
|
|||||||
PullPlugin string
|
PullPlugin string
|
||||||
RemovePlugin string
|
RemovePlugin string
|
||||||
AddMetaData string
|
AddMetaData string
|
||||||
|
AddRootNode bool
|
||||||
|
IP string
|
||||||
|
ViewConfig bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var AppConfigFlags = []cli.Flag{
|
var AppConfigFlags = []cli.Flag{
|
||||||
// Deprecated to be implemented using GRPC
|
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "Server",
|
Name: "Server",
|
||||||
Aliases: []string{"s"},
|
Aliases: []string{"s"},
|
||||||
@@ -213,6 +216,13 @@ var AppConfigFlags = []cli.Flag{
|
|||||||
EnvVars: []string{"MAPPORT"},
|
EnvVars: []string{"MAPPORT"},
|
||||||
Destination: &MAPPort,
|
Destination: &MAPPort,
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "RemoteAddress",
|
||||||
|
Aliases: []string{"ra"},
|
||||||
|
Usage: "Parameter for Map port for a remote address",
|
||||||
|
EnvVars: []string{"REMOTEADDRESS"},
|
||||||
|
Destination: &RemoteAddress,
|
||||||
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "DomainName",
|
Name: "DomainName",
|
||||||
Aliases: []string{"dn"},
|
Aliases: []string{"dn"},
|
||||||
@@ -265,4 +275,25 @@ var AppConfigFlags = []cli.Flag{
|
|||||||
EnvVars: []string{"ADDMETADATA"},
|
EnvVars: []string{"ADDMETADATA"},
|
||||||
Destination: &AddMetaData,
|
Destination: &AddMetaData,
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "AddRootNode",
|
||||||
|
Aliases: []string{"arn"},
|
||||||
|
Usage: "Adds initial root node to talk to",
|
||||||
|
EnvVars: []string{"ADDROOTNODE"},
|
||||||
|
Destination: &AddRootNode,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "IPAddress",
|
||||||
|
Aliases: []string{"ip"},
|
||||||
|
Usage: "IP address",
|
||||||
|
EnvVars: []string{"IP"},
|
||||||
|
Destination: &IP,
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "ViewConfig",
|
||||||
|
Aliases: []string{"vc"},
|
||||||
|
Usage: "View config file",
|
||||||
|
EnvVars: []string{"VC"},
|
||||||
|
Destination: &ViewConfig,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ type Config struct {
|
|||||||
ServerPort string
|
ServerPort string
|
||||||
ProxyPort string
|
ProxyPort string
|
||||||
GroupTrackContainersPath string
|
GroupTrackContainersPath string
|
||||||
FRPServerPort string
|
FRPServerPort bool
|
||||||
BehindNAT string
|
BehindNAT bool
|
||||||
IPTableKey string
|
IPTableKey string
|
||||||
PublicKeyFile string
|
PublicKeyFile string
|
||||||
PrivateKeyFile string
|
PrivateKeyFile string
|
||||||
@@ -38,7 +38,9 @@ type Config struct {
|
|||||||
KeyFile string
|
KeyFile string
|
||||||
BareMetal bool
|
BareMetal bool
|
||||||
UnsafeMode bool
|
UnsafeMode bool
|
||||||
|
Test bool
|
||||||
CustomConfig interface{}
|
CustomConfig interface{}
|
||||||
|
ConfigPath string
|
||||||
//NetworkInterface string
|
//NetworkInterface string
|
||||||
//NetworkInterfaceIPV6Index int
|
//NetworkInterfaceIPV6Index int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,9 +78,9 @@ func SetDefaults(envName string, forceDefault bool, CustomConfig interface{}, No
|
|||||||
Defaults.GroupTrackContainersPath = defaultPath + "client/trackcontainers/grouptrackcontainers.json"
|
Defaults.GroupTrackContainersPath = defaultPath + "client/trackcontainers/grouptrackcontainers.json"
|
||||||
Defaults.ServerPort = "8088"
|
Defaults.ServerPort = "8088"
|
||||||
Defaults.ProxyPort = ""
|
Defaults.ProxyPort = ""
|
||||||
Defaults.FRPServerPort = "True"
|
Defaults.FRPServerPort = true
|
||||||
Defaults.CustomConfig = CustomConfig
|
Defaults.CustomConfig = CustomConfig
|
||||||
Defaults.BehindNAT = "True"
|
Defaults.BehindNAT = true
|
||||||
Defaults.DockerRunLogs = "/tmp/"
|
Defaults.DockerRunLogs = "/tmp/"
|
||||||
// Generate a random key to be added to IPTable
|
// Generate a random key to be added to IPTable
|
||||||
Defaults.IPTableKey = String(12)
|
Defaults.IPTableKey = String(12)
|
||||||
@@ -95,6 +95,8 @@ func SetDefaults(envName string, forceDefault bool, CustomConfig interface{}, No
|
|||||||
Defaults.PrivateKeyFile = defaultPath + "p2prc.privateKey"
|
Defaults.PrivateKeyFile = defaultPath + "p2prc.privateKey"
|
||||||
Defaults.BareMetal = false
|
Defaults.BareMetal = false
|
||||||
Defaults.UnsafeMode = false
|
Defaults.UnsafeMode = false
|
||||||
|
Defaults.Test = false
|
||||||
|
Defaults.ConfigPath = defaultPath + "config.json"
|
||||||
|
|
||||||
// Generate certificate files for SSL
|
// Generate certificate files for SSL
|
||||||
err = GenerateCertificate()
|
err = GenerateCertificate()
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"crypto/x509/pkix"
|
"crypto/x509/pkix"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
|
||||||
"log"
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
@@ -54,7 +53,8 @@ func GenerateCertificate() error {
|
|||||||
|
|
||||||
//flag.Parse()
|
//flag.Parse()
|
||||||
|
|
||||||
host, err = p2p.CurrentPublicIP()
|
//host, err = p2p.CurrentPublicIP()
|
||||||
|
host = "0.0.0.0"
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ func GenerateIPTableFile(rootNodes []p2p.IpAddress) (err error) {
|
|||||||
if len(rootNodes) <= 0 {
|
if len(rootNodes) <= 0 {
|
||||||
rootnode.Name = "Node1"
|
rootnode.Name = "Node1"
|
||||||
rootnode.ServerPort = "8078"
|
rootnode.ServerPort = "8078"
|
||||||
rootnode.NAT = "False"
|
rootnode.NAT = false
|
||||||
rootnode.Ipv4 = "217.76.63.222"
|
rootnode.Ipv4 = "217.76.63.222"
|
||||||
rootnode.ProxyServer = "True"
|
rootnode.ProxyServer = true
|
||||||
|
|
||||||
rootnodes.IpAddress = append(rootnodes.IpAddress, rootnode)
|
rootnodes.IpAddress = append(rootnodes.IpAddress, rootnode)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
12
flake.lock
generated
12
flake.lock
generated
@@ -28,11 +28,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1733668782,
|
"lastModified": 1745875161,
|
||||||
"narHash": "sha256-tPsqU00FhgdFr0JiQUiBMgPVbl1jbPCY5gbFiJycL3I=",
|
"narHash": "sha256-0YkWCS13jpoo3+sX/3kcgdxBNt1VZTmvF+FhZb4rFKI=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "gomod2nix",
|
"repo": "gomod2nix",
|
||||||
"rev": "514283ec89c39ad0079ff2f3b1437404e4cba608",
|
"rev": "2cbd7fdd6eeab65c494cc426e18f4e4d2a5e35c0",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -43,11 +43,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1735834308,
|
"lastModified": 1748460289,
|
||||||
"narHash": "sha256-dklw3AXr3OGO4/XT1Tu3Xz9n/we8GctZZ75ZWVqAVhk=",
|
"narHash": "sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "6df24922a1400241dae323af55f30e4318a6ca65",
|
"rev": "96ec055edbe5ee227f28cdbc3f1ddf1df5965102",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
152
flake.nix
152
flake.nix
@@ -1,41 +1,129 @@
|
|||||||
{
|
{
|
||||||
description = "P2PRC nix flake";
|
description = "P2PRC nix flake";
|
||||||
|
|
||||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
inputs = {
|
||||||
inputs.flake-utils.url = "github:numtide/flake-utils";
|
|
||||||
inputs.gomod2nix.url = "github:nix-community/gomod2nix";
|
|
||||||
inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils";
|
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, gomod2nix }:
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
(flake-utils.lib.eachDefaultSystem
|
|
||||||
(system:
|
|
||||||
let
|
|
||||||
pkgs = import nixpkgs {
|
|
||||||
inherit system;
|
|
||||||
overlays = [ gomod2nix.overlays.default ];
|
|
||||||
};
|
|
||||||
|
|
||||||
# pkgs = nixpkgs.legacyPackages.${system};
|
flake-utils = {
|
||||||
|
url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
# The current default sdk for macOS fails to compile go projects, so we use a newer one for now.
|
gomod2nix = {
|
||||||
# This has no effect on other platforms.
|
url = "github:nix-community/gomod2nix";
|
||||||
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
in
|
inputs.flake-utils.follows = "flake-utils";
|
||||||
{
|
};
|
||||||
|
|
||||||
packages.default = callPackage ./. { };
|
};
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
outputs =
|
||||||
buildInputs = with pkgs; [
|
{
|
||||||
go
|
nixpkgs,
|
||||||
gopls
|
flake-utils,
|
||||||
gotools
|
gomod2nix,
|
||||||
go-tools
|
...
|
||||||
gomod2nix.packages.${system}.default
|
}:
|
||||||
sqlite-interactive
|
let
|
||||||
];
|
|
||||||
};
|
bindingsOverlay = import ./nix/overlays/bindings.nix;
|
||||||
})
|
coreOverlay = (final: prev: {
|
||||||
);
|
p2prc = final.callPackage ./. { };
|
||||||
|
});
|
||||||
|
|
||||||
|
in
|
||||||
|
(flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [
|
||||||
|
gomod2nix.overlays.default
|
||||||
|
coreOverlay
|
||||||
|
bindingsOverlay
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
# The current default sdk for macOS fails to compile go projects, so we use a newer one for now.
|
||||||
|
# This has no effect on other platforms.
|
||||||
|
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
|
||||||
|
|
||||||
|
p2prcDefault = callPackage ./. { };
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages.default = p2prcDefault;
|
||||||
|
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
go
|
||||||
|
gopls
|
||||||
|
gotools
|
||||||
|
go-tools
|
||||||
|
gomod2nix.packages.${system}.default
|
||||||
|
sqlite-interactive
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
packages.initHaskellProject = pkgs.writeShellApplication {
|
||||||
|
name = "initHaskellProject";
|
||||||
|
runtimeInputs = with pkgs; [
|
||||||
|
ghc
|
||||||
|
cabal2nix
|
||||||
|
cabal-install
|
||||||
|
git
|
||||||
|
p2prcDefault
|
||||||
|
];
|
||||||
|
text =
|
||||||
|
''
|
||||||
|
clear
|
||||||
|
|
||||||
|
if [ "$#" -eq 0 ]; then
|
||||||
|
echo "No arguments provided."
|
||||||
|
echo "Please provide the name of your project"
|
||||||
|
echo "nix run git+https://github:akilan1999/p2p-rendering-computation#initHaskellProject -- <NAME-PROJECT>"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
PROJECT_DIR="$1"
|
||||||
|
|
||||||
|
mkdir "$PROJECT_DIR"
|
||||||
|
|
||||||
|
cd "$PROJECT_DIR"
|
||||||
|
|
||||||
|
git init .
|
||||||
|
clear
|
||||||
|
|
||||||
|
cabal init --exe --simple
|
||||||
|
|
||||||
|
sed -i 's/base.*$/base, p2prc/' "$PROJECT_DIR".cabal
|
||||||
|
|
||||||
|
cabal2nix . > ./cabal.nix;
|
||||||
|
|
||||||
|
git add .
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
echo -e "run the following commands to finish nix development and production environment:\n\n"
|
||||||
|
|
||||||
|
echo -e "cd $PROJECT_DIR"
|
||||||
|
echo -e "nix flake init -t github:akilan1999/p2p-rendering-computation#haskell"
|
||||||
|
echo -e "nix develop"
|
||||||
|
echo -e "nix run"
|
||||||
|
echo -e "\n\n"
|
||||||
|
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)) //
|
||||||
|
{
|
||||||
|
overlays = {
|
||||||
|
default = coreOverlay;
|
||||||
|
bindings = bindingsOverlay;
|
||||||
|
};
|
||||||
|
templates.haskell = {
|
||||||
|
path = ./nix/templates/haskell;
|
||||||
|
description = "Haskell Bindings to p2prc protocol";
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
11
go.mod
11
go.mod
@@ -11,7 +11,7 @@ require (
|
|||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
github.com/lithammer/shortuuid v3.0.0+incompatible
|
github.com/lithammer/shortuuid v3.0.0+incompatible
|
||||||
github.com/otiai10/copy v1.6.0
|
github.com/otiai10/copy v1.6.0
|
||||||
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
|
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
|
||||||
github.com/shirou/gopsutil/v3 v3.22.10
|
github.com/shirou/gopsutil/v3 v3.22.10
|
||||||
github.com/urfave/cli/v2 v2.3.0
|
github.com/urfave/cli/v2 v2.3.0
|
||||||
gitlab.com/NebulousLabs/go-upnp v0.0.0-20181011194642-3a71999ed0d3
|
gitlab.com/NebulousLabs/go-upnp v0.0.0-20181011194642-3a71999ed0d3
|
||||||
@@ -31,7 +31,7 @@ require (
|
|||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||||
github.com/containerd/containerd v1.5.0-beta.1 // indirect
|
github.com/containerd/containerd v1.5.0-beta.1 // indirect
|
||||||
github.com/coreos/go-oidc v2.2.1+incompatible // indirect
|
github.com/coreos/go-oidc v2.2.1+incompatible // indirect
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
|
||||||
github.com/docker/distribution v2.7.1+incompatible // indirect
|
github.com/docker/distribution v2.7.1+incompatible // indirect
|
||||||
github.com/docker/go-connections v0.4.0 // indirect
|
github.com/docker/go-connections v0.4.0 // indirect
|
||||||
github.com/docker/go-units v0.4.0 // indirect
|
github.com/docker/go-units v0.4.0 // indirect
|
||||||
@@ -76,10 +76,9 @@ require (
|
|||||||
github.com/prometheus/client_model v0.2.0 // indirect
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
github.com/prometheus/common v0.37.0 // indirect
|
github.com/prometheus/common v0.37.0 // indirect
|
||||||
github.com/prometheus/procfs v0.8.0 // indirect
|
github.com/prometheus/procfs v0.8.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.0.1 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/sergi/go-diff v1.1.0 // indirect
|
github.com/sergi/go-diff v1.1.0 // indirect
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
github.com/sirupsen/logrus v1.7.0 // indirect
|
|
||||||
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
|
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
|
||||||
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
|
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
|
||||||
github.com/tjfoc/gmsm v1.4.1 // indirect
|
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||||
@@ -91,7 +90,7 @@ require (
|
|||||||
gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40 // indirect
|
gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40 // indirect
|
||||||
golang.org/x/net v0.10.0 // indirect
|
golang.org/x/net v0.10.0 // indirect
|
||||||
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
|
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
|
||||||
golang.org/x/sys v0.15.0 // indirect
|
golang.org/x/sys v0.29.0 // indirect
|
||||||
golang.org/x/text v0.14.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
|
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
|
|||||||
19
go.sum
19
go.sum
@@ -183,8 +183,9 @@ github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+
|
|||||||
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
@@ -548,8 +549,8 @@ github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=
|
|||||||
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
|
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
|
||||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||||
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
||||||
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
|
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI=
|
||||||
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
|
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
|
||||||
github.com/pires/go-proxyproto v0.6.2 h1:KAZ7UteSOt6urjme6ZldyFm4wDe/z0ZUP0Yv0Dos0d8=
|
github.com/pires/go-proxyproto v0.6.2 h1:KAZ7UteSOt6urjme6ZldyFm4wDe/z0ZUP0Yv0Dos0d8=
|
||||||
github.com/pires/go-proxyproto v0.6.2/go.mod h1:Odh9VFOZJCf9G8cLW5o435Xf1J95Jw9Gw5rnCjcwzAY=
|
github.com/pires/go-proxyproto v0.6.2/go.mod h1:Odh9VFOZJCf9G8cLW5o435Xf1J95Jw9Gw5rnCjcwzAY=
|
||||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
@@ -611,8 +612,9 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
|
|||||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
|
github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4=
|
||||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||||
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
|
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
|
||||||
@@ -620,7 +622,6 @@ github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
|||||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||||
github.com/shirou/gopsutil/v3 v3.22.10 h1:4KMHdfBRYXGF9skjDWiL4RA2N+E8dRdodU/bOZpPoVg=
|
github.com/shirou/gopsutil/v3 v3.22.10 h1:4KMHdfBRYXGF9skjDWiL4RA2N+E8dRdodU/bOZpPoVg=
|
||||||
github.com/shirou/gopsutil/v3 v3.22.10/go.mod h1:QNza6r4YQoydyCfo6rH0blGfKahgibh4dQmV5xdFkQk=
|
github.com/shirou/gopsutil/v3 v3.22.10/go.mod h1:QNza6r4YQoydyCfo6rH0blGfKahgibh4dQmV5xdFkQk=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
|
github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
|
||||||
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
|
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
|
||||||
@@ -628,8 +629,9 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
|
|||||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||||
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
|
|
||||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||||
@@ -917,8 +919,9 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||||
|
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// VERSION specifies the version of the platform
|
// VERSION specifies the version of the platform
|
||||||
var VERSION = "2.0.0"
|
var VERSION = "3.0.0"
|
||||||
var mode string
|
var mode string
|
||||||
|
|
||||||
// Varaibles if mode is client
|
// Varaibles if mode is client
|
||||||
@@ -34,10 +34,6 @@ func getFireSignalsChannel() chan os.Signal {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func exit() {
|
|
||||||
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "p2p-rendering-computation"
|
app.Name = "p2p-rendering-computation"
|
||||||
|
|||||||
40
main.md.org
40
main.md.org
@@ -1,40 +0,0 @@
|
|||||||
#+begin_html
|
|
||||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
|
||||||
#+end_html
|
|
||||||
|
|
||||||
* p2p-rendering-computation
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: p2p-rendering-computation
|
|
||||||
:END:
|
|
||||||
#+begin_src go
|
|
||||||
import "github.com/Akilan1999/p2p-rendering-computation"
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
** Index
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: index
|
|
||||||
:END:
|
|
||||||
- [[#variables][Variables]]
|
|
||||||
|
|
||||||
** Variables
|
|
||||||
:PROPERTIES:
|
|
||||||
:CUSTOM_ID: variables
|
|
||||||
:END:
|
|
||||||
|
|
||||||
#+begin_src go
|
|
||||||
var List_servers, Ip_table bool
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Varaibles if mode is client
|
|
||||||
|
|
||||||
#+begin_src go
|
|
||||||
var OS, Pull_location, Run_script string
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
VERSION specifies the version of the platform
|
|
||||||
|
|
||||||
#+begin_src go
|
|
||||||
var VERSION = "2.0.0"
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
Generated by [[https://github.com/princjef/gomarkdoc][gomarkdoc]]
|
|
||||||
7
nix/overlays/bindings.nix
Normal file
7
nix/overlays/bindings.nix
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
final: prev: {
|
||||||
|
haskellPackages = prev.haskellPackages.override {
|
||||||
|
overrides = hfinal: hprev: {
|
||||||
|
p2prc = hfinal.callPackage ../../Bindings/Haskell/project.nix { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
190
nix/templates/haskell/flake.lock
generated
Normal file
190
nix/templates/haskell/flake.lock
generated
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-util": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems_2"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "flake-utils",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils_2": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems_3"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"gomod2nix": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": [
|
||||||
|
"p2prc-flake",
|
||||||
|
"flake-utils"
|
||||||
|
],
|
||||||
|
"nixpkgs": [
|
||||||
|
"p2prc-flake",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1745875161,
|
||||||
|
"narHash": "sha256-0YkWCS13jpoo3+sX/3kcgdxBNt1VZTmvF+FhZb4rFKI=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "gomod2nix",
|
||||||
|
"rev": "2cbd7fdd6eeab65c494cc426e18f4e4d2a5e35c0",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "gomod2nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1748460289,
|
||||||
|
"narHash": "sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "96ec055edbe5ee227f28cdbc3f1ddf1df5965102",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1748370509,
|
||||||
|
"narHash": "sha256-QlL8slIgc16W5UaI3w7xHQEP+Qmv/6vSNTpoZrrSlbk=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "4faa5f5321320e49a78ae7848582f684d64783e9",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"p2prc-flake": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils_2",
|
||||||
|
"gomod2nix": "gomod2nix",
|
||||||
|
"nixpkgs": "nixpkgs_2"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1748646470,
|
||||||
|
"narHash": "sha256-7aZQQ+jHdlxUzFPXzEEYfH1oU3isSZlZnMC7HWUDHCk=",
|
||||||
|
"owner": "xecarlox94",
|
||||||
|
"repo": "p2p-rendering-computation",
|
||||||
|
"rev": "73a283a545d61754a0fe821287541c2cd412bc0e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "xecarlox94",
|
||||||
|
"ref": "nix",
|
||||||
|
"repo": "p2p-rendering-computation",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-util": "flake-util",
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"p2prc-flake": "p2prc-flake"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems_3": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
48
nix/templates/haskell/flake.nix
Normal file
48
nix/templates/haskell/flake.nix
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
description = "Start of Haskell P2PRC flake";
|
||||||
|
|
||||||
|
inputs =
|
||||||
|
{
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
|
||||||
|
flake-util.url = "github:numtide/flake-utils";
|
||||||
|
|
||||||
|
p2prc-flake.url = "github:akilan1999/p2p-rendering-computation";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { nixpkgs, p2prc-flake, flake-utils, ... }:
|
||||||
|
(flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [
|
||||||
|
p2prc-flake.overlays.default
|
||||||
|
p2prc-flake.overlays.bindings
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
in {
|
||||||
|
|
||||||
|
packages.default = pkgs.haskellPackages.callPackage ./cabal.nix { };
|
||||||
|
|
||||||
|
devShells.default = pkgs.haskellPackages.shellFor {
|
||||||
|
|
||||||
|
packages = p: [
|
||||||
|
(p.callPackage ./cabal.nix { })
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
p2prc-flake.packages.${system}.default
|
||||||
|
ghc
|
||||||
|
cabal2nix
|
||||||
|
cabal-install
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
cabal2nix . > ./cabal.nix
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
421
p2p/iptable.go
421
p2p/iptable.go
@@ -1,284 +1,297 @@
|
|||||||
package p2p
|
package p2p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get IP table Data
|
// Get IP table Data
|
||||||
|
|
||||||
type IpAddresses struct {
|
type IpAddresses struct {
|
||||||
IpAddress []IpAddress `json:"ip_address"`
|
IpAddress []IpAddress `json:"ip_address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IpAddress struct {
|
type IpAddress struct {
|
||||||
Name string `json:"Name"`
|
Name string `json:"Name"`
|
||||||
MachineUsername string `json:"MachineUsername"`
|
MachineUsername string `json:"MachineUsername"`
|
||||||
Ipv4 string `json:"IPV4"`
|
Ipv4 string `json:"IPV4"`
|
||||||
Ipv6 string `json:"IPV6"`
|
Ipv6 string `json:"IPV6"`
|
||||||
Latency time.Duration `json:"Latency"`
|
Latency time.Duration `json:"Latency"`
|
||||||
Download float64 `json:"Download"`
|
Download float64 `json:"Download"`
|
||||||
Upload float64 `json:"Upload"`
|
Upload float64 `json:"Upload"`
|
||||||
ServerPort string `json:"ServerPort"`
|
ServerPort string `json:"ServerPort"`
|
||||||
BareMetalSSHPort string `json:"BareMetalSSHPort"`
|
BareMetalSSHPort string `json:"BareMetalSSHPort"`
|
||||||
NAT string `json:"NAT"`
|
NAT bool `json:"NAT"`
|
||||||
EscapeImplementation string `json:"EscapeImplementation"`
|
EscapeImplementation string `json:"EscapeImplementation"`
|
||||||
ProxyServer string `json:"ProxyServer"`
|
ProxyServer bool `json:"ProxyServer"`
|
||||||
UnSafeMode bool `json:"UnSafeMode"`
|
UnSafeMode bool `json:"UnSafeMode"`
|
||||||
PublicKey string `json:"PublicKey"`
|
PublicKey string `json:"PublicKey"`
|
||||||
CustomInformation string `json:"CustomInformation"`
|
CustomInformation string `json:"CustomInformation"`
|
||||||
//CustomInformationKey []byte `json:"CustomInformationKey"`
|
//CustomInformationKey []byte `json:"CustomInformationKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IP struct {
|
type IP struct {
|
||||||
Query string
|
Query string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Test = false
|
||||||
|
|
||||||
// ReadIpTable Read data from Ip tables from json file
|
// ReadIpTable Read data from Ip tables from json file
|
||||||
func ReadIpTable() (*IpAddresses, error) {
|
func ReadIpTable() (*IpAddresses, error) {
|
||||||
// Get Path from config
|
// Get Path from config
|
||||||
config, err := config.ConfigInit(nil, nil)
|
config, err := config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
jsonFile, err := os.Open(config.IPTable)
|
jsonFile, err := os.Open(config.IPTable)
|
||||||
// if we os.Open returns an error then handle it
|
// if we os.Open returns an error then handle it
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// defer the closing of our jsonFile so that we can parse it later on
|
// defer the closing of our jsonFile so that we can parse it later on
|
||||||
defer jsonFile.Close()
|
defer jsonFile.Close()
|
||||||
|
|
||||||
// read our opened xmlFile as a byte array.
|
// read our opened xmlFile as a byte array.
|
||||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||||
|
|
||||||
// we initialize our Users array
|
// we initialize our Users array
|
||||||
var ipAddresses IpAddresses
|
var ipAddresses IpAddresses
|
||||||
|
|
||||||
// we unmarshal our byteArray which contains our
|
// we unmarshal our byteArray which contains our
|
||||||
// jsonFile's content into 'users' which we defined above
|
// jsonFile's content into 'users' which we defined above
|
||||||
json.Unmarshal(byteValue, &ipAddresses)
|
json.Unmarshal(byteValue, &ipAddresses)
|
||||||
|
|
||||||
var PublicIP IpAddress
|
var PublicIP IpAddress
|
||||||
|
|
||||||
ipv6, err := GetCurrentIPV6()
|
ipv6, err := GetCurrentIPV6()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, err := CurrentPublicIP()
|
ip, err := CurrentPublicIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
PublicIP.Ipv4 = ip
|
PublicIP.Ipv4 = ip
|
||||||
PublicIP.Ipv6 = ipv6
|
PublicIP.Ipv6 = ipv6
|
||||||
PublicIP.ServerPort = config.ServerPort
|
PublicIP.ServerPort = config.ServerPort
|
||||||
PublicIP.Name = config.MachineName
|
PublicIP.Name = config.MachineName
|
||||||
PublicIP.NAT = config.BehindNAT
|
PublicIP.NAT = config.BehindNAT
|
||||||
PublicIP.EscapeImplementation = "None"
|
PublicIP.EscapeImplementation = "None"
|
||||||
|
|
||||||
// Updates current machine IP address to the IP table
|
// Updates current machine IP address to the IP table
|
||||||
ipAddresses.IpAddress = append(ipAddresses.IpAddress, PublicIP)
|
ipAddresses.IpAddress = append(ipAddresses.IpAddress, PublicIP)
|
||||||
|
|
||||||
//before writing to iptable ensures the duplicates are removed
|
//before writing to iptable ensures the duplicates are removed
|
||||||
if err = ipAddresses.RemoveDuplicates(); err != nil {
|
if err = ipAddresses.RemoveDuplicates(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ipAddresses, nil
|
return &ipAddresses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteIpTable Write to IP table json file
|
// WriteIpTable Write to IP table json file
|
||||||
func (i *IpAddresses) WriteIpTable() error {
|
func (i *IpAddresses) WriteIpTable() error {
|
||||||
//before writing to iptable ensures the duplicates are removed
|
//before writing to iptable ensures the duplicates are removed
|
||||||
if err := i.RemoveDuplicates(); err != nil {
|
if err := i.RemoveDuplicates(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := json.MarshalIndent(i, "", " ")
|
file, err := json.MarshalIndent(i, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Path from config
|
// Get Path from config
|
||||||
config, err := config.ConfigInit(nil, nil)
|
config, err := config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(config.IPTable, file, 0644)
|
err = ioutil.WriteFile(config.IPTable, file, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrintIpTable Print Ip table data for Cli
|
// PrintIpTable Print Ip table data for Cli
|
||||||
func PrintIpTable() error {
|
func PrintIpTable() error {
|
||||||
table, err := ReadIpTable()
|
table, err := ReadIpTable()
|
||||||
//
|
//
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
//for i := 0; i < len(table.IpAddress); i++ {
|
//for i := 0; i < len(table.IpAddress); i++ {
|
||||||
// fmt.Printf("\nMachine Name: %s\nIP Address: %s\nIPV6: %s\nLatency: %s\nServerPort: %s\nbehindNAT: %s\nEscapeImplementation: %s\n-----------"+
|
// fmt.Printf("\nMachine Name: %s\nIP Address: %s\nIPV6: %s\nLatency: %s\nServerPort: %s\nbehindNAT: %s\nEscapeImplementation: %s\n-----------"+
|
||||||
// "-----------------\n", table.IpAddress[i].Name, table.IpAddress[i].Ipv4, table.IpAddress[i].Ipv6,
|
// "-----------------\n", table.IpAddress[i].Name, table.IpAddress[i].Ipv4, table.IpAddress[i].Ipv6,
|
||||||
// table.IpAddress[i].Latency, table.IpAddress[i].ServerPort, table.IpAddress[i].NAT, table.IpAddress[i].EscapeImplementation)
|
// table.IpAddress[i].Latency, table.IpAddress[i].ServerPort, table.IpAddress[i].NAT, table.IpAddress[i].EscapeImplementation)
|
||||||
//}
|
//}
|
||||||
PrettyPrint(table)
|
PrettyPrint(table)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveDuplicates This is a temporary fix current functions failing to remove
|
// RemoveDuplicates This is a temporary fix current functions failing to remove
|
||||||
// Duplicate IP addresses from local IP table
|
// Duplicate IP addresses from local IP table
|
||||||
func (table *IpAddresses) RemoveDuplicates() error {
|
func (table *IpAddresses) RemoveDuplicates() error {
|
||||||
|
|
||||||
var NoDuplicates IpAddresses
|
var NoDuplicates IpAddresses
|
||||||
for i, _ := range table.IpAddress {
|
for i, _ := range table.IpAddress {
|
||||||
Exists := false
|
Exists := false
|
||||||
for k := range NoDuplicates.IpAddress {
|
for k := range NoDuplicates.IpAddress {
|
||||||
// Statements checked for
|
// Statements checked for
|
||||||
// - duplicate IPV4 addresses [<IPV4>:<Port No>]
|
// - duplicate IPV4 addresses [<IPV4>:<Port No>]
|
||||||
// - duplicate IPV6 addresses [<IPV6>]
|
// - duplicate IPV6 addresses [<IPV6>]
|
||||||
// - Node is behind NAT and no escape implementation provided
|
// - Node is behind NAT and no escape implementation provided
|
||||||
if (NoDuplicates.IpAddress[k].Ipv4 != "" && NoDuplicates.IpAddress[k].Ipv4 == table.IpAddress[i].Ipv4 &&
|
if (NoDuplicates.IpAddress[k].Ipv4 != "" && NoDuplicates.IpAddress[k].Ipv4 == table.IpAddress[i].Ipv4 &&
|
||||||
NoDuplicates.IpAddress[k].ServerPort == table.IpAddress[i].ServerPort) ||
|
NoDuplicates.IpAddress[k].ServerPort == table.IpAddress[i].ServerPort) ||
|
||||||
(NoDuplicates.IpAddress[k].Ipv6 != "" && NoDuplicates.IpAddress[k].Ipv6 == table.IpAddress[i].Ipv6) {
|
(NoDuplicates.IpAddress[k].Ipv6 != "" && NoDuplicates.IpAddress[k].Ipv6 == table.IpAddress[i].Ipv6) {
|
||||||
Exists = true
|
Exists = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if table.IpAddress[i].NAT == "True" && table.IpAddress[i].EscapeImplementation == "None" {
|
if table.IpAddress[i].NAT && table.IpAddress[i].EscapeImplementation == "None" {
|
||||||
Exists = true
|
Exists = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if Exists {
|
if Exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
NoDuplicates.IpAddress = append(NoDuplicates.IpAddress, table.IpAddress[i])
|
NoDuplicates.IpAddress = append(NoDuplicates.IpAddress, table.IpAddress[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
table.IpAddress = NoDuplicates.IpAddress
|
table.IpAddress = NoDuplicates.IpAddress
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentPublicIP Get Current Public IP address
|
// CurrentPublicIP Get Current Public IP address
|
||||||
func CurrentPublicIP() (string, error) {
|
func CurrentPublicIP() (string, error) {
|
||||||
req, err := http.Get("http://ip-api.com/json/")
|
// Get configs
|
||||||
if err != nil {
|
Config, err := config.ConfigInit(nil, nil)
|
||||||
return "", err
|
if err != nil {
|
||||||
}
|
return "", err
|
||||||
defer req.Body.Close()
|
}
|
||||||
|
// If test mode is on then return local address
|
||||||
|
if Config.Test {
|
||||||
|
return "0.0.0.0", nil
|
||||||
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(req.Body)
|
req, err := http.Get("http://ip-api.com/json/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer req.Body.Close()
|
||||||
|
|
||||||
var ip IP
|
body, err := ioutil.ReadAll(req.Body)
|
||||||
json.Unmarshal(body, &ip)
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var ip IP
|
||||||
|
json.Unmarshal(body, &ip)
|
||||||
|
|
||||||
|
return ip.Query, nil
|
||||||
|
|
||||||
return ip.Query, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentIPV6 gets the current IPV6 address based on the interface
|
// GetCurrentIPV6 gets the current IPV6 address based on the interface
|
||||||
// specified in the config file
|
// specified in the config file
|
||||||
func GetCurrentIPV6() (string, error) {
|
func GetCurrentIPV6() (string, error) {
|
||||||
Config, err := config.ConfigInit(nil, nil)
|
Config, err := config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix in future release
|
// Fix in future release
|
||||||
//byNameInterface, err := net.InterfaceByName(Config.NetworkInterface)
|
//byNameInterface, err := net.InterfaceByName(Config.NetworkInterface)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return "",err
|
// return "",err
|
||||||
//}
|
//}
|
||||||
//addresses, err := byNameInterface.Addrs()
|
//addresses, err := byNameInterface.Addrs()
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return "",err
|
// return "",err
|
||||||
//}
|
//}
|
||||||
//if addresses[1].String() == "" {
|
//if addresses[1].String() == "" {
|
||||||
// return "",errors.New("IPV6 address not detected")
|
// return "",errors.New("IPV6 address not detected")
|
||||||
//}
|
//}
|
||||||
//IP,_,err := net.ParseCIDR(addresses[Config.NetworkInterfaceIPV6Index].String())
|
//IP,_,err := net.ParseCIDR(addresses[Config.NetworkInterfaceIPV6Index].String())
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return "",err
|
// return "",err
|
||||||
//}
|
//}
|
||||||
|
|
||||||
return Config.IPV6Address, nil
|
return Config.IPV6Address, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ViewNetworkInterface This function is created to view the network interfaces available
|
// ViewNetworkInterface This function is created to view the network interfaces available
|
||||||
func ViewNetworkInterface() error {
|
func ViewNetworkInterface() error {
|
||||||
ifaces, err := net.Interfaces()
|
ifaces, err := net.Interfaces()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, i := range ifaces {
|
for _, i := range ifaces {
|
||||||
addrs, err := i.Addrs()
|
addrs, err := i.Addrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for index, a := range addrs {
|
for index, a := range addrs {
|
||||||
switch v := a.(type) {
|
switch v := a.(type) {
|
||||||
case *net.IPAddr:
|
case *net.IPAddr:
|
||||||
fmt.Printf("(%v) %v : %s (%s)\n", index, i.Name, v, v.IP.DefaultMask())
|
fmt.Printf("(%v) %v : %s (%s)\n", index, i.Name, v, v.IP.DefaultMask())
|
||||||
|
|
||||||
case *net.IPNet:
|
case *net.IPNet:
|
||||||
fmt.Printf("(%v) %v : %s \n", index, i.Name, v)
|
fmt.Printf("(%v) %v : %s \n", index, i.Name, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ip4or6 Helper function to check if the IP address is IPV4 or
|
// Ip4or6 Helper function to check if the IP address is IPV4 or
|
||||||
// IPV6 (https://socketloop.com/tutorials/golang-check-if-ip-address-is-version-4-or-6)
|
// IPV6 (https://socketloop.com/tutorials/golang-check-if-ip-address-is-version-4-or-6)
|
||||||
func Ip4or6(s string) string {
|
func Ip4or6(s string) string {
|
||||||
for i := 0; i < len(s); i++ {
|
for i := 0; i < len(s); i++ {
|
||||||
switch s[i] {
|
switch s[i] {
|
||||||
case '.':
|
case '.':
|
||||||
return "version 4"
|
return "version 4"
|
||||||
case ':':
|
case ':':
|
||||||
return "version 6"
|
return "version 6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "version 6"
|
return "version 6"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrettyPrint(data interface{}) {
|
func PrettyPrint(data interface{}) {
|
||||||
var p []byte
|
var p []byte
|
||||||
// var err := error
|
// var err := error
|
||||||
p, err := json.MarshalIndent(data, "", "\t")
|
p, err := json.MarshalIndent(data, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("%s \n", p)
|
fmt.Printf("%s \n", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateHashSHA256(text string) []byte {
|
func GenerateHashSHA256(text string) []byte {
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write([]byte(text))
|
h.Write([]byte(text))
|
||||||
|
|
||||||
return h.Sum(nil)
|
return h.Sum(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateHashSHA256 CustomInformationKey the text and check if the text and
|
// ValidateHashSHA256 CustomInformationKey the text and check if the text and
|
||||||
@@ -287,12 +300,12 @@ func GenerateHashSHA256(text string) []byte {
|
|||||||
// SHA256 is the current hashing algorthm
|
// SHA256 is the current hashing algorthm
|
||||||
// used.
|
// used.
|
||||||
func ValidateHashSHA256(text string, Hash []byte) bool {
|
func ValidateHashSHA256(text string, Hash []byte) bool {
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write([]byte(text))
|
h.Write([]byte(text))
|
||||||
|
|
||||||
textHash := h.Sum(nil)
|
textHash := h.Sum(nil)
|
||||||
if bytes.Equal(textHash, Hash) {
|
if bytes.Equal(textHash, Hash) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
187
p2p/speedtest.go
187
p2p/speedtest.go
@@ -1,136 +1,137 @@
|
|||||||
package p2p
|
package p2p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SpeedTest Runs a speed test and does updates IP tables accordingly
|
// SpeedTest Runs a speed test and does updates IP tables accordingly
|
||||||
func (ip *IpAddresses) SpeedTest() error {
|
func (ip *IpAddresses) SpeedTest() error {
|
||||||
|
|
||||||
//temp variable to store elements IP addresses and other information
|
//temp variable to store elements IP addresses and other information
|
||||||
// of IP addresses that are pingable
|
// of IP addresses that are pingable
|
||||||
var ActiveIP IpAddresses
|
var ActiveIP IpAddresses
|
||||||
|
|
||||||
// Index to remove from struct
|
// Index to remove from struct
|
||||||
for _, value := range ip.IpAddress {
|
for _, value := range ip.IpAddress {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
//if len(ip.IpAddress) == 1 {
|
//if len(ip.IpAddress) == 1 {
|
||||||
// i = 0
|
// i = 0
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Ping Test
|
// Ping Test
|
||||||
err = value.PingTest()
|
err = value.PingTest()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
//Upload Speed Test
|
//Upload Speed Test
|
||||||
//err = value.UploadSpeed()
|
//err = value.UploadSpeed()
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return err
|
// return err
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//err = value.DownloadSpeed()
|
//err = value.DownloadSpeed()
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return err
|
// return err
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//Set value to the list
|
//Set value to the list
|
||||||
|
|
||||||
ActiveIP.IpAddress = append(ActiveIP.IpAddress, value)
|
ActiveIP.IpAddress = append(ActiveIP.IpAddress, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
ip.IpAddress = ActiveIP.IpAddress
|
ip.IpAddress = ActiveIP.IpAddress
|
||||||
|
|
||||||
err := ip.WriteIpTable()
|
err := ip.WriteIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpeedTestUpdatedIPTable Called when ip tables from httpclient/server is also passed on
|
// SpeedTestUpdatedIPTable Called when ip tables from httpclient/server is also passed on
|
||||||
func (ip *IpAddresses) SpeedTestUpdatedIPTable() error {
|
func (ip *IpAddresses) SpeedTestUpdatedIPTable() error {
|
||||||
|
|
||||||
Config, err := config.ConfigInit(nil, nil)
|
Config, err := config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
targets, err := ReadIpTable()
|
targets, err := ReadIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if baremetal mode and unsafe mode
|
// Checks if baremetal mode and unsafe mode
|
||||||
// is enabled. If it is enabled it adds the
|
// is enabled. If it is enabled it adds the
|
||||||
// the propagated public key to the list.
|
// the propagated public key to the list.
|
||||||
|
|
||||||
AddPublicKey := false
|
AddPublicKey := false
|
||||||
if Config.BareMetal && Config.UnsafeMode {
|
if Config.BareMetal && Config.UnsafeMode {
|
||||||
AddPublicKey = true
|
AddPublicKey = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// To ensure struct has no duplicates IP addresses
|
// To ensure struct has no duplicates IP addresses
|
||||||
//DoNotRead := targets
|
//DoNotRead := targets
|
||||||
|
|
||||||
// Appends all IP addresses
|
// Appends all IP addresses
|
||||||
for i, _ := range targets.IpAddress {
|
for i, _ := range targets.IpAddress {
|
||||||
|
|
||||||
//To ensure that there are no duplicate IP addresses
|
//To ensure that there are no duplicate IP addresses
|
||||||
Exists := false
|
Exists := false
|
||||||
for k := range ip.IpAddress {
|
for k := range ip.IpAddress {
|
||||||
if AddPublicKey && ip.IpAddress[k].PublicKey != "" {
|
if AddPublicKey && ip.IpAddress[k].PublicKey != "" {
|
||||||
// This function call (AddAuthorisationKey) is inefficient but to be optimised later on.
|
// This function call (AddAuthorisationKey) is inefficient but to be optimised later on.
|
||||||
// This is because when if the user is running on as unsafe mode the authorization file
|
// This is because when if the user is running on as unsafe mode the authorization file
|
||||||
// is opened from the SSH directory and then iterates through every single SSH entry
|
// is opened from the SSH directory and then iterates through every single SSH entry
|
||||||
// to find out if the SSH entry exists or not. This will incur multiple CPU cycles
|
// to find out if the SSH entry exists or not. This will incur multiple CPU cycles
|
||||||
// for no reason. A better approach would be to have been to store the states on memory and only
|
// for no reason. A better approach would be to have been to store the states on memory and only
|
||||||
// add when needed based on the memory location. This is something is to be discussed
|
// add when needed based on the memory location. This is something is to be discussed
|
||||||
// and look upon later on.
|
// and look upon later on.
|
||||||
AddAuthorisationKey(ip.IpAddress[k].PublicKey)
|
AddAuthorisationKey(ip.IpAddress[k].PublicKey)
|
||||||
}
|
}
|
||||||
// Checks if both the IPV4 addresses are the same or the IPV6 address is not
|
targets.IpAddress[i].CustomInformation = ip.IpAddress[k].CustomInformation
|
||||||
// an empty string and IPV6 address are the same
|
// Checks if both the IPV4 addresses are the same or the IPV6 address is not
|
||||||
if (ip.IpAddress[k].Ipv4 == targets.IpAddress[i].Ipv4 && targets.IpAddress[i].NAT == "True") || (targets.IpAddress[i].Ipv6 != "" && ip.IpAddress[k].Ipv6 == targets.IpAddress[i].Ipv6) {
|
// an empty string and IPV6 address are the same
|
||||||
Exists = true
|
if (ip.IpAddress[k].Ipv4 == targets.IpAddress[i].Ipv4 && targets.IpAddress[i].NAT) || (targets.IpAddress[i].Ipv6 != "" && ip.IpAddress[k].Ipv6 == targets.IpAddress[i].Ipv6) {
|
||||||
break
|
Exists = true
|
||||||
}
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If the struct exists then continues
|
// If the struct exists then continues
|
||||||
if Exists {
|
if Exists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ip.IpAddress = append(ip.IpAddress, targets.IpAddress[i])
|
ip.IpAddress = append(ip.IpAddress, targets.IpAddress[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ip.SpeedTest()
|
err = ip.SpeedTest()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalSpeedTestIpTable Runs speed test in iptables locally only
|
// LocalSpeedTestIpTable Runs speed test in iptables locally only
|
||||||
func LocalSpeedTestIpTable() error {
|
func LocalSpeedTestIpTable() error {
|
||||||
targets, err := ReadIpTable()
|
targets, err := ReadIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = targets.SpeedTest()
|
err = targets.SpeedTest()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to remove element from an array of a struct
|
// Helper function to remove element from an array of a struct
|
||||||
|
|||||||
785
server/server.go
785
server/server.go
@@ -1,480 +1,477 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
b64 "encoding/base64"
|
b64 "encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/p2p/frp"
|
"github.com/Akilan1999/p2p-rendering-computation/p2p/frp"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/server/docker"
|
"github.com/Akilan1999/p2p-rendering-computation/server/docker"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
"io/ioutil"
|
||||||
"io/ioutil"
|
"net/http"
|
||||||
"net"
|
"os/user"
|
||||||
"net/http"
|
"strconv"
|
||||||
"os/user"
|
"time"
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReverseProxy struct {
|
type ReverseProxy struct {
|
||||||
IPAddress string
|
IPAddress string
|
||||||
Port string
|
Port string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReverseProxies Reverse to the map such as ReverseProxies[<domain nane>]ReverseProxy type
|
// ReverseProxies Reverse to the map such as ReverseProxies[<domain nane>]ReverseProxy type
|
||||||
var ReverseProxies map[string]ReverseProxy
|
var ReverseProxies map[string]ReverseProxy
|
||||||
|
|
||||||
func Server() (*gin.Engine, error) {
|
func Server() (*gin.Engine, error) {
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
||||||
// "The make function allocates and initializes a hash map data
|
// "The make function allocates and initializes a hash map data
|
||||||
//structure and returns a map value that points to it.
|
//structure and returns a map value that points to it.
|
||||||
//The specifics of that data structure are an implementation
|
//The specifics of that data structure are an implementation
|
||||||
//detail of the runtime and are not specified by the language itself."
|
//detail of the runtime and are not specified by the language itself."
|
||||||
// source: https://go.dev/blog/maps
|
// source: https://go.dev/blog/maps
|
||||||
ReverseProxies = make(map[string]ReverseProxy)
|
ReverseProxies = make(map[string]ReverseProxy)
|
||||||
|
|
||||||
//Get Server port based on the config file
|
//Get Server port based on the config file
|
||||||
config, err := config.ConfigInit(nil, nil)
|
config, err := config.ConfigInit(nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// update IPTable with new port and ip address and update ip table
|
// update IPTable with new port and ip address and update ip table
|
||||||
var ProxyIpAddr p2p.IpAddress
|
var ProxyIpAddr p2p.IpAddress
|
||||||
var lowestLatencyIpAddress p2p.IpAddress
|
var lowestLatencyIpAddress p2p.IpAddress
|
||||||
|
|
||||||
// Gets default information of the server
|
// Gets default information of the server
|
||||||
r.GET("/server_info", func(c *gin.Context) {
|
r.GET("/server_info", func(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, ServerInfo())
|
c.JSON(http.StatusOK, ServerInfo())
|
||||||
})
|
})
|
||||||
|
|
||||||
// Speed test with 50 mbps
|
// Speed test with 50 mbps
|
||||||
r.GET("/50", func(c *gin.Context) {
|
r.GET("/50", func(c *gin.Context) {
|
||||||
// Get Path from config
|
// Get Path from config
|
||||||
c.File(config.SpeedTestFile)
|
c.File(config.SpeedTestFile)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Route build to do a speed test
|
// Route build to do a speed test
|
||||||
r.GET("/upload", func(c *gin.Context) {
|
r.GET("/upload", func(c *gin.Context) {
|
||||||
file, _ := c.FormFile("file")
|
file, _ := c.FormFile("file")
|
||||||
|
|
||||||
// Upload the file to specific dst.
|
// Upload the file to specific dst.
|
||||||
// c.SaveUploadedFile(file, dst)
|
// c.SaveUploadedFile(file, dst)
|
||||||
|
|
||||||
c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))
|
c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))
|
||||||
})
|
})
|
||||||
|
|
||||||
//Gets Ip Table from server node
|
//Gets Ip Table from server node
|
||||||
r.POST("/IpTable", func(c *gin.Context) {
|
r.POST("/IpTable", func(c *gin.Context) {
|
||||||
// Getting IPV4 address of client
|
// Getting IPV4 address of client
|
||||||
//var ClientHost p2p.IpAddress
|
//var ClientHost p2p.IpAddress
|
||||||
//
|
//
|
||||||
//if p2p.Ip4or6(c.ClientIP()) == "version 6" {
|
//if p2p.Ip4or6(c.ClientIP()) == "version 6" {
|
||||||
// ClientHost.Ipv6 = c.ClientIP()
|
// ClientHost.Ipv6 = c.ClientIP()
|
||||||
//} else {
|
//} else {
|
||||||
// ClientHost.Ipv4 = c.ClientIP()
|
// ClientHost.Ipv4 = c.ClientIP()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Variable to store IP table information
|
// Variable to store IP table information
|
||||||
var IPTable p2p.IpAddresses
|
var IPTable p2p.IpAddresses
|
||||||
|
|
||||||
// Receive file from POST request
|
// Receive file from POST request
|
||||||
body, err := c.FormFile("json")
|
body, err := c.FormFile("json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusOK, fmt.Sprint(err))
|
c.String(http.StatusOK, fmt.Sprint(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
open, err := body.Open()
|
open, err := body.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusOK, fmt.Sprint(err))
|
c.String(http.StatusOK, fmt.Sprint(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open received file
|
// Open received file
|
||||||
file, err := ioutil.ReadAll(open)
|
file, err := ioutil.ReadAll(open)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusOK, fmt.Sprint(err))
|
c.String(http.StatusOK, fmt.Sprint(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
json.Unmarshal(file, &IPTable)
|
json.Unmarshal(file, &IPTable)
|
||||||
|
|
||||||
//Add Client IP address to IPTable struct
|
//Add Client IP address to IPTable struct
|
||||||
//IPTable.IpAddress = append(IPTable.IpAddress, ClientHost)
|
//IPTable.IpAddress = append(IPTable.IpAddress, ClientHost)
|
||||||
|
|
||||||
// Runs speed test to return only servers in the IP table pingable
|
// Runs speed test to return only servers in the IP table pingable
|
||||||
err = IPTable.SpeedTestUpdatedIPTable()
|
err = IPTable.SpeedTestUpdatedIPTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusOK, fmt.Sprint(err))
|
c.String(http.StatusOK, fmt.Sprint(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads IP addresses from ip table
|
// Reads IP addresses from ip table
|
||||||
IpAddresses, err := p2p.ReadIpTable()
|
IpAddresses, err := p2p.ReadIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusOK, fmt.Sprint(err))
|
c.String(http.StatusOK, fmt.Sprint(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, IpAddresses)
|
c.JSON(http.StatusOK, IpAddresses)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Starts docker container in server
|
// Starts docker container in server
|
||||||
r.GET("/startcontainer", func(c *gin.Context) {
|
r.GET("/startcontainer", func(c *gin.Context) {
|
||||||
// Get Number of ports to open and whether to use GPU or not
|
// Get Number of ports to open and whether to use GPU or not
|
||||||
Ports := c.DefaultQuery("ports", "0")
|
Ports := c.DefaultQuery("ports", "0")
|
||||||
GPU := c.DefaultQuery("GPU", "false")
|
GPU := c.DefaultQuery("GPU", "false")
|
||||||
ContainerName := c.DefaultQuery("ContainerName", "")
|
ContainerName := c.DefaultQuery("ContainerName", "")
|
||||||
BaseImage := c.DefaultQuery("BaseImage", "")
|
BaseImage := c.DefaultQuery("BaseImage", "")
|
||||||
PublicKey := c.DefaultQuery("PublicKey", "")
|
PublicKey := c.DefaultQuery("PublicKey", "")
|
||||||
var PortsInt int
|
var PortsInt int
|
||||||
|
|
||||||
if PublicKey == "" {
|
if PublicKey == "" {
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", "Publickey not passed"))
|
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", "Publickey not passed"))
|
||||||
}
|
}
|
||||||
|
|
||||||
PublicKeyDecoded, err := b64.StdEncoding.DecodeString(PublicKey)
|
PublicKeyDecoded, err := b64.StdEncoding.DecodeString(PublicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Get Request value to int
|
// Convert Get Request value to int
|
||||||
fmt.Sscanf(Ports, "%d", &PortsInt)
|
fmt.Sscanf(Ports, "%d", &PortsInt)
|
||||||
|
|
||||||
fmt.Println(string(PublicKeyDecoded[:]))
|
// Creates container and returns-back result to
|
||||||
|
// access container
|
||||||
|
resp, err := docker.BuildRunContainer(PortsInt, GPU, ContainerName, BaseImage, string(PublicKeyDecoded[:]))
|
||||||
|
|
||||||
// Creates container and returns-back result to
|
if err != nil {
|
||||||
// access container
|
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||||
resp, err := docker.BuildRunContainer(PortsInt, GPU, ContainerName, BaseImage, string(PublicKeyDecoded[:]))
|
}
|
||||||
|
|
||||||
if err != nil {
|
// Ensures that FRP is triggered only if a proxy address is provided
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
if ProxyIpAddr.Ipv4 != "" && c.Request.Host != "localhost:"+config.ServerPort && c.Request.Host != "0.0.0.0:"+config.ServerPort {
|
||||||
}
|
resp, err = frp.StartFRPCDockerContainer(ProxyIpAddr.Ipv4, lowestLatencyIpAddress.ServerPort, resp)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensures that FRP is triggered only if a proxy address is provided
|
c.JSON(http.StatusOK, resp)
|
||||||
if ProxyIpAddr.Ipv4 != "" && c.Request.Host != "localhost:"+config.ServerPort && c.Request.Host != "0.0.0.0:"+config.ServerPort {
|
})
|
||||||
resp, err = frp.StartFRPCDockerContainer(ProxyIpAddr.Ipv4, lowestLatencyIpAddress.ServerPort, resp)
|
|
||||||
if err != nil {
|
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, resp)
|
//Remove container
|
||||||
})
|
r.GET("/RemoveContainer", func(c *gin.Context) {
|
||||||
|
ID := c.DefaultQuery("id", "0")
|
||||||
|
if err := docker.StopAndRemoveContainer(ID); err != nil {
|
||||||
|
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||||
|
}
|
||||||
|
c.String(http.StatusOK, "success")
|
||||||
|
})
|
||||||
|
|
||||||
//Remove container
|
//Show images available
|
||||||
r.GET("/RemoveContainer", func(c *gin.Context) {
|
r.GET("/ShowImages", func(c *gin.Context) {
|
||||||
ID := c.DefaultQuery("id", "0")
|
resp, err := docker.ViewAllContainers()
|
||||||
if err := docker.StopAndRemoveContainer(ID); err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||||
}
|
}
|
||||||
c.String(http.StatusOK, "success")
|
c.JSON(http.StatusOK, resp)
|
||||||
})
|
})
|
||||||
|
|
||||||
//Show images available
|
// Request for port no from Server with address
|
||||||
r.GET("/ShowImages", func(c *gin.Context) {
|
r.GET("/FRPPort", func(c *gin.Context) {
|
||||||
resp, err := docker.ViewAllContainers()
|
port, err := frp.StartFRPProxyFromRandom()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, resp)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Request for port no from Server with address
|
c.String(http.StatusOK, strconv.Itoa(port))
|
||||||
r.GET("/FRPPort", func(c *gin.Context) {
|
})
|
||||||
port, err := frp.StartFRPProxyFromRandom()
|
|
||||||
if err != nil {
|
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
c.String(http.StatusOK, strconv.Itoa(port))
|
r.GET("/MAPPort", func(c *gin.Context) {
|
||||||
})
|
Ports := c.DefaultQuery("port", "0")
|
||||||
|
DomainName := c.DefaultQuery("domain_name", "")
|
||||||
|
url, _, err := MapPort(Ports, DomainName)
|
||||||
|
if err != nil {
|
||||||
|
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||||
|
}
|
||||||
|
|
||||||
r.GET("/MAPPort", func(c *gin.Context) {
|
c.String(http.StatusOK, url)
|
||||||
Ports := c.DefaultQuery("port", "0")
|
})
|
||||||
DomainName := c.DefaultQuery("domain_name", "")
|
|
||||||
url, _, err := MapPort(Ports, DomainName, "")
|
|
||||||
if err != nil {
|
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
c.String(http.StatusOK, url)
|
r.GET("/AddProxy", func(c *gin.Context) {
|
||||||
})
|
DomainName := c.DefaultQuery("domain_name", "")
|
||||||
|
ip_address := c.DefaultQuery("ip_address", "")
|
||||||
|
Ports := c.DefaultQuery("port", "")
|
||||||
|
|
||||||
r.GET("/AddProxy", func(c *gin.Context) {
|
if DomainName == "" || ip_address == "" || Ports == "" {
|
||||||
DomainName := c.DefaultQuery("domain_name", "")
|
c.String(http.StatusInternalServerError, fmt.Sprintf("All get parameters npt provided"+
|
||||||
ip_address := c.DefaultQuery("ip_address", "")
|
" do ensure domain_name, ip_Address and port no is provided"))
|
||||||
Ports := c.DefaultQuery("port", "")
|
}
|
||||||
|
|
||||||
if DomainName == "" || ip_address == "" || Ports == "" {
|
err := SaveRegistration(DomainName, ip_address+":"+Ports)
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf("All get parameters npt provided"+
|
if err != nil {
|
||||||
" do ensure domain_name, ip_Address and port no is provided"))
|
c.String(http.StatusInternalServerError, fmt.Sprintf(err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
err := SaveRegistration(DomainName, ip_address+":"+Ports)
|
//_, ok := ReverseProxies[DomainName]
|
||||||
if err != nil {
|
//// To check if the subdomain entry exists
|
||||||
c.String(http.StatusInternalServerError, fmt.Sprintf(err.Error()))
|
//if ok {
|
||||||
}
|
// c.String(http.StatusInternalServerError, fmt.Sprintf("The domain entry already exists as a reverse"+
|
||||||
|
// " proxy entry"))
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//// added proxy as a map entry
|
||||||
|
//ReverseProxies[DomainName] = ReverseProxy{IPAddress: ip_address, Port: Ports}
|
||||||
|
c.String(http.StatusOK, "Sucess")
|
||||||
|
|
||||||
//_, ok := ReverseProxies[DomainName]
|
})
|
||||||
//// To check if the subdomain entry exists
|
|
||||||
//if ok {
|
|
||||||
// c.String(http.StatusInternalServerError, fmt.Sprintf("The domain entry already exists as a reverse"+
|
|
||||||
// " proxy entry"))
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//// added proxy as a map entry
|
|
||||||
//ReverseProxies[DomainName] = ReverseProxy{IPAddress: ip_address, Port: Ports}
|
|
||||||
c.String(http.StatusOK, "Sucess")
|
|
||||||
|
|
||||||
})
|
//r.GET("/RemoveProxy", func(c *gin.Context) {
|
||||||
|
// DomainName := c.DefaultQuery("domain_name", "")
|
||||||
|
//
|
||||||
|
// _, ok := ReverseProxies[DomainName]
|
||||||
|
// if !ok {
|
||||||
|
// c.String(http.StatusInternalServerError, fmt.Sprintf("Domain name does exist in entries of proxies"))
|
||||||
|
// } else {
|
||||||
|
// delete(ReverseProxies, DomainName)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//})
|
||||||
|
|
||||||
//r.GET("/RemoveProxy", func(c *gin.Context) {
|
// If there is a proxy port specified
|
||||||
// DomainName := c.DefaultQuery("domain_name", "")
|
// then starts the FRP server
|
||||||
//
|
//if config.FRPServerPort != "0" {
|
||||||
// _, ok := ReverseProxies[DomainName]
|
// go frp.StartFRPProxyFromRandom()
|
||||||
// if !ok {
|
//}
|
||||||
// c.String(http.StatusInternalServerError, fmt.Sprintf("Domain name does exist in entries of proxies"))
|
|
||||||
// } else {
|
|
||||||
// delete(ReverseProxies, DomainName)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//})
|
|
||||||
|
|
||||||
// If there is a proxy port specified
|
// Remove nodes currently not pingable
|
||||||
// then starts the FRP server
|
clientIPTable.RemoveOfflineNodes()
|
||||||
//if config.FRPServerPort != "0" {
|
|
||||||
// go frp.StartFRPProxyFromRandom()
|
|
||||||
//}
|
|
||||||
|
|
||||||
// Remove nodes currently not pingable
|
table, err := p2p.ReadIpTable()
|
||||||
clientIPTable.RemoveOfflineNodes()
|
|
||||||
|
|
||||||
table, err := p2p.ReadIpTable()
|
// TODO check if IPV6 or Proxy port is specified
|
||||||
|
// if not update current entry as proxy address
|
||||||
|
// with appropriate port on IP Table
|
||||||
|
if config.BehindNAT {
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// TODO check if IPV6 or Proxy port is specified
|
var lowestLatency int64
|
||||||
// if not update current entry as proxy address
|
// random large number
|
||||||
// with appropriate port on IP Table
|
lowestLatency = 10000000
|
||||||
if config.BehindNAT == "True" {
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var lowestLatency int64
|
for i, _ := range table.IpAddress {
|
||||||
// random large number
|
// Checks if the ping is the lowest and if the following node is acting as a proxy
|
||||||
lowestLatency = 10000000
|
//if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].ProxyPort != "" {
|
||||||
|
if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && !table.IpAddress[i].NAT {
|
||||||
|
lowestLatency = table.IpAddress[i].Latency.Milliseconds()
|
||||||
|
lowestLatencyIpAddress = table.IpAddress[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for i, _ := range table.IpAddress {
|
// If there is an identified node
|
||||||
// Checks if the ping is the lowest and if the following node is acting as a proxy
|
if lowestLatency != 10000000 {
|
||||||
//if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].ProxyPort != "" {
|
serverPort, err := frp.GetFRPServerPort("http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort)
|
||||||
if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].NAT != "" {
|
if err != nil {
|
||||||
lowestLatency = table.IpAddress[i].Latency.Milliseconds()
|
return nil, err
|
||||||
lowestLatencyIpAddress = table.IpAddress[i]
|
}
|
||||||
}
|
// Create 3 second delay to allow FRP server to start
|
||||||
}
|
time.Sleep(1 * time.Second)
|
||||||
|
// Starts FRP as a client with
|
||||||
|
proxyPort, err := frp.StartFRPClientForServer(lowestLatencyIpAddress.Ipv4, serverPort, config.ServerPort, "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// If there is an identified node
|
// updating with the current proxy address
|
||||||
if lowestLatency != 10000000 {
|
ProxyIpAddr.Ipv4 = lowestLatencyIpAddress.Ipv4
|
||||||
serverPort, err := frp.GetFRPServerPort("http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort)
|
ProxyIpAddr.ServerPort = proxyPort
|
||||||
if err != nil {
|
ProxyIpAddr.Name = config.MachineName
|
||||||
return nil, err
|
ProxyIpAddr.NAT = false
|
||||||
}
|
ProxyIpAddr.ProxyServer = false
|
||||||
// Create 3 second delay to allow FRP server to start
|
ProxyIpAddr.EscapeImplementation = "FRP"
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
// Starts FRP as a client with
|
|
||||||
proxyPort, err := frp.StartFRPClientForServer(lowestLatencyIpAddress.Ipv4, serverPort, config.ServerPort, "")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// updating with the current proxy address
|
if config.BareMetal {
|
||||||
ProxyIpAddr.Ipv4 = lowestLatencyIpAddress.Ipv4
|
_, SSHPort, err := MapPort("22", "")
|
||||||
ProxyIpAddr.ServerPort = proxyPort
|
if err != nil {
|
||||||
ProxyIpAddr.Name = config.MachineName
|
return nil, err
|
||||||
ProxyIpAddr.NAT = "False"
|
}
|
||||||
ProxyIpAddr.ProxyServer = "False"
|
ProxyIpAddr.BareMetalSSHPort = SSHPort
|
||||||
ProxyIpAddr.EscapeImplementation = "FRP"
|
}
|
||||||
|
|
||||||
if config.BareMetal {
|
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
||||||
_, SSHPort, err := MapPort("22", "", "")
|
// write information back to the IP Table
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ProxyIpAddr.BareMetalSSHPort = SSHPort
|
|
||||||
}
|
|
||||||
|
|
||||||
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
} else {
|
||||||
// write information back to the IP Table
|
ProxyIpAddr.Ipv4, err = p2p.CurrentPublicIP()
|
||||||
}
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
ProxyIpAddr.ServerPort = config.ServerPort
|
||||||
ProxyIpAddr.Ipv4, err = p2p.CurrentPublicIP()
|
ProxyIpAddr.Name = config.MachineName
|
||||||
if err != nil {
|
ProxyIpAddr.NAT = false
|
||||||
fmt.Println(err)
|
if config.ProxyPort != "" {
|
||||||
}
|
ProxyIpAddr.ProxyServer = true
|
||||||
ProxyIpAddr.ServerPort = config.ServerPort
|
}
|
||||||
ProxyIpAddr.Name = config.MachineName
|
ProxyIpAddr.EscapeImplementation = ""
|
||||||
ProxyIpAddr.NAT = "False"
|
if config.BareMetal {
|
||||||
if config.ProxyPort != "" {
|
ProxyIpAddr.BareMetalSSHPort = "22"
|
||||||
ProxyIpAddr.ProxyServer = "True"
|
}
|
||||||
}
|
|
||||||
ProxyIpAddr.EscapeImplementation = ""
|
|
||||||
if config.BareMetal {
|
|
||||||
ProxyIpAddr.BareMetalSSHPort = "22"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get machine username
|
// Get machine username
|
||||||
currentUser, err := user.Current()
|
currentUser, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Add username p2prc binary is being run under
|
// Add username p2prc binary is being run under
|
||||||
ProxyIpAddr.MachineUsername = currentUser.Username
|
ProxyIpAddr.MachineUsername = currentUser.Username
|
||||||
ProxyIpAddr.UnSafeMode = config.UnsafeMode
|
ProxyIpAddr.UnSafeMode = config.UnsafeMode
|
||||||
// Adds the public key information to the IPTable
|
// Adds the public key information to the IPTable
|
||||||
// improving transmission of IPTables without the
|
// improving transmission of IPTables without the
|
||||||
// entire public key is future work to be improved
|
// entire public key is future work to be improved
|
||||||
// in the P2PRC protocol level (Improving by adding
|
// in the P2PRC protocol level (Improving by adding
|
||||||
// UDP with TCP reliability layer).
|
// UDP with TCP reliability layer).
|
||||||
ProxyIpAddr.PublicKey, err = config.GetPublicKey()
|
ProxyIpAddr.PublicKey, err = config.GetPublicKey()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// append the following to the ip table
|
// append the following to the ip table
|
||||||
table.IpAddress = append(table.IpAddress, ProxyIpAddr)
|
table.IpAddress = append(table.IpAddress, ProxyIpAddr)
|
||||||
|
|
||||||
// Writing results to the IPTable
|
// Writing results to the IPTable
|
||||||
err = table.WriteIpTable()
|
err = table.WriteIpTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// update ip table
|
// update ip table
|
||||||
go func() error {
|
go func() error {
|
||||||
err := clientIPTable.UpdateIpTableListClient()
|
err := clientIPTable.UpdateIpTableListClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if config.ProxyPort != "" {
|
if config.ProxyPort != "" {
|
||||||
go ProxyRun(config.ProxyPort)
|
go ProxyRun(config.ProxyPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run gin server on the specified port
|
// Run gin server on the specified port
|
||||||
go r.Run(":" + config.ServerPort)
|
go r.Run(":" + config.ServerPort)
|
||||||
|
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func MapPort(port string, domainName string, serverAddress string) (string, string, error) {
|
func MapPort(port string, domainName string) (string, string, error) {
|
||||||
|
|
||||||
// if server address is provided to do call RESTAPI to remotely open port.
|
// if server address is provided to do call RESTAPI to remotely open port.
|
||||||
if serverAddress != "" {
|
//if serverAddress != "" {
|
||||||
requestURL := fmt.Sprintf("http://%v/MAPPort?port=%v&domain_name=%v", serverAddress, port, domainName)
|
// requestURL := fmt.Sprintf("http://%v/MAPPort?port=%v&domain_name=%v", serverAddress, port, domainName)
|
||||||
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
|
// req, err := http.NewRequest(http.MethodGet, requestURL, nil)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return "", "", err
|
// return "", "", err
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// res, err := http.DefaultClient.Do(req)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", "", err
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// resBody, err := io.ReadAll(res.Body)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", "", err
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// _, Exposedport, err := net.SplitHostPort(string(resBody))
|
||||||
|
// if err != nil {
|
||||||
|
// return "", "", err
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return string(resBody), Exposedport, nil
|
||||||
|
//}
|
||||||
|
|
||||||
res, err := http.DefaultClient.Do(req)
|
//Get Server port based on the config file
|
||||||
if err != nil {
|
config, err := config.ConfigInit(nil, nil)
|
||||||
return "", "", err
|
if err != nil {
|
||||||
}
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
resBody, err := io.ReadAll(res.Body)
|
// update IPTable with new port and ip address and update ip table
|
||||||
if err != nil {
|
var ProxyIpAddr p2p.IpAddress
|
||||||
return "", "", err
|
var lowestLatencyIpAddress p2p.IpAddress
|
||||||
}
|
|
||||||
|
|
||||||
_, Exposedport, err := net.SplitHostPort(string(resBody))
|
clientIPTable.RemoveOfflineNodes()
|
||||||
if err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(resBody), Exposedport, nil
|
table, err := p2p.ReadIpTable()
|
||||||
}
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
//Get Server port based on the config file
|
var lowestLatency int64
|
||||||
config, err := config.ConfigInit(nil, nil)
|
// random large number
|
||||||
if err != nil {
|
lowestLatency = 10000000
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
// update IPTable with new port and ip address and update ip table
|
for i, _ := range table.IpAddress {
|
||||||
var ProxyIpAddr p2p.IpAddress
|
// Checks if the ping is the lowest and if the following node is acting as a proxy
|
||||||
var lowestLatencyIpAddress p2p.IpAddress
|
//if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].ProxyPort != "" {
|
||||||
|
if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && !table.IpAddress[i].NAT {
|
||||||
|
// Filter based on nodes with proxy enabled
|
||||||
|
if domainName != "" && table.IpAddress[i].ProxyServer {
|
||||||
|
lowestLatency = table.IpAddress[i].Latency.Milliseconds()
|
||||||
|
lowestLatencyIpAddress = table.IpAddress[i]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
lowestLatency = table.IpAddress[i].Latency.Milliseconds()
|
||||||
|
lowestLatencyIpAddress = table.IpAddress[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clientIPTable.RemoveOfflineNodes()
|
// If there is an identified node
|
||||||
|
if lowestLatency != 10000000 {
|
||||||
|
serverPort, err := frp.GetFRPServerPort("http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
// Create 3 second delay to allow FRP server to start
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
// Starts FRP as a client with
|
||||||
|
proxyPort, err := frp.StartFRPClientForServer(lowestLatencyIpAddress.Ipv4, serverPort, port, "")
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
table, err := p2p.ReadIpTable()
|
// Doing the proxy mapping for the domain name
|
||||||
if err != nil {
|
if domainName != "" {
|
||||||
return "", "", err
|
fmt.Println("http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort + "/AddProxy?port=" + proxyPort + "&domain_name=" + domainName + "&ip_address=" + lowestLatencyIpAddress.Ipv4)
|
||||||
}
|
URL := "http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort + "/AddProxy?port=" + proxyPort + "&domain_name=" + domainName + "&ip_address=" + lowestLatencyIpAddress.Ipv4
|
||||||
|
//} else {
|
||||||
|
// URL = "http://" + IP + ":" + serverPort + "/server_info"
|
||||||
|
//}
|
||||||
|
http.Get(URL)
|
||||||
|
//SaveRegistration(domainName, lowestLatencyIpAddress.Ipv4+":"+proxyPort)
|
||||||
|
}
|
||||||
|
|
||||||
var lowestLatency int64
|
// updating with the current proxy address
|
||||||
// random large number
|
ProxyIpAddr.Ipv4 = lowestLatencyIpAddress.Ipv4
|
||||||
lowestLatency = 10000000
|
ProxyIpAddr.ServerPort = proxyPort
|
||||||
|
ProxyIpAddr.Name = config.MachineName
|
||||||
|
ProxyIpAddr.NAT = false
|
||||||
|
ProxyIpAddr.EscapeImplementation = "FRP"
|
||||||
|
|
||||||
for i, _ := range table.IpAddress {
|
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
||||||
// Checks if the ping is the lowest and if the following node is acting as a proxy
|
} else {
|
||||||
//if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].ProxyPort != "" {
|
return "", "", errors.New("proxy IP not found")
|
||||||
if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].NAT != "" {
|
}
|
||||||
// Filter based on nodes with proxy enabled
|
|
||||||
if domainName != "" && table.IpAddress[i].ProxyServer == "True" {
|
|
||||||
lowestLatency = table.IpAddress[i].Latency.Milliseconds()
|
|
||||||
lowestLatencyIpAddress = table.IpAddress[i]
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
lowestLatency = table.IpAddress[i].Latency.Milliseconds()
|
|
||||||
lowestLatencyIpAddress = table.IpAddress[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is an identified node
|
return ProxyIpAddr.Ipv4 + ":" + ProxyIpAddr.ServerPort, ProxyIpAddr.ServerPort, nil
|
||||||
if lowestLatency != 10000000 {
|
|
||||||
serverPort, err := frp.GetFRPServerPort("http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort)
|
|
||||||
if err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
// Create 3 second delay to allow FRP server to start
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
// Starts FRP as a client with
|
|
||||||
proxyPort, err := frp.StartFRPClientForServer(lowestLatencyIpAddress.Ipv4, serverPort, port, "")
|
|
||||||
if err != nil {
|
|
||||||
return "", "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Doing the proxy mapping for the domain name
|
|
||||||
if domainName != "" {
|
|
||||||
fmt.Println("http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort + "/AddProxy?port=" + proxyPort + "&domain_name=" + domainName + "&ip_address=" + lowestLatencyIpAddress.Ipv4)
|
|
||||||
URL := "http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort + "/AddProxy?port=" + proxyPort + "&domain_name=" + domainName + "&ip_address=" + lowestLatencyIpAddress.Ipv4
|
|
||||||
//} else {
|
|
||||||
// URL = "http://" + IP + ":" + serverPort + "/server_info"
|
|
||||||
//}
|
|
||||||
http.Get(URL)
|
|
||||||
//SaveRegistration(domainName, lowestLatencyIpAddress.Ipv4+":"+proxyPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
// updating with the current proxy address
|
|
||||||
ProxyIpAddr.Ipv4 = lowestLatencyIpAddress.Ipv4
|
|
||||||
ProxyIpAddr.ServerPort = proxyPort
|
|
||||||
ProxyIpAddr.Name = config.MachineName
|
|
||||||
ProxyIpAddr.NAT = "False"
|
|
||||||
ProxyIpAddr.EscapeImplementation = "FRP"
|
|
||||||
|
|
||||||
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
|
||||||
} else {
|
|
||||||
return "", "", errors.New("proxy IP not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProxyIpAddr.Ipv4 + ":" + ProxyIpAddr.ServerPort, ProxyIpAddr.ServerPort, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
32
style.css
32
style.css
@@ -1,32 +0,0 @@
|
|||||||
body {
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
span#discordJoin {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dark mode */
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
/* General Page Changing */
|
|
||||||
body {
|
|
||||||
background: #121212; /* Background Color */
|
|
||||||
color: #FFFFFF; /* Text Color */
|
|
||||||
}
|
|
||||||
|
|
||||||
a:link{ /* Unvisited Link */
|
|
||||||
color: #03DAC5;
|
|
||||||
}
|
|
||||||
|
|
||||||
a:visited { /* Visited Link */
|
|
||||||
color: #BB86FC;
|
|
||||||
}
|
|
||||||
|
|
||||||
a:hover { /* Mouse over Link */
|
|
||||||
color: #018786;
|
|
||||||
}
|
|
||||||
|
|
||||||
span#discordJoin { /* Text Color Change */
|
|
||||||
color: #cc0227;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIN
wasm/p2prc.wasm
Executable file
BIN
wasm/p2prc.wasm
Executable file
Binary file not shown.
Reference in New Issue
Block a user