mirror of
https://github.com/PeernetOfficial/WebGatewayUpload.git
synced 2026-07-16 19:47:51 +01:00
pushed WebUploadGateway with P2PRC
This commit is contained in:
71
go.mod
71
go.mod
@@ -2,7 +2,10 @@ module github.com/PeernetOfficial/WebGatewayUpload
|
|||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
replace github.com/Akilan1999/p2p-rendering-computation => /Users/akilan/Documents/p2p-rendering-computation
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/Akilan1999/p2p-rendering-computation v0.0.0-00010101000000-000000000000
|
||||||
github.com/PeernetOfficial/core v0.0.0-20220601150942-0e3e8dc9885c
|
github.com/PeernetOfficial/core v0.0.0-20220601150942-0e3e8dc9885c
|
||||||
github.com/gin-gonic/gin v1.8.1
|
github.com/gin-gonic/gin v1.8.1
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
@@ -10,30 +13,82 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect
|
||||||
github.com/IncSW/geoip2 v0.1.2 // indirect
|
github.com/IncSW/geoip2 v0.1.2 // indirect
|
||||||
|
github.com/Microsoft/go-winio v0.4.17-0.20210211115548-6eac466e5fa3 // indirect
|
||||||
|
github.com/Microsoft/hcsshim v0.8.15 // indirect
|
||||||
github.com/akrylysov/pogreb v0.10.1 // indirect
|
github.com/akrylysov/pogreb v0.10.1 // indirect
|
||||||
|
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 // indirect
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||||
|
github.com/containerd/cgroups v0.0.0-20200824123100-0b889c03f102 // indirect
|
||||||
|
github.com/containerd/containerd v1.5.0-beta.1 // indirect
|
||||||
|
github.com/containerd/continuity v0.0.0-20210315143101-93e15499afd5 // indirect
|
||||||
|
github.com/coreos/go-oidc v2.2.1+incompatible // indirect
|
||||||
|
github.com/docker/distribution v2.7.1+incompatible // indirect
|
||||||
|
github.com/docker/docker v20.10.0-beta1.0.20201113105859-b6bfff2a628f+incompatible // indirect
|
||||||
|
github.com/docker/go-connections v0.4.0 // indirect
|
||||||
|
github.com/docker/go-units v0.4.0 // indirect
|
||||||
github.com/enfipy/locker v1.1.0 // indirect
|
github.com/enfipy/locker v1.1.0 // indirect
|
||||||
|
github.com/fatedier/beego v0.0.0-20171024143340-6c6a4f5bd5eb // indirect
|
||||||
|
github.com/fatedier/frp v0.45.0 // indirect
|
||||||
|
github.com/fatedier/golib v0.1.1-0.20220321042308-c306138b83ac // indirect
|
||||||
|
github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/go-playground/locales v0.14.0 // indirect
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.10.0 // indirect
|
github.com/go-playground/validator/v10 v10.11.0 // indirect
|
||||||
github.com/goccy/go-json v0.9.7 // indirect
|
github.com/goccy/go-json v0.9.7 // indirect
|
||||||
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
|
github.com/golang/snappy v0.0.3 // indirect
|
||||||
github.com/gorilla/mux v1.8.0 // indirect
|
github.com/gorilla/mux v1.8.0 // indirect
|
||||||
github.com/gorilla/websocket v1.5.0 // indirect
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
|
github.com/hashicorp/yamux v0.1.1 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/juju/ratelimit v1.0.2 // indirect
|
github.com/juju/ratelimit v1.0.2 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
|
github.com/klauspost/cpuid/v2 v2.1.2 // indirect
|
||||||
|
github.com/klauspost/reedsolomon v1.9.15 // indirect
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
|
github.com/lithammer/shortuuid v3.0.0+incompatible // indirect
|
||||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
|
||||||
|
github.com/moby/sys/mount v0.2.0 // indirect
|
||||||
|
github.com/moby/sys/mountinfo v0.4.0 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
|
github.com/opencontainers/image-spec v1.0.1 // indirect
|
||||||
|
github.com/opencontainers/runc v1.0.0-rc93 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
|
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
|
||||||
|
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 // indirect
|
||||||
|
github.com/pires/go-proxyproto v0.6.2 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
|
||||||
|
github.com/prometheus/client_golang v1.13.0 // indirect
|
||||||
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
|
github.com/prometheus/common v0.37.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.8.0 // indirect
|
||||||
|
github.com/sirupsen/logrus v1.7.0 // indirect
|
||||||
|
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
|
||||||
|
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
|
||||||
|
github.com/tjfoc/gmsm v1.4.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
|
go.opencensus.io v0.23.0 // indirect
|
||||||
golang.org/x/net v0.0.0-20220531201128-c960675eff93 // indirect
|
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a // indirect
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
|
golang.org/x/net v0.7.0 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
|
||||||
google.golang.org/protobuf v1.28.0 // indirect
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
|
||||||
|
golang.org/x/sys v0.5.0 // indirect
|
||||||
|
golang.org/x/text v0.7.0 // indirect
|
||||||
|
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
|
||||||
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
|
google.golang.org/genproto v0.0.0-20210924002016-3dee208752a0 // indirect
|
||||||
|
google.golang.org/grpc v1.40.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.28.1 // indirect
|
||||||
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
|
gopkg.in/square/go-jose.v2 v2.4.1 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
lukechampine.com/blake3 v1.1.7 // indirect
|
lukechampine.com/blake3 v1.1.7 // indirect
|
||||||
|
|||||||
49
main.go
49
main.go
@@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Akilan1999/p2p-rendering-computation/p2p/frp"
|
||||||
"github.com/PeernetOfficial/core"
|
"github.com/PeernetOfficial/core"
|
||||||
"github.com/PeernetOfficial/core/btcec"
|
"github.com/PeernetOfficial/core/btcec"
|
||||||
"github.com/PeernetOfficial/core/webapi"
|
"github.com/PeernetOfficial/core/webapi"
|
||||||
@@ -16,6 +17,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -37,6 +39,12 @@ var (
|
|||||||
BackendAddressWithHTTP string
|
BackendAddressWithHTTP string
|
||||||
// Production mode
|
// Production mode
|
||||||
Production *bool
|
Production *bool
|
||||||
|
// P2PRC mode
|
||||||
|
P2PRC *bool
|
||||||
|
// P2PRCRootNode Root node of P2PRC
|
||||||
|
P2PRCRootNode *string
|
||||||
|
// P2PRCExposePort Public exposed port
|
||||||
|
P2PRCExposePort *string
|
||||||
)
|
)
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------
|
||||||
@@ -45,12 +53,15 @@ var (
|
|||||||
|
|
||||||
// init reading flags before any part of the code is executed
|
// init reading flags before any part of the code is executed
|
||||||
func init() {
|
func init() {
|
||||||
BackEndApiAddress = flag.String("BackEndApiAddress", "localhost:8088", "current environment")
|
BackEndApiAddress = flag.String("BackEndApiAddress", "localhost:8081", "current environment")
|
||||||
WebpageAddress = flag.String("WebpageAddress", "localhost:8098", "current environment")
|
WebpageAddress = flag.String("WebpageAddress", "localhost:8098", "current environment")
|
||||||
SSL = flag.Bool("SSL", false, "Flag to check if the SSL certificate is enabled or not")
|
SSL = flag.Bool("SSL", false, "Flag to check if the SSL certificate is enabled or not")
|
||||||
Certificate = flag.String("Certificate", "server.crt", "SSL Certificate file")
|
Certificate = flag.String("Certificate", "server.crt", "SSL Certificate file")
|
||||||
Key = flag.String("Key", "server.key", "SSL Key file")
|
Key = flag.String("Key", "server.key", "SSL Key file")
|
||||||
Production = flag.Bool("Production", false, "Flag to check if required to run on production mode")
|
Production = flag.Bool("Production", false, "Flag to check if required to run on production mode")
|
||||||
|
P2PRC = flag.Bool("P2PRC", false, "Run P2PRC mode to selfnode node")
|
||||||
|
P2PRCRootNode = flag.String("P2PRCHost", "", "Run P2PRC mode to selfnode node")
|
||||||
|
P2PRCExposePort = flag.String("P2PRCExposedPort", "", "Port exposed externally for P2PRC")
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitPeernet Initializes Peernet backend
|
// InitPeernet Initializes Peernet backend
|
||||||
@@ -124,10 +135,9 @@ type BlockchainResponse struct {
|
|||||||
// AddFileWarehouse API call for (Storing file in the warehouse)
|
// AddFileWarehouse API call for (Storing file in the warehouse)
|
||||||
func AddFileWarehouse(file io.Reader) *WarehouseResult {
|
func AddFileWarehouse(file io.Reader) *WarehouseResult {
|
||||||
url := BackendAddressWithHTTP + "/warehouse/create"
|
url := BackendAddressWithHTTP + "/warehouse/create"
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", url, file)
|
req, err := http.NewRequest("POST", url, file)
|
||||||
//req.Header.Set("X-Custom-Header", "myvalue")
|
//req.Header.Set("X-Custom-Header", "myvalue")
|
||||||
//req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "multipart/form-data")
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
@@ -309,6 +319,11 @@ func main() {
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// ----------------------- Check if P2PRC mode is selected for hosting ------------------------
|
||||||
|
if *P2PRC && *P2PRCRootNode != "" && *P2PRCExposePort != "" {
|
||||||
|
EscapeNATWebGateway()
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------- Start Gin server -----------------------------------------
|
// ---------------------------------- Start Gin server -----------------------------------------
|
||||||
// check if SSL is used or not
|
// check if SSL is used or not
|
||||||
if *SSL {
|
if *SSL {
|
||||||
@@ -322,3 +337,31 @@ func main() {
|
|||||||
}
|
}
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EscapeNATWebGateway() (ExposePortP2PRC string, err error) {
|
||||||
|
host, port, err := net.SplitHostPort(*P2PRCRootNode)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
serverPort, err := frp.GetFRPServerPort("http://" + host + ":" + port)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
_, port, err = net.SplitHostPort(*WebpageAddress)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//port for the barrierKVM server
|
||||||
|
ExposePortP2PRC, err = frp.StartFRPClientForServer(host, serverPort, port, *P2PRCExposePort)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@
|
|||||||
<h3 style="color:red"> Error: {{ .error }} </h3>
|
<h3 style="color:red"> Error: {{ .error }} </h3>
|
||||||
{{end}}
|
{{end}}
|
||||||
</form>
|
</form>
|
||||||
|
<br>
|
||||||
|
<!-- <div class="progress">-->
|
||||||
|
<!-- <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 3%"></div>-->
|
||||||
|
<!-- </div>-->
|
||||||
<!-- <h3 style="color:white"> or </h3>-->
|
<!-- <h3 style="color:white"> or </h3>-->
|
||||||
<!-- <h4 style="color:white">curl {{ .address }}/uploadCurl -F add=@<file name></h4>-->
|
<!-- <h4 style="color:white">curl {{ .address }}/uploadCurl -F add=@<file name></h4>-->
|
||||||
<!-- <a href="#" class="btn btn-white btn-outline-white" tyle="color:#3ac4e2">Upload file</a> -->
|
<!-- <a href="#" class="btn btn-white btn-outline-white" tyle="color:#3ac4e2">Upload file</a> -->
|
||||||
@@ -114,6 +118,24 @@
|
|||||||
<script src="js/bootstrap.min.js"></script>
|
<script src="js/bootstrap.min.js"></script>
|
||||||
<script src="js/main.js"></script>
|
<script src="js/main.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// For the upload and progress bar
|
||||||
|
// The first call will generate an upload ID
|
||||||
|
// The second call will start the upload based
|
||||||
|
// on the ID presented
|
||||||
|
//
|
||||||
|
// function uploader() {
|
||||||
|
// var formData = new FormData();
|
||||||
|
// formData.append("name", "Smith");
|
||||||
|
// formData.append("data", fileInputElement.files[0]);
|
||||||
|
// var request = new XMLHttpRequest();
|
||||||
|
//
|
||||||
|
// request.open("POST", "https://site[DOT]net/upload");
|
||||||
|
// request.send(formData);
|
||||||
|
// }
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user