Browse Source

wip update

master
arnaucube 5 years ago
parent
commit
77fbf230c8
12 changed files with 111 additions and 23 deletions
  1. +8
    -0
      .travis.yml
  2. +3
    -1
      README.md
  3. +4
    -4
      cmd/cmd.go
  4. +1
    -1
      config/config.go
  5. +3
    -3
      config0.yaml
  6. +3
    -3
      config1.yaml
  7. +11
    -0
      go.mod
  8. +26
    -0
      go.sum
  9. +16
    -7
      node/node.go
  10. +4
    -2
      node/node_test.go
  11. +18
    -2
      peer/peer.go
  12. +14
    -0
      run-test-nodes.sh

+ 8
- 0
.travis.yml

@ -0,0 +1,8 @@
language: go
go:
- "1.12"
env:
- GO111MODULE=on

+ 3
- 1
README.md

@ -1,9 +1,11 @@
# slowlorisdb [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucube/slowlorisdb)](https://goreportcard.com/report/github.com/arnaucube/slowlorisdb) [![GoDoc](https://godoc.org/github.com/arnaucube/slowlorisdb?status.svg)](https://godoc.org/github.com/arnaucube/slowlorisdb)
# slowlorisdb [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucube/slowlorisdb)](https://goreportcard.com/report/github.com/arnaucube/slowlorisdb) [![Build Status](https://travis-ci.org/arnaucube/slowlorisdb.svg?branch=master)](https://travis-ci.org/arnaucube/slowlorisdb) [![GoDoc](https://godoc.org/github.com/arnaucube/slowlorisdb?status.svg)](https://godoc.org/github.com/arnaucube/slowlorisdb)
Slow, decentralized and cryptographically consistent database
Basically this repo is a blockchain written from scratch, that allows to launch multiple simultaneous blockchains.
**Warning**: this project was started in the free time of a long travel, not having much more free time to continue developing it.
Watch the blockchain in action: http://www.youtubemultiplier.com/5ca9c1a540b31-slowlorisdb-visual-representation.php
![slowloris](https://04019a5a-a-62cb3a1a-s-sites.googlegroups.com/site/jchristensensdigitalportfolio/slow-loris/IO-moth-eating-frozen-apple-sauce.jpg "slowloris")

+ 4
- 4
cmd/cmd.go

@ -13,6 +13,7 @@ import (
"github.com/arnaucube/slowlorisdb/core"
"github.com/arnaucube/slowlorisdb/db"
"github.com/arnaucube/slowlorisdb/node"
"github.com/arnaucube/slowlorisdb/peer"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -117,10 +118,9 @@ func cmdStart(c *cli.Context) error {
if err != nil {
return err
}
err = node.Start()
if err != nil {
return err
}
p := peer.NewPeer(node, conf)
p.Start()
return nil
}

+ 1
- 1
config/config.go

@ -9,7 +9,7 @@ import (
type Config struct {
StoragePath string
Port string
Port int
Dest string
AuthNodes []string // PubKs in hex format of the AuthNodes for the blockchain
}

+ 3
- 3
config0.yaml

@ -1,6 +1,6 @@
storagepath: "tmp/node0"
port: 3000
dest: 3001
dest: ""
authnodes:
"16be582c80c9b9be29b60f2bcd032654c21256b6bf74535743842bef33432132"
"96758cfdc821abad27c6301439af9f6d0873e237affc60fbc4cc5b33b41b8726"
- "16be582c80c9b9be29b60f2bcd032654c21256b6bf74535743842bef33432132"
- "96758cfdc821abad27c6301439af9f6d0873e237affc60fbc4cc5b33b41b8726"

+ 3
- 3
config1.yaml

@ -1,6 +1,6 @@
storagepath: "tmp/node1"
port: 4000
dest: 4001
dest: "/ip4/127.0.0.1/tcp/3000/p2p/QmaEfH1xNum4dCGoxLBSmmYWKmWm3tWN2UH1D3putPquvS"
authnodes:
"16be582c80c9b9be29b60f2bcd032654c21256b6bf74535743842bef33432132"
"96758cfdc821abad27c6301439af9f6d0873e237affc60fbc4cc5b33b41b8726"
- "16be582c80c9b9be29b60f2bcd032654c21256b6bf74535743842bef33432132"
- "96758cfdc821abad27c6301439af9f6d0873e237affc60fbc4cc5b33b41b8726"

+ 11
- 0
go.mod

@ -3,6 +3,13 @@ module github.com/arnaucube/slowlorisdb
go 1.12
require (
github.com/allegro/bigcache v1.2.0 // indirect
github.com/aristanetworks/goarista v0.0.0-20190429220743-799535f6f364 // indirect
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/ethereum/go-ethereum v1.8.27
github.com/fjl/memsize v0.0.0-20180929194037-2a09253e352a // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/karalabe/hid v0.0.0-20181128192157-d815e0c1a2e2 // indirect
github.com/libp2p/go-libp2p v0.0.10
github.com/libp2p/go-libp2p-crypto v0.0.1
github.com/libp2p/go-libp2p-discovery v0.0.1
@ -11,9 +18,13 @@ require (
github.com/libp2p/go-libp2p-peerstore v0.0.1
github.com/libp2p/go-libp2p-protocol v0.0.1
github.com/multiformats/go-multiaddr v0.0.2
github.com/pborman/uuid v1.2.0 // indirect
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/rs/cors v1.6.0 // indirect
github.com/sirupsen/logrus v1.4.1
github.com/spf13/viper v1.3.2
github.com/stretchr/testify v1.3.0
github.com/syndtr/goleveldb v1.0.0
github.com/urfave/cli v1.20.0
gopkg.in/urfave/cli.v1 v1.20.0 // indirect
)

+ 26
- 0
go.sum

@ -1,6 +1,10 @@
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/allegro/bigcache v1.2.0 h1:qDaE0QoF29wKBb3+pXFrJFy1ihe5OT9OiXhg1t85SxM=
github.com/allegro/bigcache v1.2.0/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/aristanetworks/goarista v0.0.0-20190429220743-799535f6f364 h1:oYKfJZsLWjZM2FSZE1MRYvnRBL9cH2LE+Lo6o/lCUQ8=
github.com/aristanetworks/goarista v0.0.0-20190429220743-799535f6f364/go.mod h1:D/tb0zPVXnP7fmsLZjtdUhSsumbK/ij54UXjjVgMGxQ=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS36cXdAzJbeHaduLtnLQQwNoIi78=
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8=
@ -20,20 +24,30 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ=
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/ethereum/go-ethereum v1.8.27 h1:d+gkiLaBDk5fn3Pe/xNVaMrB/ozI+AUB2IlVBp29IrY=
github.com/ethereum/go-ethereum v1.8.27/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY=
github.com/fd/go-nat v1.0.0 h1:DPyQ97sxA9ThrWYRPcWUz/z9TnpTIGRYODIQc/dy64M=
github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
github.com/fjl/memsize v0.0.0-20180929194037-2a09253e352a h1:1znxn4+q2MrEdTk1eCk6KIV3muTYVclBIB6CTVR/zBc=
github.com/fjl/memsize v0.0.0-20180929194037-2a09253e352a/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk=
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
@ -80,6 +94,8 @@ github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5f
github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/karalabe/hid v0.0.0-20181128192157-d815e0c1a2e2 h1:BkkpZxPVs3gIf+3Tejt8lWzuo2P29N1ChGUMEpuSJ8U=
github.com/karalabe/hid v0.0.0-20181128192157-d815e0c1a2e2/go.mod h1:YvbcH+3Wo6XPs9nkgTY3u19KXLauXW+J5nB7hEHuX0A=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
@ -207,12 +223,19 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/prometheus v2.5.0+incompatible h1:7QPitgO2kOFG8ecuRn9O/4L9+10He72rVRJvMXrE9Hg=
github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8=
github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI=
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
@ -272,6 +295,7 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@ -288,6 +312,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0=
gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

+ 16
- 7
node/node.go

@ -7,6 +7,7 @@ import (
"github.com/arnaucube/slowlorisdb/core"
)
// Node
type Node struct {
PrivK *ecdsa.PrivateKey
Addr core.Address
@ -15,6 +16,7 @@ type Node struct {
PendingTxs []core.Tx
}
// NewNode creates a new node
func NewNode(privK *ecdsa.PrivateKey, bc *core.Blockchain, isMiner bool) (*Node, error) {
addr := core.AddressFromPrivK(privK)
@ -28,14 +30,12 @@ func NewNode(privK *ecdsa.PrivateKey, bc *core.Blockchain, isMiner bool) (*Node,
return node, nil
}
func (node *Node) Start() error {
return nil
}
// SignBlock performs a signature of a byte array with the node private key
func (node *Node) Sign(m []byte) (*core.Signature, error) {
return core.Sign(node.PrivK, m)
}
// SignBlock performs a signature of a block with the node private key
func (node *Node) SignBlock(block *core.Block) error {
block.CalculateHash()
sig, err := core.Sign(node.PrivK, block.Hash[:])
@ -46,10 +46,12 @@ func (node *Node) SignBlock(block *core.Block) error {
return nil
}
// AddToPendingTxs adds a transaction the the node.PendingTxs
func (node *Node) AddToPendingTxs(tx core.Tx) {
node.PendingTxs = append(node.PendingTxs, tx)
}
// BlockFromPendingTxs creates a new block from the pending transactions
func (node *Node) BlockFromPendingTxs() (*core.Block, error) {
block, err := node.NewBlock(node.PendingTxs)
if err != nil {
@ -69,6 +71,7 @@ func (node *Node) BlockFromPendingTxs() (*core.Block, error) {
return block, nil
}
// NewBlock creates a new block with the given txs
func (node *Node) NewBlock(txs []core.Tx) (*core.Block, error) {
block := &core.Block{
Height: node.Bc.GetHeight() + 1,
@ -89,10 +92,10 @@ func (node *Node) NewBlock(txs []core.Tx) (*core.Block, error) {
return block, nil
}
// CreateGenesis creates the genesis block
// pubK is the wallet where the first coins will be created
// amount is the amount of coins that will be created
func (node *Node) CreateGenesis(pubK *ecdsa.PublicKey, amount uint64) (*core.Block, error) {
// pubK is the wallet where the first coins will be created
// amount is the amount of coins that will be created
in := core.Input{
TxId: core.GenesisHashTxInput,
Vout: 0,
@ -143,3 +146,9 @@ func (node *Node) CreateGenesis(pubK *ecdsa.PublicKey, amount uint64) (*core.Blo
}
return block, nil
}
// ParseReceivedBlock is just a caller of node.Bc.AddBlock() at the Node level
func (node *Node) ParseReceivedBlock(block *core.Block) error {
err := node.Bc.AddBlock(block)
return err
}

+ 4
- 2
node/node_test.go

@ -252,13 +252,15 @@ func TestMultipleNodesAddingBlocks(t *testing.T) {
assert.NotEqual(t, genesisBlock.Signature, core.Signature{})
assert.NotEqual(t, genesisBlock.Hash, core.Hash{})
assert.True(t, nodeA.Bc.VerifyBlock(genesisBlock))
// add the genesis block into the blockchain
assert.Equal(t, nodeA.Bc.LastBlock.Hash, nodeB.Bc.LastBlock.Hash)
err = nodeA.Bc.AddBlock(genesisBlock)
assert.Nil(t, err)
assert.NotEqual(t, genesisBlock.Hash, core.Hash{})
assert.Equal(t, genesisBlock.Hash, nodeA.Bc.LastBlock.Hash)
err = nodeB.Bc.AddBlock(genesisBlock)
err = nodeB.ParseReceivedBlock(genesisBlock)
assert.Nil(t, err)
assert.NotEqual(t, genesisBlock.Hash, core.Hash{})
assert.Equal(t, genesisBlock.Hash, nodeB.Bc.LastBlock.Hash)
@ -294,7 +296,7 @@ func TestMultipleNodesAddingBlocks(t *testing.T) {
err = nodeA.Bc.AddBlock(block)
assert.Nil(t, err)
// nodeB adds the block
err = nodeB.Bc.AddBlock(block)
err = nodeB.ParseReceivedBlock(block)
assert.Nil(t, err)
balanceA, err := nodeA.Bc.GetBalance(&privKA.PublicKey)

+ 18
- 2
peer/peer.go

@ -8,7 +8,9 @@ import (
"io"
"os"
"github.com/libp2p/go-libp2p"
"github.com/arnaucube/slowlorisdb/config"
"github.com/arnaucube/slowlorisdb/node"
libp2p "github.com/libp2p/go-libp2p"
crypto "github.com/libp2p/go-libp2p-crypto"
inet "github.com/libp2p/go-libp2p-net"
peerstore "github.com/libp2p/go-libp2p-peerstore"
@ -64,7 +66,21 @@ func writeData(rw *bufio.ReadWriter) {
}
}
func Start(port int, dest string) error {
type Peer struct {
n *node.Node
c *config.Config
}
func NewPeer(n *node.Node, conf *config.Config) *Peer {
return &Peer{
n: n,
c: conf,
}
}
func (peer *Peer) Start() error {
var port int = peer.c.Port
var dest string = peer.c.Dest
var r io.Reader
r = rand.Reader

+ 14
- 0
run-test-nodes.sh

@ -0,0 +1,14 @@
#!/bin/sh
SESSION="slowlorisdb"
tmux kill-session -t $SESSION || true
tmux new-session -d -s $SESSION
tmux split-window -d -t 0 -v
tmux send-keys -t 0 "go run main.go --config config0.yaml start" enter
tmux send-keys -t 1 "go run main.go --config config1.yaml start" enter
tmux attach -t $SESSION

Loading…
Cancel
Save