core

package
v0.0.0-...-2af0010 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2025 License: GPL-3.0 Imports: 56 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version  string
	CodeHash string
)

These variables will be set at build time

View Source
var (
	NodeName   string
	ChainName  string
	NodeAccess string
	NodeConfig string
)
View Source
var CaddyConfDir = os.Getenv("WG_CONF_DIR")

WG_CONF_DIR

View Source
var CaddyFile = os.Getenv("CADDY_INTERFACE_NAME")
View Source
var CaddyJSON = "caddy.json"

var AppConfDir = "./conf"

View Source
var WalletAddress string

Functions

func ActivateNode

func ActivateNode() error

ActivateNode sets the node status to Online

func AddDIDAttribute

func AddDIDAttribute(nodeID string, systemMetadata string, nftMetadata string, privateKey *ecdsa.PrivateKey) error

AddDIDAttribute adds DID attributes to the PEAQ DID registry contract

func Authenticate

func Authenticate(mnemonic string, chain string) (string, error)

Authenticate with the API and return an authentication token

func ConnectToVPN

func ConnectToVPN() error

ConnectToVPN handles the VPN connection process

func CreatePeriodicCheckpoints

func CreatePeriodicCheckpoints(nodeID string, client *ethclient.Client, instance *contract.Contract, auth *bind.TransactOpts)

func CreateTrialSubscription

func CreateTrialSubscription(token string) error

Create a trial subscription

func DeactivateNode

func DeactivateNode() error

DeactivateNode deactivates the node in the contract

func DeleteClient

func DeleteClient(id string) error

DeleteClient from disk

func DisconnectVPN

func DisconnectVPN(configPath string) error

DisconnectVPN handles the VPN disconnection process

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately.

func GenerateEthereumWalletAddress

func GenerateEthereumWalletAddress(mnemonic string) (string, *ecdsa.PrivateKey, error)

GenerateEthereumWalletAddress generates an Ethereum wallet address from the given mnemonic

func GeneratePeaqDID

func GeneratePeaqDID() (string, error)

func GenerateWalletAddressAptos

func GenerateWalletAddressAptos(mnemonic string)

GenerateWalletAddressAptos generates an Aptos wallet address from the given mnemonic

func GenerateWalletAddressSolanaAndEclipse

func GenerateWalletAddressSolanaAndEclipse(mnemonic string)

GenerateWalletAddressSolana generates a Solana wallet address from the given mnemonic

func GenerateWalletAddressSui

func GenerateWalletAddressSui(mnemonic string)

GenerateWalletAddressSui generates a Sui wallet address from the given mnemonic

func GetAllNodes

func GetAllNodes(token string) ([]map[string]interface{}, error)

Get all available nodes

func GetAllReservedIps

func GetAllReservedIps() ([]string, error)

GetAllReservedIps the list of all reserved IPs, client and server

func GetCodeHashAndVersion

func GetCodeHashAndVersion() (string, string)

func GetIPInfo

func GetIPInfo()

func GetPort

func GetPort(max, min int) (int, error)

GetPort returns available port based on random generation

func GetServerStatus

func GetServerStatus() (*model.Status, error)

Method to get the server status

func Init

func Init()

Init initializes json file for caddy

func IsValidPeaqDID

func IsValidPeaqDID(did string) bool

func LoadNodeDetails

func LoadNodeDetails()

Function to load the node details from the environment and save it to the global variable

func MakeErrorResponse

func MakeErrorResponse(status int64, err string, server *model.Server, client *model.Client, clients []*model.Client) *model.Response

error response message

func MakeSucessResponse

func MakeSucessResponse(status int64, message string, server *model.Server, client *model.Client, clients []*model.Client) *model.Response

success response message

func ReadClient

func ReadClient(id string) (*model.Client, error)

ReadClient client by id

func ReadClientConfig

func ReadClientConfig(id string) ([]byte, error)

func ReadClients

func ReadClients() ([]*model.Client, error)

ReadClients all clients

func ReadServer

func ReadServer() (*model.Server, error)

ReadServer object, create default one

func ReadWgConfigFile

func ReadWgConfigFile() ([]byte, error)

ReadWgConfigFile return content of wireguard config file

func RegisterClient

func RegisterClient(client *model.Client) (*model.Client, error)

RegisterClient client with all necessary data

func RegisterNodeOnChain

func RegisterNodeOnChain() error

func ScanPort

func ScanPort(port int) (string, error)

ScanPort checks avilability of port

func UpdateClient

func UpdateClient(UUID string, client *model.Client) (*model.Client, error)

UpdateClient preserve keys

func UpdateServer

func UpdateServer(server *model.Server) (*model.Server, error)

UpdateServer keep private values from existing one

func UpdateServerConfigWg

func UpdateServerConfigWg() error

UpdateServerConfigWg in wg format

func Writefile

func Writefile(path string, bytes []byte) (err error)

Writefile appends data to file

Types

type AuthResponse

type AuthResponse struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
	Payload struct {
		Token string `json:"token"`
	} `json:"payload"`
}

AuthResponse represents the authentication response

type ClientResponse

type ClientResponse struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
	Payload struct {
		Client struct {
			Address      []string `json:"Address"`
			PublicKey    string   `json:"PublicKey"`
			PresharedKey string   `json:"PresharedKey"`
		} `json:"client"`
		Endpoint        string `json:"endpoint"`
		ServerPublicKey string `json:"serverPublicKey"`
	} `json:"payload"`
	PrivateKey   string `json:"privateKey"`
	PresharedKey string `json:"presharedKey"`
}

ClientResponse represents the client creation response

func CreateClient

func CreateClient(token string, nodeID string, clientName string) (*ClientResponse, error)

Create a client for a specific node

type ClientStats

type ClientStats struct {
	Client string `json:"client"`
	RX     string `json:"rx"`
	TX     string `json:"tx"`
}

ClientStats represents the bandwidth statistics of a WireGuard client

type ConnectionResult

type ConnectionResult struct {
	Success    bool             `json:"success"`
	Error      string           `json:"error,omitempty"`
	Message    string           `json:"message,omitempty"`
	ConfigPath string           `json:"configPath,omitempty"`
	Client     *ClientResponse  `json:"client,omitempty"`
	ConfigData *WireGuardConfig `json:"configData,omitempty"`
	IP         string           `json:"ip,omitempty"`
}

ConnectionResult represents the result of a connection attempt

func ConnectDvpn

func ConnectDvpn(token string, nodeID string, clientName string, configPath string) (*ConnectionResult, error)

Connect to DVPN

func ConnectToVPNWithNodeSelection

func ConnectToVPNWithNodeSelection(token string, clientName string, configPath string) (*ConnectionResult, error)

ConnectToVPNWithNodeSelection attempts to connect to VPN using available active nodes

type FlowIDResponse

type FlowIDResponse struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
	Payload struct {
		FlowID string `json:"flowId"`
		Eula   string `json:"eula"`
	} `json:"payload"`
}

FlowIDResponse represents the flowId response

type IPFSResponse

type IPFSResponse struct {
	Name string `json:"Name"`
	Hash string `json:"Hash"`
	Size string `json:"Size"`
}

type IPInfo

type IPInfo struct {
	IP       string `json:"ip"`
	City     string `json:"city"`
	Region   string `json:"region"`
	Country  string `json:"country"`
	Location string `json:"loc"`
	Org      string `json:"org"`
	Postal   string `json:"postal"`
	Timezone string `json:"timezone"`
}
var GlobalIPInfo IPInfo

type NFTAttribute

type NFTAttribute struct {
	TraitType string `json:"trait_type"`
	Value     string `json:"value"`
}

type NFTMetadata

type NFTMetadata struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Image       string         `json:"image"`
	ExternalURL string         `json:"externalUrl"`
	Attributes  []NFTAttribute `json:"attributes"`
}

type NodeConnectionInfo

type NodeConnectionInfo struct {
	NodeID     string    `json:"node_id"`
	LastUsed   time.Time `json:"last_used"`
	ClientName string    `json:"client_name"`
}

NodeConnectionInfo stores information about the last successful node connection

type NodeResponse

type NodeResponse struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
	Payload []struct {
		ID     string `json:"id"`
		Status string `json:"status"`
	} `json:"payload"`
}

NodeResponse represents the nodes response

type NodeStatus

type NodeStatus struct {
	ID         string
	Name       string
	Spec       string
	Config     string
	IPAddress  string
	Region     string
	Location   string
	Owner      common.Address
	TokenID    *big.Int
	Status     uint8
	Checkpoint string
}

NodeStatus represents the current status of a node

func GetNodeStatus

func GetNodeStatus() (*NodeStatus, error)

GetNodeStatus retrieves the current status of the node from the contract

func (*NodeStatus) GetStatusEmoji

func (ns *NodeStatus) GetStatusEmoji() string

GetStatusEmoji returns the emoji representation of the node status

func (*NodeStatus) GetStatusText

func (ns *NodeStatus) GetStatusText() string

GetStatusText returns the text representation of the node status

type PeaqIPInfo

type PeaqIPInfo struct {
	IP      string `json:"ip"`
	City    string `json:"city"`
	Region  string `json:"region"`
	Country string `json:"country"`
	Loc     string `json:"loc"`
}

type SubscriptionResponse

type SubscriptionResponse struct {
	Status       string      `json:"status"`
	Subscription interface{} `json:"subscription"`
}

SubscriptionResponse represents the subscription response

func CheckSubscription

func CheckSubscription(token string) (*SubscriptionResponse, error)

Check subscription status

type SystemMetadata

type SystemMetadata struct {
	OS             string   `json:"os"`
	Architecture   string   `json:"architecture"`
	NumCPU         int      `json:"num_cpu"`
	Hostname       string   `json:"hostname"`
	LocalIPs       []string `json:"local_ips"`
	Environment    string   `json:"environment"` // "cloud" or "local"
	GoVersion      string   `json:"go_version"`
	RuntimeVersion string   `json:"runtime_version"`
	TotalRAM       uint64   `json:"total_ram"`
	UsedRAM        uint64   `json:"used_ram"`
	FreeRAM        uint64   `json:"free_ram"`
	TotalDisk      uint64   `json:"total_disk"`
	UsedDisk       uint64   `json:"used_disk"`
	FreeDisk       uint64   `json:"free_disk"`
	CPUUsage       float64  `json:"cpu_usage"`
	Version        string   `json:"version"`
	CodeHash       string   `json:"code_hash"`
}

type SystemMetrics

type SystemMetrics struct {
	Timestamp        int64         `json:"timestamp"`
	ConnectedClients int           `json:"connected_clients"`
	ClientStats      []ClientStats `json:"client_stats"`
	Uptime           string        `json:"uptime"`
}

SystemMetrics represents the system metrics for checkpoints

type WireGuardConfig

type WireGuardConfig struct {
	Config          string `json:"config"`
	PrivateKey      string `json:"privateKey"`
	PublicKey       string `json:"publicKey"`
	PresharedKey    string `json:"presharedKey"`
	Address         string `json:"address"`
	Endpoint        string `json:"endpoint"`
	ServerPublicKey string `json:"serverPublicKey"`
}

WireGuardConfig represents the WireGuard configuration

func CreateWireGuardConfig

func CreateWireGuardConfig(clientData *ClientResponse) (*WireGuardConfig, error)

Create WireGuard configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL