Merge branch 'master' of github.com:harmony-one/harmony into rj_branch

pull/136/head
Rongjian Lan 6 years ago
commit 271c5b8211
  1. 6
      benchmark.go
  2. 8
      client/txgen/main.go
  3. 2
      deploy.sh
  4. 8
      discovery/discovery.go
  5. 2
      newnode/newnode.go
  6. 4
      node/node.go
  7. 2
      node/node_handler.go
  8. 10
      p2p/host/hostv1/hostv1.go

@ -91,8 +91,8 @@ func main() {
onlyLogTps := flag.Bool("only_log_tps", false, "Only log TPS if true")
//This IP belongs to jenkins.harmony.one
idcIP := flag.String("idc", "127.0.0.1", "IP of the identity chain")
idcPort := flag.String("idc_port", "8081", "port of the identity chain")
bcIP := flag.String("bc", "127.0.0.1", "IP of the identity chain")
bcPort := flag.String("bc_port", "8081", "port of the identity chain")
peerDiscovery := flag.Bool("peer_discovery", false, "Enable Peer Discovery")
//Leader needs to have a minimal number of peers to start consensus
@ -118,7 +118,7 @@ func main() {
//Use Peer Discovery to get shard/leader/peer/...
if *peerDiscovery {
candidateNode := pkg_newnode.New(*ip, *port)
BCPeer := p2p.Peer{IP: *idcIP, Port: *idcPort}
BCPeer := p2p.Peer{IP: *bcIP, Port: *bcPort}
candidateNode.ContactBeaconChain(BCPeer)
shardID = candidateNode.GetShardID()
leader = candidateNode.GetLeader()

@ -52,8 +52,8 @@ func main() {
versionFlag := flag.Bool("version", false, "Output version info")
crossShardRatio := flag.Int("cross_shard_ratio", 30, "The percentage of cross shard transactions.")
idcIP := flag.String("idc", "127.0.0.1", "IP of the identity chain")
idcPort := flag.String("idc_port", "8081", "port of the identity chain")
bcIP := flag.String("bc", "127.0.0.1", "IP of the identity chain")
bcPort := flag.String("bc_port", "8081", "port of the identity chain")
peerDiscovery := flag.Bool("peer_discovery", false, "Enable Peer Discovery")
flag.Parse()
@ -72,7 +72,7 @@ func main() {
if *peerDiscovery {
candidateNode := newnode.New(*ip, *port)
BCPeer := p2p.Peer{IP: *idcIP, Port: *idcPort}
BCPeer := p2p.Peer{IP: *bcIP, Port: *bcPort}
candidateNode.ContactBeaconChain(BCPeer)
peers = nil
clientPeer = &p2p.Peer{IP: *ip, Port: *port}
@ -175,7 +175,7 @@ func main() {
go clientNode.JoinShard(leader)
// wait for 3 seconds for client to send ping message to leader
time.Sleep(3 * time.Second)
clientNode.StopPing <- 1
clientNode.StopPing <- struct{}{}
clientNode.State = node.NodeJoinedShard
}

@ -37,7 +37,7 @@ EOU
exit 0
}
PEER=
PEER=-peer_discovery
DB=
TXGEN=true
DURATION=90

@ -22,7 +22,7 @@ type ConfigEntry struct {
}
func (config ConfigEntry) String() string {
return fmt.Sprintf("idc: %v:%v", config.IP, config.Port)
return fmt.Sprintf("bc: %v:%v", config.IP, config.Port)
}
// New return new ConfigEntry.
@ -38,14 +38,14 @@ func New(priK kyber.Scalar, pubK kyber.Point) *ConfigEntry {
}
// StartClientMode starts client mode.
func (config *ConfigEntry) StartClientMode(idcIP, idcPort string) error {
func (config *ConfigEntry) StartClientMode(bcIP, bcPort string) error {
config.IP = "myip"
config.Port = "myport"
fmt.Printf("idc ip/port: %v/%v\n", idcIP, idcPort)
fmt.Printf("bc ip/port: %v/%v\n", bcIP, bcPort)
// ...
// TODO: connect to idc, and wait unless acknowledge
// TODO: connect to bc, and wait unless acknowledge
return nil
}

@ -61,7 +61,7 @@ func (node *NewNode) ContactBeaconChain(BCPeer p2p.Peer) {
}
func (node NewNode) String() string {
return fmt.Sprintf("idc: %v:%v and node info %v", node.Self.IP, node.Self.Port, node.SetInfo)
return fmt.Sprintf("bc: %v:%v and node info %v", node.Self.IP, node.Self.Port, node.SetInfo)
}
// RequestBeaconChain requests beacon chain for identity data

@ -109,7 +109,7 @@ type Node struct {
host host.Host
// Channel to stop sending ping message
StopPing chan int
StopPing chan struct{}
}
// Add new crossTx and proofs to the list of crossTx that needs to be sent back to client
@ -301,7 +301,7 @@ func New(host host.Host, consensus *bft.Consensus, db *hdb.LDBDatabase) *Node {
// Setup initial state of syncing.
node.syncingState = NotDoingSyncing
node.StopPing = make(chan int)
node.StopPing = make(chan struct{})
return &node
}

@ -617,7 +617,7 @@ func (node *Node) pongMessageHandler(msgPayload []byte) int {
node.State = NodeJoinedShard
// Notify JoinShard to stop sending Ping messages
node.StopPing <- 1
node.StopPing <- struct{}{}
return node.Consensus.UpdatePublicKeys(publicKeys)
}

@ -13,14 +13,14 @@ import (
type HostV1 struct {
self p2p.Peer
listener net.Listener
quit chan bool
quit chan struct{}
}
// New creates a HostV1
func New(self p2p.Peer) *HostV1 {
h := &HostV1{
self: self,
quit: make(chan bool, 1),
quit: make(chan struct{}, 1),
}
return h
}
@ -46,12 +46,14 @@ func (host *HostV1) BindHandlerAndServe(handler p2p.StreamHandler) {
}
backoff := p2p.NewExpBackoff(250*time.Millisecond, 15*time.Second, 2.0)
for { // Keep listening
conn, err := host.listener.Accept()
select {
case <-host.quit:
// If we've already received quit signal, simply ignore the error and return
log.Info("Quit host", "addr", net.JoinHostPort(host.self.IP, host.self.Port))
return
default:
{
conn, err := host.listener.Accept()
if err != nil {
log.Error("Error listening on port.", "port", port,
"err", err)
@ -94,6 +96,6 @@ func (host *HostV1) SendMessage(peer p2p.Peer, message []byte) (err error) {
// Close closes the host
func (host *HostV1) Close() error {
host.quit <- true
host.quit <- struct{}{}
return host.listener.Close()
}

Loading…
Cancel
Save