Commit 4f71da27 authored by duanjinfei's avatar duanjinfei

Init commit

parents
.idea
logs
go.sum
nohup.out
package appNodeInterface
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"schedulerNode/log"
"schedulerNode/models"
)
var client *http.Client
func init() {
client = &http.Client{}
}
func SendSignallingInfo(ip, port string, req *models.SendSignallingReq) *models.AppNodeResponse {
reqBody, err := json.Marshal(req)
if err != nil {
log.Error("json marshal sendSignallingReq failed ", err)
return nil
}
url := fmt.Sprintf("http://%s:%s%s", ip, port, "/v1/connectSignalling")
request, err := http.NewRequest("POST", url, bytes.NewReader(reqBody))
if err != nil {
log.Error("Error connectSignalling request ", err)
return nil
}
resp, err := client.Do(request)
if err != nil {
log.Error("Error sending", err)
return nil
}
appNodeResp := &models.AppNodeResponse{}
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Error("Error reading response body", err)
return nil
}
err = json.Unmarshal(respBody, appNodeResp)
if err != nil {
log.Error("Unmarshal error: ", err)
return nil
}
return appNodeResp
}
func GetSignallingConnectStatus(ip, port string) *models.SignallingConnectStatus {
url := fmt.Sprintf("http://%s:%s%s", ip, port, "/v1/signalStatus")
request, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Error("GetSignallingConnectStatus Error new request: ", err)
return nil
}
resp, err := client.Do(request)
if err != nil {
log.Error("GetSignallingConnectStatus send request error: ", err)
return nil
}
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Error("GetSignallingConnectStatus read resp body error: ", err)
return nil
}
res := &models.SignallingConnectStatus{}
err = json.Unmarshal(respBody, &res)
if err != nil {
log.Error("GetSignallingConnectStatus json unmarshal error:", err)
return nil
}
return res
}
package nodeCommon
const (
SuccessCode = 200
FaileCode = 500
)
appname = schedulerNode
httpport = 8080
runmode = dev
autorender = false
copyrequestbody = true
distance = 1000
local_ip = 192.168.1.100
[chain]
rpcUrl = "http://124.193.167.71:7545"
[contract_address]
app_contract = "0xD42c37fe44f1a0e7CA50B8bf5a5Bb96747C73aAb"
\ No newline at end of file
[
{
"inputs": [
{
"internalType": "address",
"name": "const",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [],
"name": "_const",
"outputs": [
{
"internalType": "contract ICloudConstant",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_admin",
"type": "address"
}
],
"name": "addAdmin",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "nodeId",
"type": "string"
},
{
"internalType": "string",
"name": "appId",
"type": "string"
},
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "version",
"type": "string"
},
{
"internalType": "string",
"name": "status",
"type": "string"
},
{
"internalType": "string",
"name": "resolutionRatio",
"type": "string"
},
{
"internalType": "string",
"name": "fps",
"type": "string"
},
{
"internalType": "string",
"name": "gamePads",
"type": "string"
},
{
"internalType": "string",
"name": "isHdrSupported",
"type": "string"
}
],
"name": "addAppInfo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "nodeId",
"type": "string"
},
{
"internalType": "string",
"name": "externalIp",
"type": "string"
},
{
"internalType": "string",
"name": "serverPort",
"type": "string"
},
{
"internalType": "string[]",
"name": "stunIp",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "turnIp",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "turnUser",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "turnPwd",
"type": "string[]"
},
{
"internalType": "string",
"name": "signallingHttpIp",
"type": "string"
},
{
"internalType": "string",
"name": "signallingWsIp",
"type": "string"
}
],
"name": "addNodeNetworkInfo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "nodeId",
"type": "string"
},
{
"internalType": "string[]",
"name": "appId",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "name",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "version",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "status",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "resolutionRatio",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "fps",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "gamePads",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "isHdrSupported",
"type": "string[]"
}
],
"name": "batchAddAppInfo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_admin",
"type": "address"
}
],
"name": "delAdmin",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint8",
"name": "start",
"type": "uint8"
},
{
"internalType": "uint8",
"name": "count",
"type": "uint8"
}
],
"name": "getAppIds",
"outputs": [
{
"internalType": "string[]",
"name": "res",
"type": "string[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "nodeId",
"type": "string"
},
{
"internalType": "uint8",
"name": "start",
"type": "uint8"
},
{
"internalType": "uint8",
"name": "count",
"type": "uint8"
}
],
"name": "getAppIdsForNode",
"outputs": [
{
"internalType": "string[]",
"name": "res",
"type": "string[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "appId",
"type": "string"
}
],
"name": "getAppInfo",
"outputs": [
{
"internalType": "string",
"name": "name",
"type": "string"
},
{
"internalType": "string",
"name": "version",
"type": "string"
},
{
"internalType": "string",
"name": "status",
"type": "string"
},
{
"internalType": "string",
"name": "resolutionRatio",
"type": "string"
},
{
"internalType": "string",
"name": "fps",
"type": "string"
},
{
"internalType": "string",
"name": "gamePads",
"type": "string"
},
{
"internalType": "string",
"name": "isHdrSupported",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "appId",
"type": "string"
},
{
"internalType": "uint8",
"name": "start",
"type": "uint8"
},
{
"internalType": "uint8",
"name": "count",
"type": "uint8"
}
],
"name": "getNodeIds",
"outputs": [
{
"internalType": "string[]",
"name": "res",
"type": "string[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "nodeId",
"type": "string"
}
],
"name": "getNodeNetwork",
"outputs": [
{
"internalType": "string",
"name": "externalIp",
"type": "string"
},
{
"internalType": "string",
"name": "serverPort",
"type": "string"
},
{
"internalType": "string[]",
"name": "stunIp",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "turnIp",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "turnUser",
"type": "string[]"
},
{
"internalType": "string[]",
"name": "turnPwd",
"type": "string[]"
},
{
"internalType": "string",
"name": "signallingHttpIp",
"type": "string"
},
{
"internalType": "string",
"name": "signallingWsIp",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_addr",
"type": "address"
}
],
"name": "isAdmin",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "appId",
"type": "string"
},
{
"internalType": "string",
"name": "nodeId",
"type": "string"
}
],
"name": "isAppBoundToNode",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "const",
"type": "address"
}
],
"name": "setConstant",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
\ No newline at end of file
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package application
import (
"errors"
"math/big"
"strings"
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
)
// Reference imports to suppress errors if they are not otherwise used.
var (
_ = errors.New
_ = big.NewInt
_ = strings.NewReader
_ = ethereum.NotFound
_ = bind.Bind
_ = common.Big1
_ = types.BloomLookup
_ = event.NewSubscription
)
// ApplicationMetaData contains all meta data concerning the Application contract.
var ApplicationMetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"_const\",\"outputs\":[{\"internalType\":\"contractICloudConstant\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"addAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"nodeId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"appId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"version\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"status\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"resolutionRatio\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"fps\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"gamePads\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"isHdrSupported\",\"type\":\"string\"}],\"name\":\"addAppInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"nodeId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"externalIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"serverPort\",\"type\":\"string\"},{\"internalType\":\"string[]\",\"name\":\"stunIp\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"turnIp\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"turnUser\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"turnPwd\",\"type\":\"string[]\"},{\"internalType\":\"string\",\"name\":\"signallingHttpIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"signallingWsIp\",\"type\":\"string\"}],\"name\":\"addNodeNetworkInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"nodeId\",\"type\":\"string\"},{\"internalType\":\"string[]\",\"name\":\"appId\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"name\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"version\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"status\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"resolutionRatio\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"fps\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"gamePads\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"isHdrSupported\",\"type\":\"string[]\"}],\"name\":\"batchAddAppInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"delAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"start\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"count\",\"type\":\"uint8\"}],\"name\":\"getAppIds\",\"outputs\":[{\"internalType\":\"string[]\",\"name\":\"res\",\"type\":\"string[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"nodeId\",\"type\":\"string\"},{\"internalType\":\"uint8\",\"name\":\"start\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"count\",\"type\":\"uint8\"}],\"name\":\"getAppIdsForNode\",\"outputs\":[{\"internalType\":\"string[]\",\"name\":\"res\",\"type\":\"string[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"appId\",\"type\":\"string\"}],\"name\":\"getAppInfo\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"version\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"status\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"resolutionRatio\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"fps\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"gamePads\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"isHdrSupported\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"appId\",\"type\":\"string\"},{\"internalType\":\"uint8\",\"name\":\"start\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"count\",\"type\":\"uint8\"}],\"name\":\"getNodeIds\",\"outputs\":[{\"internalType\":\"string[]\",\"name\":\"res\",\"type\":\"string[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"nodeId\",\"type\":\"string\"}],\"name\":\"getNodeNetwork\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"externalIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"serverPort\",\"type\":\"string\"},{\"internalType\":\"string[]\",\"name\":\"stunIp\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"turnIp\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"turnUser\",\"type\":\"string[]\"},{\"internalType\":\"string[]\",\"name\":\"turnPwd\",\"type\":\"string[]\"},{\"internalType\":\"string\",\"name\":\"signallingHttpIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"signallingWsIp\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"isAdmin\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"appId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"nodeId\",\"type\":\"string\"}],\"name\":\"isAppBoundToNode\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"name\":\"setConstant\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]",
}
// ApplicationABI is the input ABI used to generate the binding from.
// Deprecated: Use ApplicationMetaData.ABI instead.
var ApplicationABI = ApplicationMetaData.ABI
// Application is an auto generated Go binding around an Ethereum contract.
type Application struct {
ApplicationCaller // Read-only binding to the contract
ApplicationTransactor // Write-only binding to the contract
ApplicationFilterer // Log filterer for contract events
}
// ApplicationCaller is an auto generated read-only Go binding around an Ethereum contract.
type ApplicationCaller struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls
}
// ApplicationTransactor is an auto generated write-only Go binding around an Ethereum contract.
type ApplicationTransactor struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls
}
// ApplicationFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
type ApplicationFilterer struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls
}
// ApplicationSession is an auto generated Go binding around an Ethereum contract,
// with pre-set call and transact options.
type ApplicationSession struct {
Contract *Application // Generic contract binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}
// ApplicationCallerSession is an auto generated read-only Go binding around an Ethereum contract,
// with pre-set call options.
type ApplicationCallerSession struct {
Contract *ApplicationCaller // Generic contract caller binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session
}
// ApplicationTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
// with pre-set transact options.
type ApplicationTransactorSession struct {
Contract *ApplicationTransactor // Generic contract transactor binding to set the session for
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}
// ApplicationRaw is an auto generated low-level Go binding around an Ethereum contract.
type ApplicationRaw struct {
Contract *Application // Generic contract binding to access the raw methods on
}
// ApplicationCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
type ApplicationCallerRaw struct {
Contract *ApplicationCaller // Generic read-only contract binding to access the raw methods on
}
// ApplicationTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
type ApplicationTransactorRaw struct {
Contract *ApplicationTransactor // Generic write-only contract binding to access the raw methods on
}
// NewApplication creates a new instance of Application, bound to a specific deployed contract.
func NewApplication(address common.Address, backend bind.ContractBackend) (*Application, error) {
contract, err := bindApplication(address, backend, backend, backend)
if err != nil {
return nil, err
}
return &Application{ApplicationCaller: ApplicationCaller{contract: contract}, ApplicationTransactor: ApplicationTransactor{contract: contract}, ApplicationFilterer: ApplicationFilterer{contract: contract}}, nil
}
// NewApplicationCaller creates a new read-only instance of Application, bound to a specific deployed contract.
func NewApplicationCaller(address common.Address, caller bind.ContractCaller) (*ApplicationCaller, error) {
contract, err := bindApplication(address, caller, nil, nil)
if err != nil {
return nil, err
}
return &ApplicationCaller{contract: contract}, nil
}
// NewApplicationTransactor creates a new write-only instance of Application, bound to a specific deployed contract.
func NewApplicationTransactor(address common.Address, transactor bind.ContractTransactor) (*ApplicationTransactor, error) {
contract, err := bindApplication(address, nil, transactor, nil)
if err != nil {
return nil, err
}
return &ApplicationTransactor{contract: contract}, nil
}
// NewApplicationFilterer creates a new log filterer instance of Application, bound to a specific deployed contract.
func NewApplicationFilterer(address common.Address, filterer bind.ContractFilterer) (*ApplicationFilterer, error) {
contract, err := bindApplication(address, nil, nil, filterer)
if err != nil {
return nil, err
}
return &ApplicationFilterer{contract: contract}, nil
}
// bindApplication binds a generic wrapper to an already deployed contract.
func bindApplication(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
parsed, err := abi.JSON(strings.NewReader(ApplicationABI))
if err != nil {
return nil, err
}
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
}
// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_Application *ApplicationRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
return _Application.Contract.ApplicationCaller.contract.Call(opts, result, method, params...)
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_Application *ApplicationRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _Application.Contract.ApplicationTransactor.contract.Transfer(opts)
}
// Transact invokes the (paid) contract method with params as input values.
func (_Application *ApplicationRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _Application.Contract.ApplicationTransactor.contract.Transact(opts, method, params...)
}
// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_Application *ApplicationCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
return _Application.Contract.contract.Call(opts, result, method, params...)
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_Application *ApplicationTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _Application.Contract.contract.Transfer(opts)
}
// Transact invokes the (paid) contract method with params as input values.
func (_Application *ApplicationTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _Application.Contract.contract.Transact(opts, method, params...)
}
// Const is a free data retrieval call binding the contract method 0xe76dba42.
//
// Solidity: function _const() view returns(address)
func (_Application *ApplicationCaller) Const(opts *bind.CallOpts) (common.Address, error) {
var out []interface{}
err := _Application.contract.Call(opts, &out, "_const")
if err != nil {
return *new(common.Address), err
}
out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address)
return out0, err
}
// Const is a free data retrieval call binding the contract method 0xe76dba42.
//
// Solidity: function _const() view returns(address)
func (_Application *ApplicationSession) Const() (common.Address, error) {
return _Application.Contract.Const(&_Application.CallOpts)
}
// Const is a free data retrieval call binding the contract method 0xe76dba42.
//
// Solidity: function _const() view returns(address)
func (_Application *ApplicationCallerSession) Const() (common.Address, error) {
return _Application.Contract.Const(&_Application.CallOpts)
}
// GetAppIds is a free data retrieval call binding the contract method 0xc317ba43.
//
// Solidity: function getAppIds(uint8 start, uint8 count) view returns(string[] res)
func (_Application *ApplicationCaller) GetAppIds(opts *bind.CallOpts, start uint8, count uint8) ([]string, error) {
var out []interface{}
err := _Application.contract.Call(opts, &out, "getAppIds", start, count)
if err != nil {
return *new([]string), err
}
out0 := *abi.ConvertType(out[0], new([]string)).(*[]string)
return out0, err
}
// GetAppIds is a free data retrieval call binding the contract method 0xc317ba43.
//
// Solidity: function getAppIds(uint8 start, uint8 count) view returns(string[] res)
func (_Application *ApplicationSession) GetAppIds(start uint8, count uint8) ([]string, error) {
return _Application.Contract.GetAppIds(&_Application.CallOpts, start, count)
}
// GetAppIds is a free data retrieval call binding the contract method 0xc317ba43.
//
// Solidity: function getAppIds(uint8 start, uint8 count) view returns(string[] res)
func (_Application *ApplicationCallerSession) GetAppIds(start uint8, count uint8) ([]string, error) {
return _Application.Contract.GetAppIds(&_Application.CallOpts, start, count)
}
// GetAppIdsForNode is a free data retrieval call binding the contract method 0x1b10a03c.
//
// Solidity: function getAppIdsForNode(string nodeId, uint8 start, uint8 count) view returns(string[] res)
func (_Application *ApplicationCaller) GetAppIdsForNode(opts *bind.CallOpts, nodeId string, start uint8, count uint8) ([]string, error) {
var out []interface{}
err := _Application.contract.Call(opts, &out, "getAppIdsForNode", nodeId, start, count)
if err != nil {
return *new([]string), err
}
out0 := *abi.ConvertType(out[0], new([]string)).(*[]string)
return out0, err
}
// GetAppIdsForNode is a free data retrieval call binding the contract method 0x1b10a03c.
//
// Solidity: function getAppIdsForNode(string nodeId, uint8 start, uint8 count) view returns(string[] res)
func (_Application *ApplicationSession) GetAppIdsForNode(nodeId string, start uint8, count uint8) ([]string, error) {
return _Application.Contract.GetAppIdsForNode(&_Application.CallOpts, nodeId, start, count)
}
// GetAppIdsForNode is a free data retrieval call binding the contract method 0x1b10a03c.
//
// Solidity: function getAppIdsForNode(string nodeId, uint8 start, uint8 count) view returns(string[] res)
func (_Application *ApplicationCallerSession) GetAppIdsForNode(nodeId string, start uint8, count uint8) ([]string, error) {
return _Application.Contract.GetAppIdsForNode(&_Application.CallOpts, nodeId, start, count)
}
// GetAppInfo is a free data retrieval call binding the contract method 0x3acefa17.
//
// Solidity: function getAppInfo(string appId) view returns(string name, string version, string status, string resolutionRatio, string fps, string gamePads, string isHdrSupported)
func (_Application *ApplicationCaller) GetAppInfo(opts *bind.CallOpts, appId string) (struct {
Name string
Version string
Status string
ResolutionRatio string
Fps string
GamePads string
IsHdrSupported string
}, error) {
var out []interface{}
err := _Application.contract.Call(opts, &out, "getAppInfo", appId)
outstruct := new(struct {
Name string
Version string
Status string
ResolutionRatio string
Fps string
GamePads string
IsHdrSupported string
})
if err != nil {
return *outstruct, err
}
outstruct.Name = *abi.ConvertType(out[0], new(string)).(*string)
outstruct.Version = *abi.ConvertType(out[1], new(string)).(*string)
outstruct.Status = *abi.ConvertType(out[2], new(string)).(*string)
outstruct.ResolutionRatio = *abi.ConvertType(out[3], new(string)).(*string)
outstruct.Fps = *abi.ConvertType(out[4], new(string)).(*string)
outstruct.GamePads = *abi.ConvertType(out[5], new(string)).(*string)
outstruct.IsHdrSupported = *abi.ConvertType(out[6], new(string)).(*string)
return *outstruct, err
}
// GetAppInfo is a free data retrieval call binding the contract method 0x3acefa17.
//
// Solidity: function getAppInfo(string appId) view returns(string name, string version, string status, string resolutionRatio, string fps, string gamePads, string isHdrSupported)
func (_Application *ApplicationSession) GetAppInfo(appId string) (struct {
Name string
Version string
Status string
ResolutionRatio string
Fps string
GamePads string
IsHdrSupported string
}, error) {
return _Application.Contract.GetAppInfo(&_Application.CallOpts, appId)
}
// GetAppInfo is a free data retrieval call binding the contract method 0x3acefa17.
//
// Solidity: function getAppInfo(string appId) view returns(string name, string version, string status, string resolutionRatio, string fps, string gamePads, string isHdrSupported)
func (_Application *ApplicationCallerSession) GetAppInfo(appId string) (struct {
Name string
Version string
Status string
ResolutionRatio string
Fps string
GamePads string
IsHdrSupported string
}, error) {
return _Application.Contract.GetAppInfo(&_Application.CallOpts, appId)
}
// GetNodeIds is a free data retrieval call binding the contract method 0xb85e84c2.
//
// Solidity: function getNodeIds(string appId, uint8 start, uint8 count) view returns(string[] res)
func (_Application *ApplicationCaller) GetNodeIds(opts *bind.CallOpts, appId string, start uint8, count uint8) ([]string, error) {
var out []interface{}
err := _Application.contract.Call(opts, &out, "getNodeIds", appId, start, count)
if err != nil {
return *new([]string), err
}
out0 := *abi.ConvertType(out[0], new([]string)).(*[]string)
return out0, err
}
// GetNodeIds is a free data retrieval call binding the contract method 0xb85e84c2.
//
// Solidity: function getNodeIds(string appId, uint8 start, uint8 count) view returns(string[] res)
func (_Application *ApplicationSession) GetNodeIds(appId string, start uint8, count uint8) ([]string, error) {
return _Application.Contract.GetNodeIds(&_Application.CallOpts, appId, start, count)
}
// GetNodeIds is a free data retrieval call binding the contract method 0xb85e84c2.
//
// Solidity: function getNodeIds(string appId, uint8 start, uint8 count) view returns(string[] res)
func (_Application *ApplicationCallerSession) GetNodeIds(appId string, start uint8, count uint8) ([]string, error) {
return _Application.Contract.GetNodeIds(&_Application.CallOpts, appId, start, count)
}
// GetNodeNetwork is a free data retrieval call binding the contract method 0xc3a616ea.
//
// Solidity: function getNodeNetwork(string nodeId) view returns(string externalIp, string serverPort, string[] stunIp, string[] turnIp, string[] turnUser, string[] turnPwd, string signallingHttpIp, string signallingWsIp)
func (_Application *ApplicationCaller) GetNodeNetwork(opts *bind.CallOpts, nodeId string) (struct {
ExternalIp string
ServerPort string
StunIp []string
TurnIp []string
TurnUser []string
TurnPwd []string
SignallingHttpIp string
SignallingWsIp string
}, error) {
var out []interface{}
err := _Application.contract.Call(opts, &out, "getNodeNetwork", nodeId)
outstruct := new(struct {
ExternalIp string
ServerPort string
StunIp []string
TurnIp []string
TurnUser []string
TurnPwd []string
SignallingHttpIp string
SignallingWsIp string
})
if err != nil {
return *outstruct, err
}
outstruct.ExternalIp = *abi.ConvertType(out[0], new(string)).(*string)
outstruct.ServerPort = *abi.ConvertType(out[1], new(string)).(*string)
outstruct.StunIp = *abi.ConvertType(out[2], new([]string)).(*[]string)
outstruct.TurnIp = *abi.ConvertType(out[3], new([]string)).(*[]string)
outstruct.TurnUser = *abi.ConvertType(out[4], new([]string)).(*[]string)
outstruct.TurnPwd = *abi.ConvertType(out[5], new([]string)).(*[]string)
outstruct.SignallingHttpIp = *abi.ConvertType(out[6], new(string)).(*string)
outstruct.SignallingWsIp = *abi.ConvertType(out[7], new(string)).(*string)
return *outstruct, err
}
// GetNodeNetwork is a free data retrieval call binding the contract method 0xc3a616ea.
//
// Solidity: function getNodeNetwork(string nodeId) view returns(string externalIp, string serverPort, string[] stunIp, string[] turnIp, string[] turnUser, string[] turnPwd, string signallingHttpIp, string signallingWsIp)
func (_Application *ApplicationSession) GetNodeNetwork(nodeId string) (struct {
ExternalIp string
ServerPort string
StunIp []string
TurnIp []string
TurnUser []string
TurnPwd []string
SignallingHttpIp string
SignallingWsIp string
}, error) {
return _Application.Contract.GetNodeNetwork(&_Application.CallOpts, nodeId)
}
// GetNodeNetwork is a free data retrieval call binding the contract method 0xc3a616ea.
//
// Solidity: function getNodeNetwork(string nodeId) view returns(string externalIp, string serverPort, string[] stunIp, string[] turnIp, string[] turnUser, string[] turnPwd, string signallingHttpIp, string signallingWsIp)
func (_Application *ApplicationCallerSession) GetNodeNetwork(nodeId string) (struct {
ExternalIp string
ServerPort string
StunIp []string
TurnIp []string
TurnUser []string
TurnPwd []string
SignallingHttpIp string
SignallingWsIp string
}, error) {
return _Application.Contract.GetNodeNetwork(&_Application.CallOpts, nodeId)
}
// IsAdmin is a free data retrieval call binding the contract method 0x24d7806c.
//
// Solidity: function isAdmin(address _addr) view returns(bool)
func (_Application *ApplicationCaller) IsAdmin(opts *bind.CallOpts, _addr common.Address) (bool, error) {
var out []interface{}
err := _Application.contract.Call(opts, &out, "isAdmin", _addr)
if err != nil {
return *new(bool), err
}
out0 := *abi.ConvertType(out[0], new(bool)).(*bool)
return out0, err
}
// IsAdmin is a free data retrieval call binding the contract method 0x24d7806c.
//
// Solidity: function isAdmin(address _addr) view returns(bool)
func (_Application *ApplicationSession) IsAdmin(_addr common.Address) (bool, error) {
return _Application.Contract.IsAdmin(&_Application.CallOpts, _addr)
}
// IsAdmin is a free data retrieval call binding the contract method 0x24d7806c.
//
// Solidity: function isAdmin(address _addr) view returns(bool)
func (_Application *ApplicationCallerSession) IsAdmin(_addr common.Address) (bool, error) {
return _Application.Contract.IsAdmin(&_Application.CallOpts, _addr)
}
// IsAppBoundToNode is a free data retrieval call binding the contract method 0xfbbaf2c1.
//
// Solidity: function isAppBoundToNode(string appId, string nodeId) view returns(bool)
func (_Application *ApplicationCaller) IsAppBoundToNode(opts *bind.CallOpts, appId string, nodeId string) (bool, error) {
var out []interface{}
err := _Application.contract.Call(opts, &out, "isAppBoundToNode", appId, nodeId)
if err != nil {
return *new(bool), err
}
out0 := *abi.ConvertType(out[0], new(bool)).(*bool)
return out0, err
}
// IsAppBoundToNode is a free data retrieval call binding the contract method 0xfbbaf2c1.
//
// Solidity: function isAppBoundToNode(string appId, string nodeId) view returns(bool)
func (_Application *ApplicationSession) IsAppBoundToNode(appId string, nodeId string) (bool, error) {
return _Application.Contract.IsAppBoundToNode(&_Application.CallOpts, appId, nodeId)
}
// IsAppBoundToNode is a free data retrieval call binding the contract method 0xfbbaf2c1.
//
// Solidity: function isAppBoundToNode(string appId, string nodeId) view returns(bool)
func (_Application *ApplicationCallerSession) IsAppBoundToNode(appId string, nodeId string) (bool, error) {
return _Application.Contract.IsAppBoundToNode(&_Application.CallOpts, appId, nodeId)
}
// Owner is a free data retrieval call binding the contract method 0x8da5cb5b.
//
// Solidity: function owner() view returns(address)
func (_Application *ApplicationCaller) Owner(opts *bind.CallOpts) (common.Address, error) {
var out []interface{}
err := _Application.contract.Call(opts, &out, "owner")
if err != nil {
return *new(common.Address), err
}
out0 := *abi.ConvertType(out[0], new(common.Address)).(*common.Address)
return out0, err
}
// Owner is a free data retrieval call binding the contract method 0x8da5cb5b.
//
// Solidity: function owner() view returns(address)
func (_Application *ApplicationSession) Owner() (common.Address, error) {
return _Application.Contract.Owner(&_Application.CallOpts)
}
// Owner is a free data retrieval call binding the contract method 0x8da5cb5b.
//
// Solidity: function owner() view returns(address)
func (_Application *ApplicationCallerSession) Owner() (common.Address, error) {
return _Application.Contract.Owner(&_Application.CallOpts)
}
// AddAdmin is a paid mutator transaction binding the contract method 0x70480275.
//
// Solidity: function addAdmin(address _admin) returns()
func (_Application *ApplicationTransactor) AddAdmin(opts *bind.TransactOpts, _admin common.Address) (*types.Transaction, error) {
return _Application.contract.Transact(opts, "addAdmin", _admin)
}
// AddAdmin is a paid mutator transaction binding the contract method 0x70480275.
//
// Solidity: function addAdmin(address _admin) returns()
func (_Application *ApplicationSession) AddAdmin(_admin common.Address) (*types.Transaction, error) {
return _Application.Contract.AddAdmin(&_Application.TransactOpts, _admin)
}
// AddAdmin is a paid mutator transaction binding the contract method 0x70480275.
//
// Solidity: function addAdmin(address _admin) returns()
func (_Application *ApplicationTransactorSession) AddAdmin(_admin common.Address) (*types.Transaction, error) {
return _Application.Contract.AddAdmin(&_Application.TransactOpts, _admin)
}
// AddAppInfo is a paid mutator transaction binding the contract method 0x5ea4ff47.
//
// Solidity: function addAppInfo(string nodeId, string appId, string name, string version, string status, string resolutionRatio, string fps, string gamePads, string isHdrSupported) returns()
func (_Application *ApplicationTransactor) AddAppInfo(opts *bind.TransactOpts, nodeId string, appId string, name string, version string, status string, resolutionRatio string, fps string, gamePads string, isHdrSupported string) (*types.Transaction, error) {
return _Application.contract.Transact(opts, "addAppInfo", nodeId, appId, name, version, status, resolutionRatio, fps, gamePads, isHdrSupported)
}
// AddAppInfo is a paid mutator transaction binding the contract method 0x5ea4ff47.
//
// Solidity: function addAppInfo(string nodeId, string appId, string name, string version, string status, string resolutionRatio, string fps, string gamePads, string isHdrSupported) returns()
func (_Application *ApplicationSession) AddAppInfo(nodeId string, appId string, name string, version string, status string, resolutionRatio string, fps string, gamePads string, isHdrSupported string) (*types.Transaction, error) {
return _Application.Contract.AddAppInfo(&_Application.TransactOpts, nodeId, appId, name, version, status, resolutionRatio, fps, gamePads, isHdrSupported)
}
// AddAppInfo is a paid mutator transaction binding the contract method 0x5ea4ff47.
//
// Solidity: function addAppInfo(string nodeId, string appId, string name, string version, string status, string resolutionRatio, string fps, string gamePads, string isHdrSupported) returns()
func (_Application *ApplicationTransactorSession) AddAppInfo(nodeId string, appId string, name string, version string, status string, resolutionRatio string, fps string, gamePads string, isHdrSupported string) (*types.Transaction, error) {
return _Application.Contract.AddAppInfo(&_Application.TransactOpts, nodeId, appId, name, version, status, resolutionRatio, fps, gamePads, isHdrSupported)
}
// AddNodeNetworkInfo is a paid mutator transaction binding the contract method 0x103418a4.
//
// Solidity: function addNodeNetworkInfo(string nodeId, string externalIp, string serverPort, string[] stunIp, string[] turnIp, string[] turnUser, string[] turnPwd, string signallingHttpIp, string signallingWsIp) returns()
func (_Application *ApplicationTransactor) AddNodeNetworkInfo(opts *bind.TransactOpts, nodeId string, externalIp string, serverPort string, stunIp []string, turnIp []string, turnUser []string, turnPwd []string, signallingHttpIp string, signallingWsIp string) (*types.Transaction, error) {
return _Application.contract.Transact(opts, "addNodeNetworkInfo", nodeId, externalIp, serverPort, stunIp, turnIp, turnUser, turnPwd, signallingHttpIp, signallingWsIp)
}
// AddNodeNetworkInfo is a paid mutator transaction binding the contract method 0x103418a4.
//
// Solidity: function addNodeNetworkInfo(string nodeId, string externalIp, string serverPort, string[] stunIp, string[] turnIp, string[] turnUser, string[] turnPwd, string signallingHttpIp, string signallingWsIp) returns()
func (_Application *ApplicationSession) AddNodeNetworkInfo(nodeId string, externalIp string, serverPort string, stunIp []string, turnIp []string, turnUser []string, turnPwd []string, signallingHttpIp string, signallingWsIp string) (*types.Transaction, error) {
return _Application.Contract.AddNodeNetworkInfo(&_Application.TransactOpts, nodeId, externalIp, serverPort, stunIp, turnIp, turnUser, turnPwd, signallingHttpIp, signallingWsIp)
}
// AddNodeNetworkInfo is a paid mutator transaction binding the contract method 0x103418a4.
//
// Solidity: function addNodeNetworkInfo(string nodeId, string externalIp, string serverPort, string[] stunIp, string[] turnIp, string[] turnUser, string[] turnPwd, string signallingHttpIp, string signallingWsIp) returns()
func (_Application *ApplicationTransactorSession) AddNodeNetworkInfo(nodeId string, externalIp string, serverPort string, stunIp []string, turnIp []string, turnUser []string, turnPwd []string, signallingHttpIp string, signallingWsIp string) (*types.Transaction, error) {
return _Application.Contract.AddNodeNetworkInfo(&_Application.TransactOpts, nodeId, externalIp, serverPort, stunIp, turnIp, turnUser, turnPwd, signallingHttpIp, signallingWsIp)
}
// BatchAddAppInfo is a paid mutator transaction binding the contract method 0x93c011c2.
//
// Solidity: function batchAddAppInfo(string nodeId, string[] appId, string[] name, string[] version, string[] status, string[] resolutionRatio, string[] fps, string[] gamePads, string[] isHdrSupported) returns()
func (_Application *ApplicationTransactor) BatchAddAppInfo(opts *bind.TransactOpts, nodeId string, appId []string, name []string, version []string, status []string, resolutionRatio []string, fps []string, gamePads []string, isHdrSupported []string) (*types.Transaction, error) {
return _Application.contract.Transact(opts, "batchAddAppInfo", nodeId, appId, name, version, status, resolutionRatio, fps, gamePads, isHdrSupported)
}
// BatchAddAppInfo is a paid mutator transaction binding the contract method 0x93c011c2.
//
// Solidity: function batchAddAppInfo(string nodeId, string[] appId, string[] name, string[] version, string[] status, string[] resolutionRatio, string[] fps, string[] gamePads, string[] isHdrSupported) returns()
func (_Application *ApplicationSession) BatchAddAppInfo(nodeId string, appId []string, name []string, version []string, status []string, resolutionRatio []string, fps []string, gamePads []string, isHdrSupported []string) (*types.Transaction, error) {
return _Application.Contract.BatchAddAppInfo(&_Application.TransactOpts, nodeId, appId, name, version, status, resolutionRatio, fps, gamePads, isHdrSupported)
}
// BatchAddAppInfo is a paid mutator transaction binding the contract method 0x93c011c2.
//
// Solidity: function batchAddAppInfo(string nodeId, string[] appId, string[] name, string[] version, string[] status, string[] resolutionRatio, string[] fps, string[] gamePads, string[] isHdrSupported) returns()
func (_Application *ApplicationTransactorSession) BatchAddAppInfo(nodeId string, appId []string, name []string, version []string, status []string, resolutionRatio []string, fps []string, gamePads []string, isHdrSupported []string) (*types.Transaction, error) {
return _Application.Contract.BatchAddAppInfo(&_Application.TransactOpts, nodeId, appId, name, version, status, resolutionRatio, fps, gamePads, isHdrSupported)
}
// DelAdmin is a paid mutator transaction binding the contract method 0x62d91855.
//
// Solidity: function delAdmin(address _admin) returns()
func (_Application *ApplicationTransactor) DelAdmin(opts *bind.TransactOpts, _admin common.Address) (*types.Transaction, error) {
return _Application.contract.Transact(opts, "delAdmin", _admin)
}
// DelAdmin is a paid mutator transaction binding the contract method 0x62d91855.
//
// Solidity: function delAdmin(address _admin) returns()
func (_Application *ApplicationSession) DelAdmin(_admin common.Address) (*types.Transaction, error) {
return _Application.Contract.DelAdmin(&_Application.TransactOpts, _admin)
}
// DelAdmin is a paid mutator transaction binding the contract method 0x62d91855.
//
// Solidity: function delAdmin(address _admin) returns()
func (_Application *ApplicationTransactorSession) DelAdmin(_admin common.Address) (*types.Transaction, error) {
return _Application.Contract.DelAdmin(&_Application.TransactOpts, _admin)
}
// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6.
//
// Solidity: function renounceOwnership() returns()
func (_Application *ApplicationTransactor) RenounceOwnership(opts *bind.TransactOpts) (*types.Transaction, error) {
return _Application.contract.Transact(opts, "renounceOwnership")
}
// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6.
//
// Solidity: function renounceOwnership() returns()
func (_Application *ApplicationSession) RenounceOwnership() (*types.Transaction, error) {
return _Application.Contract.RenounceOwnership(&_Application.TransactOpts)
}
// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6.
//
// Solidity: function renounceOwnership() returns()
func (_Application *ApplicationTransactorSession) RenounceOwnership() (*types.Transaction, error) {
return _Application.Contract.RenounceOwnership(&_Application.TransactOpts)
}
// SetConstant is a paid mutator transaction binding the contract method 0xc88e7e42.
//
// Solidity: function setConstant(address const) returns()
func (_Application *ApplicationTransactor) SetConstant(opts *bind.TransactOpts, arg0 common.Address) (*types.Transaction, error) {
return _Application.contract.Transact(opts, "setConstant", arg0)
}
// SetConstant is a paid mutator transaction binding the contract method 0xc88e7e42.
//
// Solidity: function setConstant(address const) returns()
func (_Application *ApplicationSession) SetConstant(arg0 common.Address) (*types.Transaction, error) {
return _Application.Contract.SetConstant(&_Application.TransactOpts, arg0)
}
// SetConstant is a paid mutator transaction binding the contract method 0xc88e7e42.
//
// Solidity: function setConstant(address const) returns()
func (_Application *ApplicationTransactorSession) SetConstant(arg0 common.Address) (*types.Transaction, error) {
return _Application.Contract.SetConstant(&_Application.TransactOpts, arg0)
}
// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b.
//
// Solidity: function transferOwnership(address newOwner) returns()
func (_Application *ApplicationTransactor) TransferOwnership(opts *bind.TransactOpts, newOwner common.Address) (*types.Transaction, error) {
return _Application.contract.Transact(opts, "transferOwnership", newOwner)
}
// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b.
//
// Solidity: function transferOwnership(address newOwner) returns()
func (_Application *ApplicationSession) TransferOwnership(newOwner common.Address) (*types.Transaction, error) {
return _Application.Contract.TransferOwnership(&_Application.TransactOpts, newOwner)
}
// TransferOwnership is a paid mutator transaction binding the contract method 0xf2fde38b.
//
// Solidity: function transferOwnership(address newOwner) returns()
func (_Application *ApplicationTransactorSession) TransferOwnership(newOwner common.Address) (*types.Transaction, error) {
return _Application.Contract.TransferOwnership(&_Application.TransactOpts, newOwner)
}
// ApplicationOwnershipTransferredIterator is returned from FilterOwnershipTransferred and is used to iterate over the raw logs and unpacked data for OwnershipTransferred events raised by the Application contract.
type ApplicationOwnershipTransferredIterator struct {
Event *ApplicationOwnershipTransferred // Event containing the contract specifics and raw log
contract *bind.BoundContract // Generic contract to use for unpacking event data
event string // Event name to use for unpacking event data
logs chan types.Log // Log channel receiving the found contract events
sub ethereum.Subscription // Subscription for errors, completion and termination
done bool // Whether the subscription completed delivering logs
fail error // Occurred error to stop iteration
}
// Next advances the iterator to the subsequent event, returning whether there
// are any more events found. In case of a retrieval or parsing error, false is
// returned and Error() can be queried for the exact failure.
func (it *ApplicationOwnershipTransferredIterator) Next() bool {
// If the iterator failed, stop iterating
if it.fail != nil {
return false
}
// If the iterator completed, deliver directly whatever's available
if it.done {
select {
case log := <-it.logs:
it.Event = new(ApplicationOwnershipTransferred)
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
it.fail = err
return false
}
it.Event.Raw = log
return true
default:
return false
}
}
// Iterator still in progress, wait for either a data or an error event
select {
case log := <-it.logs:
it.Event = new(ApplicationOwnershipTransferred)
if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
it.fail = err
return false
}
it.Event.Raw = log
return true
case err := <-it.sub.Err():
it.done = true
it.fail = err
return it.Next()
}
}
// Error returns any retrieval or parsing error occurred during filtering.
func (it *ApplicationOwnershipTransferredIterator) Error() error {
return it.fail
}
// Close terminates the iteration process, releasing any pending underlying
// resources.
func (it *ApplicationOwnershipTransferredIterator) Close() error {
it.sub.Unsubscribe()
return nil
}
// ApplicationOwnershipTransferred represents a OwnershipTransferred event raised by the Application contract.
type ApplicationOwnershipTransferred struct {
PreviousOwner common.Address
NewOwner common.Address
Raw types.Log // Blockchain specific contextual infos
}
// FilterOwnershipTransferred is a free log retrieval operation binding the contract event 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0.
//
// Solidity: event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
func (_Application *ApplicationFilterer) FilterOwnershipTransferred(opts *bind.FilterOpts, previousOwner []common.Address, newOwner []common.Address) (*ApplicationOwnershipTransferredIterator, error) {
var previousOwnerRule []interface{}
for _, previousOwnerItem := range previousOwner {
previousOwnerRule = append(previousOwnerRule, previousOwnerItem)
}
var newOwnerRule []interface{}
for _, newOwnerItem := range newOwner {
newOwnerRule = append(newOwnerRule, newOwnerItem)
}
logs, sub, err := _Application.contract.FilterLogs(opts, "OwnershipTransferred", previousOwnerRule, newOwnerRule)
if err != nil {
return nil, err
}
return &ApplicationOwnershipTransferredIterator{contract: _Application.contract, event: "OwnershipTransferred", logs: logs, sub: sub}, nil
}
// WatchOwnershipTransferred is a free log subscription operation binding the contract event 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0.
//
// Solidity: event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
func (_Application *ApplicationFilterer) WatchOwnershipTransferred(opts *bind.WatchOpts, sink chan<- *ApplicationOwnershipTransferred, previousOwner []common.Address, newOwner []common.Address) (event.Subscription, error) {
var previousOwnerRule []interface{}
for _, previousOwnerItem := range previousOwner {
previousOwnerRule = append(previousOwnerRule, previousOwnerItem)
}
var newOwnerRule []interface{}
for _, newOwnerItem := range newOwner {
newOwnerRule = append(newOwnerRule, newOwnerItem)
}
logs, sub, err := _Application.contract.WatchLogs(opts, "OwnershipTransferred", previousOwnerRule, newOwnerRule)
if err != nil {
return nil, err
}
return event.NewSubscription(func(quit <-chan struct{}) error {
defer sub.Unsubscribe()
for {
select {
case log := <-logs:
// New log arrived, parse the event and forward to the user
event := new(ApplicationOwnershipTransferred)
if err := _Application.contract.UnpackLog(event, "OwnershipTransferred", log); err != nil {
return err
}
event.Raw = log
select {
case sink <- event:
case err := <-sub.Err():
return err
case <-quit:
return nil
}
case err := <-sub.Err():
return err
case <-quit:
return nil
}
}
}), nil
}
// ParseOwnershipTransferred is a log parse operation binding the contract event 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0.
//
// Solidity: event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
func (_Application *ApplicationFilterer) ParseOwnershipTransferred(log types.Log) (*ApplicationOwnershipTransferred, error) {
event := new(ApplicationOwnershipTransferred)
if err := _Application.contract.UnpackLog(event, "OwnershipTransferred", log); err != nil {
return nil, err
}
event.Raw = log
return event, nil
}
package controllers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
)
type BaseController struct {
beego.Controller
}
func (d *BaseController) ResponseInfo(code int, msg interface{}, result interface{}) {
switch code {
case 500:
logs.Error(msg, result)
d.Data["json"] = map[string]interface{}{"code": "500", "msg": msg, "data": result}
case 200:
logs.Info(msg, result)
d.Data["json"] = map[string]interface{}{"code": "200", "msg": msg, "data": result}
}
d.ServeJSON()
}
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"math/big"
"schedulerNode/appNodeInterface"
nodeCommon "schedulerNode/common"
application "schedulerNode/contract/go_file"
"schedulerNode/log"
"schedulerNode/models"
"schedulerNode/utils"
"strings"
)
type SignalingController struct {
BaseController
}
func (c *SignalingController) GetConnectSignalingStatus() {
// TODO: 获取前端传入的ExternalIp 以及 Port
body := c.Ctx.Input.RequestBody
signallingStatus := models.SignallingConnectStatusReq{}
err := json.Unmarshal(body, &signallingStatus)
if err != nil {
c.ResponseInfo(500, "Error unmarshalling", err)
return
}
rpcUrl := beego.AppConfig.String("chain::rpcUrl")
appContract := beego.AppConfig.String("contract_address::app_contract")
client, err := ethclient.Dial(rpcUrl)
if err != nil {
c.ResponseInfo(nodeCommon.FaileCode, "Error connecting", err)
}
defer client.Close()
appContractAddr := common.HexToAddress(appContract)
applicationInstance, err := application.NewApplication(appContractAddr, client)
if err != nil {
c.ResponseInfo(nodeCommon.FaileCode, "Error creating application", err)
}
network, err := applicationInstance.GetNodeNetwork(&bind.CallOpts{}, signallingStatus.NodeId)
if err != nil {
c.ResponseInfo(nodeCommon.FaileCode, "Error get NodeNetwork application", err)
}
// TODO: 调用App节点接口获取连接信令状态
statusResp := appNodeInterface.GetSignallingConnectStatus(network.ExternalIp, network.ServerPort)
if !statusResp.Status || statusResp.Code != nodeCommon.SuccessCode {
c.ResponseInfo(nodeCommon.SuccessCode, "disconnected", nil)
}
c.ResponseInfo(nodeCommon.SuccessCode, "success", nil)
}
func (c *SignalingController) GetAppNodeInfo() {
body := c.Ctx.Input.RequestBody
connectAppReq := &models.ConnectAppReq{}
err := json.Unmarshal(body, connectAppReq)
if err != nil {
c.ResponseInfo(nodeCommon.FaileCode, "Error unmarshalling", err)
}
rpcUrl := beego.AppConfig.String("chain::rpcUrl")
appContract := beego.AppConfig.String("contract_address::app_contract")
client, err := ethclient.Dial(rpcUrl)
if err != nil {
c.ResponseInfo(nodeCommon.FaileCode, "Error connecting", err)
}
defer client.Close()
// TODO 获取全部的节点Id
appContractAddr := common.HexToAddress(appContract)
applicationInstance, err := application.NewApplication(appContractAddr, client)
if err != nil {
c.ResponseInfo(nodeCommon.FaileCode, "Error creating application", err)
}
nodeIds, err := applicationInstance.GetNodeIds(&bind.CallOpts{}, connectAppReq.AppId, 0, 100)
if err != nil {
c.ResponseInfo(nodeCommon.FaileCode, "Error GetNodeIds ", err)
}
if len(nodeIds) == 0 {
c.ResponseInfo(nodeCommon.SuccessCode, "There is currently no node provided to launch the application", nil)
}
nodeNetworkInfo := models.AppNodeNetworkInfo{}
// TODO 通过节点ID获取网络信息
for _, nodeId := range nodeIds {
network, err := applicationInstance.GetNodeNetwork(&bind.CallOpts{}, nodeId)
if err != nil {
c.ResponseInfo(nodeCommon.FaileCode, "Error GetAppNodeNetwork ", err)
}
//if i == len(nodeIds)-1 {
if utils.IsCreateVmCondition(network.ExternalIp) {
nodeNetworkInfo.NodeId = nodeId
nodeNetworkInfo.ExternalIp = network.ExternalIp
nodeNetworkInfo.ServerPort = network.ServerPort
nodeNetworkInfo.StunIp = network.StunIp
nodeNetworkInfo.TurnIp = network.TurnIp
nodeNetworkInfo.TurnUser = network.TurnUser
nodeNetworkInfo.TurnPwd = network.TurnPwd
nodeNetworkInfo.SignallingHttpIp = network.SignallingHttpIp
nodeNetworkInfo.SignallingWsIp = network.SignallingWsIp
break
}
//}
}
// TODO 如果没有对应的服务信息
updateServerInfo(&nodeNetworkInfo)
// TODO 通知应用节点连接信令节点
sendSignallingReq := handlerSendSignallingInfo(&nodeNetworkInfo)
rep := appNodeInterface.SendSignallingInfo(nodeNetworkInfo.ExternalIp, nodeNetworkInfo.ServerPort, sendSignallingReq)
if rep.Code != nodeCommon.SuccessCode {
log.Error("Error sending signalling information failed", rep.Msg)
c.ResponseInfo(nodeCommon.FaileCode, "Notice signalling information failed", rep.Msg)
}
// TODO: 反馈前端信息
res := models.AppNodeInfoRep{
NodeID: nodeNetworkInfo.NodeId,
ExternalIp: nodeNetworkInfo.ExternalIp,
StunIp: nodeNetworkInfo.StunIp,
SignallingHttpIp: nodeNetworkInfo.SignallingHttpIp,
SignallingWsIp: nodeNetworkInfo.SignallingWsIp,
}
turnInfoArr := make([]*models.TurnInfo, 0)
for i := 0; i < len(nodeNetworkInfo.TurnIp); i++ {
turnInfo := &models.TurnInfo{
TurnIp: nodeNetworkInfo.TurnIp[i],
User: nodeNetworkInfo.TurnUser[i],
Pwd: nodeNetworkInfo.TurnPwd[i],
}
turnInfoArr = append(turnInfoArr, turnInfo)
}
res.TurnInfo = turnInfoArr
c.ResponseInfo(nodeCommon.SuccessCode, "success", res)
}
func handlerSendSignallingInfo(nodeNetworkInfo *models.AppNodeNetworkInfo) *models.SendSignallingReq {
signallingHttpIpInfo := nodeNetworkInfo.SignallingHttpIp
signallingHttpIpPort := strings.Split(signallingHttpIpInfo, ":")
signallingHttpPort, _ := new(big.Int).SetString(signallingHttpIpPort[1], 10)
signallingWsInfo := nodeNetworkInfo.SignallingWsIp
signallingWsIpPort := strings.Split(signallingWsInfo, ":")
signallingWsPort, _ := new(big.Int).SetString(signallingWsIpPort[1], 10)
turnInfoReqArr := make([]*models.TurnInfoReq, 0)
for i := 0; i < len(nodeNetworkInfo.TurnIp); i++ {
turnInfoReq := &models.TurnInfoReq{
Url: nodeNetworkInfo.TurnIp[i],
UserName: nodeNetworkInfo.TurnUser[i],
Credential: nodeNetworkInfo.TurnPwd[i],
}
turnInfoReqArr = append(turnInfoReqArr, turnInfoReq)
}
sendSignallingReq := &models.SendSignallingReq{
MQTTConnectInfo: &models.MQTTConnectInfo{
Broker: signallingHttpIpPort[0],
Port: signallingHttpPort,
WsPort: signallingWsPort,
},
ICEConnectInfo: &models.ICEConnectInfo{
Stuns: nodeNetworkInfo.StunIp,
Turns: turnInfoReqArr,
},
}
return sendSignallingReq
}
func updateServerInfo(info *models.AppNodeNetworkInfo) {
// TODO: 获取网关合约提供的服务信息
if len(info.TurnIp) == 0 {
}
if len(info.StunIp) == 0 {
}
if info.SignallingHttpIp == "" && info.SignallingWsIp == "" {
}
log.Info("updateServer", info.ExternalIp)
}
module schedulerNode
go 1.19
require github.com/astaxie/beego v1.12.1
require (
github.com/ethereum/go-ethereum v1.13.3
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/oschwald/geoip2-golang v1.9.0
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/sirupsen/logrus v1.9.3
github.com/smartystreets/goconvey v1.6.4
)
require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/bits-and-blooms/bitset v1.5.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.10.0 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/oschwald/maxminddb-golang v1.11.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/shiena/ansicolor v0.0.0-20230509054315-a9deabde6e02 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
package log
import (
"context"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"github.com/rifflock/lfshook"
"github.com/sirupsen/logrus"
"os"
"path"
"time"
)
var (
mlog = logrus.New()
)
type LogConfig struct {
Save uint `json:"save"`
Path string `json:"path"`
Level string `json:"level"`
}
func InitLog(logConfig LogConfig) {
mlog.Out = os.Stdout
var loglevel logrus.Level
err := loglevel.UnmarshalText([]byte(logConfig.Level))
if err != nil {
mlog.Panicf("set log level failed: %v", err)
}
mlog.SetLevel(loglevel)
mlog.Formatter = &logrus.TextFormatter{FullTimestamp: true, TimestampFormat: "2006-01-2 15:04:05.000"}
localFilesystemLogger(mlog, logConfig.Path, logConfig.Save)
}
func logWriter(logPath string, level string, save uint) *rotatelogs.RotateLogs {
logFullPath := path.Join(logPath, level)
logWriter, err := rotatelogs.New(
logFullPath+".%Y%m%d",
rotatelogs.WithLinkName(logFullPath),
rotatelogs.WithRotationCount(save),
rotatelogs.WithRotationTime(24*time.Hour),
)
if err != nil {
panic(err)
}
return logWriter
}
func localFilesystemLogger(log *logrus.Logger, logPath string, save uint) {
lfHook := lfshook.NewHook(lfshook.WriterMap{
logrus.DebugLevel: logWriter(logPath, "debug", save), // 为不同级别设置不同的输出目的
logrus.InfoLevel: logWriter(logPath, "info", save),
logrus.WarnLevel: logWriter(logPath, "warn", save),
logrus.ErrorLevel: logWriter(logPath, "error", save),
logrus.FatalLevel: logWriter(logPath, "fatal", save),
logrus.PanicLevel: logWriter(logPath, "panic", save),
}, &logrus.TextFormatter{FullTimestamp: true, TimestampFormat: "2006-01-2 15:04:05.000"})
log.AddHook(lfHook)
}
// WithField allocates a new entry and adds a field to it.
// Debug, Print, Info, Warn, Error, Fatal or Panic must be then applied to
// this new returned entry.
// If you want multiple fields, use `WithFields`.
func WithField(key string, value interface{}) *logrus.Entry {
return mlog.WithField(key, value)
}
// Adds a struct of fields to the log entry. All it does is call `WithField` for
// each `Field`.
func WithFields(fields logrus.Fields) *logrus.Entry {
return mlog.WithFields(fields)
}
// Add an error as single field to the log entry. All it does is call
// `WithError` for the given `error`.
func WithError(err error) *logrus.Entry {
return mlog.WithError(err)
}
// Add a context to the log entry.
func WithContext(ctx context.Context) *logrus.Entry {
return mlog.WithContext(ctx)
}
// Overrides the time of the log entry.
func WithTime(t time.Time) *logrus.Entry {
return mlog.WithTime(t)
}
func Logf(level logrus.Level, format string, args ...interface{}) {
mlog.Logf(level, format, args...)
}
func Tracef(format string, args ...interface{}) {
mlog.Tracef(format, args...)
}
func Debugf(format string, args ...interface{}) {
mlog.Debugf(format, args...)
}
func Infof(format string, args ...interface{}) {
mlog.Infof(format, args...)
}
func Printf(format string, args ...interface{}) {
mlog.Printf(format, args...)
}
func Warnf(format string, args ...interface{}) {
mlog.Warnf(format, args...)
}
func Warningf(format string, args ...interface{}) {
mlog.Warningf(format, args...)
}
func Errorf(format string, args ...interface{}) {
mlog.Errorf(format, args)
}
func Fatalf(format string, args ...interface{}) {
mlog.Fatalf(format, args...)
}
func Panicf(format string, args ...interface{}) {
mlog.Panicf(format, args...)
}
func Log(level logrus.Level, args ...interface{}) {
mlog.Log(level, args...)
}
func LogFn(level logrus.Level, fn logrus.LogFunction) {
mlog.LogFn(level, fn)
}
func Trace(args ...interface{}) {
mlog.Trace(args...)
}
func Debug(args ...interface{}) {
mlog.Debug(args...)
}
func Info(args ...interface{}) {
mlog.Info(args...)
}
func Print(args ...interface{}) {
mlog.Print(args...)
}
func Warn(args ...interface{}) {
mlog.Warn(args...)
}
func Warning(args ...interface{}) {
mlog.Warning(args...)
}
func Error(args ...interface{}) {
mlog.Error(args...)
}
func Fatal(args ...interface{}) {
mlog.Fatal(args...)
}
func Panic(args ...interface{}) {
mlog.Panic(args...)
}
func TraceFn(fn logrus.LogFunction) {
mlog.TraceFn(fn)
}
func DebugFn(fn logrus.LogFunction) {
mlog.DebugFn(fn)
}
func InfoFn(fn logrus.LogFunction) {
mlog.InfoFn(fn)
}
func PrintFn(fn logrus.LogFunction) {
mlog.PrintFn(fn)
}
func WarnFn(fn logrus.LogFunction) {
mlog.WarnFn(fn)
}
func WarningFn(fn logrus.LogFunction) {
mlog.WarningFn(fn)
}
func ErrorFn(fn logrus.LogFunction) {
mlog.ErrorFn(fn)
}
func FatalFn(fn logrus.LogFunction) {
mlog.FatalFn(fn)
}
func PanicFn(fn logrus.LogFunction) {
mlog.PanicFn(fn)
}
func Logln(level logrus.Level, args ...interface{}) {
mlog.Logln(level, args...)
}
func Traceln(args ...interface{}) {
mlog.Traceln(args...)
}
func Debugln(args ...interface{}) {
mlog.Debugln(args...)
}
func Infoln(args ...interface{}) {
mlog.Infoln(args...)
}
func Println(args ...interface{}) {
mlog.Println(args...)
}
func Warnln(args ...interface{}) {
mlog.Warnln(args...)
}
func Warningln(args ...interface{}) {
mlog.Warningln(args...)
}
func Errorln(args ...interface{}) {
mlog.Errorln(args...)
}
func Fatalln(args ...interface{}) {
mlog.Fatalln(args...)
}
func Panicln(args ...interface{}) {
mlog.Panicln(args...)
}
package main
import (
"github.com/astaxie/beego"
"schedulerNode/log"
"schedulerNode/middleware"
_ "schedulerNode/routers"
)
func main() {
beego.InsertFilter("*", beego.BeforeRouter, middleware.CorsMiddleware)
log.InitLog(log.LogConfig{Path: "logs", Level: "debug", Save: 3})
beego.Run()
}
package middleware
import "github.com/astaxie/beego/context"
func CorsMiddleware(ctx *context.Context) {
// 设置允许跨域的域名
ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
// 允许的方法
ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
// 允许的请求标头
ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "Origin, Authorization, Content-Type")
// 允许跨域 cookie 传递
ctx.ResponseWriter.Header().Set("Access-Control-Allow-Credentials", "true")
// 预检请求的处理
if ctx.Input.Method() == "OPTIONS" {
ctx.ResponseWriter.Header().Set("Access-Control-Max-Age", "86400") // 预检请求结果的缓存时间,单位秒
ctx.ResponseWriter.WriteHeader(200)
}
}
package models
type AppNodeNetworkInfo struct {
NodeId string
ExternalIp string
ServerPort string
StunIp []string
TurnIp []string
TurnUser []string
TurnPwd []string
SignallingHttpIp string
SignallingWsIp string
}
type TurnInfo struct {
TurnIp string
User string
Pwd string
}
package models
import "math/big"
type SignallingConnectStatusReq struct {
NodeId string `json:"nodeId"`
}
type ConnectAppReq struct {
AppId string `json:"appId"`
}
type SendSignallingReq struct {
MQTTConnectInfo *MQTTConnectInfo `json:"MQTTConnectInfo"`
ICEConnectInfo *ICEConnectInfo `json:"ICEConnectInfo"`
}
type MQTTConnectInfo struct {
Broker string `json:"broker"`
Port *big.Int `json:"port"`
WsPort *big.Int `json:"ws_port"`
}
type ICEConnectInfo struct {
Stuns []string `json:"stuns"`
Turns []*TurnInfoReq `json:"turns"`
}
type TurnInfoReq struct {
Url string `json:"url"`
UserName string `json:"username"`
Credential string `json:"credential"`
}
package models
type AppNodeInfoRep struct {
NodeID string `json:"nodeID"`
ExternalIp string `json:"externalIp"`
StunIp []string `json:"stunIp"`
TurnInfo []*TurnInfo `json:"turnInfo"`
SignallingHttpIp string `json:"signallingHttpIp"`
SignallingWsIp string `json:"signallingWsIp"`
}
type SignallingConnectStatusRep struct {
Status string `json:"status"`
}
type AppNodeResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
type SignallingConnectStatus struct {
Code int `json:"code"`
Status bool `json:"status"`
}
package routers
import (
"github.com/astaxie/beego"
"schedulerNode/controllers"
)
func init() {
beego.Router("/api/v1/connect/app", &controllers.SignalingController{}, "post:GetAppNodeInfo")
beego.Router("/api/v1/get/connectStatus", &controllers.SignalingController{}, "post:GetConnectSignalingStatus")
}
package test
import (
"net/http"
"net/http/httptest"
"path/filepath"
"runtime"
_ "schedulerNode/routers"
"testing"
"github.com/astaxie/beego"
. "github.com/smartystreets/goconvey/convey"
)
func init() {
_, file, _, _ := runtime.Caller(0)
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
beego.TestBeegoInit(apppath)
}
// TestBeego is a sample to run an endpoint test
func TestBeego(t *testing.T) {
r, _ := http.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r)
beego.Trace("testing", "TestBeego", "Code[%d]\n%s", w.Code, w.Body.String())
Convey("Subject: Test Station Endpoint\n", t, func() {
Convey("Status Code Should Be 200", func() {
So(w.Code, ShouldEqual, 200)
})
Convey("The Result Should Not Be Empty", func() {
So(w.Body.Len(), ShouldBeGreaterThan, 0)
})
})
}
package utils
import (
"fmt"
"github.com/astaxie/beego"
"github.com/oschwald/geoip2-golang"
"math"
"net"
"schedulerNode/log"
)
// EarthRadius 地球半径(单位:千米)
const EarthRadius = 6371
// Coordinates 经纬度坐标结构体
type Coordinates struct {
Latitude float64 // 纬度
Longitude float64 // 经度
}
// IsCreateVmCondition 本机是否符合创建Vm的要求
func IsCreateVmCondition(callerIp string) bool {
localIp := beego.AppConfig.String("local_ip")
distance := calculateDistance(getIpAddr(callerIp), getIpAddr(localIp))
settingDistance := beego.AppConfig.DefaultFloat("distance", 1000)
if distance <= settingDistance {
return true
}
return true
}
// 将角度转换为弧度
func degreesToRadians(degrees float64) float64 {
return degrees * (math.Pi / 180.0)
}
// CalculateDistance 计算两个经纬度坐标之间的距离(单位:千米)
func calculateDistance(coord1, coord2 *Coordinates) float64 {
lat1 := degreesToRadians(coord1.Latitude)
lat2 := degreesToRadians(coord2.Latitude)
lon1 := degreesToRadians(coord1.Longitude)
lon2 := degreesToRadians(coord2.Longitude)
// Haversine 公式
dlon := lon2 - lon1
dlat := lat2 - lat1
a := math.Pow(math.Sin(dlat/2), 2) + math.Cos(lat1)*math.Cos(lat2)*math.Pow(math.Sin(dlon/2), 2)
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
distance := EarthRadius * c
return distance
}
// GetIpAddr 获取Ip地址信息
func getIpAddr(ipAddress string) *Coordinates {
// 打开 MaxMind 的 GeoIP2 数据库文件
db, err := geoip2.Open("GeoLite2-City.mmdb")
if err != nil {
log.Error(" geoip2 open error:", err)
return nil
}
defer func(db *geoip2.Reader) {
err := db.Close()
if err != nil {
log.Error(" geoip2 close error:", err)
}
}(db)
// 解析 IP 地址
ip := net.ParseIP(ipAddress)
// 查询 IP 地址的位置信息
record, err := db.City(ip)
if err != nil {
log.Error("Get ip city error:", err)
return nil
}
// 打印经纬度信息
fmt.Printf("IP地址: %s\n", ipAddress)
fmt.Printf("经度: %f\n", record.Location.Longitude)
fmt.Printf("纬度: %f\n", record.Location.Latitude)
res := &Coordinates{
Latitude: record.Location.Latitude,
Longitude: record.Location.Longitude,
}
return res
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment