todo sustain node server to receive pingback

pull/76/head
ak 6 years ago
parent 1f489f3776
commit 5b1d0c1d81
  1. 15
      beaconchain/beaconchain.go
  2. 2
      beaconchain/beaconchain_handler.go
  3. 6
      node/node.go
  4. 5
      p2p/peer.go
  5. 12
      runid/run-identity.go
  6. 26
      runid/run_identity.go
  7. 21
      runnode/run-node.go

@ -1,6 +1,7 @@
package beaconchain
import (
"fmt"
"net"
"os"
"sync"
@ -35,7 +36,6 @@ func New(filename string) *BeaconChain {
idc.log = log.New()
idc.NumberOfShards = 2
idc.PubKey = generateIDCKeys()
idc.StartServer()
return &idc
}
@ -57,7 +57,8 @@ func (IDC *BeaconChain) AcceptConnections(b []byte) {
func (IDC *BeaconChain) registerNode(Node *node.Node) {
IDC.Identities = append(IDC.Identities, Node)
IDC.CommunicatePublicKeyToNode(Node.SelfPeer)
fmt.Println(IDC.Identities)
//IDC.CommunicatePublicKeyToNode(Node.SelfPeer)
return
}
@ -74,17 +75,19 @@ func (IDC *BeaconChain) StartServer() {
}
func (IDC *BeaconChain) listenOnPort() {
addr := net.JoinHostPort("", "8081")
listen, err := net.Listen("tcp4", addr)
addr := net.JoinHostPort("127.0.0.1", "8081")
listen, err := net.Listen("tcp", addr)
if err != nil {
IDC.log.Crit("Socket listen port failed") //Log.Crit does nothing for me!
IDC.log.Crit("Socket listen port failed")
os.Exit(1)
} else {
IDC.log.Info("Identity chain is now listening ..") //log.Info does nothing for me! (ak) remove this
IDC.log.Info("Identity chain is now listening ..")
}
defer listen.Close()
for {
IDC.log.Info("I am accepting connections now")
conn, err := listen.Accept()
fmt.Println(conn)
if err != nil {
IDC.log.Crit("Error listening on port. Exiting", "8081")
continue

@ -17,6 +17,8 @@ func (IDC *BeaconChain) BeaconChainHandler(conn net.Conn) {
if err != nil {
IDC.log.Error("Read p2p data failed")
return
} else {
IDC.log.Info("received connection")
}
msgCategory, err := proto.GetMessageCategory(content)
if err != nil {

@ -81,8 +81,9 @@ func (node *Node) StartServer(port string) {
node.listenOnPort(port)
}
func (node *Node) SetLog() {
func (node *Node) SetLog() *Node {
node.log = log.New()
return node
}
func (node *Node) listenOnPort(port string) {
@ -125,8 +126,7 @@ func (node *Node) countNumTransactionsInBlockchain() int {
}
//ConnectIdentityChain connects to identity chain
func (node *Node) ConnectIdentityChain() {
fmt.Println("In identity chain now")
func (node *Node) ConnectBeaconChain() {
msg := node.SerializeNode()
msgToSend := proto_identity.ConstructIdentityMessage(proto_identity.Register, msg)
p2p.SendMessage(node.IDCPeer, msgToSend)

@ -8,7 +8,6 @@ import (
"runtime"
"time"
"github.com/simple-rules/harmony-benchmark/attack"
"github.com/simple-rules/harmony-benchmark/log"
"github.com/dedis/kyber"
@ -30,7 +29,6 @@ const MaxBroadCast = 20
func SendMessage(peer Peer, msg []byte) {
// Construct normal p2p message
content := ConstructP2pMessage(byte(0), msg)
go send(peer.Ip, peer.Port, content)
}
@ -131,8 +129,7 @@ func sendWithSocketClient(ip, port string, message []byte) (err error) {
// Send a message to another node with given port.
func send(ip, port string, message []byte) {
// Add attack code here.
attack.GetInstance().Run()
//attack.GetInstance().Run()
backoff := NewExpBackoff(250*time.Millisecond, 10*time.Second, 2)
for trial := 0; trial < 10; trial++ {

@ -0,0 +1,12 @@
package main
import (
"github.com/simple-rules/harmony-benchmark/beaconchain"
)
func main() {
bc := beaconchain.New("temp")
bc.StartServer()
}

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

@ -2,7 +2,7 @@ package main
import (
"flag"
"fmt"
"time"
"github.com/simple-rules/harmony-benchmark/node"
"github.com/simple-rules/harmony-benchmark/p2p"
@ -10,21 +10,20 @@ import (
func main() {
ip := flag.String("ip", "127.0.0.0", "IP of the node")
ip := flag.String("ip", "127.0.0.1", "IP of the node")
port := flag.String("port", "9000", "port of the node.")
flag.Parse()
peer := p2p.Peer{Ip: *ip, Port: *port}
// c, err := net.Dial("tcp4", "127.0.0.1:8081")
// fmt.Println(c)
// fmt.Println(err)
node := node.Node{}
node.SelfPeer = peer
node.IDCPeer = p2p.Peer{Ip: *ip, Port: "8081"}
fmt.Println("now in go run mode")
msg := node.SerializeNode()
node.SetLog()
fmt.Println("set the log")
go node.StartServer(*port)
node.ConnectIdentityChain()
fmt.Print(msg)
// fmt.Println(ip)
// fmt.Println(peer)
// node.SetLog()
// go node.StartServer(*port)
// time.Sleep(5 * time.Second)
node.ConnectBeaconChain()
time.Sleep(5 * time.Second)
}
Loading…
Cancel
Save