aboutsummaryrefslogtreecommitdiffstats
path: root/simulation/network.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-07-30 09:05:58 +0800
committerWei-Ning Huang <aitjcize@gmail.com>2018-07-30 09:05:58 +0800
commit279daea6e004ab6ad9d079ccc35b7c52d79630ad (patch)
tree6e07c9ddf5608339c216c4657250f7df238bd75e /simulation/network.go
parent568ce1f526d10184af2ccfe342394f57ae689a14 (diff)
downloaddexon-consensus-279daea6e004ab6ad9d079ccc35b7c52d79630ad.tar
dexon-consensus-279daea6e004ab6ad9d079ccc35b7c52d79630ad.tar.gz
dexon-consensus-279daea6e004ab6ad9d079ccc35b7c52d79630ad.tar.bz2
dexon-consensus-279daea6e004ab6ad9d079ccc35b7c52d79630ad.tar.lz
dexon-consensus-279daea6e004ab6ad9d079ccc35b7c52d79630ad.tar.xz
dexon-consensus-279daea6e004ab6ad9d079ccc35b7c52d79630ad.tar.zst
dexon-consensus-279daea6e004ab6ad9d079ccc35b7c52d79630ad.zip
Add a config that PeerServer can shutdown after receiving enough of block. (#19)
Diffstat (limited to 'simulation/network.go')
-rw-r--r--simulation/network.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/simulation/network.go b/simulation/network.go
index 7ce0dbc..e69dd43 100644
--- a/simulation/network.go
+++ b/simulation/network.go
@@ -18,10 +18,37 @@
package simulation
import (
+ "encoding/json"
+
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
)
+type messageType string
+
+const (
+ shutdownAck messageType = "shutdownAck"
+)
+
+// Message is a struct for peer sending message to server.
+type Message struct {
+ Type messageType `json:"type"`
+ Payload json.RawMessage `json:"payload"`
+}
+
+type infoStatus string
+
+const (
+ normal infoStatus = "normal"
+ shutdown infoStatus = "shutdown"
+)
+
+// InfoMessage is a struct used by peerServer's /info.
+type InfoMessage struct {
+ Status infoStatus `json:"status"`
+ Peers map[types.ValidatorID]string `json:"peers"`
+}
+
// Endpoint is the interface for a client network endpoint.
type Endpoint interface {
GetID() types.ValidatorID
@@ -39,4 +66,6 @@ type Network interface {
// PeerServerNetwork is the interface for peerServer network related functions
type PeerServerNetwork interface {
DeliverBlocks(blocks common.Hashes, id int)
+ NotifyServer(msg Message)
+ GetServerInfo() InfoMessage
}