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

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

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

@ -8,7 +8,6 @@ import (
"runtime" "runtime"
"time" "time"
"github.com/simple-rules/harmony-benchmark/attack"
"github.com/simple-rules/harmony-benchmark/log" "github.com/simple-rules/harmony-benchmark/log"
"github.com/dedis/kyber" "github.com/dedis/kyber"
@ -30,7 +29,6 @@ const MaxBroadCast = 20
func SendMessage(peer Peer, msg []byte) { func SendMessage(peer Peer, msg []byte) {
// Construct normal p2p message // Construct normal p2p message
content := ConstructP2pMessage(byte(0), msg) content := ConstructP2pMessage(byte(0), msg)
go send(peer.Ip, peer.Port, content) 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. // Send a message to another node with given port.
func send(ip, port string, message []byte) { func send(ip, port string, message []byte) {
// Add attack code here. // Add attack code here.
attack.GetInstance().Run() //attack.GetInstance().Run()
backoff := NewExpBackoff(250*time.Millisecond, 10*time.Second, 2) backoff := NewExpBackoff(250*time.Millisecond, 10*time.Second, 2)
for trial := 0; trial < 10; trial++ { 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 ( import (
"flag" "flag"
"fmt" "time"
"github.com/simple-rules/harmony-benchmark/node" "github.com/simple-rules/harmony-benchmark/node"
"github.com/simple-rules/harmony-benchmark/p2p" "github.com/simple-rules/harmony-benchmark/p2p"
@ -10,21 +10,20 @@ import (
func main() { 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.") port := flag.String("port", "9000", "port of the node.")
flag.Parse() flag.Parse()
peer := p2p.Peer{Ip: *ip, Port: *port} 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 := node.Node{}
node.SelfPeer = peer node.SelfPeer = peer
node.IDCPeer = p2p.Peer{Ip: *ip, Port: "8081"} node.IDCPeer = p2p.Peer{Ip: *ip, Port: "8081"}
fmt.Println("now in go run mode") // node.SetLog()
msg := node.SerializeNode() // go node.StartServer(*port)
node.SetLog() // time.Sleep(5 * time.Second)
fmt.Println("set the log") node.ConnectBeaconChain()
go node.StartServer(*port) time.Sleep(5 * time.Second)
node.ConnectIdentityChain()
fmt.Print(msg)
// fmt.Println(ip)
// fmt.Println(peer)
} }
Loading…
Cancel
Save