adding a way to test node and id chain locally

pull/76/head
ak 6 years ago
parent 05f35fff3d
commit c2209baa37
  1. 2
      beaconchain/beaconchain.go
  2. 4
      node/node.go
  3. 14
      runid/run_identity.go
  4. 24
      runnode/run_node.go

@ -51,7 +51,7 @@ func generateIDCKeys() kyber.Point {
//AcceptConnections welcomes new connections //AcceptConnections welcomes new connections
func (IDC *BeaconChain) AcceptConnections(b []byte) { func (IDC *BeaconChain) AcceptConnections(b []byte) {
Node := node.DeserializeWaitNode(b) Node := node.DeserializeNode(b)
IDC.registerNode(Node) //This copies lock value of sync.mutex, we need to have a way around it by creating auxiliary data struct. IDC.registerNode(Node) //This copies lock value of sync.mutex, we need to have a way around it by creating auxiliary data struct.
} }

@ -127,7 +127,7 @@ func (node *Node) ConnectIdentityChain() {
// SerializeWaitNode serializes the node // SerializeWaitNode serializes the node
// https://stackoverflow.com/questions/12854125/how-do-i-dump-the-struct-into-the-byte-array-without-reflection/12854659#12854659 // https://stackoverflow.com/questions/12854125/how-do-i-dump-the-struct-into-the-byte-array-without-reflection/12854659#12854659
func (node *Node) SerializeWaitNode() []byte { func (node *Node) SerializeNode() []byte {
//Needs to escape the serialization of unexported fields //Needs to escape the serialization of unexported fields
result := new(bytes.Buffer) result := new(bytes.Buffer)
encoder := gob.NewEncoder(result) encoder := gob.NewEncoder(result)
@ -142,7 +142,7 @@ func (node *Node) SerializeWaitNode() []byte {
} }
// DeserializeWaitNode deserializes the node // DeserializeWaitNode deserializes the node
func DeserializeWaitNode(d []byte) *Node { func DeserializeNode(d []byte) *Node {
var wn Node var wn Node
r := bytes.NewBuffer(d) r := bytes.NewBuffer(d)
decoder := gob.NewDecoder(r) decoder := gob.NewDecoder(r)

@ -1,12 +1,26 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"github.com/simple-rules/harmony-benchmark/beaconchain" "github.com/simple-rules/harmony-benchmark/beaconchain"
"github.com/simple-rules/harmony-benchmark/node"
"github.com/simple-rules/harmony-benchmark/p2p"
) )
func main() { func main() {
bc := beaconchain.New("temp") bc := beaconchain.New("temp")
ip := flag.String("ip", "127.0.0.0", "IP of the node")
port := flag.String("port", "9000", "port of the node.")
flag.Parse()
peer := p2p.Peer{Ip: *ip, Port: *port}
node := node.Node{}
node.Self = peer
msg := node.SerializeNode()
fmt.Print(msg)
// fmt.Println(ip)
// fmt.Println(peer)
fmt.Print(bc) fmt.Print(bc)
} }

@ -0,0 +1,24 @@
package main
import (
"flag"
"fmt"
"github.com/simple-rules/harmony-benchmark/node"
"github.com/simple-rules/harmony-benchmark/p2p"
)
func main() {
ip := flag.String("ip", "127.0.0.0", "IP of the node")
port := flag.String("port", "9000", "port of the node.")
flag.Parse()
peer := p2p.Peer{Ip: *ip, Port: *port}
node := node.Node{}
node.Self = peer
msg := node.SerializeNode()
fmt.Print(msg)
// fmt.Println(ip)
// fmt.Println(peer)
}
Loading…
Cancel
Save