added P2RPC support to run webgateway on hosted node

This commit is contained in:
2023-04-22 17:49:32 +01:00
parent a11f820dd9
commit 0686c2539c
4 changed files with 1538 additions and 67 deletions

BIN
Cmd

Binary file not shown.

162
Main.go
View File

@@ -1,61 +1,101 @@
/*
File Name: Main.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/
package main
import (
"fmt"
"os"
"github.com/PeernetOfficial/core"
)
const configFile = "Config.yaml"
const appName = "Peernet Web Gateway"
var config struct {
// HTTP settings for the web gateway
WebListen []string `yaml:"WebListen"` // WebListen is in format IP:Port and declares where the web-interface should listen on. IP can also be ommitted to listen on any.
WebUseSSL bool `yaml:"WebUseSSL"` // Enables SSL.
WebCertificateFile string `yaml:"WebCertificateFile"` // This is the certificate received from the CA. This can also include the intermediate certificate from the CA.
WebCertificateKey string `yaml:"WebCertificateKey"` // This is the private key.
WebTimeoutRead string `yaml:"WebTimeoutRead"` // The maximum duration for reading the entire request, including the body.
WebTimeoutWrite string `yaml:"WebTimeoutWrite"` // The maximum duration before timing out writes of the response. This includes processing time and is therefore the max time any HTTP function may take.
Redirect80 string `yaml:"Redirect80"` // Redirect 80 listen address. Empty if not used.
// WebFiles is the directory holding all HTML and other files to be served by the server
WebFiles string `yaml:"WebFiles"`
}
func main() {
userAgent := appName + "/" + core.Version
backend, status, err := core.Init(userAgent, configFile, nil, &config)
if status != core.ExitSuccess {
switch status {
case core.ExitErrorConfigAccess:
fmt.Printf("Unknown error accessing config file '%s': %s\n", configFile, err.Error())
case core.ExitErrorConfigRead:
fmt.Printf("Error reading config file '%s': %s\n", configFile, err.Error())
case core.ExitErrorConfigParse:
fmt.Printf("Error parsing config file '%s' (make sure it is valid YAML format): %s\n", configFile, err.Error())
case core.ExitErrorLogInit:
fmt.Printf("Error opening log file '%s': %s\n", backend.Config.LogFile, err.Error())
default:
fmt.Printf("Unknown error %d initializing backend: %s\n", status, err.Error())
}
os.Exit(status)
}
backend.Stdout.Subscribe(os.Stdout)
go startWebGateway(backend)
backend.Connect()
select {}
}
/*
File Name: Main.go
Copyright: 2021 Peernet s.r.o.
Author: Peter Kleissner
*/
package main
import (
"fmt"
"net"
"os"
"time"
"github.com/Akilan1999/p2p-rendering-computation/p2p/frp"
"github.com/PeernetOfficial/core"
)
const configFile = "Config.yaml"
const appName = "Peernet Web Gateway"
var config struct {
// HTTP settings for the web gateway
WebListen []string `yaml:"WebListen"` // WebListen is in format IP:Port and declares where the web-interface should listen on. IP can also be ommitted to listen on any.
WebUseSSL bool `yaml:"WebUseSSL"` // Enables SSL.
WebCertificateFile string `yaml:"WebCertificateFile"` // This is the certificate received from the CA. This can also include the intermediate certificate from the CA.
WebCertificateKey string `yaml:"WebCertificateKey"` // This is the private key.
WebTimeoutRead string `yaml:"WebTimeoutRead"` // The maximum duration for reading the entire request, including the body.
WebTimeoutWrite string `yaml:"WebTimeoutWrite"` // The maximum duration before timing out writes of the response. This includes processing time and is therefore the max time any HTTP function may take.
Redirect80 string `yaml:"Redirect80"` // Redirect 80 listen address. Empty if not used.
P2PRC bool `yaml:"P2PRC"` // Using a P2PRC TURN server for testing on a self-hosted bare-metal machine
ExposePortP2PRC string `yaml:"ExposePortP2PRC"` // Expose external port using P2PRC (FRP)
P2PRCRootPeer string `yaml:"P2PRCRootPeer"` // Expose external port using P2PRC (FRP)
// WebFiles is the directory holding all HTML and other files to be served by the server
WebFiles string `yaml:"WebFiles"`
}
func main() {
userAgent := appName + "/" + core.Version
backend, status, err := core.Init(userAgent, configFile, nil, &config)
if status != core.ExitSuccess {
switch status {
case core.ExitErrorConfigAccess:
fmt.Printf("Unknown error accessing config file '%s': %s\n", configFile, err.Error())
case core.ExitErrorConfigRead:
fmt.Printf("Error reading config file '%s': %s\n", configFile, err.Error())
case core.ExitErrorConfigParse:
fmt.Printf("Error parsing config file '%s' (make sure it is valid YAML format): %s\n", configFile, err.Error())
case core.ExitErrorLogInit:
fmt.Printf("Error opening log file '%s': %s\n", backend.Config.LogFile, err.Error())
default:
fmt.Printf("Unknown error %d initializing backend: %s\n", status, err.Error())
}
os.Exit(status)
}
backend.Stdout.Subscribe(os.Stdout)
go startWebGateway(backend)
backend.Connect()
// If the config file consists of P2PRC
// and the Config file has a exposed port
if config.P2PRC && config.ExposePortP2PRC != "" && config.WebListen[0] != "" {
EscapeNATWebGateway()
}
select {}
}
func EscapeNATWebGateway() (ExposePortP2PRC string, err error) {
host, port, err := net.SplitHostPort(config.P2PRCRootPeer)
if err != nil {
return
}
serverPort, err := frp.GetFRPServerPort("http://" + host + ":" + port)
if err != nil {
return
}
time.Sleep(1 * time.Second)
_, port, err = net.SplitHostPort(config.WebListen[0])
if err != nil {
return
}
//port for the barrierKVM server
ExposePortP2PRC, err = frp.StartFRPClientForServer(host, serverPort, port, config.ExposePortP2PRC)
if err != nil {
return
}
return
}

65
go.mod
View File

@@ -2,21 +2,82 @@ module github.com/PeernetOfficial/Cmd
go 1.19
replace github.com/Akilan1999/p2p-rendering-computation => /Users/akilan/Documents/p2p-rendering-computation
require (
github.com/Akilan1999/p2p-rendering-computation v0.0.0-00010101000000-000000000000
github.com/PeernetOfficial/core v0.0.0-20220601150942-0e3e8dc9885c
github.com/gorilla/mux v1.8.0
)
require (
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // 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/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/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/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.0 // 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/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
github.com/klauspost/reedsolomon v1.9.15 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lithammer/shortuuid v3.0.0+incompatible // 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/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/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
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/net v0.0.0-20220531201128-c960675eff93 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.7 // 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.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)

1378
go.sum

File diff suppressed because it is too large Load Diff