mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2025-01-08 05:52:10 +07:00
Compare commits
4 commits
c250e8e3bb
...
73308d2a32
Author | SHA1 | Date | |
---|---|---|---|
73308d2a32 | |||
4d1a2da49c | |||
ef553dab9e | |||
9a44cd9546 |
6 changed files with 35 additions and 59 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
v0.0.3
|
||||
v0.0.4
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "xmr-nodes-frontend",
|
||||
"version": "v0.0.3",
|
||||
"version": "v0.0.4",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "VITE_API_URL=http://127.0.0.1:18901 vite dev --host 127.0.0.1",
|
||||
|
|
|
@ -9,12 +9,7 @@ import (
|
|||
"github.com/ditatompel/xmr-remote-nodes/internal/database"
|
||||
)
|
||||
|
||||
type CronRepository interface {
|
||||
RunCronProcess(chan struct{})
|
||||
Crons() ([]Cron, error)
|
||||
}
|
||||
|
||||
type CronRepo struct {
|
||||
type cronRepo struct {
|
||||
db *database.DB
|
||||
}
|
||||
|
||||
|
@ -33,11 +28,11 @@ type Cron struct {
|
|||
|
||||
var rerunTimeout = 300
|
||||
|
||||
func New() CronRepository {
|
||||
return &CronRepo{db: database.GetDB()}
|
||||
func New() *cronRepo {
|
||||
return &cronRepo{db: database.GetDB()}
|
||||
}
|
||||
|
||||
func (r *CronRepo) RunCronProcess(c chan struct{}) {
|
||||
func (r *cronRepo) RunCronProcess(c chan struct{}) {
|
||||
for {
|
||||
select {
|
||||
case <-time.After(60 * time.Second):
|
||||
|
@ -73,7 +68,7 @@ func (r *CronRepo) RunCronProcess(c chan struct{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *CronRepo) Crons() ([]Cron, error) {
|
||||
func (r *cronRepo) Crons() ([]Cron, error) {
|
||||
var tasks []Cron
|
||||
err := r.db.Select(&tasks, `
|
||||
SELECT
|
||||
|
@ -92,7 +87,7 @@ func (r *CronRepo) Crons() ([]Cron, error) {
|
|||
return tasks, err
|
||||
}
|
||||
|
||||
func (r *CronRepo) queueList() ([]Cron, error) {
|
||||
func (r *cronRepo) queueList() ([]Cron, error) {
|
||||
tasks := []Cron{}
|
||||
query := `
|
||||
SELECT
|
||||
|
@ -112,7 +107,7 @@ func (r *CronRepo) queueList() ([]Cron, error) {
|
|||
return tasks, err
|
||||
}
|
||||
|
||||
func (r *CronRepo) preRunTask(id int, lastRunTs int64) {
|
||||
func (r *cronRepo) preRunTask(id int, lastRunTs int64) {
|
||||
query := `
|
||||
UPDATE tbl_cron
|
||||
SET
|
||||
|
@ -127,7 +122,7 @@ func (r *CronRepo) preRunTask(id int, lastRunTs int64) {
|
|||
defer row.Close()
|
||||
}
|
||||
|
||||
func (r *CronRepo) postRunTask(id int, nextRun int64, runtime float64) {
|
||||
func (r *cronRepo) postRunTask(id int, nextRun int64, runtime float64) {
|
||||
query := `
|
||||
UPDATE tbl_cron
|
||||
SET
|
||||
|
@ -143,7 +138,7 @@ func (r *CronRepo) postRunTask(id int, nextRun int64, runtime float64) {
|
|||
defer row.Close()
|
||||
}
|
||||
|
||||
func (r *CronRepo) execCron(slug string) {
|
||||
func (r *cronRepo) execCron(slug string) {
|
||||
switch slug {
|
||||
case "delete_old_probe_logs":
|
||||
slog.Info(fmt.Sprintf("[CRON] Start running task: %s", slug))
|
||||
|
@ -154,7 +149,7 @@ func (r *CronRepo) execCron(slug string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *CronRepo) deleteOldProbeLogs() {
|
||||
func (r *cronRepo) deleteOldProbeLogs() {
|
||||
// for now, we only delete stats older than 1 month +2 days
|
||||
startTs := time.Now().AddDate(0, -1, -2).Unix()
|
||||
query := `DELETE FROM tbl_probe_log WHERE date_checked < ?`
|
||||
|
@ -164,7 +159,7 @@ func (r *CronRepo) deleteOldProbeLogs() {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *CronRepo) calculateMajorityFee() {
|
||||
func (r *cronRepo) calculateMajorityFee() {
|
||||
netTypes := [3]string{"mainnet", "stagenet", "testnet"}
|
||||
for _, net := range netTypes {
|
||||
row, err := r.db.Query(`
|
||||
|
|
|
@ -16,23 +16,12 @@ import (
|
|||
"github.com/jmoiron/sqlx/types"
|
||||
)
|
||||
|
||||
type MoneroRepository interface {
|
||||
Node(id int) (Node, error)
|
||||
Add(protocol string, host string, port uint) error
|
||||
Nodes(QueryNodes) (Nodes, error)
|
||||
NetFees() []NetFee
|
||||
Countries() ([]Countries, error)
|
||||
GiveJob(acceptTor int) (Node, error)
|
||||
ProcessJob(report ProbeReport, proberId int64) error
|
||||
Logs(QueryLogs) (FetchLogs, error)
|
||||
}
|
||||
|
||||
type MoneroRepo struct {
|
||||
type moneroRepo struct {
|
||||
db *database.DB
|
||||
}
|
||||
|
||||
func New() MoneroRepository {
|
||||
return &MoneroRepo{db: database.GetDB()}
|
||||
func New() *moneroRepo {
|
||||
return &moneroRepo{db: database.GetDB()}
|
||||
}
|
||||
|
||||
// Node represents a single remote node
|
||||
|
@ -68,7 +57,7 @@ type Node struct {
|
|||
}
|
||||
|
||||
// Get node from database by id
|
||||
func (r *MoneroRepo) Node(id int) (Node, error) {
|
||||
func (r *moneroRepo) Node(id int) (Node, error) {
|
||||
var node Node
|
||||
err := r.db.Get(&node, `SELECT * FROM tbl_node WHERE id = ?`, id)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
|
@ -162,7 +151,7 @@ type Nodes struct {
|
|||
}
|
||||
|
||||
// Get nodes from database
|
||||
func (r *MoneroRepo) Nodes(q QueryNodes) (Nodes, error) {
|
||||
func (r *moneroRepo) Nodes(q QueryNodes) (Nodes, error) {
|
||||
args, where, sortBy, sortDirection := q.toSQL()
|
||||
|
||||
var nodes Nodes
|
||||
|
@ -198,7 +187,7 @@ func (r *MoneroRepo) Nodes(q QueryNodes) (Nodes, error) {
|
|||
return nodes, err
|
||||
}
|
||||
|
||||
func (repo *MoneroRepo) Add(protocol string, hostname string, port uint) error {
|
||||
func (r *moneroRepo) Add(protocol string, hostname string, port uint) error {
|
||||
if protocol != "http" && protocol != "https" {
|
||||
return errors.New("Invalid protocol, must one of or HTTP/HTTPS")
|
||||
}
|
||||
|
@ -233,7 +222,7 @@ func (repo *MoneroRepo) Add(protocol string, hostname string, port uint) error {
|
|||
ip = hostIp.String()
|
||||
}
|
||||
|
||||
row, err := repo.db.Query(`
|
||||
row, err := r.db.Query(`
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
|
@ -252,7 +241,7 @@ func (repo *MoneroRepo) Add(protocol string, hostname string, port uint) error {
|
|||
return errors.New("Node already monitored")
|
||||
}
|
||||
statusDb, _ := json.Marshal([5]int{2, 2, 2, 2, 2})
|
||||
_, err = repo.db.Exec(`
|
||||
_, err = r.db.Exec(`
|
||||
INSERT INTO tbl_node (
|
||||
protocol,
|
||||
hostname,
|
||||
|
@ -296,7 +285,7 @@ func (repo *MoneroRepo) Add(protocol string, hostname string, port uint) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *MoneroRepo) Delete(id uint) error {
|
||||
func (r *moneroRepo) Delete(id uint) error {
|
||||
if _, err := r.db.Exec(`DELETE FROM tbl_node WHERE id = ?`, id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -314,7 +303,7 @@ type NetFee struct {
|
|||
}
|
||||
|
||||
// Get majority net fee from table tbl_fee
|
||||
func (r *MoneroRepo) NetFees() []NetFee {
|
||||
func (r *moneroRepo) NetFees() []NetFee {
|
||||
var netFees []NetFee
|
||||
err := r.db.Select(&netFees, `
|
||||
SELECT
|
||||
|
@ -338,7 +327,7 @@ type Countries struct {
|
|||
}
|
||||
|
||||
// Get list of countries (count by nodes)
|
||||
func (r *MoneroRepo) Countries() ([]Countries, error) {
|
||||
func (r *moneroRepo) Countries() ([]Countries, error) {
|
||||
var c []Countries
|
||||
err := r.db.Select(&c, `
|
||||
SELECT
|
||||
|
|
|
@ -12,15 +12,7 @@ import (
|
|||
|
||||
const ProberAPIKey = "X-Prober-Api-Key" // HTTP header key
|
||||
|
||||
type ProberRepository interface {
|
||||
Add(name string) (Prober, error)
|
||||
Edit(id int, name string) error
|
||||
Probers(QueryProbers) ([]Prober, error)
|
||||
CheckAPI(key string) (Prober, error)
|
||||
Delete(id int) error
|
||||
}
|
||||
|
||||
type ProberRepo struct {
|
||||
type proberRepo struct {
|
||||
db *database.DB
|
||||
}
|
||||
|
||||
|
@ -34,12 +26,12 @@ type Prober struct {
|
|||
// Initializes a new ProberRepository
|
||||
//
|
||||
// NOTE: This "prober" is different with "probe" which is used to fetch a new job
|
||||
func NewProber() ProberRepository {
|
||||
return &ProberRepo{db: database.GetDB()}
|
||||
func NewProber() *proberRepo {
|
||||
return &proberRepo{db: database.GetDB()}
|
||||
}
|
||||
|
||||
// Add a new prober machine
|
||||
func (r *ProberRepo) Add(name string) (Prober, error) {
|
||||
func (r *proberRepo) Add(name string) (Prober, error) {
|
||||
apiKey := uuid.New()
|
||||
query := `
|
||||
INSERT INTO tbl_prober (
|
||||
|
@ -59,7 +51,7 @@ func (r *ProberRepo) Add(name string) (Prober, error) {
|
|||
}
|
||||
|
||||
// Edit an existing prober
|
||||
func (r *ProberRepo) Edit(id int, name string) error {
|
||||
func (r *proberRepo) Edit(id int, name string) error {
|
||||
query := `UPDATE tbl_prober SET name = ? WHERE id = ?`
|
||||
res, err := r.db.Exec(query, name, id)
|
||||
if err != nil {
|
||||
|
@ -76,7 +68,7 @@ func (r *ProberRepo) Edit(id int, name string) error {
|
|||
}
|
||||
|
||||
// Delete an existing prober
|
||||
func (r *ProberRepo) Delete(id int) error {
|
||||
func (r *proberRepo) Delete(id int) error {
|
||||
res, err := r.db.Exec(`DELETE FROM tbl_prober WHERE id = ?`, id)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -120,7 +112,7 @@ func (q QueryProbers) toSQL() (args []interface{}, where, sortBy, sortDirection
|
|||
return args, where, sortBy, sortDirection
|
||||
}
|
||||
|
||||
func (r *ProberRepo) Probers(q QueryProbers) ([]Prober, error) {
|
||||
func (r *proberRepo) Probers(q QueryProbers) ([]Prober, error) {
|
||||
args, where, sortBy, sortDirection := q.toSQL()
|
||||
|
||||
var probers []Prober
|
||||
|
@ -153,7 +145,7 @@ func (r *ProberRepo) Probers(q QueryProbers) ([]Prober, error) {
|
|||
return probers, nil
|
||||
}
|
||||
|
||||
func (r *ProberRepo) CheckAPI(key string) (Prober, error) {
|
||||
func (r *proberRepo) CheckAPI(key string) (Prober, error) {
|
||||
var p Prober
|
||||
query := `
|
||||
SELECT
|
||||
|
|
|
@ -78,7 +78,7 @@ type FetchLogs struct {
|
|||
}
|
||||
|
||||
// Logs returns list of fetched log result for given query
|
||||
func (r *MoneroRepo) Logs(q QueryLogs) (FetchLogs, error) {
|
||||
func (r *moneroRepo) Logs(q QueryLogs) (FetchLogs, error) {
|
||||
args, where, sortBy, sortDirection := q.toSQL()
|
||||
|
||||
var fetchLogs FetchLogs
|
||||
|
@ -108,7 +108,7 @@ func (r *MoneroRepo) Logs(q QueryLogs) (FetchLogs, error) {
|
|||
}
|
||||
|
||||
// GiveJob returns node that should be probed for the next time
|
||||
func (r *MoneroRepo) GiveJob(acceptTor int) (Node, error) {
|
||||
func (r *moneroRepo) GiveJob(acceptTor int) (Node, error) {
|
||||
args := []interface{}{}
|
||||
wq := []string{}
|
||||
where := ""
|
||||
|
@ -196,7 +196,7 @@ func (p *ProbeReport) parseStatuses() string {
|
|||
}
|
||||
|
||||
// Process report data from probers
|
||||
func (r *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error {
|
||||
func (r *moneroRepo) ProcessJob(report ProbeReport, proberId int64) error {
|
||||
if report.Node.ID == 0 {
|
||||
return errors.New("Invalid node")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue