Skip to content

Commit

Permalink
v0.22.0 (#53)
Browse files Browse the repository at this point in the history
* v0.22.0

* Delete clientops.go

* Delete ipfs.go

* Delete queue.go

* Delete trtl.go
  • Loading branch information
RocksteadyTC authored Oct 8, 2020
1 parent 50eb53b commit 982b98e
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 719 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 RockSteady, The TurtleCoin Developers
Copyright (c) 2020 RockSteadyTC, The TurtleCoin Developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 2 additions & 14 deletions api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"net/http"
"strconv"

Expand Down Expand Up @@ -48,30 +47,19 @@ func restAPI(keyCollection *ED25519Keys) {
// Version
api.HandleFunc("/version", returnVersion).Methods(http.MethodGet)

// Peer
api.HandleFunc("/peer", func(w http.ResponseWriter, r *http.Request) {
returnPeerID(w, r, keyCollection.publicKey)
}).Methods(http.MethodGet)

// Stats
api.HandleFunc("/stats", func(w http.ResponseWriter, r *http.Request) {
returnStatsWeb(w, r, keyCollection)
}).Methods(http.MethodGet)

// REMOVED: https://discord.com/channels/388915017187328002/453726546868305962/761045558336421918
// // Transactions
// api.HandleFunc("/transactions", func(w http.ResponseWriter, r *http.Request) {
// returnTransactions(w, r)
// }).Methods(http.MethodGet)

// Transaction by ID
api.HandleFunc("/transaction/{hash}", func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
hash := vars["hash"]
returnSingleTransaction(w, r, hash)
}).Methods(http.MethodGet)

// Transaction by ID
// Transaction by qty
api.HandleFunc("/transactions/{number}", func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
number := vars["number"]
Expand All @@ -83,7 +71,7 @@ func restAPI(keyCollection *ED25519Keys) {
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
conn, _ := upgrader.Upgrade(w, r, nil)
defer conn.Close()
fmt.Printf(brightgreen+"\n[%s] [%s] Peer socket opened!\n"+white, timeStamp(), conn.RemoteAddr())
// fmt.Printf(brightgreen+"\n[%s] [%s] Peer socket opened!"+white, timeStamp(), conn.RemoteAddr())
socketAuthAgent(conn, keyCollection)
})

Expand Down
99 changes: 0 additions & 99 deletions clientops.go

This file was deleted.

51 changes: 16 additions & 35 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const (
privKeyFilePath = certPathSelfDir + "/" + "priv.key"
signedKeyFilePath = certPathSelfDir + "/" + "signed.key"
selfCertFilePath = certPathSelfDir + "/" + "self.cert"
currentJSON = "./config/milestone.json"
p2pConfigFile = "peer.id"
)

// Channel values
Expand All @@ -38,43 +36,28 @@ const (

// Coordinator values
var (
nodePubKeySignature []byte
dbUser string = "postgres"
dbName string = "karai"
dbSSL string = "disable"
joinMsg []byte = []byte("JOIN")
ncasMsg []byte = []byte("NCAS")
capkMsg []byte = []byte("CAPK")
certMsg []byte = []byte("CERT")
peerMsg []byte = []byte("PEER")
pubkMsg []byte = []byte("PUBK")
nsigMsg []byte = []byte("NSIG")
sendMsg []byte = []byte("send")
rtrnMsg []byte = []byte("RTRN")
numTx int
consumeData bool = false
// isCoordinator bool = false
wantsClean bool = false
graphDir string = ""
batchDir string = ""
showIP bool = false
chunkSize int
dbUser string = "postgres"
dbName string = "karai"
dbSSL string = "disable"
joinMsg []byte = []byte("JOIN")
ncasMsg []byte = []byte("NCAS")
capkMsg []byte = []byte("CAPK")
certMsg []byte = []byte("CERT")
peerMsg []byte = []byte("PEER")
pubkMsg []byte = []byte("PUBK")
nsigMsg []byte = []byte("NSIG")
sendMsg []byte = []byte("SEND")
rtrnMsg []byte = []byte("RTRN")
numTx int
wantsClean bool = false
karaiAPIPort int
p2pPeerID string
upgrader = websocket.Upgrader{
EnableCompression: true,
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}
)

// Client Values
var (
trimmedPubKey string
isFNG = true
isTrusted = false
)

// Matrix Values
var (
wantsMatrix bool = false
Expand All @@ -88,8 +71,6 @@ var (
var (
thisSubgraph string = ""
thisSubgraphShortName string = ""
// poolSubLeader string = ""
arrangePool bool = false
poolInterval int = 10 // seconds
txCount int = 0
poolInterval int = 10 // seconds
txCount int = 0
)
64 changes: 3 additions & 61 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,64 +33,13 @@ type Transaction struct {
Lead bool `json:"lead" db:"tx_lead"`
}

// MilestoneData is a struct that defines the contents of the data field to be parsed
type MilestoneData struct {
TxInterval int
}

// SubGraph defines participants and child transactions of a subgraph
type SubGraph struct {
PubKeys []string
Children []string
}

// connect will create an active DB connection
func connect() (*sqlx.DB, error) {
connectParams := fmt.Sprintf("user=%s dbname=%s sslmode=%s", dbUser, dbName, dbSSL)
db, err := sqlx.Connect("postgres", connectParams)
return db, err
}

// verifyGraph will check each transaction in the graph
func verifyGraph() (bool, error) {
return true, nil
}

// loadGraphArray outputs the entire graph as an array of Transactions
func loadGraphArray() []byte {
db, connectErr := connect()
defer db.Close()
handle("Error creating a DB connection: ", connectErr)

graph := []Transaction{}
err := db.Select(&graph, "SELECT * FROM transactions")
graphJSON, _ := json.MarshalIndent(&graph, "", " ")
switch {
case err != nil:
handle("There was a problem loading the graph: ", err)
return graphJSON
default:
return graphJSON
}
}

// loadGraphElementsArray outputs the entire graph as an array of Transactions
func loadGraphElementsArray(number string) []byte {
db, connectErr := connect()
defer db.Close()
handle("Error creating a DB connection: ", connectErr)
graph := []Transaction{}
err := db.Select(&graph, "SELECT * FROM transactions ORDER BY tx_time DESC LIMIT $1", number)
graphJSON, _ := json.MarshalIndent(&graph, "", " ")
switch {
case err != nil:
handle("There was a problem loading the graph: ", err)
return graphJSON[0:0]
default:
return graphJSON
}
}

// addBulkTransactions adds $number of tx to the graph immediately
func addBulkTransactions(number int) {
sum := 0
Expand Down Expand Up @@ -137,15 +86,6 @@ func generateRandomTransactions() {
generateRandomTransactions()
}

func createBenchmark(number int) {
// start := time.Now()

addBulkTransactions(10)
// t := time.Now()
// elapsed := t.Sub(start)
// fmt.Printf(brightcyan+"\nBenchmark\nFinished %v operations in %s\n"+nc, number, elapsed)
}

// createRoot Transaction channels start with a rootTx transaction always
func createRoot() error {
db, connectErr := connect()
Expand Down Expand Up @@ -184,7 +124,7 @@ func createRoot() error {
}

// createTransaction This will add a transaction to the graph
func createTransaction(txType, data string) {
func createTransaction(txType, data string) bool {
var txData string
var txSubg string
var txPrev string
Expand Down Expand Up @@ -226,10 +166,12 @@ func createTransaction(txType, data string) {
txSubg = thisSubgraph
thisSubgraphShortName = thisSubgraph[0:4]
}

tx.MustExec("INSERT INTO transactions (tx_time, tx_type, tx_hash, tx_data, tx_prev, tx_epoc, tx_subg, tx_prnt, tx_mile, tx_lead ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", txTime, txType, txHash, txData, txPrev, txEpoc, txSubg, txPrnt, txMile, txLead)
tx.Commit()
txCount++
}
return true
}

// newSubGraphTimer timer for collection interval
Expand Down
8 changes: 1 addition & 7 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ import "flag"
// and assigns the values of those flags according to sane defaults.
func flags() {
flag.StringVar(&matrixToken, "matrixToken", "", "Matrix homeserver token")
flag.StringVar(&graphDir, "graphDir", "./graph", "Path where graph objects should be saved")
flag.StringVar(&batchDir, "batchDir", "./graph/batch", "Path where batched transactions should be saved")
flag.StringVar(&matrixURL, "matrixURL", "", "Matrix homeserver URL")
flag.StringVar(&matrixRoomID, "matrixRoomID", "", "Room ID for matrix publishd events")
flag.IntVar(&chunkSize, "chunkSize", 100, "Number of transactions per batch on disk.")
flag.IntVar(&karaiAPIPort, "apiport", 4200, "Port to run Karai Coordinator API on.")
flag.BoolVar(&consumeData, "consume", false, "Consume data from sources.")
// flag.BoolVar(&isCoordinator, "coordinator", false, "Run as coordinator.")
flag.BoolVar(&wantsClean, "clean", false, "Clear all peer certs and graph objects")
flag.BoolVar(&wantsFiles, "write", true, "Write each graph object to disk.")
flag.BoolVar(&wantsClean, "clean", false, "Clear all peer certs")
flag.BoolVar(&wantsMatrix, "matrix", false, "Enable Matrix functions. Requires -matrixToken, -matrixURL, and -matrixRoomID")
flag.Parse()
}
Loading

0 comments on commit 982b98e

Please sign in to comment.