func NewTransaction() { if betternode.CountNodes() == 0 { fmt.Println("Unable to initiate transaction: No nodes connected.") return } from := betternode.RandomNode() to := betternode.RandomNode() for i := 1; i < 1000; i++ { if to != from { break } to = betternode.RandomNode() } log.Message("NewTransmission()") t := betternode.NewTransaction( <-idgen, mapping[to], hops, "Lorem ipsum", fine, ceil, RoundId, ) // Send transaction log.Message("NewTransmission() 1") betternode.SendTransaction(t, from) log.Message("NewTransmission() 2") database.Insert(t) log.Message("NewTransmission() 3") transaction.Add <- t log.Message("NewTransmission() 4") }
// Gets the data from a node and saves into the database func (n *Node) receiver() { dec := json.NewDecoder(n.Conn) for { var obj interface{} err := dec.Decode(&obj) if err != nil { log.Error(err) if err.Error() == "EOF" { close(n.Transactions) return } // Hack: recover dec = json.NewDecoder(n.Conn) } log.Message("Received message from " + n.Conn.RemoteAddr().String() + ".") // n.updateDevices(obj) database.Insert(obj) } }
func NewRound() { RoundId = fmt.Sprintf("maniac%s", time.Now().Format(time.RFC3339Nano)) database.Inject(RoundId) database.Insert(map[string]string{"round": RoundId}) }